Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseSerializer Implemented #13

Merged
merged 1 commit into from
Aug 22, 2018

Conversation

atb00ker
Copy link
Member

Added new file openwisp_utils/api/serializers.py and implemented a base serializer that can be used in other projects.

Fixes #12

@coveralls
Copy link

coveralls commented Aug 19, 2018

Coverage Status

Coverage increased (+0.5%) to 94.393% when pulling 29f7295 on atb00ker:issues/12_Shelf_Class into dc977d2 on openwisp:master.

@atb00ker atb00ker force-pushed the issues/12_Shelf_Class branch 2 times, most recently from df68b70 to 32d4598 Compare August 19, 2018 16:29
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atb00ker great patch! I appreciate your effort to add the test 👍

Could you address my 2 comments below?

setup.py Outdated
@@ -33,7 +33,7 @@
packages=find_packages(exclude=['tests', 'docs']),
include_package_data=True,
zip_safe=False,
install_requires=['django-model-utils'],
install_requires=['django-model-utils', 'djangorestframework'],
Copy link
Member

@nemesifier nemesifier Aug 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.9 to requirements-test.txt
  • add a try/except ImportError block when you import serializers in openwisp_utils/api/serializers.py, see my other comment

@@ -0,0 +1,8 @@
from rest_framework import serializers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, a lot better! 👍

@atb00ker
Copy link
Member Author

Made the required changes. 😄

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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@nemesifier nemesifier merged commit 9c544e0 into openwisp:master Aug 22, 2018
@atb00ker atb00ker deleted the issues/12_Shelf_Class branch September 30, 2018 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants