-
Notifications
You must be signed in to change notification settings - Fork 21
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
Collection methods 1.0.x #34
Collection methods 1.0.x #34
Conversation
djangocms_moderation/models.py
Outdated
@@ -16,6 +16,11 @@ | |||
|
|||
from cms.models.fields import PlaceholderField | |||
|
|||
from djangocms_moderation.exceptions import ( |
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.
use relative import
djangocms_moderation/models.py
Outdated
@@ -275,6 +286,34 @@ class ModerationCollection(models.Model): | |||
# TODO: proper implementations and handlers coming later for is_locked | |||
is_locked = models.BooleanField(verbose_name=_('is locked'), default=False) | |||
|
|||
def create_moderation_request_from_content_object(self, content_object): |
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.
rename to add_content_object
or add_object
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.
@czpython We decided to use the name create_moderation_request_from_content_object()
to make it explicit that we are creating a ModerationRequest, and not a ContentObject here, i.e ModerationRequest.objects.get_or_create()
.
This is the data flow we are following as far as I understand content_object (via content_type framework) -> moderation_request -> collections
.
Naming this method add_content_object()
implies that we are adding content_objects directly to the collections, which is not the case. If we want to treat moderation_request like a sort of tracking object, thereby making it silent or transparent, then, I'd prefer a method name like add_content_object_from_moderation_request
In any case, we shouldn't be inadvertently treating moderation_request
like a content_object
, or making it silent in the relationship between content_objects
and collections
.
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 find that being super explicit in these cases leads to more confusion.
ModerationRequest is an implementation detail as such I don't see why we need to expose it.
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 see your perspective, I was of the impression that ModerationRequest is at core to of djgangocms_moderation, as it capture the states of the objects, i.e approved, rejected. Makes sense to me.
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.
Reverting back to add_object
djangocms_moderation/models.py
Outdated
).exclude(collection=self).exists() | ||
|
||
if not existing_request_exists: | ||
return ModerationRequest.objects.get_or_create( |
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.
use self.moderation_requests.create()
"Can't add the object to the collection, because it is locked" | ||
) | ||
|
||
content_type = ContentType.objects.get_for_model(content_object) |
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 check should be on a helper function
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 am not sure I am following this. Do you mean something like creating a new get_content_type
helper function, or is your comment talking about if self.is_locked
which is above?
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.
the check if moderation request for x object exists
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.
Hmm, it is a requirement that object is never part of another active collection, so I think it should be here to raise an Exception if that's the case?
We could add an optional force
argument which will ignore is_locked
and also existing requests check
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.
OK I've made the changes as discussed
@czpython looks like that the tests are broken due to django-cms/django-cms@83d38db and AldrynForms
|
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.
At some point the check for existing requests will have to change because of archived collections
This ended-up only one method - a way of adding a content object to a collection/moderation request