当前位置: 首页>>代码示例>>Python>>正文


Python Permissions.can_complete_electee_survey方法代码示例

本文整理汇总了Python中mig_main.utility.Permissions.can_complete_electee_survey方法的典型用法代码示例。如果您正苦于以下问题:Python Permissions.can_complete_electee_survey方法的具体用法?Python Permissions.can_complete_electee_survey怎么用?Python Permissions.can_complete_electee_survey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mig_main.utility.Permissions的用法示例。


在下文中一共展示了Permissions.can_complete_electee_survey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_permissions

# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_complete_electee_survey [as 别名]
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
开发者ID:dadrian,项目名称:mig-website,代码行数:14,代码来源:views.py

示例2: complete_survey_for_term

# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_complete_electee_survey [as 别名]
def complete_survey_for_term(request,term_id):
    if not Permissions.can_complete_electee_survey(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)
    submitter=request.user.userprofile.memberprofile
    if current_surveys.exists():
        current_survey=current_surveys[0]
        existed=True
    else:
        raise Http404
    questions = current_survey.questions.all()
    if request.method =='POST':
        form = ElecteeSurveyForm(request.POST,questions=questions)
        if form.is_valid():
            print form.cleaned_data
            for (question, answer) in form.get_answers():

                existing_answer = SurveyAnswer.objects.filter(term=term,submitter=submitter,question=question)
                if existing_answer.exists():
                    old_answer = existing_answer[0]
                    if len(answer):
                        old_answer.answer=answer
                        old_answer.save()
                    else:
                        existing_answer.delete()
                    
                else:
                    if len(answer):
                        new_answer = SurveyAnswer(term=term,submitter=submitter,answer=answer,question=question)
                        new_answer.save()
            request.session['success_message']='Electee survey updated successfully'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        answers = SurveyAnswer.objects.filter(submitter=submitter,term=term,question__in=questions).distinct()
        form = ElecteeSurveyForm(questions=questions,answers=answers)
    template = loader.get_template('electees/complete_survey.html')
    
    context_dict = {
        'real_form':True,
        'form':form,
        'survey':current_survey,
        'questions':questions,
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context)) 
开发者ID:dadrian,项目名称:mig-website,代码行数:54,代码来源:views.py


注:本文中的mig_main.utility.Permissions.can_complete_electee_survey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。