Exemplo n.º 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)
Exemplo n.º 2
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)
Exemplo n.º 3
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'))
Exemplo n.º 4
0
def Public():
    if AUTHORITY_TEST("STAFF") == False:
        return render_template("INVALID_AUTHORITY.html",
                               a1=current_user.authority,
                               a2="STAFF")
    sp = model.Surveys_Pool()
    l = sp.Show()
    return render_template('Public.html', surveys=l)
Exemplo n.º 5
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="")
Exemplo n.º 6
0
def Survey_Pool():
    if AUTHORITY_TEST("STAFF") == False:
        return render_template("INVALID_AUTHORITY.html",
                               a1=current_user.authority,
                               a2="STAFF")
    if current_user.authority == "STAFF":
        return redirect(url_for('index'))
    sp = model.Surveys_Pool()
    sl = sp.Show()
    cl = []
    for s in sl:
        print(s)
        if s.Course_Semester not in cl:
            cl.append(s.Course_Semester)
    cl.sort()
    return render_template('Survey_Pool.html', surveys=sl, cl=cl)
Exemplo n.º 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'))
Exemplo n.º 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)
Exemplo n.º 9
0
def index():
    print(current_user.authority)
    print(current_user.id)
    sc = model.Student_Course()
    if current_user.authority == "STAFF" or current_user.authority == "STUDENT" or current_user.authority == "GUEST":
        sp = model.Surveys_Pool()
        sl = sp.Show()
        cl = []
        for s in sl:
            rv = sc.Get(current_user.id, s.Course_Semester)
            if rv == 1 and current_user.authority != "ADMIN":
                continue
            if s.Course_Semester not in cl:
                cl.append(s.Course_Semester)

        cl.sort()
        scl = sc.Show()
        cl2 = []
        for x in scl:
            if x[1] == int(current_user.id):
                cl2.append(x[0])
        cl2.sort()
        for x in cl2:
            if x not in cl:
                cl.append(x)

        if current_user.authority == "STUDENT" or current_user.authority == "GUEST":
            return render_template("student_index.html",
                                   ID=current_user.id,
                                   surveys=sl,
                                   cl=cl)
        else:
            return render_template("staff_index.html",
                                   ID=current_user.id,
                                   surveys=sl,
                                   cl=cl)
    g = model.Guest()
    gl = g.Show()
    return render_template('index.html', guest_list=gl)
Exemplo n.º 10
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)
Exemplo n.º 11
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")