コード例 #1
0
ファイル: views.py プロジェクト: kylelady/mig-website
def get_permissions(user):
    permission_dict = get_member_permissions(user)
    permission_dict.update(
        {
            "can_create_groups": Permissions.can_manage_electee_progress(user),
            "can_edit_resources": Permissions.can_manage_electee_progress(user),
        }
    )
    return permission_dict
コード例 #2
0
ファイル: views.py プロジェクト: kylelady/mig-website
def get_permissions(user):
    permission_dict = get_member_permissions(user)
    permission_dict.update({
        'can_create_groups':
        Permissions.can_manage_electee_progress(user),
        'can_edit_resources':
        Permissions.can_manage_electee_progress(user),
    })
    return permission_dict
コード例 #3
0
ファイル: views.py プロジェクト: dadrian/mig-website
def get_permissions(user):
    permission_dict = get_member_permissions(user)
    permission_dict.update({
        'can_edit_resources':Permissions.can_manage_electee_progress(user),
        'can_edit_surveys':Permissions.can_manage_electee_progress(user),
        'can_complete_surveys':Permissions.can_complete_electee_survey(user),
        'can_submit_background_form':can_submit_background_form(user),
        'can_submit_interview_followups':user_is_member(user) and user.userprofile.memberprofile.status.name=='Active',
        'can_view_interview_pairings':Permissions.can_view_interview_pairings(user),
        'can_view_followups':Permissions.can_see_follow_up(user),
        })
    return permission_dict
コード例 #4
0
ファイル: views.py プロジェクト: simonzli/mig-website
def get_permissions(user):
    permission_dict = get_member_permissions(user)
    permission_dict.update({
        'can_edit_resources':Permissions.can_manage_electee_progress(user),
        'can_edit_surveys':Permissions.can_manage_electee_progress(user),
        'can_complete_surveys':Permissions.can_complete_electee_survey(user),
        'can_submit_background_form':can_submit_background_form(user),
        'can_submit_interview_followups':user_is_member(user) and user.userprofile.memberprofile.status.name=='Active',
        'can_view_interview_pairings':Permissions.can_view_interview_pairings(user),
        'can_view_followups':Permissions.can_see_follow_up(user),
        })
    return permission_dict
コード例 #5
0
ファイル: views.py プロジェクト: simonzli/mig-website
def edit_electee_process_visibility(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit the electee process visibility settings.'
        return redirect('electees:view_electee_groups')
    current_vis = ElecteeProcessVisibility.objects.get_or_create(term=AcademicTerm.get_current_term())
    VisibilityForm = modelform_factory(ElecteeProcessVisibility,exclude=['term'])
    prefix='visibility'
    form = VisibilityForm(request.POST or None ,prefix=prefix,instance=current_vis[0])
    if request.method =='POST':
        if form.is_valid():
            form.save()
            request.session['success_message']='Electee settings updated successfully'
            return redirect('electees:manage_survey')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'

    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':form,
        'prefix':prefix,
        'has_files':False,
        'submit_name':'Update Visibility Settings',
        'form_title':'Update Electee Visibility Settings for %s'%(unicode(AcademicTerm.get_current_term())),
        'help_text':'Change whether certain electee items are visible to all actives.',
        'base':'electees/base_electees.html',
        'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #6
0
ファイル: views.py プロジェクト: dadrian/mig-website
def manually_edit_electee_group_membership(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee teams'
        return redirect('electees:view_electee_groups')
    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
    prefix = 'manual_groups'
    term =AcademicTerm.get_current_term()
    formset=ManualElecteeGroupMembersFormSet(request.POST or None,prefix=prefix,queryset=ElecteeGroup.objects.filter(term=term))
    if request.method=='POST':
        if formset.is_valid():
            formset.save()
            request.session['success_message']='Electee team membership updated successfully'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':prefix,
        'subsubnav':'members',
        'has_files':False,
        'submit_name':'Update Electee Team Membership',
        'form_title':'Add Electee Team Members',
        'help_text':'Add members to electee teams. This is for initial addition only, for edits use the drag-and-drop interface.',
        'can_add_row':False,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #7
0
ファイル: views.py プロジェクト: dadrian/mig-website
def edit_electee_group_points(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee team points.'
        return redirect('electees:view_electee_groups')
    term =AcademicTerm.get_current_term()
    GroupPointsFormSet = modelformset_factory(ElecteeGroupEvent,exclude=('related_event_id',),can_delete=True)
    GroupPointsFormSet.form.base_fields['electee_group'].queryset=ElecteeGroup.objects.filter(term=term)
    if request.method =='POST':
        formset = GroupPointsFormSet(request.POST,prefix='group_points',queryset=ElecteeGroupEvent.objects.filter(related_event_id=None,electee_group__term=term))
        if formset.is_valid():
            formset.save()
            request.session['success_message']='Electee team points updated successfully'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        formset = GroupPointsFormSet(prefix='group_points',queryset=ElecteeGroupEvent.objects.filter(related_event_id=None,electee_group__term=term))
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':'group_points',
        'subsubnav':'points',
        'has_files':False,
        'submit_name':'Update Electee Team Points',
        'form_title':'Update/Add Remove Electee Team Points',
        'help_text':'Track the electee team points. You should not note any points from threshold participation at service or social events here. Those are tabulated automatically.',
        'can_add_row':True,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #8
0
ファイル: views.py プロジェクト: simonzli/mig-website
def edit_survey_questions(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit the electee survey.'
        return redirect('electees:view_electee_groups')
    SurveyQuestionFormSet = modelformset_factory(SurveyQuestion, exclude=[])
    prefix='surveyquestions'
   
    if request.method =='POST':
        formset = SurveyQuestionFormSet(request.POST,prefix=prefix,queryset=SurveyQuestion.objects.all())
        if formset.is_valid():
            formset.save()
            request.session['success_message']='Electee interview survey questions updated successfully'
            return redirect('electees:manage_survey')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        formset = SurveyQuestionFormSet(prefix=prefix,queryset=SurveyQuestion.objects.all())
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':prefix,
        'has_files':False,
        'can_add_row':True,
        'submit_name':'Update Electee Survey Questions',
        'form_title':'Update Electee Interview Survey Questions',
        'help_text':'Add or edit the different questions for the survey. Questions will only be displayed if they are added to the current survey. There should be no need to remove survey parts. If there is no word limit for a question, leave that field blank.',
        'base':'electees/base_electees.html',
        'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #9
0
ファイル: views.py プロジェクト: dadrian/mig-website
def edit_electee_group_membership(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee teams'
        return redirect('electees:view_electee_groups')
    if request.method =='POST':
        electee_groups_json=request.POST['electee_groups']
        electee_groups = json.loads(electee_groups_json)
        for group_id in electee_groups:
            members = electee_groups[group_id]
            group = ElecteeGroup.objects.get(id=group_id)
            group.members.clear()
            for member in members:
                group.members.add(MemberProfile.objects.get(uniqname=member))
        request.session['success_message']='Your changes have been saved'

    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
    template = loader.get_template('electees/edit_electee_group_membership.html')
    context_dict = {
        'electee_groups':e_groups,
        'unassigned_electees':get_unassigned_electees(),
        'subsubnav':'members',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #10
0
ファイル: views.py プロジェクト: dadrian/mig-website
def eligibility(request):
    """
    The joining page. The name eligibility is a backwards compatibility to the
    old name of the page. Unfortunately changing the view names is a big hassle
    as all the links throughout the website are kind of based on those. Shows
    text determined by the JoiningTextField table and a static photo that
    desperately needs updating.
    """
    template = loader.get_template('about/eligibility.html')
    eligibility_text = JoiningTextField.objects.filter(section='EL')
    ugrad_reqs_text = JoiningTextField.objects.filter(section='UG')
    grad_reqs_text = JoiningTextField.objects.filter(section='GR')
    why_join_text = JoiningTextField.objects.filter(section='Y')
    context_dict = {
        'eligibility_text': eligibility_text,
        'ugrad_text': ugrad_reqs_text,
        'grad_text': grad_reqs_text,
        'why_join_text': why_join_text,
        'can_edit_page': Permissions.can_manage_electee_progress(request.user),
        'subnav': 'joining',
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #11
0
ファイル: views.py プロジェクト: simonzli/mig-website
def edit_electee_resources(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee resources.'
        return redirect('electees:view_electee_groups')
    ResourceFormSet = modelformset_factory(ElecteeResource,exclude=('term',),can_delete=True)
    term =AcademicTerm.get_current_term()
    if request.method =='POST':
        formset = ResourceFormSet(request.POST,request.FILES,prefix='resources',queryset=ElecteeResource.objects.filter(term=term))
        if formset.is_valid():
            instances=formset.save(commit=False)
            for obj in formset.deleted_objects:
                obj.delete()
            for instance in instances:
                instance.term=term
                instance.save()
            request.session['success_message']='Electee resources updated successfully'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        formset = ResourceFormSet(prefix='resources',queryset=ElecteeResource.objects.filter(term=term))
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':'resources',
        'has_files':True,
        'submit_name':'Update Electee Resources',
        'form_title':'Update/Add/Remove Electee Resources for %s'%(unicode(term)),
        'help_text':'These are the full packets and their constituent parts. If you need a part that isn\'t listed here, contact the web chair.',
        'can_add_row':True,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #12
0
ファイル: views.py プロジェクト: simonzli/mig-website
def edit_electee_group_points(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee team points.'
        return redirect('electees:view_electee_groups')
    term =AcademicTerm.get_current_term()
    GroupPointsFormSet = modelformset_factory(ElecteeGroupEvent,exclude=('related_event_id',),can_delete=True)
    GroupPointsFormSet.form.base_fields['electee_group'].queryset=ElecteeGroup.objects.filter(term=term)
    if request.method =='POST':
        formset = GroupPointsFormSet(request.POST,prefix='group_points',queryset=ElecteeGroupEvent.objects.filter(related_event_id=None,electee_group__term=term))
        if formset.is_valid():
            formset.save()
            request.session['success_message']='Electee team points updated successfully'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        formset = GroupPointsFormSet(prefix='group_points',queryset=ElecteeGroupEvent.objects.filter(related_event_id=None,electee_group__term=term))
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':'group_points',
        'subsubnav':'points',
        'has_files':False,
        'submit_name':'Update Electee Team Points',
        'form_title':'Update/Add Remove Electee Team Points',
        'help_text':'Track the electee team points. You should not note any points from threshold participation at service or social events here. Those are tabulated automatically.',
        'can_add_row':True,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #13
0
ファイル: views.py プロジェクト: simonzli/mig-website
def manually_edit_electee_group_membership(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee teams'
        return redirect('electees:view_electee_groups')
    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
    prefix = 'manual_groups'
    term =AcademicTerm.get_current_term()
    formset=ManualElecteeGroupMembersFormSet(request.POST or None,prefix=prefix,queryset=ElecteeGroup.objects.filter(term=term))
    if request.method=='POST':
        if formset.is_valid():
            formset.save()
            request.session['success_message']='Electee team membership updated successfully'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':prefix,
        'subsubnav':'members',
        'has_files':False,
        'submit_name':'Update Electee Team Membership',
        'form_title':'Add Electee Team Members',
        'help_text':'Add members to electee teams. This is for initial addition only, for edits use the drag-and-drop interface.',
        'can_add_row':False,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #14
0
ファイル: views.py プロジェクト: simonzli/mig-website
def edit_electee_group_membership(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee teams'
        return redirect('electees:view_electee_groups')
    if request.method =='POST':
        electee_groups_json=request.POST['electee_groups']
        electee_groups = json.loads(electee_groups_json)
        for group_id in electee_groups:
            members = electee_groups[group_id]
            group = ElecteeGroup.objects.get(id=group_id)
            group.members.clear()
            for member in members:
                group.members.add(MemberProfile.objects.get(uniqname=member))
        request.session['success_message']='Your changes have been saved'

    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
    template = loader.get_template('electees/edit_electee_group_membership.html')
    context_dict = {
        'electee_groups':e_groups,
        'unassigned_electees':get_unassigned_electees(),
        'subsubnav':'members',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #15
0
ファイル: views.py プロジェクト: tbpmig/mig-website
def eligibility(request):
    """
    The joining page. The name eligibility is a backwards compatibility to the
    old name of the page. Unfortunately changing the view names is a big hassle
    as all the links throughout the website are kind of based on those. Shows
    text determined by the :model:`about.JoiningTextField`
    table and a static photo that
    desperately needs updating.
    """
    template = loader.get_template('about/eligibility.html')
    eligibility_text = JoiningTextField.objects.filter(section='EL')
    ugrad_reqs_text = JoiningTextField.objects.filter(section='UG')
    grad_reqs_text = JoiningTextField.objects.filter(section='GR')
    why_join_text = JoiningTextField.objects.filter(section='Y')
    context_dict = {
        'eligibility_text': eligibility_text,
        'ugrad_text': ugrad_reqs_text,
        'grad_text': grad_reqs_text,
        'why_join_text': why_join_text,
        'can_edit_page': Permissions.can_manage_electee_progress(request.user),
        'subnav': 'joining',
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #16
0
ファイル: views.py プロジェクト: kylelady/mig-website
def update_joining_page(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to update joining page text.'
        return redirect('about:eligibility')
    JoiningTextForm = modelformset_factory(JoiningTextField,extra=0)
    if request.method=='POST':
        formset = JoiningTextForm(request.POST)
        if formset.is_valid():
            instances = formset.save()
            request.session['success_message']='Joining page successfully updated.'
            return redirect('about:eligibility')
        else:
            request.session['error_message']='Your submision contained errors, please correct and resubmit.'
    else:
       formset=JoiningTextForm()
    context_dict = {
        'formset':formset,
        'subnav':'joining',
        'has_files':False,
        'submit_name':'Update Joining Page',
        'back_button':{'link':reverse('about:eligibility'),'text':'To Joining Page'},
        'form_title':'Edit Joining Page Text',
        'help_text':'These sections use markdown syntax. You can change the content and how it is displayed here.',
        'can_add_row':False,
        'base':'about/base_about.html',
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    template = loader.get_template('generic_formset.html')
    return HttpResponse(template.render(context))
コード例 #17
0
ファイル: views.py プロジェクト: kylelady/mig-website
def edit_electee_groups(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session[
            'error_message'] = 'You are not authorized to edit electee groups'
        return redirect('electees:view_electee_groups')
    e_groups = ElecteeGroup.objects.filter(term=get_current_term())
    ElecteeGroupFormSet = modelformset_factory(ElecteeGroup,
                                               exclude=(
                                                   'term',
                                                   'members',
                                                   'points',
                                               ),
                                               can_delete=True,
                                               widgets={
                                                   'leaders':
                                                   CheckboxSelectMultiple,
                                                   'officers':
                                                   CheckboxSelectMultiple
                                               })
    ElecteeGroupFormSet.form.base_fields['leaders'].queryset = get_actives(
    ).order_by('last_name', 'first_name')
    #ElecteeGroupFormSet.form.base_fields['leaders'].widget=CheckboxSelectMultiple
    ElecteeGroupFormSet.form.base_fields[
        'officers'].queryset = get_current_officers().order_by(
            'last_name', 'first_name')
    if request.method == 'POST':
        formset = ElecteeGroupFormSet(request.POST, prefix='groups')
        if formset.is_valid():
            instances = formset.save(commit=False)
            for instance in instances:
                if not instance.id:
                    instance.term = get_current_term()
                    instance.points = 0
                instance.save()
            formset.save_m2m()
            request.session[
                'success_message'] = 'Electee groups successfully updated'
            return redirect('electees:view_electee_groups')
        else:
            request.session[
                'error_message'] = 'Form is invalid. Please correct the noted errors'
    else:
        formset = ElecteeGroupFormSet(queryset=e_groups, prefix='groups')
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset': formset,
        'prefix': 'groups',
        'subsubnav': 'groups',
        'has_files': False,
        'submit_name': 'Update Electee Groups',
        'form_title': 'Update/Add/Remove Electee Groups',
        'help_text':
        'Create the electee groups for this semester, and specify the leaders nd officers. You can also remove or edit here.',
        'can_add_row': True,
        'base': 'electees/base_electees.html',
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #18
0
ファイル: views.py プロジェクト: dadrian/mig-website
def edit_electee_process_visibility(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit the electee process visibility settings.'
        return redirect('electees:view_electee_groups')
    current_vis = ElecteeProcessVisibility.objects.get_or_create(term=AcademicTerm.get_current_term())
    VisibilityForm = modelform_factory(ElecteeProcessVisibility,exclude=['term'])
    prefix='visibility'
    form = VisibilityForm(request.POST or None ,prefix=prefix,instance=current_vis[0])
    if request.method =='POST':
        if form.is_valid():
            form.save()
            request.session['success_message']='Electee settings updated successfully'
            return redirect('electees:manage_survey')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'

    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':form,
        'prefix':prefix,
        'has_files':False,
        'submit_name':'Update Visibility Settings',
        'form_title':'Update Electee Visibility Settings for %s'%(unicode(AcademicTerm.get_current_term())),
        'help_text':'Change whether certain electee items are visible to all actives.',
        'base':'electees/base_electees.html',
        'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))  
コード例 #19
0
ファイル: views.py プロジェクト: kylelady/mig-website
def edit_electee_group_membership(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session["error_message"] = "You are not authorized to edit electee groups"
        return redirect("electees:view_electee_groups")
    if request.method == "POST":
        electee_groups_json = request.POST["electee_groups"]
        electee_groups = json.loads(electee_groups_json)
        for group_id in electee_groups:
            members = electee_groups[group_id]
            group = ElecteeGroup.objects.get(id=group_id)
            group.members.clear()
            for member in members:
                group.members.add(MemberProfile.objects.get(uniqname=member))
        request.session["success_message"] = "Your changes have been saved"

    e_groups = ElecteeGroup.objects.filter(term=get_current_term())
    template = loader.get_template("electees/edit_electee_group_membership.html")
    context_dict = {
        "electee_groups": e_groups,
        "unassigned_electees": get_unassigned_electees(),
        "subsubnav": "members",
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #20
0
ファイル: views.py プロジェクト: dadrian/mig-website
def edit_survey_questions(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit the electee survey.'
        return redirect('electees:view_electee_groups')
    SurveyQuestionFormSet = modelformset_factory(SurveyQuestion)
    prefix='surveyquestions'
   
    if request.method =='POST':
        formset = SurveyQuestionFormSet(request.POST,prefix=prefix,queryset=SurveyQuestion.objects.all())
        if formset.is_valid():
            formset.save()
            request.session['success_message']='Electee interview survey questions updated successfully'
            return redirect('electees:manage_survey')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        formset = SurveyQuestionFormSet(prefix=prefix,queryset=SurveyQuestion.objects.all())
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':prefix,
        'has_files':False,
        'can_add_row':True,
        'submit_name':'Update Electee Survey Questions',
        'form_title':'Update Electee Interview Survey Questions',
        'help_text':'Add or edit the different questions for the survey. Questions will only be displayed if they are added to the current survey. There should be no need to remove survey parts. If there is no word limit for a question, leave that field blank.',
        'base':'electees/base_electees.html',
        'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #21
0
ファイル: views.py プロジェクト: tbpmig/mig-website
def edit_survey_parts(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit the electee survey.'
        return redirect('electees:view_electee_groups')
    SurveyPartFormSet = modelformset_factory(SurveyPart, exclude=[])
    prefix='surveyparts'
   
    if request.method =='POST':
        formset = SurveyPartFormSet(request.POST,prefix=prefix,queryset=SurveyPart.objects.all())
        if formset.is_valid():
            formset.save()
            request.session['success_message']='Electee interview survey parts updated successfully'
            return redirect('electees:manage_survey')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        formset = SurveyPartFormSet(prefix=prefix,queryset=SurveyPart.objects.all())
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':prefix,
        'has_files':False,
        'can_add_row':True,
        'submit_name':'Update Electee Survey Parts',
        'form_title':'Update Electee Interview Survey Parts',
        'help_text':'Add or edit the different parts of the survey. Questions will be associated with a particular part. Only those parts that have questions which appear in a given survey will be included in that survey. There should be no need to remove survey parts. If all questions in a part are required, leave that field blank.',
        'base':'electees/base_electees.html',
        'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #22
0
ファイル: views.py プロジェクト: kylelady/mig-website
def edit_electee_groups(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session["error_message"] = "You are not authorized to edit electee groups"
        return redirect("electees:view_electee_groups")
    e_groups = ElecteeGroup.objects.filter(term=get_current_term())
    ElecteeGroupFormSet = modelformset_factory(
        ElecteeGroup,
        exclude=("term", "members", "points"),
        can_delete=True,
        widgets={"leaders": CheckboxSelectMultiple, "officers": CheckboxSelectMultiple},
    )
    ElecteeGroupFormSet.form.base_fields["leaders"].queryset = get_actives().order_by("last_name", "first_name")
    # ElecteeGroupFormSet.form.base_fields['leaders'].widget=CheckboxSelectMultiple
    ElecteeGroupFormSet.form.base_fields["officers"].queryset = get_current_officers().order_by(
        "last_name", "first_name"
    )
    if request.method == "POST":
        formset = ElecteeGroupFormSet(request.POST, prefix="groups")
        if formset.is_valid():
            instances = formset.save(commit=False)
            for instance in instances:
                if not instance.id:
                    instance.term = get_current_term()
                    instance.points = 0
                instance.save()
            formset.save_m2m()
            request.session["success_message"] = "Electee groups successfully updated"
            return redirect("electees:view_electee_groups")
        else:
            request.session["error_message"] = "Form is invalid. Please correct the noted errors"
    else:
        formset = ElecteeGroupFormSet(queryset=e_groups, prefix="groups")
    template = loader.get_template("generic_formset.html")
    context_dict = {
        "formset": formset,
        "prefix": "groups",
        "subsubnav": "groups",
        "has_files": False,
        "submit_name": "Update Electee Groups",
        "form_title": "Update/Add/Remove Electee Groups",
        "help_text": "Create the electee groups for this semester, and specify the leaders nd officers. You can also remove or edit here.",
        "can_add_row": True,
        "base": "electees/base_electees.html",
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #23
0
ファイル: views.py プロジェクト: kylelady/mig-website
def eligibility(request):
    template = loader.get_template('about/eligibility.html')
    eligibility_text = JoiningTextField.objects.filter(section='EL')
    ugrad_reqs_text = JoiningTextField.objects.filter(section='UG')
    grad_reqs_text = JoiningTextField.objects.filter(section='GR')
    why_join_text = JoiningTextField.objects.filter(section='Y')
    context_dict = {
            'eligibility_text':eligibility_text,
            'ugrad_text':ugrad_reqs_text,
            'grad_text':grad_reqs_text,
            'why_join_text':why_join_text,
            'can_edit_page':Permissions.can_manage_electee_progress(request.user),
            'subnav':'joining',
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #24
0
ファイル: views.py プロジェクト: dadrian/mig-website
def update_joining_page(request):
    """
    Standard form view based on the generic_formset. Used to update the text
    in the joining page.
    """
    denied_message = 'You are not authorized to update joining page text.'
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message'] = denied_message
        return redirect('about:eligibility')
    prefix = 'joining'
    # messages and static text
    success_message = 'Joining page successfully updated.'
    help_text = ('These sections use markdown syntax. You can change the '
                 'content and how it is displayed here.')
    JoiningTextForm = modelformset_factory(JoiningTextField, extra=0,
                                           exclude=[])
    formset = JoiningTextForm(request.POST or None, prefix=prefix)
    if request.method == 'POST':
        if formset.is_valid():
            instances = formset.save()
            request.session['success_message'] = success_message
            return redirect('about:eligibility')
        else:
            request.session['error_message'] = FORM_ERROR
    context_dict = {
        'formset': formset,
        'prefix': prefix,
        'subnav': 'joining',
        'has_files': False,
        'submit_name': 'Update Joining Page',
        'back_button': {'link': reverse('about:eligibility'),
                        'text': 'To Joining Page'},
        'form_title': 'Edit Joining Page Text',
        'help_text': help_text,
        'can_add_row': False,
        'base': 'about/base_about.html',
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    template = loader.get_template('generic_formset.html')
    return HttpResponse(template.render(context))
コード例 #25
0
ファイル: views.py プロジェクト: simonzli/mig-website
def preview_survey_for_term(request,term_id):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to preview the electee survey.'
        return redirect('electees:view_electee_groups')
    term = get_object_or_404(AcademicTerm,id=term_id)
    current_surveys = ElecteeInterviewSurvey.objects.filter(term = term)
    if current_surveys.exists():
        current_survey=current_surveys[0]
        existed=True
    else:
        raise Http404
        
    template = loader.get_template('electees/preview_survey.html')
    context_dict = {
        'real_form':False,
        'questions':current_survey.questions.all(),
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #26
0
ファイル: views.py プロジェクト: tbpmig/mig-website
def update_joining_page(request):
    """
    Standard form view based on the generic_formset. Used to update the text
    in the joining page.
    """
    denied_message = 'You are not authorized to update joining page text.'
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message'] = denied_message
        return redirect('about:eligibility')
    prefix = 'joining'
    # messages and static text
    success_message = 'Joining page successfully updated.'
    help_text = ('These sections use markdown syntax. You can change the '
                 'content and how it is displayed here.')
    JoiningTextForm = modelformset_factory(JoiningTextField, extra=0,
                                           exclude=[])
    formset = JoiningTextForm(request.POST or None, prefix=prefix)
    if request.method == 'POST':
        if formset.is_valid():
            instances = formset.save()
            request.session['success_message'] = success_message
            return redirect('about:eligibility')
        else:
            request.session['error_message'] = FORM_ERROR
    context_dict = {
        'formset': formset,
        'prefix': prefix,
        'subnav': 'joining',
        'has_files': False,
        'submit_name': 'Update Joining Page',
        'back_button': {'link': reverse('about:eligibility'),
                        'text': 'To Joining Page'},
        'form_title': 'Edit Joining Page Text',
        'help_text': help_text,
        'can_add_row': False,
        'base': 'about/base_about.html',
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    template = loader.get_template('generic_formset.html')
    return HttpResponse(template.render(context_dict,request))
コード例 #27
0
ファイル: views.py プロジェクト: dadrian/mig-website
def edit_survey_for_term(request,term_id):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit the electee survey.'
        return redirect('electees:view_electee_groups')
    SurveyForm = modelform_factory(ElecteeInterviewSurvey,exclude=('term','questions'))
    term = get_object_or_404(AcademicTerm,id=term_id)
    current_surveys = ElecteeInterviewSurvey.objects.filter(term = term)
    prefix='survey'
    if current_surveys.exists():
        current_survey=current_surveys[0]
        existed=True
    else:
        current_survey = ElecteeInterviewSurvey(term=term)
        existed = False
    if request.method =='POST':
        form = SurveyForm(request.POST,prefix=prefix,instance=current_survey)
        if form.is_valid():
            form.save()
            request.session['success_message']='Electee interview survey updated successfully'
            return redirect('electees:manage_survey')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        form = SurveyForm(prefix=prefix,instance=current_survey)
    template = loader.get_template('generic_form.html')
    verb = 'Update' if existed else 'Add'
    context_dict = {
        'form':form,
        'prefix':prefix,
        'has_files':False,
        'submit_name':'Update Electee Survey',
        'form_title':verb+' Electee Interview Survey for %s'%(unicode(term)),
        'help_text':'This is the meta survey object that will group the questions for a particular term.',
        'base':'electees/base_electees.html',
        'dp_ids':['id_survey-due_date'],
        'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #28
0
ファイル: views.py プロジェクト: simonzli/mig-website
def edit_survey_for_term(request,term_id):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit the electee survey.'
        return redirect('electees:view_electee_groups')
    SurveyForm = modelform_factory(ElecteeInterviewSurvey,exclude=('term','questions'))
    term = get_object_or_404(AcademicTerm,id=term_id)
    current_surveys = ElecteeInterviewSurvey.objects.filter(term = term)
    prefix='survey'
    if current_surveys.exists():
        current_survey=current_surveys[0]
        existed=True
    else:
        current_survey = ElecteeInterviewSurvey(term=term)
        existed = False
    if request.method =='POST':
        form = SurveyForm(request.POST,prefix=prefix,instance=current_survey)
        if form.is_valid():
            form.save()
            request.session['success_message']='Electee interview survey updated successfully'
            return redirect('electees:manage_survey')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        form = SurveyForm(prefix=prefix,instance=current_survey)
    template = loader.get_template('generic_form.html')
    verb = 'Update' if existed else 'Add'
    context_dict = {
        'form':form,
        'prefix':prefix,
        'has_files':False,
        'submit_name':'Update Electee Survey',
        'form_title':verb+' Electee Interview Survey for %s'%(unicode(term)),
        'help_text':'This is the meta survey object that will group the questions for a particular term.',
        'base':'electees/base_electees.html',
        'dp_ids':['id_survey-due_date'],
        'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #29
0
ファイル: views.py プロジェクト: dadrian/mig-website
def edit_electee_groups(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee groups'
        return redirect('electees:view_electee_groups')
    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
    ElecteeGroupFormSet = modelformset_factory(ElecteeGroup,form =BaseElecteeGroupForm,can_delete=True)
    if request.method =='POST':
        formset = ElecteeGroupFormSet(request.POST,prefix='groups')
        if formset.is_valid():
            instances=formset.save(commit=False)
            for obj in formset.deleted_objects:
                obj.delete()
            for instance in instances:
                if not instance.id:
                    instance.term = AcademicTerm.get_current_term()
                    instance.points = 0
                instance.save()
            formset.save_m2m()
            request.session['success_message']='Electee teams successfully updated'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors'
    else:
        formset = ElecteeGroupFormSet(queryset=e_groups,prefix='groups')
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':'groups',
        'subsubnav':'groups',
        'has_files':False,
        'submit_name':'Update Electee Teams',
        'form_title':'Update/Add/Remove Electee Teams',
        'help_text':'Create the electee teams for this semester, and specify the leaders and officers. You can also remove or edit here.',
        'can_add_row':True,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #30
0
ファイル: views.py プロジェクト: simonzli/mig-website
def edit_electee_groups(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee groups'
        return redirect('electees:view_electee_groups')
    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
    ElecteeGroupFormSet = modelformset_factory(ElecteeGroup,form =BaseElecteeGroupForm,can_delete=True)
    if request.method =='POST':
        formset = ElecteeGroupFormSet(request.POST,prefix='groups')
        if formset.is_valid():
            instances=formset.save(commit=False)
            for obj in formset.deleted_objects:
                obj.delete()
            for instance in instances:
                if not instance.id:
                    instance.term = AcademicTerm.get_current_term()
                    instance.points = 0
                instance.save()
            formset.save_m2m()
            request.session['success_message']='Electee teams successfully updated'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors'
    else:
        formset = ElecteeGroupFormSet(queryset=e_groups,prefix='groups')
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':'groups',
        'subsubnav':'groups',
        'has_files':False,
        'submit_name':'Update Electee Teams',
        'form_title':'Update/Add/Remove Electee Teams',
        'help_text':'Create the electee teams for this semester, and specify the leaders and officers. You can also remove or edit here.',
        'can_add_row':True,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #31
0
ファイル: views.py プロジェクト: simonzli/mig-website
def manage_survey(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit the electee survey.'
        return redirect('electees:view_electee_groups')
        
    template = loader.get_template('electees/manage_survey.html')
    term = AcademicTerm.get_current_term()
    current_survey = ElecteeInterviewSurvey.objects.filter(term = term)
    survey_exists = current_survey.exists()
    if survey_exists:
        survey_has_q = current_survey[0].questions.all().exists()
    else:
        survey_has_q = False
    context_dict = {
        'survey_exists':survey_exists,
        'parts_exist':SurveyPart.objects.all().exists(),
        'questions_exist':SurveyQuestion.objects.all().exists(),
        'survey_has_questions':survey_has_q,
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #32
0
ファイル: views.py プロジェクト: kylelady/mig-website
def edit_electee_group_points(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session["error_message"] = "You are not authorized to edit electee group points."
        return redirect("electees:view_electee_groups")
    GroupPointsFormSet = modelformset_factory(ElecteeGroupEvent, exclude=("related_event_id",), can_delete=True)
    term = get_current_term()
    if request.method == "POST":
        formset = GroupPointsFormSet(
            request.POST,
            prefix="group_points",
            queryset=ElecteeGroupEvent.objects.filter(related_event_id=None, electee_group__term=term),
        )
        if formset.is_valid():
            formset.save()
            request.session["success_message"] = "Electee group points updated successfully"
            return redirect("electees:view_electee_groups")
        else:
            request.session["error_message"] = "Form is invalid. Please correct the noted errors."
    else:
        formset = GroupPointsFormSet(
            prefix="group_points",
            queryset=ElecteeGroupEvent.objects.filter(related_event_id=None, electee_group__term=term),
        )
    template = loader.get_template("generic_formset.html")
    context_dict = {
        "formset": formset,
        "prefix": "group_points",
        "subsubnav": "points",
        "has_files": False,
        "submit_name": "Update Electee Group Points",
        "form_title": "Update/Add Remove Electee Group Points",
        "help_text": "Track the electee group points. You should not note any points from threshold participation at service or social events here. Those are tabulated automatically.",
        "can_add_row": True,
        "base": "electees/base_electees.html",
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
コード例 #33
0
ファイル: views.py プロジェクト: tbpmig/mig-website
def add_survey_questions_for_term(request,term_id):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit the electee survey.'
        return redirect('electees:view_electee_groups')
    term = get_object_or_404(AcademicTerm,id=term_id)
    current_surveys = ElecteeInterviewSurvey.objects.filter(term = term)
    prefix='survey'
    if current_surveys.exists():
        current_survey=current_surveys[0]
        existed=True
    else:
        raise Http404

    if request.method =='POST':
        form = AddSurveyQuestionsForm(request.POST,prefix=prefix,instance=current_survey)
        if form.is_valid():
            form.save()
            request.session['success_message']='Electee survey questions updated successfully'
            return redirect('electees:manage_survey')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        form = AddSurveyQuestionsForm(prefix=prefix,instance=current_survey)
    template = loader.get_template('generic_form.html')
    verb = 'Update' if existed else 'Add'
    context_dict = {
        'form':form,
        'prefix':prefix,
        'has_files':False,
        'submit_name':'Update Electee Survey Questions',
        'form_title':verb+' Electee Survey Questions for %s'%(unicode(term)),
        'help_text':'Add questions for the particular term\'s survey.',
        'base':'electees/base_electees.html',
        'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
コード例 #34
0
ファイル: views.py プロジェクト: kylelady/mig-website
def edit_electee_resources(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session["error_message"] = "You are not authorized to edit electee resources."
        return redirect("electees:view_electee_groups")
    ResourceFormSet = modelformset_factory(ElecteeResource, exclude=("term",), can_delete=True)
    term = get_current_term()
    if request.method == "POST":
        formset = ResourceFormSet(
            request.POST, request.FILES, prefix="resources", queryset=ElecteeResource.objects.filter(term=term)
        )
        if formset.is_valid():
            instances = formset.save(commit=False)
            for instance in instances:
                instance.term = term
                instance.save()
            request.session["success_message"] = "Electee resources updated successfully"
            return redirect("electees:view_electee_groups")
        else:
            request.session["error_message"] = "Form is invalid. Please correct the noted errors."
    else:
        formset = ResourceFormSet(prefix="resources", queryset=ElecteeResource.objects.filter(term=term))
    template = loader.get_template("generic_formset.html")
    context_dict = {
        "formset": formset,
        "prefix": "resources",
        "has_files": True,
        "submit_name": "Update Electee Resources",
        "form_title": "Update/Add/Remove Electee Resources for %s" % (unicode(term)),
        "help_text": "These are the full packets and their constituent parts. If you need a part that isn't listed here, contact the web chair.",
        "can_add_row": True,
        "base": "electees/base_electees.html",
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))