Skip to content

BaseSerializer Implemented#13

Merged
nemesifier merged 1 commit intoopenwisp:masterfrom
atb00ker:issues/12_Shelf_Class
Aug 22, 2018
Merged

BaseSerializer Implemented#13
nemesifier merged 1 commit intoopenwisp:masterfrom
atb00ker:issues/12_Shelf_Class

Conversation

@atb00ker
Copy link
Copy Markdown
Member

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

Fixes #12

@atb00ker atb00ker force-pushed the issues/12_Shelf_Class branch from c4ff77a to ad65ef6 Compare August 19, 2018 14:41
@coveralls
Copy link
Copy Markdown

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
Copy Markdown
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?

Comment thread setup.py Outdated
include_package_data=True,
zip_safe=False,
install_requires=['django-model-utils'],
install_requires=['django-model-utils', 'djangorestframework'],
Copy link
Copy Markdown
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

Comment thread openwisp_utils/api/serializers.py Outdated
@@ -0,0 +1,8 @@
from rest_framework import serializers
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 atb00ker force-pushed the issues/12_Shelf_Class branch from 32d4598 to f32bc32 Compare August 22, 2018 10:09
@atb00ker
Copy link
Copy Markdown
Member Author

Made the required changes. 😄

Comment thread openwisp_utils/api/serializers.py Outdated
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
Copy Markdown
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?

@atb00ker atb00ker force-pushed the issues/12_Shelf_Class branch from f32bc32 to 29f7295 Compare August 22, 2018 12:31
Copy link
Copy Markdown
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