Set has_unpublished_changes in Page.save_revision

Fixes #746
This commit is contained in:
Karl Hobley 2015-03-31 16:55:41 +01:00
parent 5d9eeb25ae
commit d087d303b3
2 changed files with 12 additions and 14 deletions

View file

@ -201,10 +201,8 @@ def create(request, content_type_app_name, content_type_model_name, parent_page_
is_publishing = bool(request.POST.get('action-publish')) and parent_page_perms.can_publish_subpage()
is_submitting = bool(request.POST.get('action-submit'))
# Set live to False and has_unpublished_changes to True if we are not publishing
if not is_publishing:
page.live = False
page.has_unpublished_changes = True
# Save page
parent_page.add_child(instance=page)
@ -339,15 +337,6 @@ def edit(request, page_id):
# Publish
if is_publishing:
revision.publish()
else:
# Set has_unpublished_changes flag
if page.live:
# To avoid overwriting the live version, we only save the page
# to the revisions table
Page.objects.filter(id=page.id).update(has_unpublished_changes=True)
else:
page.has_unpublished_changes = True
page.save()
# Notifications
if is_publishing:

View file

@ -481,7 +481,7 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
else:
raise Http404
def save_revision(self, user=None, submitted_for_moderation=False, approved_go_live_at=None):
def save_revision(self, user=None, submitted_for_moderation=False, approved_go_live_at=None, changed=True):
# Create revision
revision = self.revisions.create(
content_json=self.to_json(),
@ -490,8 +490,17 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
approved_go_live_at=approved_go_live_at,
)
update_fields = []
self.latest_revision_created_at = revision.created_at
self.save(update_fields=['latest_revision_created_at'])
update_fields.append('latest_revision_created_at')
if changed:
self.has_unpublished_changes = True
update_fields.append('has_unpublished_changes')
if update_fields:
self.save(update_fields=update_fields)
# Log
logger.info("Page edited: \"%s\" id=%d revision_id=%d", self.title, self.id, revision.id)
@ -823,7 +832,7 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
for field, value in update_attrs.items():
setattr(latest_revision, field, value)
latest_revision.save_revision(user=user)
latest_revision.save_revision(user=user, changed=False)
# Log
logger.info("Page copied: \"%s\" id=%d from=%d", page_copy.title, page_copy.id, self.id)