コード例 #1
0
ファイル: views.py プロジェクト: skadai/doubanJ
def movie_profile(movie_id):
    form = PostForm()
    if form.validate_on_submit():
        if not current_user.is_guest():
            post = Post(body=form.body.data,
                        author=current_user._get_current_object(),
                        movie_id=movie_id)
            db.session.add(post)
            db.session.commit()
            return redirect(url_for('.movie_profile', movie_id=movie_id))
        else:
            return redirect(url_for('auth.login'))
    movie = Movie.query.filter_by(id=movie_id).first_or_404()
    wishes = Wish.query.filter_by(movie_id=movie.id)
    users = [{
        'user': wish.seer,
        'timestamp': wish.timestamp
    } for wish in wishes]
    posts = [post for post in movie.posts.all()]
    return render_template('movie_profile.html',
                           form=form,
                           user=current_user,
                           movie=movie,
                           users=users,
                           posts=posts)
コード例 #2
0
def student(survey_id):
    # neccessary instance for survey creation
    s = Survey()
    res = Respond()
    error = None
    if current_user.is_admin() or current_user.is_staff():
        # the Admin and staff can preview the survey
        pass
    elif res.is_submitted(survey_id, current_user.get_id()) or \
    not (current_user.is_student() or current_user.is_guest()):
        return redirect(url_for("permission_deny"))

    # get the basic information for this survey_id
    this_survey = s.id_filter(survey_id).one()
    qids = s.get_qids(survey_id)
    if request.method == "POST":
        answerlist = []
        for qid in qids:
            try:
                # get all the answer form student
                # because the questoin_id in survey is start form 1
                # so add 1 in i and find the answer
                this_q = request.form[str(qid)]
                if not this_q:
                    error = "You must finish all the questions."
                answerlist.append(this_q)
            except:
                error = "You must finish all the questions."
        if not error:
            # push the recorded answers to database
            res.new_res(survey_id, current_user.get_id(), answerlist)
            return render_template("finish_survey.html")
    # get the question information form here
    q = Question()
    # all the question is here
    q_list = q.find_q(qids)


    return render_template("student.html", \
            course_name = this_survey[1]+" "+this_survey[2],\
            msg_err = error,\
            quest_list = q_list)
コード例 #3
0
def dashboard():

    # route by the current user type
    c = Course()
    # get the survey instance
    s = Survey()

    # muti type of user respond
    if current_user.is_student():
        return render_template('dash/student.html',\
                survey_l = s.get_survey_by_user(current_user.uid))
    if current_user.is_staff():
        return render_template('dash/staff.html',\
                survey_l = s.get_survey_by_user(current_user.uid))
    if current_user.is_admin():
        # get all the ongoning survey and all the courses
        return render_template('dash/admin.html',survey_l = s.get_survey(),\
                course_l= c.get_course(),guest_l = UserData().show_unguest(),\
                enrol_l = EnrolRequest().get_requests())
    if current_user.is_guest():
        return render_template('dash/guest.html',\
                    survey_l = s.get_survey_by_user(current_user.uid),\
                    course_l= c.get_course())
コード例 #4
0
def enrol(course_id):
    # enrol for guest
    if not current_user.is_guest():
        return redirect(url_for('permission_deny'))
    # record the error message
    error = None
    # sent this request to system
    try:
        current_user.enrol(course_id)
        # successful add this message
    except Exception as e:
        # not place to pront the error...
        error = format(e)
    if error:
        return render_template("msg.html",
                               msg_err_l=[
                                   'Error:', error,
                                   url_for("dashboard"), 'Return to Dashboard'
                               ])
    else:
        return render_template("msg.html",msg_suc_l=[
            "Successful Request","Your enrol has been sent to admin.",\
            url_for('dashboard'),"Return to Dashboard"
            ])
コード例 #5
0
def profile():
    if not current_user.is_guest():
        return render_template('profile.html')
    else:
        return render_template('guesterror.html')