|
| 1 | +# Copyright The IETF Trust 2020 All Rights Reserved |
| 2 | + |
| 3 | +import os |
| 4 | + |
| 5 | +from django.conf import settings |
| 6 | +from django.db import migrations |
| 7 | + |
| 8 | +class Helper(object): |
| 9 | + |
| 10 | + def __init__(self, review_path, comments_by, document_class): |
| 11 | + self.review_path = review_path |
| 12 | + self.comments_by = comments_by |
| 13 | + self.document_class = document_class |
| 14 | + |
| 15 | + def remove_file(self,name): |
| 16 | + filename = os.path.join(self.review_path, '{}.txt'.format(name)) |
| 17 | + os.remove(filename) |
| 18 | + |
| 19 | + def rename_file(self, old_name, new_name): |
| 20 | + old_filename = os.path.join(self.review_path, '{}.txt'.format(old_name)) |
| 21 | + new_filename = os.path.join(self.review_path, '{}.txt'.format(new_name)) |
| 22 | + os.rename(old_filename, new_filename) |
| 23 | + |
| 24 | + def add_comment(self, name, comment): |
| 25 | + doc = self.document_class.objects.get(name=name) |
| 26 | + doc.docevent_set.create( |
| 27 | + type = 'added_comment', |
| 28 | + by = self.comments_by, |
| 29 | + rev = doc.rev, |
| 30 | + desc = comment, |
| 31 | + ) |
| 32 | + |
| 33 | +def forward(apps,schema_editor): |
| 34 | + ReviewAssignment = apps.get_model('review','ReviewAssignment') |
| 35 | + Document = apps.get_model('doc','Document') |
| 36 | + State = apps.get_model('doc','State') |
| 37 | + Person = apps.get_model('person','Person') |
| 38 | + |
| 39 | + # The calculation of review_path makes the assumption that DOCUMENT_PATH_PATTERN only uses |
| 40 | + # things that are invariant for review documents. For production, as of this commit, that's |
| 41 | + # DOCUMENT_PATH_PATTERN = '/a/www/ietf-ftp/{doc.type_id}/'. There are plans to change that pattern |
| 42 | + # soon to '/a/ietfdata/doc/{doc.type_id}/' |
| 43 | + |
| 44 | + helper = Helper( |
| 45 | + review_path = settings.DOCUMENT_PATH_PATTERN.format(doc=Document.objects.filter(type_id='review').last()), |
| 46 | + comments_by = Person.objects.get(name='(System)'), |
| 47 | + document_class = Document, |
| 48 | + ) |
| 49 | + |
| 50 | + # In [2]: for d in Document.objects.filter(name__startswith='review-ietf-capport-api-07-opsdir'): |
| 51 | + # ...: print(d.name,d.time) |
| 52 | + # review-ietf-capport-api-07-opsdir-lc-dunbar-2020-05-09 2020-05-09 14:59:40 |
| 53 | + # review-ietf-capport-api-07-opsdir-lc-dunbar-2020-05-09-2 2020-05-09 15:06:44 |
| 54 | + # This is similar to draft-ietf-capport-architecture-08-genart-lc-halpern... |
| 55 | + # Only -2 exists on disk. |
| 56 | + # But the Document for ...-2020-05-09 has not type or state - it was very incompletely set up - deleting it results in: |
| 57 | + # (3, |
| 58 | + # {'community.CommunityList_added_docs': 0, |
| 59 | + # 'community.SearchRule_name_contains_index': 0, |
| 60 | + # 'doc.RelatedDocument': 0, |
| 61 | + # 'doc.DocumentAuthor': 0, |
| 62 | + # 'doc.Document_states': 0, |
| 63 | + # 'doc.Document_tags': 0, |
| 64 | + # 'doc.Document_formal_languages': 0, |
| 65 | + # 'doc.DocumentURL': 0, |
| 66 | + # 'doc.DocExtResource': 0, |
| 67 | + # 'doc.DocAlias_docs': 1, |
| 68 | + # 'doc.DocReminder': 0, |
| 69 | + # 'group.GroupMilestone_docs': 0, |
| 70 | + # 'group.GroupMilestoneHistory_docs': 0, |
| 71 | + # 'liaisons.LiaisonStatementAttachment': 0, |
| 72 | + # 'meeting.SessionPresentation': 0, |
| 73 | + # 'message.Message_related_docs': 0, |
| 74 | + # 'review.ReviewWish': 0, |
| 75 | + # 'doc.DocEvent': 1, |
| 76 | + # 'doc.Document': 1}) |
| 77 | + # Repairing that back to remove the -2 will hide more information than simply removing the incompletely set up document object. |
| 78 | + # But the -2 document currently has no type (see #3145) |
| 79 | + Document.objects.get(name='review-ietf-capport-api-07-opsdir-lc-dunbar-2020-05-09').delete() |
| 80 | + review = Document.objects.get(name='review-ietf-capport-api-07-opsdir-lc-dunbar-2020-05-09-2') |
| 81 | + review.type_id='review' |
| 82 | + review.save() |
| 83 | + helper.add_comment('draft-ietf-capport-api','Removed an unintended duplicate version of the opsdir lc review') |
| 84 | + |
| 85 | +def reverse(apps,schema_editor): |
| 86 | + # There is no point in returning to the broken version |
| 87 | + pass |
| 88 | + |
| 89 | + |
| 90 | +class Migration(migrations.Migration): |
| 91 | + |
| 92 | + dependencies = [ |
| 93 | + ('review', '0025_repair_assignments'), |
| 94 | + ('doc','0039_auto_20201109_0439'), |
| 95 | + ('person','0018_auto_20201109_0439'), |
| 96 | + ] |
| 97 | + |
| 98 | + operations = [ |
| 99 | + migrations.RunPython(forward, reverse), |
| 100 | + ] |
0 commit comments