Ejemplo n.º 1
0
def surveyAddAction(request):
    # print request.REQUEST
    # 读取问卷标识
    paperIdSigned = request.REQUEST['paperId']

    # 验证问卷的数字签名
    sign = Signer()
    paperId = sign.unsign(paperIdSigned)
    # print  'paperId=', paperId

    # 检查用户的登录状态
    user = getCurrentUser(request)
    if user is None:
        raise Exception(u'没有登录')

    # 读取问卷并创建实例
    paper = Paper.objects.get(id=paperId)
    paperInstance = paper.createPaperInstance(user)
    # 如果文件设置了跳转,但其step却设置为False,这样很容易造成困扰
    # 这里对问卷在发布的时候强行修改step为True
    if paperInstance.isStepNeed():
        paperInstance.step = True
        paperInstance.save()

    # 创建survey对象
    survey = Survey()
    updateModelInstance(survey, request.REQUEST, tryUnsigned=True)
    survey.paper = paperInstance
    survey.createBy = user
    survey.modifyBy = user
    survey.save()

    # 设置文件到调查的反向连接,主要用于级联删除时使用
    paperInstance.survey = survey
    paperInstance.save()

    # 返回调查列表
    return HttpResponseRedirect(reverse('survey:view.survey.publish', args=[survey.id]))
Ejemplo n.º 2
0
def paperPreview(request, paperId):
    '''
    问卷预览
    '''
    # 检查用户的登录状态
    user = getCurrentUser(request)
    if user is None:
        raise Exception(u'没有登录')

    # 读取问卷并创建实例
    paper = Paper.objects.get(id=paperId)
    if paper.createBy != user:
        raise Exception(u'没有权限预览该问卷')

    # 在系统系统管理源的名下创建一个调查
    admin = User.objects.get(code='admin')
    paperInstance = paper.createPaperInstance(admin)
    # 如果文件设置了跳转,但其step却设置为False,这样很容易造成困扰
    # 这里对问卷在发布的时候强行修改step为True
    if paperInstance.isStepNeed():
        paperInstance.step = True
        paperInstance.save()

    # 创建survey对象
    survey = Survey()
    survey.paper = paperInstance
    survey.createBy = admin
    survey.modifyBy = admin
    survey.save()

    # 清理之前的预览对象, 关联当前预览对象
    if paper.previewSurvey:
        paper.previewSurvey.delete()
    paper.previewSurvey = survey
    paper.save()

    # 返回答题界面
    return HttpResponseRedirect(reverse('survey:view.survey.answer', args=[survey.id]))