You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
label=models.CharField(max_length=255, help_text="Label that should be used (e.g. in admin) for state drop-down for this type of state") # State, IESG state, WG state, ...
@@ -432,6 +431,27 @@ def display_name(self):
432
431
name=name.upper()
433
432
returnname
434
433
434
+
defsave_with_history(self, events):
435
+
"""Save document and put a snapshot in the history models where they
436
+
can be retrieved later. You must pass in at least one event
437
+
with a description of what happened."""
438
+
439
+
assertevents, "You must always add at least one event to describe the changes in the history log"
440
+
self.time=max(self.time, events[0].time)
441
+
442
+
self._has_an_event_so_saving_is_allowed=True
443
+
self.save()
444
+
delself._has_an_event_so_saving_is_allowed
445
+
446
+
fromietf.doc.utilsimportsave_document_in_history
447
+
save_document_in_history(self)
448
+
449
+
defsave(self, *args, **kwargs):
450
+
# if there's no primary key yet, we can allow the save to go
451
+
# through to break the cycle between the document and any
452
+
# events
453
+
assertkwargs.get("force_insert", False) orgetattr(self, "_has_an_event_so_saving_is_allowed", None), "Use .save_with_history to save documents"
454
+
super(Document, self).save(*args, **kwargs)
435
455
436
456
deftelechat_date(self, e=None):
437
457
ifnote:
@@ -568,50 +588,6 @@ class Meta:
568
588
verbose_name="document history"
569
589
verbose_name_plural="document histories"
570
590
571
-
defsave_document_in_history(doc):
572
-
"""This should be called before saving changes to a Document instance,
573
-
so that the DocHistory entries contain all previous states, while
574
-
the Group entry contain the current state. XXX TODO: Call this
575
-
directly from Document.save(), and add event listeners for save()
576
-
on related objects so we can save as needed when they change, too.
0 commit comments