示例#1
0
def Create_Survey():
    if AUTHORITY_TEST("ADMIN") == False:
        return render_template("INVALID_AUTHORITY.html",
                               a1=current_user.authority,
                               a2="ADMIN")


#create not reviewed survey (by admin)
    s = model.Survey()
    sp = model.Surveys_Pool()
    form = Survey_Form()
    form.questionlist_init()
    if form.validate_on_submit():

        if s.form_admin_init(form) == False:
            #print("***************")
            return render_template('Create_Survey.html', form=form)
        else:
            #print(s)
            if sp.Create(s) == False:
                flash("Can't create survey!")
                print("Can't create survey!")
                return render_template('Create_Survey.html', form=form)
            return redirect(url_for('Survey_Pool'))
    return render_template('Create_Survey.html', form=form)
示例#2
0
            def create_surveys(hsons):
                surveys = []
                for hson in hsons:
                    survey = model.Survey(program=program,
                                          title=hson['title'],
                                          description=hson['description'],
                                          deleted=hson.get('deleted', False))
                    survey.structure = hson['structure']
                    session.add(survey)

                    # Explicitly add to collection because backref is one-way.
                    if not hson.get('deleted', False):
                        program.surveys.append(survey)

                    survey.qnodes = create_qnodes(hson['qnodes'], survey)
                    survey.qnodes.reorder()

                    if 'dependencies' in hson:
                        link_measures(survey, hson['dependencies'])

                    calculator = Calculator.structural()
                    calculator.mark_entire_survey_dirty(survey)
                    calculator.execute()
                    # print_survey(survey)
                return surveys
示例#3
0
def Edit_Survey(Survey_name):
    if AUTHORITY_TEST("ADMIN") == False:
        return render_template("INVALID_AUTHORITY.html",
                               a1=current_user.authority,
                               a2="ADMIN")
    sp = model.Surveys_Pool()
    s = model.Survey()
    s.Name = Survey_name
    if s.exist() == False:
        return render_template('Edit_Survey.html')
    s = sp.Get(Survey_name)
    form = c_Survey_Form()
    form.questionlist_init()
    if form.validate_on_submit():
        if s.form_edit(form, Survey_name) == False:
            return render_template('Edit_Survey.html', form=form)
        else:
            new_name = form.name.data
            s.Name = Survey_name
            if sp.Update(s, new_name) == False:
                flash("Can not edit Survey in Survey pool!")
                return render_template('Edit_Survey.html', form=form)
            else:
                return redirect(url_for('Survey_Pool'))
    form = s.form_create()
    return render_template('Edit_Survey.html', form=form)
示例#4
0
def Publish_to_public(Survey_name):
    if AUTHORITY_TEST("STAFF") == False:
        return render_template("INVALID_AUTHORITY.html",
                               a1=current_user.authority,
                               a2="STAFF")
    sp = model.Surveys_Pool()
    s = model.Survey()
    s.Name = Survey_name
    if s.exist() == False:
        flash("can't find survey name")
        return redirect(url_for('Survey_Pool'))
    s = sp.Get(Survey_name)
    sc = model.Student_Course()
    rv = sc.Get(current_user.id, s.Course_Semester)
    if rv == 1 and current_user.authority != "ADMIN":
        flash("You Are Not Enrolled in This Course!!!")
        if current_user.authority == "STAFF":
            return redirect(url_for('index'))
        return redirect(url_for('Survey_Pool'))
    s.publish_to_public()
    sp.Update(s)
    if current_user.authority == "STAFF":
        return redirect(url_for('index'))

    return redirect(url_for('Survey_Pool'))
示例#5
0
    def post(self, survey_id):
        '''Create new.'''
        if survey_id:
            raise errors.MethodError("Can't use POST for existing object")

        program_id = self.get_argument('programId', '')

        with model.session_scope() as session:
            user_session = self.get_user_session(session)

            program = (session.query(model.Program).options(
                joinedload('surveygroups')).get(program_id))
            if not program:
                raise errors.ModelError("No such program")

            ## set only last level indexing_form 1 if no value, remove other level indexing_form
            levels = len(self.request_son.structure.levels)

            for i, l in enumerate(self.request_son.structure.levels):
                if i + 1 != levels and l.indexing_from:
                    del l.indexing_from
                if i + 1 == levels and (
                    (not l.indexing_from and l.indexing_from != 0) or
                    (not isinstance(l.indexing_from, Number))
                        or l.indexing_from < 0):
                    l.indexing_from = 1

            survey = model.Survey(program=program)
            self._update(survey, self.request_son)
            session.add(survey)

            # Need to flush so object has an ID to record action against.
            session.flush()

            policy = user_session.policy.derive({
                'program':
                program,
                'survey':
                survey,
                'surveygroups':
                program.surveygroups,
            })
            policy.verify('surveygroup_interact')
            policy.verify('survey_add')

            act = Activities(session)
            act.record(user_session.user, survey, ['create'])
            act.ensure_subscription(user_session.user, survey, survey.program,
                                    self.reason)

            survey_id = str(survey.id)

        self.get(survey_id)
示例#6
0
def survey_display(Survey_name):

    if AUTHORITY_TEST(
            "STUDENT") == False and current_user.authority != "GUEST":
        return render_template("INVALID_AUTHORITY.html",
                               a1=current_user.authority,
                               a2="STUDENT")

    sp = model.Surveys_Pool()
    s = model.Survey()
    s.Name = Survey_name
    if s.exist() == False:
        return render_template('display_Survey.html', text="Survey not exist")
    s = sp.Get(Survey_name)

    sc = model.Student_Course()
    rv = sc.Get(current_user.id, s.Course_Semester)
    if rv == 1 and current_user.authority != "ADMIN":
        return render_template('display_Survey.html',
                               text="You Are Not Enrolled in This Course!!!")

    if s.survey_open() == False:
        return render_template('display_Survey.html',
                               text="Survey is not opened")

    form = s.create_survey_form()

    if form == False:
        return render_template('display_Survey.html',
                               text="Can not create form!")

    if form.validate_on_submit():
        print(s)
        if s.form_update_answer_attend(form, current_user.id) == False:
            return render_template('display_Survey.html',
                                   form=form,
                                   survey=s,
                                   text="")
        else:
            if sp.Update(s) == False:
                flash("Can not edit Survey in Survey pool!")
                return render_template('display_Survey.html',
                                       form=form,
                                       survey=s,
                                       text="")
            else:
                return render_template(
                    'Thankyou.html', message="Thank you for complete survey! ")

    return render_template('display_Survey.html', form=form, survey=s, text="")
示例#7
0
def Publish_Survey(Survey_name):
    if AUTHORITY_TEST("STAFF") == False:
        return render_template("INVALID_AUTHORITY.html",
                               a1=current_user.authority,
                               a2="STAFF")
    sp = model.Surveys_Pool()
    s = model.Survey()
    s.Name = Survey_name
    if s.exist() == False:
        if current_user.authority == "STAFF":
            return redirect(url_for('index'))
        return redirect(url_for('Survey_Pool'))
    s = sp.Get(Survey_name)
    s.publish()
    if sp.Update(s) == False:
        flash("Can not Publish Survey!")
    if current_user.authority == "STAFF":
        return redirect(url_for('index'))
    return redirect(url_for('Survey_Pool'))
示例#8
0
def Delete_Survey(Survey_name):
    if AUTHORITY_TEST("ADMIN") == False:
        return render_template("INVALID_AUTHORITY.html",
                               a1=current_user.authority,
                               a2="ADMIN")
    sp = model.Surveys_Pool()
    s = model.Survey()
    s.Name = Survey_name
    if s.exist() == False:
        return render_template('Delete_Survey.html')
    form = Delete_Form()

    if form.validate_on_submit():
        if sp.Delete(Survey_name) == False:
            flash("Can not delete survey in survey pool!")
            return render_template('Delete_Survey.html',
                                   form=form,
                                   name=Survey_name)
        else:
            return redirect(url_for('Survey_Pool'))
    return render_template('Delete_Survey.html', form=form, name=Survey_name)
示例#9
0
def Review_Survey(Survey_name):
    if AUTHORITY_TEST("STAFF") == False:
        return render_template("INVALID_AUTHORITY.html",
                               a1=current_user.authority,
                               a2="STAFF")
    sp = model.Surveys_Pool()
    s = model.Survey()
    s.Name = Survey_name
    if s.exist() == False:
        return render_template('Review_Survey.html')
    s = sp.Get(Survey_name)
    sc = model.Student_Course()
    rv = sc.Get(current_user.id, s.Course_Semester)
    if rv == 1 and current_user.authority != "ADMIN":
        flash("You are not enroll in this course!!!!!")
        if current_user.authority == "STAFF":
            return redirect(url_for('index'))
        return render_template('Review_Survey.html', )

    form = Optional_Q()
    form.questionlist_init()
    if form.validate_on_submit():
        if s.form_staff_append(form) == False:
            flash("Can not append optional question!")
            return render_template('Review_Survey.html', form=form, survey=s)
        else:
            if s.publish_to_public() == False:
                flash("Can not publish")
                return render_template('Edit_Survey.html', form=form)

            if sp.Update(s) == False:
                flash("Can not edit Survey in Survey pool!")
                return render_template('Edit_Survey.html', form=form)

            return redirect(url_for('Survey_Pool'))
    form.oq_list.data = [oq.Name for oq in s.Optional_Question_list]

    return render_template('Review_Survey.html', form=form, survey=s)
示例#10
0
def Survey_result(Survey_name):
    ct = model.Counter()
    ct2 = model.Counter()
    sp = model.Surveys_Pool()
    s = model.Survey()
    s.Name = Survey_name
    if s.exist() == False:
        return render_template('Survey_result.html')
    s = sp.Get(Survey_name)
    '''
    if AUTHORITY_TEST("STAFF") == False:
        if s.to_public():
            pass
        else:
            return render_template("INVALID_AUTHORITY.html",a1 = current_user.authority,a2 = "STAFF")
    '''
    sc = model.Student_Course()
    rv = sc.Get(current_user.id, s.Course_Semester)
    if current_user.authority == "ADMIN":
        return render_template('Survey_result.html',
                               survey=s,
                               c=ct,
                               c2=ct2,
                               a1=current_user.authority)
    if rv == 1:
        return render_template('display_Survey.html',
                               text="You Are Not Enrolled in This Course!!!")
    if s.survey_open() == False and s.State != "NOT_REVIEWED":
        return render_template('Survey_result.html',
                               survey=s,
                               c=ct,
                               c2=ct2,
                               a1=current_user.authority)
    else:
        return render_template('display_Survey.html',
                               text="Survey result closed")
示例#11
0
    def process_structure_file(self, all_rows, session, program):
        response_types = self.create_response_types(session, program)

        survey = model.Survey()
        survey.program = program
        survey.title = "Imported Survey"
        survey.description = None
        with open(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             'aquamark_hierarchy.json')) as data_file:
            survey.structure = json.load(data_file)
        session.add(survey)
        session.flush()

        log.info("survey: %s" % survey.id)

        function_title_row = [{
            "title": row[col2num("J")],
            "order": row[col2num("C")],
            "row_num": all_rows.index(row)
        } for row in all_rows if str(row[col2num("S")]) == "Function Header"]

        process_title_row = [{
            "title": row[col2num("J")],
            "order": row[col2num("D")],
            "row_num": all_rows.index(row)
        } for row in all_rows if str(row[col2num("S")]) == "Process Header"]

        subprocess_title_row = [{
            "title": row[col2num("J")],
            "order": row[col2num("E")],
            "row_num": all_rows.index(row)
        } for row in all_rows if str(row[col2num("S")]) == "SubProcess Header"]

        for function in function_title_row:
            function_order = int(function['order'])
            function_title = function['title'].replace(
                "{} - ".format(function_order), "")
            function_description = self.parse_description(
                all_rows, function['row_num'])

            qnode_function = model.QuestionNode()
            qnode_function.program = program
            qnode_function.survey = survey
            qnode_function.seq = function_order - 1
            qnode_function.title = function_title
            qnode_function.description = bleach.clean(function_description,
                                                      strip=True)

            session.add(qnode_function)
            session.flush()

            process_row = [
                row for row in process_title_row
                if "{}.".format(function_order) in row['title']
            ]

            for process in process_row:
                process_order = int(process['order'])
                process_title = process['title'].replace(
                    "{}.{} - ".format(function_order, process_order), "")

                # print("process order:", process_order)
                # print("process title:", process_title)
                process_description = self.parse_description(
                    all_rows, process['row_num'], "")

                qnode_process = model.QuestionNode()
                qnode_process.program = program
                qnode_process.survey = survey
                qnode_process.parent = qnode_function
                qnode_process.seq = process_order - 1
                qnode_process.title = process_title
                qnode_process.description = bleach.clean(process_description,
                                                         strip=True)
                # log.info("qnode_process: %s" % qnode_process)
                session.add(qnode_process)
                session.flush()

                subprocess_row = [
                    row for row in subprocess_title_row if "{}.{}.".format(
                        function_order, process_order) in row['title']
                ]
                for subprocess in subprocess_row:
                    subprocess_order = int(subprocess['order'])
                    subprocess_title = subprocess['title'].replace(
                        "{}.{}.{} - ".format(function_order, process_order,
                                             subprocess_order), "")

                    # print("subprocess order:", subprocess_order)
                    # print("subprocess title:", subprocess_title)
                    subprocess_description = self.parse_description(
                        all_rows, subprocess['row_num'], "")

                    qnode_subprocess = model.QuestionNode()
                    qnode_subprocess.program = program
                    qnode_subprocess.survey = survey
                    qnode_subprocess.parent = qnode_process
                    qnode_subprocess.seq = subprocess_order - 1
                    qnode_subprocess.title = subprocess_title
                    qnode_subprocess.description = bleach.clean(
                        subprocess_description, strip=True)

                    session.add(qnode_subprocess)
                    session.flush()

                    measure_title_row = [
                        {
                            "title": row[col2num("k")],
                            "row_num": all_rows.index(row),
                            "order": row[col2num("F")],
                            "weight": row[col2num("L")],
                            "resp_num": row[col2num("F")]
                        } for row in all_rows
                        if function_order == row[col2num("C")]
                        and process_order == row[col2num("D")]
                        and subprocess_order == row[col2num("E")]
                        and row[col2num("F")] != 0 and row[col2num("G")] == 1
                    ]

                    for measure in measure_title_row:
                        measure_order = int(measure["order"])
                        measure_title = measure['title'].replace(
                            "{}.{}.{}.{} - ".format(function_order,
                                                    process_order,
                                                    subprocess_order,
                                                    measure_order), "")

                        measure_description = self.parse_description(
                            all_rows, measure['row_num'], "Description")
                        # Comments are part of the response, so ignore that
                        # row
                        measure_weight = measure['weight']

                        m = model.Measure()
                        m.program = program
                        m.title = measure_title
                        m.weight = measure_weight
                        m.description = bleach.clean(measure_description,
                                                     strip=True)
                        rt_id = "standard"
                        if function_order == 7:
                            rt_id = "business-support-%s" % int(
                                measure['resp_num'])
                        # log.info("response_type: %s", rt_id)
                        m.response_type = response_types[rt_id]
                        session.add(m)
                        session.flush()
                        qnode_measure = model.QnodeMeasure(
                            program=program,
                            survey=survey,
                            qnode=qnode_subprocess,
                            measure=m)
                        qnode_subprocess.qnode_measures.reorder()
                        session.add(qnode_measure)
                        session.flush()

        calculator = Calculator.structural()
        calculator.mark_entire_survey_dirty(survey)
        calculator.execute()