BaseSerializer Implemented#13
Merged
nemesifier merged 1 commit intoopenwisp:masterfrom Aug 22, 2018
Merged
Conversation
c4ff77a to
ad65ef6
Compare
df68b70 to
32d4598
Compare
nemesifier
reviewed
Aug 20, 2018
Member
nemesifier
left a comment
There was a problem hiding this comment.
@atb00ker great patch! I appreciate your effort to add the test 👍
Could you address my 2 comments below?
| include_package_data=True, | ||
| zip_safe=False, | ||
| install_requires=['django-model-utils'], | ||
| install_requires=['django-model-utils', 'djangorestframework'], |
Member
There was a problem hiding this comment.
not all the packages using openwisp-utils have APIs and adding this here would make them download DRF even when not needed.
I suggest the following solution:
- remove this requirement here
- add
djangorestframework>=3.8.2,<3.9torequirements-test.txt - add a try/except
ImportErrorblock when you importserializersinopenwisp_utils/api/serializers.py, see my other comment
| @@ -0,0 +1,8 @@ | |||
| from rest_framework import serializers | |||
Member
There was a problem hiding this comment.
following the text of the other comment, here you could do something like:
try:
from rest_framework import serializers
except ImportError: # pragma: nocover
import sys
print('Django REST Framework is required to use this feature but it is not installed')
sys.exit(1)
Member
Author
There was a problem hiding this comment.
How about using django's abstraction for this?
from django.core.exceptions import ImproperlyConfigured
try:
from rest_framework import serializers
except ImportError: # pragma: nocover
raise ImproperlyConfigured('Django REST Framework is required to use this feature but it is not installed')
32d4598 to
f32bc32
Compare
Member
Author
|
Made the required changes. 😄 |
nemesifier
reviewed
Aug 22, 2018
| from rest_framework import serializers | ||
| except ImportError: # pragma: nocover | ||
| raise ImproperlyConfigured( | ||
| 'Django REST Framework is required to use this feature but it is not installed') |
Member
There was a problem hiding this comment.
we usually break this kind of code into multiple lines with something like:
raise ImproperlyConfigured('Django REST Framework is required to use '
'this feature but it is not installed')Could you update these 2 lines for consistency reasons please?
f32bc32 to
29f7295
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added new file
openwisp_utils/api/serializers.pyand implemented a base serializer that can be used in other projects.Fixes #12