def configure(request): """ Process the configuration form for a Stage 1 Process. """ auth = ContributorProfile.auth_status(request.user) if auth != 'staff' or request.method != 'POST': raise PermissionDenied form = Stage1Configure(request.POST) if form.is_valid(): # If there is an old root, make it no longer the master. old_master = CITreeInfo.get_master_tree_root() if old_master is not None: old_master.is_master = False old_master.save() #Create the initial stage1 hierarchy from the submission #form. We need the CI Tree Info as well as one root node #to begin master_tree_info = CITreeInfo(is_master=True) master_tree_info.save() root_node = ConceptNode( ci_tree_info=master_tree_info, content=form.cleaned_data['root_name'], max_children=form.cleaned_data['max_children'], child_typename=form.cleaned_data['child_typename']) root_node.save() return redirect('stage1 dispatch') else: raise SuspiciousOperation
def signup(self, request, user): """ Invoked at signup time to complete the signup of the user. """ user_institution = self.cleaned_data.get('institution') user_homepage = self.cleaned_data.get('homepage') user_i_devel = self.cleaned_data.get('interest_in_devel') user_i_deploy = self.cleaned_data.get('interest_in_deploy') user_text_info = self.cleaned_data.get('text_info') user_profile = ContributorProfile(user=user, institution = user_institution, homepage=user_homepage, interest_in_devel=user_i_devel, interest_in_deploy=user_i_deploy, text_info=user_text_info ) user_profile.save()
def landing(request): auth = ContributorProfile.auth_status(request.user) if not auth: raise PermissionDenied if auth == 'staff': isstaff = True else: isstaff = False root = CITreeInfo.get_master_tree_root() if root: tree = root.get_descendants(include_self=True) # TODO: this probably shouldn't be here. Move to nodemanager #for node in tree: # if node.is_stage_finished(): # node.transition_node_state() return render(request, 'cistage1/landing.html', { 'tree': tree, 'user': request.user, 'staff': isstaff }) else: if isstaff: return redirect('stage1 setup') else: return render(request, 'cistage1/notstarted.html')
def signup(self, request, user): """ Invoked at signup time to complete the signup of the user. """ user_institution = self.cleaned_data.get('institution') user_homepage = self.cleaned_data.get('homepage') user_i_devel = self.cleaned_data.get('interest_in_devel') user_i_deploy = self.cleaned_data.get('interest_in_deploy') user_text_info = self.cleaned_data.get('text_info') user_profile = ContributorProfile(user=user, institution=user_institution, homepage=user_homepage, interest_in_devel=user_i_devel, interest_in_deploy=user_i_deploy, text_info=user_text_info) user_profile.save()
def edit_tree(request): auth = ContributorProfile.auth_status(request.user) if auth != 'staff': raise PermissionDenied # If it's a GET, construct the editing page. if request.method == 'GET': root = CITreeInfo.get_master_tree_root() if root: tree = root.get_descendants(include_self=True) context = {'tree': tree, 'user': request.user, 'open_ids': '[]'} return render(request, 'cistage1/edit_tree.html', context) else: return redirect('stage1 setup') # If it's a POST, handle the submission. if request.method == 'POST': print request.POST if request.POST['operation'] == 'edit': return edit_node(request) elif request.POST['operation'] == 'addchild': return add_child(request) elif request.POST['operation'] == 'delete': return delete_node(request) else: raise SuspiciousOperation
def landing(request): auth = ContributorProfile.auth_status(request.user) if not auth: raise PermissionDenied if auth == 'staff': isstaff = True else: isstaff = False root = CITreeInfo.get_master_tree_root() if root: tree = root.get_descendants(include_self=True) # TODO: this probably shouldn't be here. Move to nodemanager #for node in tree: # if node.is_stage_finished(): # node.transition_node_state() return render(request, 'cistage1/landing.html', {'tree': tree, 'user': request.user, 'staff': isstaff}) else: if isstaff: return redirect('stage1 setup') else: return render(request, 'cistage1/notstarted.html')
def configure(request): """ Process the configuration form for a Stage 1 Process. """ auth = ContributorProfile.auth_status(request.user) if auth != 'staff' or request.method != 'POST': raise PermissionDenied form = Stage1Configure(request.POST) if form.is_valid(): # If there is an old root, make it no longer the master. old_master = CITreeInfo.get_master_tree_root() if old_master is not None: old_master.is_master = False old_master.save() #Create the initial stage1 hierarchy from the submission #form. We need the CI Tree Info as well as one root node #to begin master_tree_info = CITreeInfo(is_master=True) master_tree_info.save() root_node = ConceptNode( ci_tree_info = master_tree_info, content = form.cleaned_data['root_name'], max_children = form.cleaned_data['max_children'], child_typename = form.cleaned_data['child_typename'] ) root_node.save() return redirect('stage1 dispatch') else: raise SuspiciousOperation
def dispatch(request): """ Redirects to the correct view function based on whether or not a Stage 1 process has been started. """ auth = ContributorProfile.auth_status(request.user) if not auth: raise PermissionDenied if not CITreeInfo.get_master_tree_root() and auth == 'staff': return redirect('stage1 setup') else: return landing(request)
def advance(request, node_id): """ Administratively advance a node to the next step. """ auth = ContributorProfile.auth_status(request.user) if auth != 'staff' or request.method != 'POST': raise PermissionDenied node = get_object_or_404(ConceptNode,pk=node_id) node.transition_node_state() return HttpResponse('{"success": true}')
def finalize(request, node_id): """ This function is called when a user makes a final submission, and needs to be added to the list of users that have submitted items """ auth = ContributorProfile.auth_status(request.user) if not auth or request.method != 'POST': raise PermissionDenied node = get_object_or_404(ConceptNode,pk=node_id) if not request.user in node.users_contributed_set(): #no duplicates node.user.add(request.user) if node.is_stage_finished(): node.transition_node_state() return HttpResponse('{"success": true}')
def display(request, node_id): auth = ContributorProfile.auth_status(request.user) if not auth: raise PermissionDenied node = get_object_or_404(ConceptNode,pk=node_id) context = { 'node': node, 'user': request.user } if auth == 'staff': context['staff'] = node.get_contribution_sets() else: context['staff'] = False return display_func[(node.node_type, auth)](request, node, context)
def setup(request): """ If the Stage 1 Process hasn't been set up yet, allow a superuser to configure it. """ auth = ContributorProfile.auth_status(request.user) if auth != 'staff': raise PermissionDenied # If the stage has already been set up, issue a warning to the user. root = CITreeInfo.get_master_tree_root() if root: warning = True else: warning = False form = Stage1Configure() return render(request, 'cistage1/configure.html', {'form': form, 'warning': warning})
def setup(request): """ If the Stage 1 Process hasn't been set up yet, allow a superuser to configure it. """ auth = ContributorProfile.auth_status(request.user) if auth != 'staff': raise PermissionDenied # If the stage has already been set up, issue a warning to the user. root = CITreeInfo.get_master_tree_root() if root: warning = True else: warning = False form = Stage1Configure() return render(request, 'cistage1/configure.html', { 'form': form, 'warning': warning })
def submit_entry(request, node_id): """ This function processes a user-submitted form containing their brainstormed picks. It handles users deleting/modifying pre-entered picks, as well as entering new ones. """ auth = ContributorProfile.auth_status(request.user) if not auth: raise PermissionDenied if request.method == 'POST': node = get_object_or_404(ConceptNode,pk=node_id) AtomFormSet = formset_factory(AtomForm, can_delete=True, max_num=node.max_children, extra=node.max_children, validate_max=True) formset = AtomFormSet(request.POST) if formset.is_valid(): #We iterate through each form in the formset, which #represents a different concept entered. If there is data #in the form, the user has either edited an existing #concept or entered a new one. for form in formset: form_text = form.cleaned_data.get('text') pk = form.cleaned_data.get('pk') if form_text: if not pk: new_atom = ConceptAtom( concept_node=node, user=request.user, text=form_text, final_choice=False ) new_atom.save() continue #if there is an associated pk, get the model instance atom = ConceptAtom.objects.filter(pk=pk).get() if not form_text == atom.text: #update if necessary atom.text = form_text atom.save() if form in formset.deleted_forms: #or delete it atom.delete() return HttpResponse('{"success": true}') else: reason = '' for (i, form) in enumerate(formset.errors): for field, problems in form.iteritems(): reason += 'Entry %d, %s:\\n' for problem in problems: reason += ' %s\\n' % problem return HttpResponse('{"success": false, "reason": "%s"}' % reason) else: return redirect('stage1 dispatch')
def get_merge(request, node_id, merge_type=None): """ This function handles a submitted form containing information about merging concepts. """ auth = ContributorProfile.auth_status(request.user) if auth != 'staff': raise PermissionDenied if request.method == 'POST': node = get_object_or_404(ConceptNode,pk=node_id) #differentiate between different forms if merge_type == 'add merge': form = CreateMergeForm(request.POST, node=node) elif merge_type == 'subtract merge': form = UpdateMergeFormSet(request.POST) else: #should never get here print "ERROR No Merge type was called" # note that "form" could be either a single form or a formset # depending on whether the user did a 'add merge' or an # 'update merge'. For this reason, we have to do an additional # attribute check if form.is_valid(): #could be a form or a formset depending on request # user merged under a new concept atom if hasattr(form,'add_merge_id') and form.add_merge_id in request.POST: new_atom = ConceptAtom(concept_node=node, user=request.user, text=form.cleaned_data.get('new_atom_name'), final_choice=True,) new_atom.save() new_atom.add_merge_atoms(form.cleaned_data.get('free_atoms')) #user merged atoms to an existing concept atom elif hasattr(form,'subtract_merge_id') and form.subtract_merge_id in request.POST: curr_atom = form.cleaned_data.get('merged_atoms') curr_atom.add_merge_atoms(form.cleaned_data.get('free_atoms')) #user has edited an existing concept atom else: formset = form #small name-change to enhance clarity for form in formset: if form.cleaned_data.get('delete'): atom = ConceptAtom.objects.filter(pk=form.cleaned_data.get('pk')).get() atom.delete() else: for atom in form.cleaned_data.get('choices'): atom.merged_atoms = None atom.save() return redirect('merge', node_id=node.id) #the form is invalid, and we redirect the errors to the user else: render_args = {'node': node, 'user': request.user} #need to set arguments differently based on whether it was #an add merge or subtract merge, since this chooses #between a form or formset if merge_type == 'add merge': render_args['create_form'] = form render_args['edit_formset'] = UpdateMergeFormSet(initial=[{'pk': atom.pk} for atom in ConceptAtom.get_final_atoms(node)]) elif merge_type == 'subtract merge': render_args['create_form'] = CreateMergeForm(node) render_args['edit_formset'] = form else: #again, should never be here print "ERROR unknown merge type" return render(request, 'nodemanager/merge.html', context) else: return redirect('stage1 dispatch')