Skip to content

Commit

Permalink
fixed Type warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
genonfire committed Sep 18, 2024
1 parent a1e7bf9 commit 4291802
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ pyrightconfig.json
/frontend/upload/
/.tox/
/*.egg-info/
/typings/
4 changes: 2 additions & 2 deletions accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Meta:


class _PasswordChangeSerializer(Serializer):
def save(self):
def save(self, **kwargs):
self.user.set_password(self.validated_data.get('new_password'))
self.user.save(update_fields=['password'])
self.user.token().delete()
Expand Down Expand Up @@ -162,7 +162,7 @@ def validate(self, attrs):
return attrs

@async_func
def save(self):
def save(self, **kwargs):
if settings.DO_NOT_SEND_EMAIL:
return

Expand Down
2 changes: 1 addition & 1 deletion communities/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def validate(self, attrs):

return attrs

def save(self):
def save(self, **kwargs):
if not self.instance.files:
self.instance.files.set('')

Expand Down
21 changes: 21 additions & 0 deletions core/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,62 +18,83 @@ def ValidationError(code, field=''):


class Error(object):

@staticmethod
def invalid_page():
ValidationError('INVALID_VALUE', 'page')

@staticmethod
def required_field(field):
ValidationError('REQUIRED_FIELD', field)

@staticmethod
def alpha_number_only(field):
ValidationError('ALPHABETS_NUMBER_ONLY', field)

@staticmethod
def you_must_consent(field=''):
ValidationError('YOU_MUST_CONSENT', field)

@staticmethod
def invalid_password():
ValidationError('INVALID_PASSWORD')

@staticmethod
def same_password():
ValidationError('SAME_AS_OLD_PASSWORD')

@staticmethod
def invalid_uid():
ValidationError('INVALID_UID')

@staticmethod
def invalid_token():
ValidationError('INVALID_TOKEN')

@staticmethod
def unable_to_login():
ValidationError('UNABLE_TO_LOGIN')

@staticmethod
def used_auth_code():
ValidationError('USED_AUTH_CODE')

@staticmethod
def expired_auth_code():
ValidationError('EXPIRED_AUTH_CODE')

@staticmethod
def invalid_auth_code():
ValidationError('INVALID_AUTH_CODE')

@staticmethod
def file_not_exist(field):
ValidationError('FILE_NOT_EXIST', field)

@staticmethod
def file_too_large():
ValidationError('FILE_TOO_LARGE', 'file')

@staticmethod
def invalid_permission_type(attr=''):
ValidationError('INVALID_PERMISSION_TYPE', attr)

@staticmethod
def vote_own_thread():
ValidationError('ERROR_VOTE_OWN_THREAD')

@staticmethod
def vote_own_reply():
ValidationError('ERROR_VOTE_OWN_REPLY')

@staticmethod
def invalid_category():
ValidationError('INVALID_VALUE', 'category')

@staticmethod
def like_own_blog():
ValidationError('ERROR_LIKE_OWN_BLOG')

@staticmethod
def already_liked():
ValidationError('ERROR_LIKED_ALREADY')
4 changes: 2 additions & 2 deletions core/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PrevNextPagination(_BasePagination):
page_size_query_param = 'page_size'
page_size_query_param_all = 'all'

def get_page_size(self, request, queryset):
def get_page_size_with_queryset(self, request, queryset):
if self.page_size_query_param:
try:
page_size = request.query_params[self.page_size_query_param]
Expand All @@ -50,7 +50,7 @@ def get_first_link(self):
return remove_query_param(url, self.page_query_param)

def paginate_queryset(self, queryset, request, view=None):
page_size = self.get_page_size(request, queryset)
page_size = self.get_page_size_with_queryset(request, queryset)
if not page_size:
return None

Expand Down
32 changes: 16 additions & 16 deletions core/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,28 @@ def check_between(self, *args, **kwargs):
self.loooog(kwargs.get('tag', ''), args[0], args[2])
assert args[0] >= args[1] and args[0] <= args[2]

def get(self, path, data=None, format='json', auth=False, **extra):
def get(self, path, data={}, format='json', auth=False, **extra):
if auth:
response = self.client.get(
path, data, format,
path, data, format=format,
HTTP_AUTHORIZATION=self.auth_header, **extra
)
else:
response = self.client.get(path, data, format, **extra)
response = self.client.get(path, data, format=format, **extra)

self.response = response
if hasattr(response, 'data'):
self.data = response.data.get('data')
return response

def post(self, path, data=None, format='json', auth=False, **extra):
def post(self, path, data={}, format='json', auth=False, **extra):
if auth:
response = self.client.post(
path, data, format,
path, data, format=format,
HTTP_AUTHORIZATION=self.auth_header, **extra
)
else:
response = self.client.post(path, data, format, **extra)
response = self.client.post(path, data, format=format, **extra)

self.response = response

Expand All @@ -123,38 +123,38 @@ def post(self, path, data=None, format='json', auth=False, **extra):
self.data = response.data.get('data')
return response

def put(self, path, data=None, format='json', auth=False, **extra):
def put(self, path, data={}, format='json', auth=False, **extra):
if auth:
response = self.client.put(
path, data, format,
path, data, format=format,
HTTP_AUTHORIZATION=self.auth_header, **extra
)
else:
response = self.client.put(path, data, format, **extra)
response = self.client.put(path, data, format=format, **extra)

self.response = response
if hasattr(response, 'data'):
self.data = response.data.get('data')
return response

def patch(self, path, data=None, format='json', auth=False, **extra):
def patch(self, path, data={}, format='json', auth=False, **extra):
if auth:
response = self.client.patch(
path, data, format,
path, data, format=format,
HTTP_AUTHORIZATION=self.auth_header, **extra
)
else:
response = self.client.patch(path, data, format, **extra)
response = self.client.patch(path, data, format=format, **extra)

self.response = response
if hasattr(response, 'data'):
self.data = response.data.get('data')
return response

def delete(self, path, data=None, format='json', auth=False, **extra):
def delete(self, path, data={}, format='json', auth=False, **extra):
if auth:
response = self.client.delete(
path, data, format,
path, data, format=format,
HTTP_AUTHORIZATION=self.auth_header, **extra
)
else:
Expand All @@ -165,10 +165,10 @@ def delete(self, path, data=None, format='json', auth=False, **extra):
self.data = response.data.get('data')
return response

def options(self, path, data=None, format='json', auth=False, **extra):
def options(self, path, data={}, format='json', auth=False, **extra):
if auth:
response = self.client.options(
path, data, format,
path, data, format=format,
HTTP_AUTHORIZATION=self.auth_header, **extra
)
else:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
codecov
coreapi
Django>=4.2,<5.0
djangorestframework
django-cors-headers
Expand Down
2 changes: 1 addition & 1 deletion utils/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class _EmailHelper(object):
def _recipient_list(self, recipients):
if not recipients:
return None
return []

if isinstance(recipients, list):
return recipients
Expand Down
2 changes: 1 addition & 1 deletion utils/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_not_null(self, item):
else:
return ''

def make_data(self, instance=None):
def make_data(self, key=None, index=0):
data = [
self.title
]
Expand Down

0 comments on commit 4291802

Please sign in to comment.