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

[admin] Removed logic duplicates #40 #41

Closed
wants to merge 1 commit into from

Conversation

NoumbissiValere
Copy link
Contributor

Removed the logics which were duplicated
in the others modules and redefined it here to enable reusability and ease debugging.

Fixes #40

@coveralls
Copy link

coveralls commented Apr 21, 2019

Coverage Status

Coverage decreased (-1.7%) to 95.735% when pulling 6506253 on NoumbissiValere:issue/40 into fb2d656 on openwisp:master.

@NoumbissiValere
Copy link
Contributor Author

@nemesisdesign Please can you can review this when you have time so that i make corrections if needed. I have equally done the modifications in the other repos as indicated at the issue's page. but travis test will fail for them if this one is not merge.
Thanks.

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.

@NoumbissiValere great progress 👍

class Media:
js = ('openwisp-utils/js/uuid.js',)

def _get_fields(self, fields, request, obj=None):
Copy link
Member

Choose a reason for hiding this comment

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

why are you adding this code and the lines below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I adding those lines so that the readonly fields (uuid in this case) should be should come up only in the change_view. without this, the uuid field will appear in the add_view with a None value. Equally this was the same approach used in OrganizationAdmin found in the openwisp_users repo.

fields = ['name', 'key', 'uuid']

class Media:
js = ('openwisp-utils/js/uuid.js',)
Copy link
Member

Choose a reason for hiding this comment

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

does it work also without adding openwisp_utils to INSTALLED_APPS? Can it actually be loaded in the browser correctly? Did you try running the test project in the browser and check this?

@NoumbissiValere
Copy link
Contributor Author

NoumbissiValere commented Apr 24, 2019

@nemesisdesign Please can you look at the receive_url i added. i wish to know if it's ok before i add the tests. Even though i feel that receive_url should be left out from this module and used it explicitly during the template share feature.

Removed the logics which were duplicated
in the others modules and redefined it
here to enable reusability and ease debugging.

Fixes openwisp#40
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.

This looks good but has to be tested and I haven't had time, it's been sitting here for a while.

@atb00ker could you help me out to test this? If we merge this, we can then create issues (and GCI tasks) in other modules to remove the duplication and use the new code here.

Copy link
Member

@atb00ker atb00ker left a comment

Choose a reason for hiding this comment

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

Hi @nemesisdesign ,

Please checkout the following commits testing these changes:

field.click(function () {
$(this).select();
});
};
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be }); uneven brackets. 😄

Comment on lines +34 to +47
class Media:
js = ('openwisp-utils/js/uuid.js',)

def _get_fields(self, fields, request, obj=None):
"""
removes readonly_fields in add view
"""
if obj:
return fields
new_fields = fields[:]
for field in self.readonly_fields:
if field in new_fields:
new_fields.remove(field)
return new_fields
Copy link
Member

Choose a reason for hiding this comment

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

Can't this be generalized and added to the UUIDAdmin class?

Copy link
Member

Choose a reason for hiding this comment

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

Correct, I think this should be generalized in the UUIDAdmin class.

@nemesifier nemesifier self-assigned this Dec 13, 2019
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.

I'm leaving this review in case somebody will pick this up.

Another improvement we can do to avoid having to add openwisp_utils to INSTALLED_APPS:

we can patch DependencyFinder to automatically add openwisp_utils in the dependencies, that way the static files of openwisp-utils will be available without having to add it to INSTALLED_APPS, which would require changing other projects like ansible-openwisp2 and docker-openwisp.
I also think this improvement makes sense since adding openwisp_utils to INSTALLED_APPS to load is static files even though we are explicitly using its own staticfile finder class is redundant.

Comment on lines +34 to +47
class Media:
js = ('openwisp-utils/js/uuid.js',)

def _get_fields(self, fields, request, obj=None):
"""
removes readonly_fields in add view
"""
if obj:
return fields
new_fields = fields[:]
for field in self.readonly_fields:
if field in new_fields:
new_fields.remove(field)
return new_fields
Copy link
Member

Choose a reason for hiding this comment

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

Correct, I think this should be generalized in the UUIDAdmin class.

@nemesifier
Copy link
Member

Thanks a lot @NoumbissiValere for your work, we merged your initial work after some improvements in PR #71. 👍

@nemesifier nemesifier closed this Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Generalize easy to copy uuid, secret key and secret URL logic
4 participants