def __init__(self, request, *args, **kwargs): super(ProjectForm, self).__init__(*args, **kwargs) lst = [(u.id, get_public_name(u, request)) for u in request.course.user_set.all()] self.fields["participants"].choices = sorted(lst, key=lambda participant: participant[1]) self.fields["participants"].widget.attrs = {"id": "id_participants_%s" % self.instance.id} col = kwargs["instance"].collaboration() if col: pol = col._policy.policy_name if pol not in dict(self.fields["publish"].choices): self.fields["publish"].choices.append((pol, pol)) self.initial["publish"] = pol if request.course.is_faculty(request.user): # Faculty self.fields["publish"].choices = [ choice for choice in self.fields["publish"].choices if choice[0] in PUBLISH_OPTIONS_FACULTY ] else: # Student if kwargs["instance"].assignment(): # Assignment response self.fields["publish"].choices = [ choice for choice in self.fields["publish"].choices if choice[0] in PUBLISH_OPTIONS_STUDENT_ASSIGNMENT ] else: self.fields["publish"].choices = [ choice for choice in self.fields["publish"].choices if choice[0] in PUBLISH_OPTIONS_STUDENT_COMPOSITION ] if course_details.allow_public_compositions(request.course): self.fields["publish"].choices.append(PUBLISH_OPTIONS_PUBLIC) self.fields["participants"].required = False self.fields["body"].required = False self.fields["submit"].required = False self.fields["publish"].required = False self.fields["title"].widget.attrs["maxlength"] = 80 # for structured collaboration
def __init__(self,request, *args, **kwargs): super(ProjectForm,self).__init__(*args,**kwargs) self.fields['participants'].widget = widgets.FilteredSelectMultiple("participants",False) lst = [(u.id,get_public_name(u, request)) for u in request.course.user_set.all()] self.fields['participants'].choices = sorted(lst, key=lambda participant: participant[1]) # sort by name col = kwargs['instance'].collaboration() if col: pol = col._policy.policy_name if pol not in dict(self.fields['publish'].choices): self.fields['publish'].choices.append( (pol,pol) ) self.initial['publish'] = pol if not request.course.is_faculty(request.user): self.fields['publish'].choices = [choice for choice in self.fields['publish'].choices if choice[0] not in PUBLISH_OPTIONS_FACULTY_ONLY] if not course_details.allow_public_compositions(request.course): self.fields['publish'].choices = [choice for choice in self.fields['publish'].choices if choice[0] not in PUBLISH_OPTIONS_PUBLIC] #not restrictive enough -- people can add children to their own projects # is that a good idea? # necessary to add a discussion to it, but maybe that's a workaround # how about we just have people 'create' a project from the assignment page for now. #self.fields['parent'].choices = [(sc.id,sc.title) for sc in # Collaboration.objects.filter(context=request.collaboration_context, # content_type = ContentType.objects.get_for_model(Project)) # if sc.permission_to('add_child',request) # ] self.fields['participants'].required = False self.fields['body'].required = False self.fields['submit'].required = False self.fields['publish'].required = False self.fields['title'].widget.attrs['maxlength'] = 80 #for structured collaboration
def __init__(self, request, *args, **kwargs): super(ProjectForm,self).__init__(*args,**kwargs) lst = [(u.id,get_public_name(u, request)) for u in request.course.user_set.all()] self.fields['participants'].choices = sorted(lst, key=lambda participant: participant[1]) self.fields['participants'].widget.attrs = { 'id': "id_participants_%s" % self.instance.id } col = kwargs['instance'].collaboration() if col: pol = col._policy.policy_name if pol not in dict(self.fields['publish'].choices): self.fields['publish'].choices.append( (pol,pol) ) self.initial['publish'] = pol if request.course.is_faculty(request.user): # Faculty self.fields['publish'].choices = [choice for choice in self.fields['publish'].choices if choice[0] in PUBLISH_OPTIONS_FACULTY] else: # Student if kwargs['instance'].assignment(): # Assignment response self.fields['publish'].choices = [choice for choice in self.fields['publish'].choices if choice[0] in PUBLISH_OPTIONS_STUDENT_ASSIGNMENT] else: self.fields['publish'].choices = [choice for choice in self.fields['publish'].choices if choice[0] in PUBLISH_OPTIONS_STUDENT_COMPOSITION] if course_details.allow_public_compositions(request.course): self.fields['publish'].choices.append(PUBLISH_OPTIONS_PUBLIC) self.fields['participants'].required = False self.fields['body'].required = False self.fields['submit'].required = False self.fields['publish'].required = False self.fields['title'].widget.attrs['maxlength'] = 80 #for structured collaboration