Exemplo n.º 1
0
def organisation_survey(organisation_code=None):
    organisation = dqorganisations.organisations(organisation_code)
    # make sure survey exists
    dqsurveys.getOrCreateSurvey({'organisation_id':organisation.id})

    survey = dqsurveys.getSurvey(organisation_code)
    surveydata = dqsurveys.getSurveyDataAllWorkflows(organisation_code)
    workflows = dqsurveys.workflowsAll()
    pct_complete = completion_percentage(survey)
    users = dqusers.surveyPermissions(organisation_code)
    admin = usermanagement.check_perms('admin')
    loggedinuser = current_user
    checksurveyOK = dqsurveys.checkSurveyData(organisation_code)

    return render_template("surveys/survey.html", 
                           **locals())
Exemplo n.º 2
0
def organisation_survey_edit(organisation_code=None, workflow_name=None):
    
    workflow = dqsurveys.workflowByName(workflow_name)
    if not workflow:
        flash('That workflow does not exist.', 'error')
        return abort(404)

    organisation = dqorganisations.organisations(organisation_code)
    organisationsurvey = dqsurveys.getOrCreateSurvey({
                'organisation_id': organisation.id
                })

    def allowed(method):
        permission_name = "survey_" + workflow_name
        permission_value = {'organisation_code': organisation_code}
        return usermanagement.check_perms(permission_name,
                                          method,
                                          permission_value)
    allowed_to_edit = allowed("edit")
    allowed_to_view = allowed("view")

    def no_permission():
        # If not logged in, redirect to login page
        
        if not current_user.is_authenticated():
            flash('You must log in to access that page.', 'error')
            return redirect(url_for('login', next=request.path))

        # Otherwise, redirect to previous page and warn user
        # they don't have permissions to access the survey.
        flash("Sorry, you do not have permission to view that survey", 'error')
        if request.referrer is not None:
            redir_to = request.referrer
        else:
            redir_to = url_for('home')
        return redirect(redir_to)
    
    if not allowed_to_view:
        return no_permission()

    if request.method != 'POST':
        return organisation_survey_view(
            organisation_code, workflow, 
            workflow_name, organisationsurvey, allowed_to_edit)

    if not allowed_to_edit:
        return no_permission()

    handlers = {
        "collect": _survey_process_collect,
        "send": _survey_process_send,
        "review": _survey_process_review,
        "comment": _survey_process_comment,
        "finalreview": _survey_process_finalreview
        }

    workflow_name = workflow.WorkflowType.name

    if workflow_name == "send":
        if workflow.Workflow.id == organisationsurvey.currentworkflow_id:
            _survey_process_send(
                organisation_code, workflow, request, organisationsurvey)
        else:
            flash("Not possible to send survey to donor because it's "
                  "not at the current stage in the workflow. "
                  "Maybe you didn't submit the data, or maybe you "
                  "already sent it to the donor?", 'error')
    elif workflow_name in handlers:
        handlers[workflow_name](
            organisation, workflow, request, organisationsurvey)
    elif workflow_name == 'finalised':
        return "finalised"
    return redirect(url_for("organisations", 
                            organisation_code=organisation_code))