def save(self, commit=True):
        article = super(CreateNewsBlogArticleForm, self).save(commit=False)

        # Set owner to current user
        article.owner = self.user

        # If 'content' field has value, create a TextPlugin with same and add
        # it to the PlaceholderField
        content = clean_html(self.cleaned_data.get('content', ''), False)
        if content and permissions.has_plugin_permission(
                self.user, 'TextPlugin', 'add'):

            # If the article has not been saved, then there will be no
            # Placeholder set-up for this article yet, so, ensure we have saved
            # first.
            if not article.pk:
                article.save()

            if article and article.content:
                add_plugin(
                    placeholder=article.content,
                    plugin_type='TextPlugin',
                    language=self.language_code,
                    body=content,
                )

        with transaction.atomic():
            with revision_context_manager.create_revision():
                article.save()
                if self.user:
                    revision_context_manager.set_user(self.user)
                revision_context_manager.set_comment(
                    ugettext("Initial version."))

        return article
Example #2
0
    def save(self, commit=True):
        article = super(CreateNewsBlogArticleForm, self).save(commit=False)

        # Set owner to current user
        article.owner = self.user

        # If 'content' field has value, create a TextPlugin with same and add
        # it to the PlaceholderField
        content = clean_html(self.cleaned_data.get('content', ''), False)
        if content and permissions.has_plugin_permission(
                self.user, 'TextPlugin', 'add'):
            # If the article has not been saved, then there will be no
            # Placeholder set-up for this article yet, so, ensure we have saved
            # first.
            if not article.pk:
                article.save()

            if article and article.content:
                add_plugin(
                    placeholder=article.content,
                    plugin_type='TextPlugin',
                    language=self.language_code,
                    body=content,
                )

        if ENABLE_REVERSION:
            from reversion.revisions import revision_context_manager
            with transaction.atomic():
                with revision_context_manager.create_revision():
                    article.save()
                    if self.user:
                        revision_context_manager.set_user(self.user)
                    revision_context_manager.set_comment(
                        ugettext("Initial version."))
        return article
Example #3
0
 def log_addition(self, request, object):
     """Sets the version meta information."""
     super(VersionAdmin, self).log_addition(request, object)
     revision_context_manager.set_user(request.user)
     revision_context_manager.set_comment(_(u"Initial version."))
     revision_context_manager.set_ignore_duplicates(
         self.ignore_duplicate_revisions)
Example #4
0
 def log_change(self, request, object, message):
     """Sets the version meta information."""
     super(VersionAdmin, self).log_change(request, object, message)
     revision_context_manager.set_user(request.user)
     revision_context_manager.set_comment(message)
     revision_context_manager.set_ignore_duplicates(
         self.ignore_duplicate_revisions)
Example #5
0
    def save(self, commit=True):
        job_opening = super(CreateJobOpeningForm, self).save(commit=False)

        # If 'content' field has value, create a TextPlugin with same and add
        # it to the PlaceholderField
        content = clean_html(self.cleaned_data.get('content', ''), False)
        content_plugin = get_cms_setting('WIZARD_CONTENT_PLUGIN')
        if content and permissions.has_plugin_permission(
                self.user, 'TextPlugin', 'add'):

            # If the job_opening has not been saved, then there will be no
            # Placeholder set-up for this question yet, so, ensure we have saved
            # first.
            if not job_opening.pk:
                job_opening.save()

            if job_opening and job_opening.content:
                plugin_kwargs = {
                    'placeholder': job_opening.content,
                    'plugin_type': content_plugin,
                    'language': self.language_code,
                    get_cms_setting('WIZARD_CONTENT_PLUGIN_BODY'): content,
                }
                add_plugin(**plugin_kwargs)

        with transaction.atomic():
            with revision_context_manager.create_revision():
                job_opening.save()
                if self.user:
                    revision_context_manager.set_user(self.user)
                revision_context_manager.set_comment(
                    ugettext("Initial version."))

        return job_opening
Example #6
0
    def save(self, *args, **kwargs):
        # save both forms
        profile = self.profileForm.save(commit=False)

        """
        Ensure we create a revision for reversion.
        """
        person = super(PersonForm, self).save(commit=False)

        # Ensure we make an initial revision
        with transaction.atomic():
            with revision_context_manager.create_revision():
                profile.save()
                person.profile = profile
                person.save()
                self.save_m2m()
                if self.user:
                    revision_context_manager.set_user(self.user)
                object_repr = build_obj_repr(person) + build_obj_repr(profile)
                translation_info = get_translation_info_message(person)
                revision_context_manager.set_comment(
                    ugettext(
                        "Initial version of {object_repr}. {trans_info}".format(
                            object_repr=object_repr,
                            trans_info=translation_info)))
        return person
Example #7
0
 def log_deletion(self, request, object, object_repr):
     """Sets the version meta information."""
     super(VersionAdmin, self).log_deletion(request, object, object_repr)
     revision_context_manager.set_user(request.user)
     revision_context_manager.set_comment(
         _(u"Deleted %(verbose_name)s.") %
         {"verbose_name": self.model._meta.verbose_name})
     revision_context_manager.set_ignore_duplicates(
         self.ignore_duplicate_revisions)
Example #8
0
def create_revision(obj, user=None, comment=None):
    with revision_context_manager.create_revision():
        if user:
            revision_context_manager.set_user(user)
        if comment:
            revision_context_manager.set_comment(comment)

        _add_to_context(obj)

        if hasattr(obj._meta, 'placeholder_field_names'):
            add_placeholders_to_revision(instance=obj)
Example #9
0
def create_revision(obj, user=None, comment=None):
    with revision_context_manager.create_revision():
        if user:
            revision_context_manager.set_user(user)
        if comment:
            revision_context_manager.set_comment(comment)

        _add_to_context(obj)

        if hasattr(obj._meta, 'placeholder_field_names'):
            add_placeholders_to_revision(instance=obj)
Example #10
0
    def save(self, commit=True):
        event = super(CreateEventForm, self).save(commit=False)

        if not commit:
            return event

        # If 'content' field has value, create a TextPlugin with same and add
        # it to the PlaceholderField
        description = clean_html(self.cleaned_data.get('description', ''),
                                 False)

        try:
            # CMS >= 3.3.x
            content_plugin = get_cms_setting('PAGE_WIZARD_CONTENT_PLUGIN')
        except KeyError:
            # CMS <= 3.2.x
            content_plugin = get_cms_setting('WIZARD_CONTENT_PLUGIN')

        try:
            # CMS >= 3.3.x
            content_field = get_cms_setting('PAGE_WIZARD_CONTENT_PLUGIN_BODY')
        except KeyError:
            # CMS <= 3.2.x
            content_field = get_cms_setting('WIZARD_CONTENT_PLUGIN_BODY')

        if description and permissions.has_plugin_permission(
                self.user, content_plugin, 'add'):
            # If the event has not been saved, then there will be no
            # Placeholder set-up for this event yet, so, ensure we have saved
            # first.
            if not event.pk:
                event.save()

            if event and event.description:
                # we have to use kwargs because we don't know in advance what
                # is the 'body' field for configured plugin
                plugin_kwargs = {
                    'placeholder': event.description,
                    'plugin_type': content_plugin,
                    'language': self.language_code,
                    content_field: description,
                }
                add_plugin(**plugin_kwargs)

        with transaction.atomic():
            with revision_context_manager.create_revision():
                event.save()

                if self.user:
                    revision_context_manager.set_user(self.user)
                revision_context_manager.set_comment(
                    ugettext("Initial version."))
        return event
Example #11
0
    def save(self, commit=True):
        category = super(CreateJobCategoryForm, self).save(commit=False)

        with transaction.atomic():
            with revision_context_manager.create_revision():
                category.save()
                if self.user:
                    revision_context_manager.set_user(self.user)
                revision_context_manager.set_comment(
                    ugettext("Initial version."))

        return category
    def save(self, commit=True):
        event = super(CreateEventForm, self).save(commit=False)

        if not commit:
            return event

        # If 'content' field has value, create a TextPlugin with same and add
        # it to the PlaceholderField
        description = clean_html(
            self.cleaned_data.get('description', ''), False)

        try:
            # CMS >= 3.3.x
            content_plugin = get_cms_setting('PAGE_WIZARD_CONTENT_PLUGIN')
        except KeyError:
            # CMS <= 3.2.x
            content_plugin = get_cms_setting('WIZARD_CONTENT_PLUGIN')

        try:
            # CMS >= 3.3.x
            content_field = get_cms_setting('PAGE_WIZARD_CONTENT_PLUGIN_BODY')
        except KeyError:
            # CMS <= 3.2.x
            content_field = get_cms_setting('WIZARD_CONTENT_PLUGIN_BODY')

        if description and permissions.has_plugin_permission(
                self.user, content_plugin, 'add'):
            # If the event has not been saved, then there will be no
            # Placeholder set-up for this event yet, so, ensure we have saved
            # first.
            if not event.pk:
                event.save()

            if event and event.description:
                # we have to use kwargs because we don't know in advance what
                # is the 'body' field for configured plugin
                plugin_kwargs = {
                    'placeholder': event.description,
                    'plugin_type': content_plugin,
                    'language': self.language_code,
                    content_field: description,
                }
                add_plugin(**plugin_kwargs)

        with transaction.atomic():
            with revision_context_manager.create_revision():
                event.save()

                if self.user:
                    revision_context_manager.set_user(self.user)
                revision_context_manager.set_comment(
                    ugettext("Initial version."))
        return event
Example #13
0
    def save(self, commit=True):
        category = super(CreateJobCategoryForm, self).save(commit=False)

        with transaction.atomic():
            with revision_context_manager.create_revision():
                category.save()
                if self.user:
                    revision_context_manager.set_user(self.user)
                revision_context_manager.set_comment(
                    ugettext("Initial version."))

        return category
Example #14
0
    def process_response(self, request, response):
        """Closes the revision."""
        if (hasattr(request, 'user') and request.user is not None
                and request.user.is_authenticated()
                and revision_context_manager.is_active()):
            revision_context_manager.set_user(request.user)

        if revision_context_manager.is_active():
            revision_context_manager.set_comment(
                'Request log from "RevisionMiddleware", path "%s"' %
                request.path)

        self._close_revision(request)
        return response
Example #15
0
    def save(self, commit=True):
        question = super(CreateFaqQuestionForm, self).save(commit=False)

        # If 'content' field has value, create a TextPlugin with same and add
        # it to the PlaceholderField
        answer = clean_html(self.cleaned_data.get('answer', ''), False)

        try:
            # CMS >= 3.3.x
            content_plugin = get_cms_setting('PAGE_WIZARD_CONTENT_PLUGIN')
        except KeyError:
            # CMS <= 3.2.x
            content_plugin = get_cms_setting('WIZARD_CONTENT_PLUGIN')

        try:
            # CMS >= 3.3.x
            content_field = get_cms_setting('PAGE_WIZARD_CONTENT_PLUGIN_BODY')
        except KeyError:
            # CMS <= 3.2.x
            content_field = get_cms_setting('WIZARD_CONTENT_PLUGIN_BODY')

        if answer and permissions.has_plugin_permission(
                self.user, content_plugin, 'add'):

            # If the question has not been saved, then there will be no
            # Placeholder set-up for this question yet, so, ensure we have saved
            # first.
            if not question.pk:
                question.save()

            if question and question.answer:
                plugin_kwarg = {
                    'placeholder': question.answer,
                    'plugin_type': content_plugin,
                    'language': self.language_code,
                    content_field: answer,
                }
                add_plugin(**plugin_kwarg)

        # Ensure we make an initial revision
        with transaction.atomic():
            with revision_context_manager.create_revision():
                question.save()
                if self.user:
                    revision_context_manager.set_user(self.user)
                revision_context_manager.set_comment(
                    ugettext("Initial version."))

        return question
    def process_response(self, request, response):
        """Closes the revision."""
        if (
            hasattr(request, "user")
            and request.user is not None
            and request.user.is_authenticated()
            and revision_context_manager.is_active()
        ):
            revision_context_manager.set_user(request.user)

        if revision_context_manager.is_active():
            revision_context_manager.set_comment('Request log from "RevisionMiddleware", path "%s"' % request.path)

        self._close_revision(request)
        return response
Example #17
0
    def save(self, commit=True):
        """
        Ensure we create a revision for reversion.
        """
        category = super(CreateFaqCategoryForm, self).save(commit=False)

        # Ensure we make an initial revision
        with transaction.atomic():
            with revision_context_manager.create_revision():
                category.save()
                if self.user:
                    revision_context_manager.set_user(self.user)
                revision_context_manager.set_comment(
                    ugettext("Initial version."))

        return category
Example #18
0
    def save(self, commit=True):
        """
        Ensure we create a revision for reversion.
        """
        group = super(CreatePeopleGroupForm, self).save(commit=False)

        # Ensure we make an initial revision
        with transaction.atomic():
            with revision_context_manager.create_revision():
                group.save()
                if self.user:
                    revision_context_manager.set_user(self.user)
                revision_context_manager.set_comment(
                    ugettext("Initial version."))

        return group
Example #19
0
    def save(self, commit=True):
        """
        Ensure we create a revision for reversion.
        """
        person = super(CreatePeoplePersonForm, self).save(commit=False)

        # Ensure we make an initial revision
        with transaction.atomic():
            with revision_context_manager.create_revision():
                person.save()
                self.save_m2m()
                if self.user:
                    revision_context_manager.set_user(self.user)
                object_repr = build_obj_repr(person)
                translation_info = get_translation_info_message(person)
                revision_context_manager.set_comment(
                    ugettext("Initial version of {object_repr}. {trans_info}".
                             format(object_repr=object_repr,
                                    trans_info=translation_info)))
        return person
Example #20
0
    def save(self, commit=True):
        """
        Ensure we create a revision for reversion.
        """
        person = super(CreatePeoplePersonForm, self).save(commit=False)

        # Ensure we make an initial revision
        with transaction.atomic():
            with revision_context_manager.create_revision():
                person.save()
                self.save_m2m()
                if self.user:
                    revision_context_manager.set_user(self.user)
                object_repr = build_obj_repr(person)
                translation_info = get_translation_info_message(person)
                revision_context_manager.set_comment(
                    ugettext(
                        "Initial version of {object_repr}. {trans_info}".format(
                            object_repr=object_repr,
                            trans_info=translation_info)))
        return person
Example #21
0
 def log_deletion(self, request, object, object_repr):
     """Sets the version meta information."""
     super(VersionAdmin, self).log_deletion(request, object, object_repr)
     revision_context_manager.set_user(request.user)
     revision_context_manager.set_comment(_(u"Deleted %(verbose_name)s.") % {"verbose_name": self.model._meta.verbose_name})
     revision_context_manager.set_ignore_duplicates(self.ignore_duplicate_revisions)
Example #22
0
 def log_change(self, request, object, message):
     """Sets the version meta information."""
     super(VersionAdmin, self).log_change(request, object, message)
     revision_context_manager.set_user(request.user)
     revision_context_manager.set_comment(message)
     revision_context_manager.set_ignore_duplicates(self.ignore_duplicate_revisions)
Example #23
0
 def log_addition(self, request, object):
     """Sets the version meta information."""
     super(VersionAdmin, self).log_addition(request, object)
     revision_context_manager.set_user(request.user)
     revision_context_manager.set_comment(_(u"Initial version."))
     revision_context_manager.set_ignore_duplicates(self.ignore_duplicate_revisions)