コード例 #1
0
ファイル: review.py プロジェクト: nellace/ustc-course
def new_review(course_id):
    course = Course.query.get(course_id)
    if not course:
        abort(404)
    user = current_user
    review = Review.query.filter_by(course=course, author=user).first()
    if not review:
        review = Review()
        review.course = course
        review.author = user
        is_new = True
    else:
        is_new = False

    message = ''
    form = ReviewForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            # check validity of term
            if str(form.term.data) not in course.term_ids:
                abort(404)

            if form.is_mobile.data:
                form.content.data = markdown.markdown(form.content.data)
            form.content.data, mentioned_users = editor_parse_at(form.content.data)
            form.content.data = sanitize(form.content.data)
            form.populate_obj(review)

            if is_new:
                review.add()
                for user in set(current_user.followers + course.followers + course.joined_users):
                    user.notify('review', review, ref_display_class='Course')
                # users can only receive @ notifications for new reviews
                for user in mentioned_users:
                    user.notify('mention', review)
            else:
                review.save()
            return redirect(url_for('course.view_course',course_id=course_id))
        else: # invalid submission, try again
            if form.content.data:
                review.content = sanitize(form.content.data)
            if form.difficulty.data:
                review.difficulty = form.difficulty.data
            if form.homework.data:
                review.homework = form.homework.data
            if form.gain.data:
                review.gain = form.gain.data
            if form.rate.data:
                review.rate = form.rate.data
            message = '提交失败,请编辑后重新提交!'

    polls = [
        {'name': 'difficulty', 'display': '课程难度', 'options': ['简单', '中等', '困难'] },
        {'name': 'homework', 'display': '作业多少', 'options': ['不多', '中等', '超多'] },
        {'name': 'grading', 'display': '给分好坏', 'options': ['超好', '厚道', '杀手'] },
        {'name': 'gain', 'display': '收获多少', 'options': ['很多', '一般', '没有'] },
    ]
    return render_template('new-review.html', form=form, course=course, review=review, polls=polls, message=message, is_new=is_new)
コード例 #2
0
def create_review():
    form = ReviewForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        data = Review()
        form.populate_obj(data)
        print(str(form))
        data.assigneeId = current_user.id
        db.session.add(data)
        db.session.commit()
        return data.to_dict()
    return('Invalid Info')
コード例 #3
0
ファイル: routes.py プロジェクト: myersc7/seniorproject
def sprint_endpoint(sprint_id):
    #gets the current retro data
    old_retro = Sprint.query.get(sprint_id)
    sprintretro = RetroForm(obj=old_retro)
    #populates the modal with the information and makes it editable
    if sprintretro.validate_on_submit():
        sprintretro.populate_obj(old_retro)
        Retro = str(sprintretro.Retro.data)
        if len(Retro) <= 200:
            db.engine.execute("UPDATE sprint SET Retro= \"" + Retro + "\" WHERE sprint_id= '" + sprint_id + "'")
            flash("Sprint Retrospective added")
            return redirect(url_for('sprint_endpoint', sprint_id=sprint_id))
        else:
            flash('Exceeded char limit.')

    #makes the review modal work
    old_review = Sprint.query.get(sprint_id)
    sprintreview = ReviewForm(obj=old_review)
    if sprintreview.validate_on_submit():
        sprintreview.populate_obj(old_retro)
        Review = str(sprintreview.Review.data)
        if len(Review) <= 200:
            db.engine.execute("UPDATE sprint SET Review= \"" + Review + "\" WHERE sprint_id= '" + sprint_id + "'")
            flash("Sprint Review added")
            return redirect(url_for('sprint_endpoint', sprint_id=sprint_id))
        else:
            flash('Exceeded char limit.')

    #gets project id
    project_id = str(
        db.engine.execute("select project_id from project_sprint_table where sprint_id ='" + sprint_id + "'").scalar())


    todo_us = db.engine.execute("select user_stories.user_stories_id from user_stories"
                                " join user_stories_sprint_table on (user_stories.user_stories_id = user_stories_sprint_table.user_stories_id)"
                                " where user_stories_sprint_table.sprint_id = '" + str(sprint_id) +
                                "' and user_stories.status = 'To do'")

    #sends an array of user story id that have the status "To do"
    todo = []
    for user_story in todo_us:
        todo.append(user_story[0])

    inprogress_us = db.engine.execute("select user_stories.user_stories_id from user_stories"
                                      " join user_stories_sprint_table on (user_stories.user_stories_id = user_stories_sprint_table.user_stories_id)"
                                      " where user_stories_sprint_table.sprint_id = '" + sprint_id +
                                      "' and user_stories.status = 'In Progress'")

    # sends an array of user story id that have the status "In progress"
    in_progress = []
    for ip_us in inprogress_us:
        in_progress.append(ip_us[0])

    done_us = db.engine.execute("select user_stories.user_stories_id from user_stories"
                                " join user_stories_sprint_table on (user_stories.user_stories_id = user_stories_sprint_table.user_stories_id)"
                                " where user_stories_sprint_table.sprint_id = '" + sprint_id +
                                "' and user_stories.status = 'Done'")

    # sends an array of user story id that have the status "Done"
    done = []
    for dn_us in done_us:
        done.append(dn_us[0])

    pb = db.engine.execute("select user_stories.user_stories_id from user_stories"
                           " join user_stories_project_table on (user_stories_project_table.user_stories_id = user_stories.user_stories_id)"
                           " where user_stories_project_table.project_id ='" + project_id +
                           "' and user_stories.status = 'PBI'")

    # sends an array of user story id that have the status "PBI"
    prod_back_ids = []
    for prod_back in pb:
        prod_back_ids.append(prod_back[0])

    #sends an array of the sprints associated with a project
    s_id = db.engine.execute("select sprint_id from project_sprint_table where project_id = " + project_id)
    sprint_ids = []
    for s in s_id:
        sprint_ids.append(s[0])

    return render_template('Sprint.html', title="Sprint Page", project_id=project_id, todo=todo, inprogress=in_progress,
                           done=done, prod_back_ids=prod_back_ids, get_title=get_title, get_difficulty=get_difficulty,
                           get_description=get_description, get_acceptance_criteria=get_acceptance_criteria,
                           sprintretro=sprintretro, sprintreview=sprintreview, sprint_ids=sprint_ids,
                           get_sprint_num=get_sprint_num, sprint_id=sprint_id)