|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +from __future__ import unicode_literals |
| 3 | + |
| 4 | +import os |
| 5 | + |
| 6 | +from django.db import migrations |
| 7 | +from django.conf import settings |
| 8 | + |
| 9 | + |
| 10 | +def official_time(session): |
| 11 | + return session.timeslotassignments.filter(schedule=session.meeting.agenda).first() |
| 12 | + |
| 13 | +def forward(apps, schema_editor): |
| 14 | + Document = apps.get_model('doc','Document') |
| 15 | + State = apps.get_model('doc','State') |
| 16 | + Group = apps.get_model('group','Group') |
| 17 | + Meeting = apps.get_model('meeting', 'Meeting') |
| 18 | + |
| 19 | + active = State.objects.get(type_id='bluesheets',slug='active') |
| 20 | + |
| 21 | + for num in [95, 96]: |
| 22 | + mtg = Meeting.objects.get(number=num) |
| 23 | + bs_path = '%s/bluesheets/'% os.path.join(settings.AGENDA_PATH,mtg.number) |
| 24 | + bs_files = os.listdir(bs_path) |
| 25 | + bs_acronyms = set([x[14:-7] for x in bs_files]) |
| 26 | + group_acronyms = set([x.group.acronym for x in mtg.session_set.all() if official_time(x) and x.group.type_id in ['wg','rg','ag'] and not x.agenda_note.lower().startswith('cancel')]) |
| 27 | + |
| 28 | + if bs_acronyms-group_acronyms: |
| 29 | + print "Warning IETF%s : groups that have bluesheets but did not appear to meet: %s"%(num,list(bs_acronyms-group_acronyms)) |
| 30 | + if group_acronyms-bs_acronyms: |
| 31 | + print "Warning IETF%s : groups that appeared to meet but have no bluesheets: %s"%(num,list(group_acronyms-bs_acronyms)) |
| 32 | + |
| 33 | + for acronym in group_acronyms & bs_acronyms: |
| 34 | + group = Group.objects.get(acronym=acronym) |
| 35 | + bs = sorted([x for x in bs_files if '-%s-'%acronym in x]) |
| 36 | + bs_count = len(bs) |
| 37 | + sess = sorted([ x for x in mtg.session_set.filter(group__acronym=acronym) if not x.agenda_note.lower().startswith('cancel')], |
| 38 | + key = lambda x: official_time(x).timeslot.time) |
| 39 | + sess_count = len(sess) |
| 40 | + if bs_count != sess_count: |
| 41 | + print "Warning IETF%s: %s : different number of bluesheets (%d) than sessions (%d)"%(num,acronym,bs_count,sess_count) |
| 42 | + numdocs = min(bs_count,sess_count) |
| 43 | + for n in range(numdocs): |
| 44 | + doc = Document.objects.create( |
| 45 | + name=bs[n][:-4], |
| 46 | + type_id='bluesheets', |
| 47 | + title='Bluesheets IETF%d : %s : %s ' % (num,acronym,official_time(sess[n]).timeslot.time.strftime('%a %H:%M')), |
| 48 | + group=group, |
| 49 | + rev='00', |
| 50 | + external_url=bs[n], |
| 51 | + ) |
| 52 | + doc.states.add(active) |
| 53 | + sess[n].sessionpresentation_set.create(document=doc,rev='00') |
| 54 | + |
| 55 | +def reverse(apps, schema_editor): |
| 56 | + Document = apps.get_model('doc','Document') |
| 57 | + Document.objects.filter(type_id='bluesheets',sessionpresentation__session__meeting__number_in=[95,96]).exclude(group__acronym='openpgp').delete() |
| 58 | + |
| 59 | +class Migration(migrations.Migration): |
| 60 | + |
| 61 | + dependencies = [ |
| 62 | + ('meeting', '0028_add_audio_stream_data'), |
| 63 | + ('doc', '0012_auto_20160207_0537'), |
| 64 | + ('group','0008_auto_20160505_0523'), |
| 65 | + ] |
| 66 | + |
| 67 | + operations = [ |
| 68 | + migrations.RunPython(forward,reverse) |
| 69 | + ] |
0 commit comments