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] Change empty org label #171 #209

Merged
merged 5 commits into from
Dec 30, 2020

Conversation

purhan
Copy link
Contributor

@purhan purhan commented Dec 28, 2020

Closes #171

@purhan
Copy link
Contributor Author

purhan commented Dec 28, 2020

image
This is how it looks right now.

In my opinion, this should be different when organization field is required. Otherwise it might leave the impression that systemwide is available but then it'd raise validation error while submitting the form. I was thinking we could do this:

if fields['organization'].required:
    # Do something here to change the label, like a strikethrough
    fields['organization'].empty_label = '\u0336'.join(
        'Shared systemwide (no organization)'
    )

To add a strike to indicate that this option is not available.

Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

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

In my opinion, this should be different when organization field is required. Otherwise it might leave the impression that systemwide is available but then it'd raise validation error while submitting the form.

I totally agree with you @purhan, but the code you have suggested can be modified as below.

if not fields['organization'].required:
    fields['organization'].empty_label = _('Shared systemwide (no organization)')

I don't think, we need to add strikethrough to show that a field is required. We can keep the default empty_label when the organization field is required.

openwisp_users/multitenancy.py Outdated Show resolved Hide resolved
@purhan
Copy link
Contributor Author

purhan commented Dec 29, 2020

@pandafy Done. Like I said, I removed the test as well.

@coveralls
Copy link

coveralls commented Dec 29, 2020

Coverage Status

Coverage decreased (-0.09%) to 98.391% when pulling 5e3fc77 on Purhan:issues/171-change-empty-org-label into 4569b60 on openwisp:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 98.354% when pulling 04a1856 on Purhan:issues/171-change-empty-org-label into 4569b60 on openwisp:master.

Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

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

@pandafy Done. Like I said, I removed the test as well.

@purhan tests are good. Let's add a test.

@pandafy sure. One more thing, as you can see I wrote a test for this, but after implementing these changes, I can't test this feature as there is no model with optional organization field in this project.

I was not able to reply to this before. But better later than never.

You can add an admin site for Template model below. Since it uses ShareableOrgMixin, the organization field is optional.

class Template(ShareableOrgMixin):
name = models.CharField(max_length=16)
def clean(self):
self._validate_org_reverse_relation('config_set')

@devkapilbansal the optional organization field is not used directly in this module, but in other modules of OpenWISP. Sometimes, you will need to think about OpenWISP as whole instead of individual module. Then only, some features make sense.

@purhan
Copy link
Contributor Author

purhan commented Dec 29, 2020

You can add an admin site for Template model below.

Template is also not registered on the admin site by default. Should I register it?

@purhan purhan force-pushed the issues/171-change-empty-org-label branch from 813baa8 to 2a807f6 Compare December 29, 2020 16:27
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.

Great work @purhan, looks good but while testing it I realized there's a few things to improve which are not related to this PR.

The empty label should be available only to super users (I found out is simple: fields['organization'].empty_label = None, let me know if you can help with this (we'll need a test for this).

openwisp_users/multitenancy.py Outdated Show resolved Hide resolved
openwisp_users/multitenancy.py Outdated Show resolved Hide resolved
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.

Great work @purhan 👍 👍

@nemesifier nemesifier merged commit a23e05f into openwisp:master Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

[admin] Add a human readable value for empty org selection
4 participants