Delete the DocumentChangeDates model from CommunityList, it's being
used as a cache, but won't be necessary once the display code is rewritten since it will be able to calculate the data on the fly - Legacy-Id: 10682
This commit is contained in:
parent
1b8e9eb7e4
commit
22e2a6a2b8
|
@ -182,14 +182,14 @@ class PublicationSort(SortMethod):
|
|||
description = 'Date of publication of current version of the document'
|
||||
|
||||
def get_sort_field(self):
|
||||
return '-documentchangedates__new_version_date'
|
||||
return '-time' # FIXME: latest revision date
|
||||
|
||||
class ChangeSort(SortMethod):
|
||||
codename = 'recent_change'
|
||||
description = 'Date of most recent change of status of any type'
|
||||
|
||||
def get_sort_field(self):
|
||||
return '-documentchangedates__normal_change_date'
|
||||
return '-time' # FIXME: latest doc event
|
||||
|
||||
|
||||
class SignificantSort(SortMethod):
|
||||
|
@ -197,7 +197,7 @@ class SignificantSort(SortMethod):
|
|||
description = 'Date of most recent significant change of status'
|
||||
|
||||
def get_sort_field(self):
|
||||
return '-documentchangedates__significant_change_date'
|
||||
return '-time' # FIXME: latest significant state change
|
||||
|
||||
|
||||
TYPES_OF_SORT = [(i.codename, i.description) for i in SortMethod.__subclasses__()]
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
import sys
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from ietf.community.constants import SIGNIFICANT_STATES
|
||||
from ietf.community.models import DocumentChangeDates
|
||||
from ietf.doc.models import Document
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = (u"Update drafts in community lists by reviewing their rules")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
documents = Document.objects.filter(type='draft')
|
||||
index = 1
|
||||
total = documents.count()
|
||||
|
||||
for doc in documents.iterator():
|
||||
(changes, created) = DocumentChangeDates.objects.get_or_create(document=doc)
|
||||
new_version = doc.latest_event(type='new_revision')
|
||||
normal_change = doc.latest_event()
|
||||
significant_change = None
|
||||
for event in doc.docevent_set.filter(type='changed_document'):
|
||||
for state in SIGNIFICANT_STATES:
|
||||
if ('<b>%s</b>' % state) in event.desc:
|
||||
significant_change = event
|
||||
break
|
||||
|
||||
changes.new_version_date = new_version and new_version.time.date()
|
||||
changes.normal_change_date = normal_change and normal_change.time.date()
|
||||
changes.significant_change_date = significant_change and significant_change.time.date()
|
||||
|
||||
changes.save()
|
||||
|
||||
sys.stdout.write('Document %s/%s\r' % (index, total))
|
||||
sys.stdout.flush()
|
||||
index += 1
|
||||
print
|
|
@ -203,29 +203,15 @@ def notify_events(sender, instance, **kwargs):
|
|||
return
|
||||
if instance.doc.type.slug != 'draft' or instance.type == 'added_comment':
|
||||
return
|
||||
(changes, created) = DocumentChangeDates.objects.get_or_create(document=instance.doc)
|
||||
changes.normal_change_date = instance.time
|
||||
significant = False
|
||||
if instance.type == 'changed_document' and 'tate changed' in instance.desc:
|
||||
for i in SIGNIFICANT_STATES:
|
||||
if ('<b>%s</b>' % i) in instance.desc:
|
||||
significant = True
|
||||
changes.significant_change_date = instance.time
|
||||
break
|
||||
elif instance.type == 'new_revision':
|
||||
changes.new_version_date = instance.time
|
||||
changes.save()
|
||||
notification = ListNotification.objects.create(
|
||||
event=instance,
|
||||
significant=significant,
|
||||
)
|
||||
notification.notify_by_email()
|
||||
signals.post_save.connect(notify_events)
|
||||
|
||||
|
||||
class DocumentChangeDates(models.Model):
|
||||
|
||||
document = models.ForeignKey(Document)
|
||||
new_version_date = models.DateTimeField(blank=True, null=True)
|
||||
normal_change_date = models.DateTimeField(blank=True, null=True)
|
||||
significant_change_date = models.DateTimeField(blank=True, null=True)
|
||||
|
|
|
@ -88,20 +88,3 @@ class EmailSubscriptionResource(ModelResource):
|
|||
"community_list": ALL_WITH_RELATIONS,
|
||||
}
|
||||
api.community.register(EmailSubscriptionResource())
|
||||
|
||||
from ietf.doc.resources import DocumentResource
|
||||
class DocumentChangeDatesResource(ModelResource):
|
||||
document = ToOneField(DocumentResource, 'document')
|
||||
class Meta:
|
||||
queryset = DocumentChangeDates.objects.all()
|
||||
serializer = api.Serializer()
|
||||
#resource_name = 'documentchangedates'
|
||||
filtering = {
|
||||
"id": ALL,
|
||||
"new_version_date": ALL,
|
||||
"normal_change_date": ALL,
|
||||
"significant_change_date": ALL,
|
||||
"document": ALL_WITH_RELATIONS,
|
||||
}
|
||||
api.community.register(DocumentChangeDatesResource())
|
||||
|
||||
|
|
Loading…
Reference in a new issue