Tweaked the admin for doc.models.Document to capture a comment about changes made, and save those in the document history, using .save_with_history(). This makes the admin useful again for doing document changes. See issue #2067.

- Legacy-Id: 12434
This commit is contained in:
Henrik Levkowetz 2016-12-01 16:35:23 +00:00
parent c79b40bc88
commit e3ce2a9657

View file

@ -80,6 +80,9 @@ class StatesField(forms.ModelMultipleChoiceField):
class DocumentForm(forms.ModelForm):
states = StatesField(queryset=State.objects.all(), required=False)
comment_about_changes = forms.CharField(
widget=forms.Textarea(attrs={'rows':10,'cols':40,'class':'vLargeTextField'}),
help_text="This comment about the changes made will be saved in the document history.")
def __init__(self, *args, **kwargs):
super(DocumentForm, self).__init__(*args, **kwargs)
@ -100,6 +103,15 @@ class DocumentAdmin(admin.ModelAdmin):
inlines = [DocAliasInline, DocAuthorInline, RelatedDocumentInline, ]
form = DocumentForm
def save_model(self, request, obj, form, change):
e = DocEvent.objects.create(
doc=obj,
by=request.user.person,
type='changed_document',
desc=form.cleaned_data.get('comment_about_changes'),
)
obj.save_with_history([e])
def state(self, instance):
return self.get_state()