|
11 | 11 | import json |
12 | 12 | import pytz |
13 | 13 | from pyquery import PyQuery |
| 14 | +from wsgiref.handlers import format_date_time |
| 15 | +from time import mktime |
14 | 16 |
|
15 | 17 | import debug # pyflakes:ignore |
16 | 18 |
|
|
28 | 30 | from django.views.decorators.csrf import ensure_csrf_cookie |
29 | 31 |
|
30 | 32 | from ietf.doc.fields import SearchableDocumentsField |
31 | | -from ietf.doc.models import Document, State, DocEvent |
| 33 | +from ietf.doc.models import Document, State, DocEvent, NewRevisionDocEvent |
32 | 34 | from ietf.group.models import Group |
33 | 35 | from ietf.group.utils import can_manage_materials |
34 | 36 | from ietf.ietfauth.utils import role_required, has_role |
@@ -892,6 +894,83 @@ def ical_agenda(request, num=None, name=None, ext=None): |
892 | 894 | "updated": updated |
893 | 895 | }, content_type="text/calendar") |
894 | 896 |
|
| 897 | +def json_agenda(request, num=None ): |
| 898 | + meeting = get_meeting(num) |
| 899 | + |
| 900 | + sessions = [] |
| 901 | + room_names = set() |
| 902 | + parent_acronyms = set() |
| 903 | + for asgn in meeting.agenda.assignments.exclude(session__type__in=['lead','offagenda','break','reg']): |
| 904 | + sessdict = dict() |
| 905 | + sessdict['objtype'] = 'session' |
| 906 | + if asgn.session.group.type_id in ['wg','rg']: |
| 907 | + sessdict['group'] = asgn.session.group.acronym |
| 908 | + sessdict['parent'] = asgn.session.group.parent.acronym |
| 909 | + parent_acronyms.add(asgn.session.group.parent.acronym) |
| 910 | + if asgn.session.name: |
| 911 | + sessdict['name'] = asgn.session.name |
| 912 | + elif asgn.session.short: |
| 913 | + sessdict['name'] = asgn.session.short |
| 914 | + else: |
| 915 | + sessdict['name'] = asgn.session.group.name |
| 916 | + sessdict['start'] = str(asgn.timeslot.time) |
| 917 | + sessdict['duration'] = str(asgn.timeslot.duration) |
| 918 | + sessdict['location'] = asgn.room_name |
| 919 | + room_names.add(asgn.room_name) |
| 920 | + if asgn.session.agenda(): |
| 921 | + sessdict['agenda'] = '/api/v1/doc/document/%s'%asgn.session.agenda().name |
| 922 | + if asgn.session.slides(): |
| 923 | + sessdict['slides'] = [] |
| 924 | + for slides in asgn.session.slides(): |
| 925 | + sessdict['slides'].append('/api/v1/doc/document/%s'%slides.name) |
| 926 | + modified = asgn.session.modified |
| 927 | + for doc in asgn.session.materials.all(): |
| 928 | + rev_docevent = doc.latest_event(NewRevisionDocEvent,'new_revision') |
| 929 | + modified = max(modified, (rev_docevent and rev_docevent.time) or modified) |
| 930 | + sessdict['modified'] = modified |
| 931 | + sessions.append(sessdict) |
| 932 | + |
| 933 | + rooms = [] |
| 934 | + for room in meeting.room_set.filter(name__in=room_names): |
| 935 | + roomdict = dict() |
| 936 | + roomdict['objtype'] = 'location' |
| 937 | + roomdict['name'] = room.name |
| 938 | + if room.floorplan: |
| 939 | + roomdict['level_name'] = room.floorplan.name |
| 940 | + roomdict['level_sort'] = room.floorplan.order |
| 941 | + if room.x1 is not None: |
| 942 | + roomdict['x'] = room.x1+(room.x2/2.0) |
| 943 | + roomdict['y'] = room.y1+(room.y2/2.0) |
| 944 | + roomdict['modified'] = room.time |
| 945 | + if room.floorplan and room.floorplan.image: |
| 946 | + roomdict['map'] = room.floorplan.image.url |
| 947 | + roomdict['modified'] = max(room.time,room.floorplan.time) |
| 948 | + rooms.append(roomdict) |
| 949 | + |
| 950 | + parents = [] |
| 951 | + for parent in Group.objects.filter(acronym__in=parent_acronyms): |
| 952 | + parentdict = dict() |
| 953 | + parentdict['objtype'] = 'parent' |
| 954 | + parentdict['name'] = parent.acronym |
| 955 | + parentdict['description'] = parent.name |
| 956 | + parentdict['modified'] = parent.time |
| 957 | + parents.append(parentdict) |
| 958 | + |
| 959 | + meetinfo = [] |
| 960 | + meetinfo.extend(sessions) |
| 961 | + meetinfo.extend(rooms) |
| 962 | + meetinfo.extend(parents) |
| 963 | + meetinfo.sort(key=lambda x: x['modified'],reverse=True) |
| 964 | + last_modified = meetinfo[0]['modified'] |
| 965 | + for obj in meetinfo: |
| 966 | + obj['modified'] = obj['modified'].strftime('%Y-%m-%dT%H:%M:%S') |
| 967 | + |
| 968 | + data = {"%s"%num: meetinfo} |
| 969 | + |
| 970 | + response = HttpResponse(json.dumps(data, indent=2), content_type='application/json;charset=%s'%settings.DEFAULT_CHARSET) |
| 971 | + response['Last-Modified'] = format_date_time(mktime(last_modified.timetuple())) |
| 972 | + return response |
| 973 | + |
895 | 974 | def meeting_requests(request, num=None): |
896 | 975 | meeting = get_meeting(num) |
897 | 976 | sessions = Session.objects.filter(meeting__number=meeting.number, type__slug='session', group__parent__isnull = False).exclude(requested_by=0).order_by("group__parent__acronym","status__slug","group__acronym") |
|
0 commit comments