-
Notifications
You must be signed in to change notification settings - Fork 46
Replace create default dashboard trigger with django signal #3585
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Change default dashboard trigger to use django signal |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||
| """ | ||||||
| signals.py | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repeating the filename in the docstring is wholly unnecessary. However, the file lacks the license boilerplate, as mentioned in https://nav.readthedocs.io/en/latest/hacking/hacking.html#python-boilerplate-headers |
||||||
| Defines Django signal handlers for model events within the application. | ||||||
| Handles actions such as creating default dashboards and navlets when new Accounts | ||||||
| are created. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| """ | ||||||
|
|
||||||
| from django.db.models.signals import post_save | ||||||
| from django.dispatch import receiver | ||||||
| from .profiles import Account, AccountDashboard, AccountNavlet | ||||||
|
|
||||||
|
|
||||||
| @receiver(post_save, sender=Account) | ||||||
| def create_default_dashboard(sender, instance, created, **_kwargs): | ||||||
| """ | ||||||
| Signal handler that creates a default dashboard and navlets for a new Account. | ||||||
| """ | ||||||
| if created: | ||||||
| dashboard = AccountDashboard.objects.create( | ||||||
| name='My dashboard', account=instance, num_columns=4, is_default=True | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ) | ||||||
| default_navlets = AccountNavlet.objects.filter(account_id=0) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| for navlet in default_navlets: | ||||||
| AccountNavlet.objects.create( | ||||||
| account=instance, | ||||||
| navlet=navlet.navlet, | ||||||
| order=navlet.order, | ||||||
| column=navlet.column, | ||||||
| preferences=navlet.preferences, | ||||||
| dashboard=dashboard, | ||||||
| ) | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -- Drop the trigger | ||
| DROP TRIGGER IF EXISTS add_default_dashboard_on_account_create ON profiles.account; | ||
|
|
||
| -- Drop the function | ||
| DROP FUNCTION IF EXISTS create_new_dashboard() CASCADE; |
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.
just to be specific which rule you're intentionally breaking