-
-
Notifications
You must be signed in to change notification settings - Fork 797
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
Remove code duplication from mixins.py and admin.py #1277
Remove code duplication from mixins.py and admin.py #1277
Conversation
Looks good to me! |
bc1fda1
to
8895443
Compare
Thanks for reviewing @ZuluPro |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far. 👏 for the refactor and the increased coverage.
@manelclos Many thanks for reviewing this. I have responded to your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, great work on the refactor and the tests, thanks!
|
||
def get_export_filename(self, file_format): | ||
def get_filename(self, file_format): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say that you can keep this function as get_export_filename
and don't implement it in ExportViewMixin
, but not important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might have misunderstood you, but I think this runs into the problem of get_export_filename()
being called in two places with the different args.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the admin.py
uses the different arguments, and you are already adapting that call inside ExportMixin
:
But I could be wrong :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the work @matthewhegarty
@@ -453,8 +385,7 @@ def get_export_data(self, file_format, queryset, *args, **kwargs): | |||
if not self.has_export_permission(request): | |||
raise PermissionDenied | |||
|
|||
resource_class = self.get_export_resource_class() | |||
data = resource_class(**self.get_export_resource_kwargs(request)).export(queryset, *args, **kwargs) | |||
data = self.get_data_for_export(request, queryset, *args, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice refactor. Its nice to see
data = resource_class(**self.get_export_resource_kwargs(request)).export(queryset, *args, **kwargs)
go.
Problem
get_export_resource_kwargs()
admin.py
andmixins.py
Solution
When looking into this issue, I noticed that we have a fair amount of code duplication in mixins.py and admin.py.
I removed the duplication as part of this fix.
I tried to keep code changes to a minimum, and also not to affect the public API defined in mixins.
I added some tests to improve the coverage in this area.
Would appreciate a code review from @manelclos and @ZuluPro
Related comments by @manelclos
Issue 1268
Added
get_data_for_export()
to remove duplication and to pass the args and kwargs toget_export_resource_kwargs()
which was the original issue reported in #1268.Also added a unit test for this.
Updated
mixins.py
Removed the following duplicate methods from
ExportViewMixin
and added toImportExportMixin
:Removed the following duplicate methods from
ExportViewMixin
and added toBaseImportMixin
:Removed the following duplicate methods from
ExportViewMixin
and added toBaseExportMixin
:Updated
admin.py
I didn't rename any classes here because they might be part of the public API.
ImportMixin
now subclassesBaseImportMixin
(andImportExportMixinBase
)Updated
ImportMixin
: Removed the following duplicate methods (now inheritedfrom
BaseImportMixin
):ExportMixin
now subclassesBaseExportMixin
(andImportExportMixinBase
)Updated
ExportMixin
: Removed the following duplicate methods (now inheritedfrom
BaseExportMixin
):Acceptance Criteria
Test coverage
admin.py
coverage to 100%mixins.py
coverage to 100%Testing