Skip to content

Commit 754ee80

Browse files
committed
snapshot before SIPit - have a working session presentation edit form
- Legacy-Id: 8358
1 parent 67782ad commit 754ee80

8 files changed

Lines changed: 129 additions & 4 deletions

File tree

ietf/doc/models.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@ def meeting_related(self):
184184
self.name.split("-")[1] == "interim"
185185
or (self.session_set.exists() if isinstance(self, Document) else self.doc.session_set.exists())))
186186

187+
def future_presentations(self):
188+
""" returns related SessionPresentation objects for meetings that
189+
have not yet ended. This implementation allows for 2 week meetings """
190+
candidate_presentations = self.sessionpresentation_set.filter(session__meeting__date__gte=datetime.date.today()-datetime.timedelta(days=15))
191+
return [pres for pres in candidate_presentations if pres.session.meeting.end_date()>=datetime.date.today()]
192+
193+
def last_presented(self):
194+
""" returns related SessionPresentation objects for the most recent meeting in the past"""
195+
# Assumes no two meetings have the same start date - if the assumption is violated, one will be chosen arbitrariy
196+
candidate_presentations = self.sessionpresentation_set.filter(session__meeting__date__lte=datetime.date.today())
197+
candidate_meetings = set([p.session.meeting for p in candidate_presentations if p.session.meeting.end_date()<datetime.date.today()])
198+
if candidate_meetings:
199+
mtg = sorted(list(candidate_meetings),key=lambda x:x.date,reverse=True)[0]
200+
return self.sessionpresentation_set.filter(session__meeting=mtg)
201+
else:
202+
return None
203+
204+
187205
class Meta:
188206
abstract = True
189207

ietf/doc/urls_material.py

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

33
urlpatterns = patterns('ietf.doc.views_material',
44
url(r'^(?P<action>state|title|revise)/$', "edit_material", name="material_edit"),
5+
url(r'^sessions/$', "material_presentations", name="material_presentations"),
56
)
67

ietf/doc/views_doc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ def document_main(request, name, rev=None):
493493

494494
if doc.type_id in ("slides", "agenda", "minutes"):
495495
can_manage_material = can_manage_materials(request.user, doc.group)
496+
presentations = None
497+
if doc.type_id=='slides' and doc.get_state_slug('slides') in ['sessonly','active']:
498+
presentations = doc.future_presentations()
496499
if doc.meeting_related():
497500
# disallow editing meeting-related stuff through this
498501
# interface for the time being
@@ -530,6 +533,7 @@ def document_main(request, name, rev=None):
530533
snapshot=snapshot,
531534
can_manage_material=can_manage_material,
532535
other_types=other_types,
536+
presentations=presentations,
533537
),
534538
context_instance=RequestContext(request))
535539

ietf/doc/views_material.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
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.models import Session
2021

2122
@login_required
2223
def choose_material_type(request, acronym):
@@ -168,3 +169,56 @@ def edit_material(request, name=None, acronym=None, action=None, doc_type=None):
168169
'document_type': document_type,
169170
'doc_name': doc.name if doc else "",
170171
})
172+
173+
class MaterialPresentationForm(forms.Form):
174+
175+
sesspres = forms.MultipleChoiceField(required=False,widget=forms.CheckboxSelectMultiple,label='Place this document on the agenda for the selected sessions')
176+
177+
def __init__(self,*args,**kwargs):
178+
choices = kwargs.pop('choices')
179+
super(MaterialPresentationForm,self).__init__(*args,**kwargs)
180+
self.fields['sesspres'].choices=choices
181+
182+
@login_required
183+
def material_presentations(request, name):
184+
185+
doc = get_object_or_404(Document, name=name)
186+
if not (doc.type_id=='slides' and doc.get_state('slides').slug=='active'):
187+
raise Http404
188+
189+
group = doc.group
190+
if not (group.features.has_materials and can_manage_materials(request.user,group)):
191+
raise Http404
192+
193+
# Find all the sessions for meetings that haven't ended that the user could affect
194+
# This motif is also in Document.future_presentations - it would be nice to consolodate it somehow
195+
candidate_sessions = Session.objects.filter(meeting__date__gte=datetime.date.today()-datetime.timedelta(days=15))
196+
refined_candidates = [ sess for sess in candidate_sessions if sess.meeting.end_date()>=datetime.date.today()]
197+
changeable_sessions = [ sess for sess in refined_candidates if can_manage_materials(request.user, sess.group) ]
198+
for sess in changeable_sessions:
199+
sess.has_presentation = sess.sessionpresentation_set.filter(document=doc)
200+
sorted_sessions = sorted(changeable_sessions,key=lambda x:'%s%s%s'%('0' if x.has_presentation else '1',x.meeting,x.short_name))
201+
202+
choices=[(sess.pk,'%s: %s'%(sess.meeting,sess.short_name)) for sess in sorted_sessions]
203+
initial = {'sesspres': [sess.pk for sess in sorted_sessions if sess.has_presentation]}
204+
205+
if request.method == 'POST':
206+
form = MaterialPresentationForm(request.POST,choices=choices)
207+
if form.is_valid():
208+
print "STUFF",request.POST.get("action","nothing to be gotten")
209+
if request.POST.get("action", "") == "Save":
210+
new_selections = form.cleaned_data['sesspres']
211+
doc.sessionpresentation_set.filter(session_id__in=(set(initial['sesspres'])-set(new_selections))).delete()
212+
for sess_pk in set(new_selections)-set(initial['sesspres']):
213+
doc.sessionpresentation_set.create(session_id=sess_pk,rev=doc.rev)
214+
return redirect('doc_view',name=doc.name)
215+
else:
216+
form = MaterialPresentationForm(choices=choices,
217+
initial=initial,
218+
)
219+
220+
return render(request, 'doc/material/material_presentations.html', {
221+
'sessions' : sorted_sessions,
222+
'doc': doc,
223+
'form': form,
224+
})

ietf/group/info.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def concluded_groups(request):
268268

269269
def get_group_materials(group):
270270
# return Document.objects.filter(group=group, type__in=group.features.material_types, session=None).exclude(states__slug="deleted")
271-
return Document.objects.filter(group=group, type__in=group.features.material_types).exclude(states__slug="deleted")
271+
return Document.objects.filter(group=group, type__in=group.features.material_types).exclude(states__slug__in=['deleted','archived'])
272272

273273
def construct_group_menu_context(request, group, selected, group_type, others):
274274
"""Return context with info for the group menu filled in."""
@@ -451,8 +451,6 @@ def materials(request, acronym, group_type=None):
451451
if d.type not in doc_types:
452452
doc_types[d.type] = []
453453
doc_types[d.type].append(d)
454-
# This needs to be better - probably looking at ScheduledSession, and perhaps ignoring future Sessions
455-
d.last_presented = d.sessionpresentation_set.order_by('-session__meeting__date').first()
456454

457455
return render(request, 'group/materials.html',
458456
construct_group_menu_context(request, group, "materials", group_type, {

ietf/templates/doc/document_material.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
</td>
2727
</tr>
2828

29+
{% if doc.abstract %}
30+
<tr>
31+
<td>Abstract:</td>
32+
<td> {{ doc.abstract | format_snippet }} </td>
33+
</tr>
34+
{% endif %}
35+
2936
<tr>
3037
<td>State:</td>
3138
<td>
@@ -44,6 +51,21 @@
4451
</tr>
4552
{% endif %}
4653

54+
{% if presentations or can_manage_material %}
55+
<tr>
56+
<td>On Agenda:</td>
57+
<td>
58+
<a {% if not snapshot and can_manage_material %} class="editlink" href="{% url "material_presentations" name=doc.name %}"{%endif%}>
59+
{% if presentations %}
60+
{% for pres in presentations %}{{pres.session.short_name}} at {{pres.session.meeting}} {% if pres.rev != doc.rev %}(version -{{pres.rev}}){% endif %}{% if not forloop.last %}, {% endif %}{% endfor %}
61+
{% else %}
62+
None
63+
{% endif %}
64+
</a>
65+
</td>
66+
</tr>
67+
{% endif %}
68+
4769
<tr>
4870
<td>Last updated:</td>
4971
<td>{{ doc.time|date:"Y-m-d" }}</td>
@@ -74,3 +96,6 @@ <h3>{{ doc.title }}</h3>
7496

7597
{% endblock %}
7698

99+
{% block content_end %}
100+
<script src="/js/snippet.js" type="text/javascript"></script>
101+
{% endblock %}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{% extends "base.html" %}
2+
3+
{% block title %}
4+
Edit Upcoming Presentations
5+
{% endblock %}
6+
7+
{% block morecss %}
8+
{{ block.super }}
9+
ul#id_sesspres { list-style-type: none; padding: 0px; margin: 0px; }
10+
{% endblock %}
11+
12+
{% block content %}
13+
{% load ietf_filters %}
14+
15+
<h1>Edit Upcoming Presentations of<br/>{{doc.title}}<br/>{{doc.name}}</h1>
16+
17+
<form class="session-presentations" action="" method="post">{% csrf_token %}
18+
{{form.as_p}}
19+
<input style="button" type="submit" name="action" value="Save">
20+
<input style="button" type="submit" name="action" value="Cancel">
21+
</form>
22+
23+
{% endblock content %}

ietf/templates/group/materials.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ <h2>{{ doc_type.name }}</h2>
2424
<th>Curr. Rev.</th>
2525
<th>Date</th>
2626
<th>Last Presented</th>
27+
<th>On Agenda</th>
2728
</tr>
2829

2930
{% for d in docs %}
@@ -32,7 +33,8 @@ <h2>{{ doc_type.name }}</h2>
3233
<td class='snippable'>{{ d.abstract|format_snippet }} </td>
3334
<td>{{ d.rev }}</td>
3435
<td>{{ d.time|date:"Y-m-d" }}</td>
35-
<td>{% if d.last_presented %}-{{ d.last_presented.rev }} at {{d.last_presented.session.meeting}}{% endif %}</td>
36+
<td>{% for p in d.last_presented %}{{p.session.meeting}}{% if d.rev != p.rev %} (-{{ p.rev }}){% endif %}{%if not forloop.last%}, {% endif %}{% endfor %}</td>
37+
<td>{% for p in d.future_presentations %}{{p.session.meeting}}{% if d.rev != p.rev %} (-{{p.rev}}){%endif%}{%if not forloop.last%}, {%endif%}{%endfor%}</td>
3638
</tr>
3739
{% endfor %}
3840
</table>

0 commit comments

Comments
 (0)