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

Collection methods 1.0.x #34

Merged

Conversation

mmoravcik
Copy link
Contributor

This ended-up only one method - a way of adding a content object to a collection/moderation request

@@ -16,6 +16,11 @@

from cms.models.fields import PlaceholderField

from djangocms_moderation.exceptions import (
Copy link
Contributor

Choose a reason for hiding this comment

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

use relative import

@@ -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):
Copy link
Contributor

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

Copy link
Contributor

@damilare damilare Jul 25, 2018

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@mmoravcik mmoravcik Jul 27, 2018

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

).exclude(collection=self).exists()

if not existing_request_exists:
return ModerationRequest.objects.get_or_create(
Copy link
Contributor

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)
Copy link
Contributor

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

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 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?

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@mmoravcik
Copy link
Contributor Author

@czpython looks like that the tests are broken due to django-cms/django-cms@83d38db and AldrynForms

  File "/Users/fantiago/.virtualenvs/moderation/lib/python3.6/site-packages/aldryn_forms/models.py", line 9, in <module>
    from cms.utils.plugins import build_plugin_tree, downcast_plugins
ImportError: cannot import name 'build_plugin_tree'

Copy link
Contributor

@czpython czpython left a 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

@czpython czpython merged commit 3178ac2 into django-cms:release/1.0.x Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants