Added a 'rev' field to DocEvent, and removed the corresponding field from NewRevisionDocEvent and SubmissionDocEvent. Added a migration for an initial schema change, one data migration to copy and infer revision information, another schema migration to remove extraneous revision field, and another data migration to fix up bad timestamps and bad revision info from the period 2016-09-10 to 2016-10-04.

- Legacy-Id: 12974
This commit is contained in:
Henrik Levkowetz 2017-03-05 19:59:27 +00:00
parent fd9a0d12b5
commit 05d57f6577
7 changed files with 130 additions and 20 deletions

View file

@ -107,6 +107,7 @@ class DocumentAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
e = DocEvent.objects.create(
doc=obj,
rev=obj.rev,
by=request.user.person,
type='changed_document',
desc=form.cleaned_data.get('comment_about_changes'),
@ -149,15 +150,14 @@ admin.site.register(BallotType, BallotTypeAdmin)
# events
class DocEventAdmin(admin.ModelAdmin):
def rev(self, obj):
h = obj.get_dochistory()
return h.rev if h else ""
def event_type(self, obj):
return str(obj.type)
def doc_time(self, obj):
h = obj.get_dochistory()
return h.time if h else ""
def short_desc(self, obj):
return obj.desc[:32]
list_display = ["id", "doc", "type", "rev", "by", "time", "doc_time", "short_desc" ]
list_display = ["id", "doc", "event_type", "rev", "by", "time", "doc_time", "short_desc" ]
search_fields = ["doc__name", "by__name"]
raw_id_fields = ["doc", "by"]
admin.site.register(DocEvent, DocEventAdmin)

View file

@ -35,7 +35,7 @@ class DocumentChangesFeed(Feed):
return events
def item_title(self, item):
return u"[%s] %s [rev. %s]" % (item.by, truncatewords(strip_tags(item.desc), 15), item.get_rev())
return u"[%s] %s [rev. %s]" % (item.by, truncatewords(strip_tags(item.desc), 15), item.rev)
def item_description(self, item):
return truncatewords_html(format_textarea(item.desc), 20)

View file

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-04 08:20
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('doc', '0021_add_wg_states'),
]
operations = [
migrations.RenameField(
model_name='newrevisiondocevent',
old_name='rev',
new_name='revision',
),
migrations.RenameField(
model_name='submissiondocevent',
old_name='rev',
new_name='revision',
),
migrations.AddField(
model_name='docevent',
name='rev',
field=models.CharField(blank=True, max_length=16, verbose_name=b'revision'),
),
]

View file

@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-04 08:30
from __future__ import unicode_literals, print_function
from tqdm import tqdm
from django.db import migrations
import debug # pyflakes:ignore
from ietf.doc.models import DocHistory
def ename(event):
return u"%s %s by %s at %s" % (event.doc.name, event.get_type_display().lower(), event.by.name, event.time)
def get_dochistory(event):
h = DocHistory.objects.filter(time__lte=event.time,doc__name=event.doc.name).order_by('-time', '-pk')
if not h.exists():
h = DocHistory.objects.filter(time__gte=event.time,doc__name=event.doc.name).order_by('time', 'pk')
return h
def get_history_rev(e):
h = e.get_dochistory()
rev = None
if h.exists():
for i in h:
if i.rev:
break
if i and i.rev:
rev = i.rev
return rev
def forwards(apps,schema_editor):
DocEvent = apps.get_model('doc', 'DocEvent')
DocEvent.get_dochistory = get_dochistory
NewRevisionDocEvent = apps.get_model('doc', 'NewRevisionDocEvent')
SubmissionDocEvent = apps.get_model('doc', 'SubmissionDocEvent')
print("\nProcessing NewRevisionDocEvents:")
for e in tqdm(list(NewRevisionDocEvent.objects.filter(rev=''))):
if e.revision:
e.rev = e.revision
e.save()
print("\nProcessing SubmissionDocEvents:")
for e in tqdm(list(SubmissionDocEvent.objects.filter(rev=''))):
if e.revision:
e.rev = e.revision
e.save()
print("\nProcessing remaining DocEvents:")
for e in tqdm(list(DocEvent.objects.filter(rev=''))):
rev = get_history_rev(e)
if rev:
e.rev = rev
e.save()
def backwards(apps,schema_editor):
DocEvent = apps.get_model('doc', 'DocEvent')
print("\nProcessing DocEvents:")
for e in tqdm(list(DocEvent.objects.exclude(rev=''))):
e.rev = ''
e.save()
class Migration(migrations.Migration):
dependencies = [
('doc', '0022_add_docevent_rev'),
]
operations = [
migrations.RunPython(forwards, backwards),
]

View file

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-04 12:10
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('doc', '0023_set_docevent_rev_data'),
]
operations = [
migrations.RemoveField(
model_name='newrevisiondocevent',
name='revision',
),
migrations.RemoveField(
model_name='submissiondocevent',
name='revision',
),
]

View file

@ -760,6 +760,7 @@ class DocEvent(models.Model):
type = models.CharField(max_length=50, choices=EVENT_TYPES)
by = models.ForeignKey(Person)
doc = models.ForeignKey('doc.Document')
rev = models.CharField(verbose_name="revision", max_length=16, blank=True)
desc = models.TextField()
def for_current_revision(self):
@ -772,23 +773,11 @@ class DocEvent(models.Model):
def __unicode__(self):
return u"%s %s by %s at %s" % (self.doc.name, self.get_type_display().lower(), self.by.plain_name(), self.time)
def get_rev(self):
e = self
# check subtypes which has a rev attribute
for sub in ['newrevisiondocevent', 'submissiondocevent', ]:
if hasattr(e, sub):
e = getattr(e, sub)
break
if hasattr(e, 'rev'):
return e.rev
else:
return None
class Meta:
ordering = ['-time', '-id']
class NewRevisionDocEvent(DocEvent):
rev = models.CharField(max_length=16)
pass
class StateDocEvent(DocEvent):
state_type = models.ForeignKey(StateType)
@ -911,7 +900,6 @@ class AddedMessageEvent(DocEvent):
class SubmissionDocEvent(DocEvent):
import ietf.submit.models
rev = models.CharField(max_length=16)
submission = models.ForeignKey(ietf.submit.models.Submission)
# dumping store for removed events

View file

@ -103,7 +103,7 @@
{% for e in events %}
<tr class="anchor-target" id="history-{{ e.pk }}">
<td class="text-nowrap">{{ e.time|date:"Y-m-d" }}</td>
<td class="text-center">{{ e.get_rev }}</td>
<td class="text-center">{{ e.rev }}</td>
<td>{{ e.by|escape }}</td>
<td>{{ e.desc|format_history_text|safe }}</td>
</tr>