2020from ietf .doc .utils import get_tags_for_stream_id , add_state_change_event
2121from ietf .group .models import ( Group , Role , GroupEvent , GroupHistory , GroupStateName ,
2222 GroupStateTransitions , GroupTypeName , GroupURL , ChangeStateGroupEvent )
23- from ietf .group .utils import ( save_group_in_history , can_manage_group_type , can_manage_materials ,
24- get_group_or_404 )
23+ from ietf .group .utils import save_group_in_history , can_manage_group_type , can_manage_materials
24+ from ietf . group . utils import get_group_or_404
2525from ietf .ietfauth .utils import has_role
2626from ietf .person .forms import EmailsField
2727from ietf .person .models import Person , Email
@@ -458,17 +458,28 @@ def customize_workflow(request, group_type, acronym):
458458 'tags' : tags ,
459459 })
460460
461+ @login_required
462+ def choose_material_type (request , acronym , group_type = None ):
463+ group = get_group_or_404 (acronym , group_type )
464+ if not group .features .has_materials :
465+ raise Http404
466+
467+ return render (request , 'group/choose_material_type.html' , {
468+ 'group' : group ,
469+ 'material_types' : DocTypeName .objects .filter (slug__in = group .features .material_types ),
470+ })
471+
472+
461473class UploadMaterialForm (forms .Form ):
462474 title = forms .CharField (max_length = Document ._meta .get_field ("title" ).max_length )
463- state = forms .ModelChoiceField (State .objects .filter ( type = "material" ), empty_label = None )
475+ state = forms .ModelChoiceField (State .objects .all ( ), empty_label = None )
464476 material = forms .FileField (label = 'File' , help_text = "PDF or text file (ASCII/UTF-8)" )
465477
466- def __init__ (self , * args , ** kwargs ):
467- action = kwargs .pop ("action" )
468- doc = kwargs .pop ("doc" , None )
469-
478+ def __init__ (self , doc_type , action , doc , * args , ** kwargs ):
470479 super (UploadMaterialForm , self ).__init__ (* args , ** kwargs )
471480
481+ self .fields ["state" ].queryset = self .fields ["state" ].queryset .filter (type = doc_type )
482+
472483 if action == "new" :
473484 self .fields ["state" ].widget = forms .HiddenInput ()
474485 self .fields ["state" ].queryset = self .fields ["state" ].queryset .filter (slug = "active" )
@@ -482,27 +493,29 @@ def __init__(self, *args, **kwargs):
482493
483494
484495@login_required
485- def edit_material (request , acronym , action = "new" , name = None , group_type = None ):
496+ def edit_material (request , acronym , action = "new" , name = None , doc_type = None , group_type = None ):
486497 group = get_group_or_404 (acronym , group_type )
487498 if not group .features .has_materials :
488499 raise Http404
489500
490501 if not can_manage_materials (request .user , group ):
491502 return HttpResponseForbidden ("You don't have permission to access this view" )
492503
504+ document_type = get_object_or_404 (DocTypeName , slug = doc_type )
505+
493506 existing = None
494507 if name and action != "new" :
495508 existing = get_object_or_404 (Document , type = "material" , name = name )
496509
497510 if request .method == 'POST' :
498- form = UploadMaterialForm (request .POST , request .FILES , action = action , doc = existing )
511+ form = UploadMaterialForm (document_type , action , existing , request .POST , request .FILES )
499512
500513 if form .is_valid ():
501514 if action == "new" :
502515 d = Document ()
503- d .type = DocTypeName . objects . get ( slug = "material" )
516+ d .type = document_type
504517 d .group = group
505- d .rev = "01 "
518+ d .rev = "00 "
506519 else :
507520 d = existing
508521
@@ -514,12 +527,12 @@ def edit_material(request, acronym, action="new", name=None, group_type=None):
514527 d .time = datetime .datetime .now ()
515528
516529 if not d .name :
517- d .name = "material -%s-%s" % (d .group .acronym , slugify (d .title ))
530+ d .name = "%s -%s-%s" % (d . type_id , d .group .acronym , slugify (d .title ))
518531 i = 2
519532 while True :
520533 if not Document .objects .filter (name = d .name ).exists ():
521534 break
522- d .name = "material -%s-%s-%s" % (d .group .acronym , slugify (d .title ), i )
535+ d .name = "%s -%s-%s-%s" % (d . type_id , d .group .acronym , slugify (d .title ), i )
523536 i += 1
524537
525538 if "material" in form .fields :
@@ -555,7 +568,7 @@ def edit_material(request, acronym, action="new", name=None, group_type=None):
555568
556569 return redirect ("group_materials" , acronym = group .acronym )
557570 else :
558- form = UploadMaterialForm (action = action , doc = existing )
571+ form = UploadMaterialForm (document_type , action , existing )
559572
560573 return render (request , 'group/edit_material.html' , {
561574 'group' : group ,
0 commit comments