-
Notifications
You must be signed in to change notification settings - Fork 49
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
signal handlers for syncing of project views and tasks #1218
base: 2.3.0
Are you sure you want to change the base?
Conversation
15fd305
to
d708437
Compare
Signed-off-by: David Wallace <[email protected]>
d708437
to
9065876
Compare
from rdmo.projects.models import Project | ||
from rdmo.tasks.models import Task | ||
|
||
from .helpers import assert_other_projects_unchanged |
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 like this. We should stick to helpers
for tests (and use sparingly) and utils
for regular code.
@@ -0,0 +1,10 @@ | |||
|
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 don't think those methods should exist, this should be inline in the handlers (and without the getattr
).
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 could make it more explicit but it would require a lot more boilerplate code.
The signal handlers for View
and Task
are basically duplicates, so there would be 18 branches instead of the 9 if action == ...
in total in the different functions for .catalogs
, .sites
and .groups
.
But we already agreed about this in the meeting right?
Or would there be an extra use case that would require an update on the Issues as well, when project.tasks are handled?
Example for an explicit function
# Identify the catalogs affected by this change
catalogs = model.objects.filter(pk__in=pk_set)
# Determine the projects to be modified
if action == 'post_add':
projects = Project.objects.filter_catalogs(catalogs).exclude(views=instance)
for project in projects:
project.views.add(instance)
elif action == 'post_remove':
projects = Project.objects.filter_catalogs(catalogs).filter(views=instance)
for project in projects:
project.views.remove(instance)
elif action == 'post_clear':
projects = Project.objects.filter(views=instance)
for project in projects:
project.views.remove(instance)
# Conflicts: # rdmo/projects/handlers.py
…ange Fix: remove views from projects if catalog is changed
…hange in catalog Signed-off-by: David Wallace <[email protected]>
@@ -15,6 +15,16 @@ class TaskQuestionSet(CurrentSiteQuerySetMixin, GroupsQuerySetMixin, Availabilit | |||
def filter_catalog(self, catalog): | |||
return self.filter(models.Q(catalogs=None) | models.Q(catalogs=catalog)) | |||
|
|||
def filter_available_views_for_project(self, project): |
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 think that a Project
should be able to find the views
that are available for itself. Do you agree and would this query be correct for that?
I've changed the filter_group
a little bit to handle a list of users
as well as a single user
.
if 'cancel' in self.data: | ||
return self.instance | ||
|
||
# if the catalog is the same, do nothing |
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 tried to prevent calling the save
method if nothing was changed
@@ -160,6 +160,16 @@ class Meta: | |||
'catalog': forms.RadioSelect() | |||
} | |||
|
|||
def save(self, commit=True, *args, **kwargs): | |||
if 'cancel' in self.data: |
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.
this was just still missing right? ;)
return | ||
|
||
# Defer synchronization of views | ||
setattr(instance, DEFERRED_SYNC_TASKS_KEY, True) |
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 needed a pre_save
to check if the catalog
was changed or not. And afterwards it passes this boolean (with deferred name) to the post_save
.
It seems complicated for just a project.save()
but could not find another way.
for catalog in view.catalogs.all(): | ||
catalog_views_mapping[catalog.id].append({ | ||
'id': view.id, | ||
'sites': list(view.sites.values_list('id', flat=True)), |
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 wanted to explicitly test this filter filter_available_views_for_project
with this mapping but have not implemented that test yet.
Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
…bled Signed-off-by: David Wallace <[email protected]>
55905ba
to
e19be64
Compare
Description
For the settings this PR removes:
PROJECT_REMOVE_VIEWS = True
and adds:
The
projects/handlers.py
are refactored into aproject/handlers
package with aproject/handlers/generic_handlers.py
module that contains the logic for signal receivers.It handles the signals for changes in
View.catalogs
,View.sites
,View.groups
as well asTask.catalogs
,Task.sites
,Task.groups
and updates theproject.views
orprojects.tasks
.Tests, that only use db
view.catalog.add(...)
methods and not the client, are included.Related issues: #966, #1198, #345, #431
Related PRs: #1200
Motivation and Context
ToBeDone:
How has this been tested?
Screenshots (if appropriate)