1717from ietf .doc .utils import add_state_change_event , check_common_doc_name_rules
1818from ietf .group .models import Group
1919from ietf .group .utils import can_manage_materials
20+ from ietf .meeting .models import Session
2021
2122@login_required
2223def choose_material_type (request , acronym ):
@@ -32,8 +33,9 @@ def choose_material_type(request, acronym):
3233class UploadMaterialForm (forms .Form ):
3334 title = forms .CharField (max_length = Document ._meta .get_field ("title" ).max_length )
3435 name = forms .CharField (max_length = Document ._meta .get_field ("name" ).max_length )
36+ abstract = forms .CharField (max_length = Document ._meta .get_field ("abstract" ).max_length ,widget = forms .Textarea )
3537 state = forms .ModelChoiceField (State .objects .all (), empty_label = None )
36- material = forms .FileField (label = 'File' , help_text = "PDF or text file (ASCII/UTF-8)" )
38+ material = forms .FileField (label = 'File' )
3739
3840 def __init__ (self , doc_type , action , group , doc , * args , ** kwargs ):
3941 super (UploadMaterialForm , self ).__init__ (* args , ** kwargs )
@@ -53,16 +55,15 @@ def __init__(self, doc_type, action, group, doc, *args, **kwargs):
5355 del self .fields ["name" ]
5456
5557 self .fields ["title" ].initial = doc .title
58+ self .fields ["abstract" ].initial = doc .abstract
5659 self .fields ["state" ].initial = doc .get_state ().pk if doc .get_state () else None
5760 if doc .get_state_slug () == "deleted" :
5861 self .fields ["state" ].help_text = "Note: If you wish to revise this document, you may wish to change the state so it's not deleted."
5962
60- if action == "title" :
61- del self .fields ["state" ]
62- del self .fields ["material" ]
63- elif action == "state" :
64- del self .fields ["title" ]
65- del self .fields ["material" ]
63+ if action in ["title" ,"state" ,"abstract" ]:
64+ for fieldname in ["title" ,"state" ,"material" ,"abstract" ]:
65+ if fieldname != action :
66+ del self .fields [fieldname ]
6667
6768 def clean_name (self ):
6869 name = self .cleaned_data ["name" ].strip ().rstrip ("-" )
@@ -120,6 +121,9 @@ def edit_material(request, name=None, acronym=None, action=None, doc_type=None):
120121 if "title" in form .cleaned_data :
121122 doc .title = form .cleaned_data ["title" ]
122123
124+ if "abstract" in form .cleaned_data :
125+ doc .abstract = form .cleaned_data ["abstract" ]
126+
123127 doc .time = datetime .datetime .now ()
124128
125129 if "material" in form .fields :
@@ -168,3 +172,120 @@ def edit_material(request, name=None, acronym=None, action=None, doc_type=None):
168172 'document_type' : document_type ,
169173 'doc_name' : doc .name if doc else "" ,
170174 })
175+
176+ class MaterialVersionForm (forms .Form ):
177+
178+ version = forms .ChoiceField (required = False ,
179+ label = 'Which version of this document will be presented at this session' )
180+
181+ def __init__ (self , * args , ** kwargs ):
182+ choices = kwargs .pop ('choices' )
183+ super (MaterialVersionForm ,self ).__init__ (* args ,** kwargs )
184+ self .fields ['version' ].choices = choices
185+
186+ @login_required
187+ def material_presentations (request , name , acronym = None , date = None , seq = None , week_day = None ):
188+
189+ doc = get_object_or_404 (Document , name = name )
190+ if not (doc .type_id == 'slides' and doc .get_state ('slides' ).slug == 'active' ):
191+ raise Http404
192+
193+ group = doc .group
194+ if not (group .features .has_materials and can_manage_materials (request .user ,group )):
195+ raise Http404
196+
197+ # Find all the sessions for meetings that haven't ended that the user could affect
198+ # This motif is also in Document.future_presentations - it would be nice to consolodate it somehow
199+
200+ candidate_sessions = Session .objects .exclude (status__in = ['canceled' ,'disappr' ,'notmeet' ,'deleted' ]).filter (meeting__date__gte = datetime .date .today ()- datetime .timedelta (days = 15 ))
201+ refined_candidates = [ sess for sess in candidate_sessions if sess .meeting .end_date ()>= datetime .date .today ()]
202+
203+ if acronym :
204+ refined_candidates = [ sess for sess in refined_candidates if sess .group .acronym == acronym ]
205+
206+ if date :
207+ if len (date )== 15 :
208+ start = datetime .datetime .strptime (date ,"%Y-%m-%d-%H%M" )
209+ refined_candidates = [ sess for sess in refined_candidates if sess .scheduledsession_set .filter (schedule = sess .meeting .agenda ,timeslot__time = start ) ]
210+ else :
211+ start = datetime .datetime .strptime (date ,"%Y-%m-%d" ).date ()
212+ end = start + datetime .timedelta (days = 1 )
213+ refined_candidates = [ sess for sess in refined_candidates if sess .scheduledsession_set .filter (schedule = sess .meeting .agenda ,timeslot__time__range = (start ,end )) ]
214+
215+ if week_day :
216+ try :
217+ dow = ['sun' ,'mon' ,'tue' ,'wed' ,'thu' ,'fri' ,'sat' ].index (week_day .lower ()[:3 ]) + 1
218+ except ValueError :
219+ raise Http404
220+ refined_candidates = [ sess for sess in refined_candidates if sess .scheduledsession_set .filter (schedule = sess .meeting .agenda ,timeslot__time__week_day = dow ) ]
221+
222+ changeable_sessions = [ sess for sess in refined_candidates if can_manage_materials (request .user , sess .group ) ]
223+
224+ if not changeable_sessions :
225+ raise Http404
226+
227+ for sess in changeable_sessions :
228+ sess .has_presentation = bool (sess .sessionpresentation_set .filter (document = doc ))
229+ if sess .has_presentation :
230+ sess .version = sess .sessionpresentation_set .get (document = doc ).rev
231+
232+ # Since Python 2.2 sorts are stable, so this series results in a list sorted first by whether
233+ # the session has any presentations, then by the meeting 'number', then by session's group
234+ # acronym, then by scheduled time (or the time of the session request if the session isn't
235+ # scheduled).
236+
237+ def time_sort_key (session ):
238+ official_sessions = session .scheduledsession_set .filter (schedule = session .meeting .agenda )
239+ if official_sessions :
240+ return official_sessions .first ().timeslot .time
241+ else :
242+ return session .requested
243+
244+ time_sorted = sorted (changeable_sessions ,key = time_sort_key )
245+ acronym_sorted = sorted (time_sorted ,key = lambda x : x .group .acronym )
246+ meeting_sorted = sorted (acronym_sorted ,key = lambda x : x .meeting .number )
247+ sorted_sessions = sorted (meeting_sorted ,key = lambda x : '0' if x .has_presentation else '1' )
248+
249+ if seq :
250+ iseq = int (seq ) - 1
251+ if not iseq in range (0 ,len (sorted_sessions )):
252+ raise Http404
253+ else :
254+ sorted_sessions = [sorted_sessions [iseq ]]
255+
256+ for index ,session in enumerate (sorted_sessions ):
257+ session .sequence = index + 1
258+
259+ if len (sorted_sessions )== 1 :
260+ session = sorted_sessions [0 ]
261+ choices = [('notpresented' ,'Not Presented' )]
262+ choices .extend ([(x ,x ) for x in doc .docevent_set .filter (type = 'new_revision' ).values_list ('newrevisiondocevent__rev' ,flat = True )])
263+ initial = {'version' : session .version if hasattr (session ,'version' ) else 'notpresented' }
264+
265+ if request .method == 'POST' :
266+ form = MaterialVersionForm (request .POST ,choices = choices )
267+ if form .is_valid ():
268+ if request .POST .get ("action" , "" ) == "Save" :
269+ new_selection = form .cleaned_data ['version' ]
270+ if initial ['version' ] != new_selection :
271+ if initial ['version' ] == 'notpresented' :
272+ doc .sessionpresentation_set .create (session = session ,rev = new_selection )
273+ elif new_selection == 'notpresented' :
274+ doc .sessionpresentation_set .filter (session = session ).delete ()
275+ else :
276+ doc .sessionpresentation_set .filter (session = session ).update (rev = new_selection )
277+ return redirect ('doc_view' ,name = doc .name )
278+ else :
279+ form = MaterialVersionForm (choices = choices ,initial = initial )
280+
281+ return render (request , 'doc/material/edit_material_presentations.html' , {
282+ 'session' : session ,
283+ 'doc' : doc ,
284+ 'form' : form ,
285+ })
286+
287+ else :
288+ return render (request , 'doc/material/material_presentations.html' , {
289+ 'sessions' : sorted_sessions ,
290+ 'doc' : doc ,
291+ })
0 commit comments