|
17 | 17 | from ietf.doc.utils import add_state_change_event, check_common_doc_name_rules |
18 | 18 | from ietf.group.models import Group |
19 | 19 | from ietf.group.utils import can_manage_materials |
| 20 | +from ietf.meeting.models import Session |
20 | 21 |
|
21 | 22 | @login_required |
22 | 23 | def choose_material_type(request, acronym): |
@@ -168,3 +169,56 @@ def edit_material(request, name=None, acronym=None, action=None, doc_type=None): |
168 | 169 | 'document_type': document_type, |
169 | 170 | 'doc_name': doc.name if doc else "", |
170 | 171 | }) |
| 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 | + }) |
0 commit comments