def save_with_revision(self, author=None): revision_context_manager.start() if author: revision_context_manager.set_user(author) self.save() try: add_to_revision(self) try: add_to_revision(self.submission) except ReportSubmission.DoesNotExist: """ Saving for Interim Report """ if self.have_conflict_income: for income in self.incomeconflict_set.all(): add_to_revision(income) if self.have_conflict_activities: for business in self.businessconflict_set.all(): add_to_revision(business) for consulting in self.consultingconflict_set.all(): add_to_revision(consulting) for travel in self.travelconflict_set.all(): add_to_revision(travel) except: revision_context_manager.invalidate() raise finally: revision_context_manager.end()
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)
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)
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
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
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
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
def process_response(self, request, response): """Closes the revision.""" # look to see if the session has been accessed before looking for user to stop Vary: Cookie if hasattr(request, 'session') and request.session.accessed \ and hasattr(request, "user") and request.user.is_authenticated(): revision_context_manager.set_user(request.user) self._close_revision(request) return response
def process_request(self, request): if request_creates_revision(request): context = revision_context_manager.create_revision() context.__enter__() revision_context_manager.set_user(request.user) if not hasattr(request, "_revision_middleware"): setattr(request, "_revision_middleware", {}) request._revision_middleware[self] = context
def process_request(self, request): """Starts a new revision.""" if request.META.get(REVISION_MIDDLEWARE_FLAG, False): raise ImproperlyConfigured("RevisionMiddleware can only be included in MIDDLEWARE_CLASSES once.") request.META[REVISION_MIDDLEWARE_FLAG] = True revision_context_manager.start() if hasattr(request, "user") and request.user.is_authenticated(): revision_context_manager.set_user(request.user)
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)
def process_request(self, request): """Starts a new revision.""" try: raise request.META[(REVISION_MIDDLEWARE_FLAG, self)] = True revision_context_manager.start() if hasattr(request, "user") and request.user.is_authenticated(): revision_context_manager.set_user(request.user) except: pass
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)
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
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
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
def process_response(self, request, response): """Closes the revision.""" # look to see if the session has been accessed before looking for user to stop Vary: Cookie if hasattr(request, 'session') and request.session.accessed \ and hasattr(request, "user") and request.user.is_authenticated() \ and revision_context_manager.is_active(): revision_context_manager.set_user(request.user) role = { 'type': request.session[ROLE_TYPE_KEY], 'id': request.session[ROLE_ID_KEY] } revision_context_manager.set_role(role) self._close_revision(request) return response
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
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
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
def dispatch(self, request, *args, **kwargs): revision_context_manager.start() try: response = super().dispatch(request, *args, **kwargs) except Exception as e: revision_context_manager.invalidate() revision_context_manager.end() raise if self.request.user.is_authenticated(): revision_context_manager.set_user(self.request.user) if response.status_code > 206: revision_context_manager.invalidate() revision_context_manager.end() return response
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
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
def do_revision_view(request, *args, **kwargs): if request_creates_revision(request): with revision_context_manager.create_revision(): revision_context_manager.set_user(request.user) return func(request, *args, **kwargs) return func(request, *args, **kwargs)
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)
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)
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)