예제 #1
0
def create_post(option, id):
    if option == 'commit_comment':
        form = CommentForm()
        if form.is_submitted():
            if len(form.comment_post.data) >= 140 or len(form.comment_post.data) <= 5:
                flash('Your post must be between 5 and 140 characters!')
                return redirect(request.referrer)
            else:
                addition = CommitComment(commit_id=id, user_id=current_user.id, comment=form.comment_post.data)
    else:
        if option == 'commit':
            form = CommitForm()
        else:
            form = PostForm()
        assignment_id = form.assignment.data
        schoology_id = Assignment.query.filter_by(id=assignment_id).first().schoology_id
        if form.is_submitted() and option == 'commit':
            if len(form.post.data) <= 5:
                flash('Your post must be longer than 5 characters!')
                return redirect(request.referrer)
            elif len(form.post.data) >= 140:
                flash('Your post must be shorter than 140 characters!')
                return redirect(request.referrer)
            elif type(form.time_spent.data) != int:
                flash('Your time spent must be a number')
                return redirect(request.referrer)
            elif schoology_id is None:
                flash('You cannot post about a sample assignment')
                return redirect(request.referrer)
            else:
                addition = Commit(user_id=int(current_user.id), assignment_id=int(assignment_id), schoology_id=int(schoology_id),
                        body=str(form.post.data), time_spent=int(form.time_spent.data))
        if form.is_submitted() and option == 'post':
            if len(form.post.data) <= 12:
                flash('Your post must be longer than 12 characters!')
                return redirect(request.referrer)
            elif schoology_id is None:
                flash('You cannot post about a sample assignment')
                return redirect(request.referrer)
            else:
                addition = Post(user_id=int(current_user.id), assignment_id=int(assignment_id), schoology_id=int(schoology_id),
                                body=form.post.data)

    db.session.add(addition)
    db.session.commit()
    flash('Congratulations for posting!')
    return redirect(request.referrer)
예제 #2
0
def user(username):
    user = User.query.filter_by(username=username).first_or_404()
    comment_form = CommentForm()
    if comment_form.is_submitted():
        comment_form = CommentForm(formdata=None)
    page = request.args.get('page', 1, type=int)
    commits = user.commits.paginate(
        page, app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('explore', page=commits.next_num) \
        if commits.has_next else None
    prev_url = url_for('explore', page=commits.prev_num) \
        if commits.has_prev else None
    return render_template("user.html", user=user, comment_form=comment_form, posts=commits.items, next_url=next_url, prev_url=prev_url)
예제 #3
0
def index():
    commit_form = CommitForm()
    commit_form.course.choices = [(section.id, section.title) for section in current_user.sections]
    commit_form.assignment.choices = []
    if commit_form.is_submitted():
        commit_form = CommitForm(formdata=None)

    comment_form = CommentForm()
    if comment_form.is_submitted():
        comment_form = CommentForm(formdata=None)

    page = request.args.get('page', 1, type=int)
    posts = current_user.followed_commits().paginate(
        page, app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('index', page=posts.next_num) \
        if posts.has_next else None
    prev_url = url_for('index', page=posts.prev_num) \
        if posts.has_prev else None

    return render_template('index.html', title='Home', posts=posts.items, commit_form=commit_form, comment_form=comment_form, next_url=next_url, prev_url=prev_url,
                           )
예제 #4
0
def assignment(id):
    assignment = Assignment.query.filter_by(id=id).first_or_404()
    section = Section.query.filter_by(id=assignment.section_id).first_or_404()

    # commit form
    commit_form = CommitForm()
    set_options(commit_form, section, assignment)
    if commit_form.is_submitted():
        commit_form = CommitForm(formdata=None)
        set_options(commit_form, section, assignment)

    post_form = PostForm()
    set_options(post_form, section, assignment)
    if post_form.is_submitted():
        post_form = PostForm(formdata=None)
        set_options(post_form, section, assignment)

    comment_form = CommentForm()
    if comment_form.is_submitted():
        comment_form = CommentForm(formdata=None)

    return render_template('_assignment.html', assignment=assignment, commit_form=commit_form, post_form=post_form, comment_form=comment_form)