From 20f79316ffa7102361c08849d811f31fa002841a Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Mon, 12 Oct 2015 13:19:45 +0000 Subject: [PATCH] Summary: Make the pruning of empty BOF charters look at a history for empty files too - Legacy-Id: 10187 --- .../migrations/0007_auto_20150930_0758.py | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/ietf/group/migrations/0007_auto_20150930_0758.py b/ietf/group/migrations/0007_auto_20150930_0758.py index 0425110d7..f1eb8ab09 100644 --- a/ietf/group/migrations/0007_auto_20150930_0758.py +++ b/ietf/group/migrations/0007_auto_20150930_0758.py @@ -21,20 +21,28 @@ def get_rid_of_empty_charters(apps, schema_editor): if group.charter: charter = group.charter + # clean up any empty files left behind + revisions = set() + revisions.add(charter.rev) + for h in charter.history_set.all(): + revisions.add(h.rev) + + for rev in revisions: + path = os.path.join(settings.CHARTER_PATH, '%s-%s.txt' % (charter.name, rev)) + try: + if os.path.exists(path): + with open(path, 'r') as f: + if f.read() == "": + os.remove(path) + except IOError: + pass + group.charter = None group.save() - path = os.path.join(settings.CHARTER_PATH, '%s-%s.txt' % (charter.name, charter.rev)) - try: - if os.path.exists(path): - with open(path, 'r') as f: - if f.read() == "": - os.remove(path) - except IOError: - pass - charter.delete() + def fix_empty_rrg_charter(apps, schema_editor): Document = apps.get_model("doc", "Document") DocEvent = apps.get_model("doc", "DocEvent")