Skip to content

Commit 1a2b885

Browse files
committed
checkpoint. Refactor to put session oriented utilites back in the meeting app. Minimize the use of the /materials url. Provide better access control to the remaining materials url functions.
- Legacy-Id: 10850
1 parent fe17f6d commit 1a2b885

13 files changed

Lines changed: 75 additions & 67 deletions

ietf/doc/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ def test_view_document_meetings(self):
933933
doc.sessionpresentation_set.create(session=self.inprog,rev=None)
934934
doc.sessionpresentation_set.create(session=self.interim,rev=None)
935935

936-
url = urlreverse('ietf.doc.views_material.all_presentations', kwargs=dict(name=doc.name))
936+
url = urlreverse('ietf.doc.views_doc.all_presentations', kwargs=dict(name=doc.name))
937937
response = self.client.get(url)
938938
self.assertEqual(response.status_code, 200)
939939
q = PyQuery(response.content)

ietf/doc/tests_material.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from StringIO import StringIO
77
from pyquery import PyQuery
88

9+
import debug # pyflakes:ignore
10+
911
from django.conf import settings
1012
from django.core.urlresolvers import reverse as urlreverse
1113

@@ -18,6 +20,7 @@
1820
from ietf.utils.test_utils import TestCase, login_testing_unauthorized, unicontent
1921
from ietf.utils.test_data import make_test_data
2022

23+
2124
class GroupMaterialTests(TestCase):
2225
def setUp(self):
2326
self.materials_dir = os.path.abspath("tmp-document-dir")

ietf/doc/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
(r'^(?P<name>charter-[A-Za-z0-9._+-]+)/', include('ietf.doc.urls_charter')),
119119
(r'^(?P<name>[A-Za-z0-9._+-]+)/conflict-review/', include('ietf.doc.urls_conflict_review')),
120120
(r'^(?P<name>[A-Za-z0-9._+-]+)/status-change/', include('ietf.doc.urls_status_change')),
121+
url(r'^(?P<name>[A-Za-z0-9._+-]+)/meetings$', 'ietf.doc.views_doc.all_presentations', name="all_presentations"),
121122
(r'^(?P<name>[A-Za-z0-9._+-]+)/material/', include('ietf.doc.urls_material')),
122123
url(r'^(?P<name>[A-Za-z0-9._+-]+)/session/', include(session_patterns)),
123124
)

ietf/doc/urls_material.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
urlpatterns = patterns('ietf.doc.views_material',
44
url(r'^(?P<action>state|title|abstract|revise)/$', "edit_material", name="material_edit"),
5-
url(r'^meetings/$', "all_presentations", name="all_presentations"),
65
)
76

ietf/doc/views_doc.py

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from ietf.doc.mails import email_comment
6262
from ietf.mailtrigger.utils import gather_relevant_expansions
6363
from ietf.meeting.models import Session
64+
from ietf.meeting.utils import group_sessions, get_upcoming_manageable_sessions, sort_sessions
6465

6566
def render_document_top(request, doc, tab, name):
6667
tabs = []
@@ -1094,7 +1095,6 @@ def email_aliases(request,name=''):
10941095

10951096
class VersionForm(forms.Form):
10961097

1097-
# TODO is required=False correct here?
10981098
version = forms.ChoiceField(required=True,
10991099
label='Which version of this document will be discussed at this session?')
11001100

@@ -1126,7 +1126,7 @@ def edit_sessionpresentation(request,name,session_id):
11261126
c = DocEvent(type="added_comment", doc=doc, by=request.user.person)
11271127
c.desc = "Revision for session %s changed to %s" % (sp.session,new_selection)
11281128
c.save()
1129-
return redirect('ietf.doc.views_material.all_presentations', name=name)
1129+
return redirect('ietf.doc.views_doc.all_presentations', name=name)
11301130
else:
11311131
form = VersionForm(choices=choices,initial=initial)
11321132

@@ -1147,47 +1147,10 @@ def remove_sessionpresentation(request,name,session_id):
11471147
c = DocEvent(type="added_comment", doc=doc, by=request.user.person)
11481148
c.desc = "Removed from session: %s" % (sp.session)
11491149
c.save()
1150-
return redirect('ietf.doc.views_material.all_presentations', name=name)
1150+
return redirect('ietf.doc.views_doc.all_presentations', name=name)
11511151

11521152
return render(request,'doc/remove_sessionpresentation.html', {'sp': sp })
11531153

1154-
1155-
def get_upcoming_manageable_sessions(user):
1156-
1157-
# TODO: Move this into meeting.models or utils, or maybe person.models or utils - it doesn't depend on doc
1158-
# Find all the sessions for meetings that haven't ended that the user could affect
1159-
# This motif is also in Document.future_presentations - it would be nice to consolodate it somehow
1160-
1161-
# Consider adding an argument that has some Qs to append to the queryset
1162-
1163-
candidate_sessions = Session.objects.exclude(status__in=['canceled','disappr','notmeet','deleted']).filter(meeting__date__gte=datetime.date.today()-datetime.timedelta(days=15))
1164-
refined_candidates = [ sess for sess in candidate_sessions if sess.meeting.end_date()>=datetime.date.today()]
1165-
1166-
# Consider keeping this (put acronym=None back in argument list
1167-
#if acronym:
1168-
# refined_candidates = [ sess for sess in refined_candidates if sess.group.acronym==acronym]
1169-
1170-
return [ sess for sess in refined_candidates if can_manage_materials(user, sess.group) ]
1171-
1172-
def sort_sessions(sessions):
1173-
1174-
# Python sorts are stable since version 2,2, so this series results in a list sorted first
1175-
# by the meeting 'number', then by session's group acronym, then by scheduled time
1176-
# (or the time of the session request if the session isn't scheduled).
1177-
1178-
def time_sort_key(session):
1179-
official_sessions = session.timeslotassignments.filter(schedule=session.meeting.agenda)
1180-
if official_sessions:
1181-
return official_sessions.first().timeslot.time
1182-
else:
1183-
return session.requested
1184-
1185-
time_sorted = sorted(sessions,key=time_sort_key)
1186-
acronym_sorted = sorted(time_sorted,key=lambda x: x.group.acronym)
1187-
meeting_sorted = sorted(acronym_sorted,key=lambda x: x.meeting.number)
1188-
1189-
return meeting_sorted
1190-
11911154
class SessionChooserForm(forms.Form):
11921155
session = forms.ChoiceField(label="Which session should this document be added to?",required=True)
11931156

@@ -1221,10 +1184,27 @@ def add_sessionpresentation(request,name):
12211184
c = DocEvent(type="added_comment", doc=doc, by=request.user.person)
12221185
c.desc = "%s to session: %s" % ('Added -%s'%rev if rev else 'Added', Session.objects.get(pk=session_id))
12231186
c.save()
1224-
return redirect('ietf.doc.views_material.all_presentations', name=name)
1187+
return redirect('ietf.doc.views_doc.all_presentations', name=name)
12251188

12261189
else:
12271190
version_form = VersionForm(choices=version_choices,initial={'version':'current'})
12281191
session_form = SessionChooserForm(choices=session_choices)
12291192

12301193
return render(request,'doc/add_sessionpresentation.html',{'doc':doc,'version_form':version_form,'session_form':session_form})
1194+
1195+
def all_presentations(request, name):
1196+
doc = get_object_or_404(Document, name=name)
1197+
1198+
1199+
sessions = doc.session_set.filter(status__in=['sched','schedw','appr','canceled'],
1200+
type__in=['session','plenary','other'])
1201+
1202+
future, in_progress, past = group_sessions(sessions)
1203+
1204+
return render(request, 'doc/material/all_presentations.html', {
1205+
'user': request.user,
1206+
'doc': doc,
1207+
'future': future,
1208+
'in_progress': in_progress,
1209+
'past' : past,
1210+
})

ietf/doc/views_material.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from ietf.doc.utils import add_state_change_event, check_common_doc_name_rules
1818
from ietf.group.models import Group
1919
from ietf.group.utils import can_manage_materials
20-
from ietf.meeting.utils import group_sessions
2120

2221
@login_required
2322
def choose_material_type(request, acronym):
@@ -92,10 +91,15 @@ def edit_material(request, name=None, acronym=None, action=None, doc_type=None):
9291

9392
doc = None
9493
document_type = get_object_or_404(DocTypeName, slug=doc_type)
94+
if document_type not in DocTypeName.objects.filter(slug__in=group.features.material_types):
95+
raise Http404
9596
else:
9697
doc = get_object_or_404(Document, name=name)
9798
group = doc.group
9899
document_type = doc.type
100+
if document_type not in DocTypeName.objects.filter(slug__in=group.features.material_types):
101+
raise Http404
102+
99103

100104
if not can_manage_materials(request.user, group):
101105
return HttpResponseForbidden("You don't have permission to access this view")
@@ -172,20 +176,3 @@ def edit_material(request, name=None, acronym=None, action=None, doc_type=None):
172176
'document_type': document_type,
173177
'doc_name': doc.name if doc else "",
174178
})
175-
176-
def all_presentations(request, name):
177-
doc = get_object_or_404(Document, name=name)
178-
179-
180-
sessions = doc.session_set.filter(status__in=['sched','schedw','appr','canceled'],
181-
type__in=['session','plenary','other'])
182-
183-
future, in_progress, past = group_sessions(sessions)
184-
185-
return render(request, 'doc/material/all_presentations.html', {
186-
'user': request.user,
187-
'doc': doc,
188-
'future': future,
189-
'in_progress': in_progress,
190-
'past' : past,
191-
})

ietf/meeting/utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import datetime
22

3+
from ietf.meeting.models import Session
4+
from ietf.group.utils import can_manage_materials
5+
36
def group_sessions(sessions):
47

58
def sort_key(session):
@@ -33,3 +36,38 @@ def sort_key(session):
3336
past.append(s)
3437

3538
return future, in_progress, past
39+
40+
def get_upcoming_manageable_sessions(user):
41+
""" Find all the sessions for meetings that haven't ended that the user could affect """
42+
43+
# Consider adding an argument that has some Qs to append to the queryset
44+
# to allow filtering to a particular group, etc. if we start seeing a lot of code
45+
# that calls this function and then immediately starts whittling down the returned list
46+
47+
# Note the days=15 - this allows this function to find meetings in progress that last up to two weeks.
48+
# This notion of searching by end-of-meeting is also present in Document.future_presentations.
49+
# It would be nice to make it easier to use querysets to talk about meeting endings wthout a heuristic like this one
50+
51+
candidate_sessions = Session.objects.exclude(status__in=['canceled','disappr','notmeet','deleted']).filter(meeting__date__gte=datetime.date.today()-datetime.timedelta(days=15))
52+
refined_candidates = [ sess for sess in candidate_sessions if sess.meeting.end_date()>=datetime.date.today()]
53+
54+
return [ sess for sess in refined_candidates if can_manage_materials(user, sess.group) ]
55+
56+
def sort_sessions(sessions):
57+
58+
# Python sorts are stable since version 2,2, so this series results in a list sorted first
59+
# by the meeting 'number', then by session's group acronym, then by scheduled time
60+
# (or the time of the session request if the session isn't scheduled).
61+
62+
def time_sort_key(session):
63+
official_sessions = session.timeslotassignments.filter(schedule=session.meeting.agenda)
64+
if official_sessions:
65+
return official_sessions.first().timeslot.time
66+
else:
67+
return session.requested
68+
69+
time_sorted = sorted(sessions,key=time_sort_key)
70+
acronym_sorted = sorted(time_sorted,key=lambda x: x.group.acronym)
71+
meeting_sorted = sorted(acronym_sorted,key=lambda x: x.meeting.number)
72+
73+
return meeting_sorted

ietf/templates/doc/add_sessionpresentation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1>Add document to session<br><small>{{doc.name}}<br>{{doc.title}}</small></h1>
1818

1919
{% buttons %}
2020
<button class="btn btn-primary" type="submit" name="save">Save</button>
21-
<a class="btn btn-default" href="{% url 'ietf.doc.views_material.all_presentations' name=doc.name %}">Cancel</a>
21+
<a class="btn btn-default" href="{% url 'ietf.doc.views_doc.all_presentations' name=doc.name %}">Cancel</a>
2222
{% endbuttons %}
2323

2424
</form>

ietf/templates/doc/document_draft.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
<th>On Agenda</th>
251251
<td class="edit">
252252
{% if not snapshot and can_edit_stream_info %}
253-
{% doc_edit_button "ietf.doc.views_material.all_presentations" name=doc.name %}
253+
{% doc_edit_button "ietf.doc.views_doc.all_presentations" name=doc.name %}
254254
{% endif %}
255255
</td>
256256

ietf/templates/doc/document_material.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<th>On agenda</th>
9494
<td class="edit">
9595
{% if not snapshot and can_manage_material %}
96-
{% doc_edit_button "material_presentations" name=doc.name %}
96+
{% doc_edit_button "all_presentations" name=doc.name %}
9797
{% endif %}
9898
</td>
9999

0 commit comments

Comments
 (0)