Esempio n. 1
0
def edit_event(event_id):
    form = CommentForm()
    entry = Comment.query.filter_by(id = event_id).first_or_404()
    print entry.text2
    if form.validate_on_submit():
        comment = Comment(
            form.text.data,
            form.text2.data,
            form.longitude.data,
            form.latitude.data,
            form.date.data,
            datetime.now(),
            current_user.get_id()
        )
        entry.text = form.text.data 
        entry.text2 = form.text2.data
        entry.longitude = form.longitude.data
        entry.latitude = form.latitude.data
        entry.date = form.date.data
        db.session.commit()
        return redirect(url_for('my_events'))
    else:
        form = CommentForm(obj=entry)
        form.populate_obj(entry)
    return render_template('edit_event.html', entry=entry, form=form)
Esempio n. 2
0
def comment_new(id):
    post = Post.get_by_id(id)

    if post is None or post.is_hidden:
        abort(404)

    form = CommentForm()

    if form.is_submitted():
        try:
            if not form.validate():
                raise Exception(_('ERROR_INVALID_SUBMISSION'))

            comment = Comment(user=current_user, post=post)
            form.populate_obj(comment)
            comment.save()

            flash(_('COMMENT_SAVE_SUCESS'))

            if comment.parent_comment:
                send_email('reply_comment', comment)
            else:
                send_email('comment', post, comment)

            return redirect(
                url_for('stamp.show',
                        id=post.id,
                        _anchor='comment-%s' % comment.id))

        except Exception as e:
            flash(e.message, 'error')

    return render_template('main/stamp/show.html', post=post, form=form)
Esempio n. 3
0
def comment_new(id):
    post = Post.get_by_id(id)

    if post is None or post.is_hidden:
        abort(404)

    form = CommentForm()

    if form.is_submitted():
        try:
            if not form.validate():
                raise Exception(_('ERROR_INVALID_SUBMISSION'))

            comment = Comment(user=current_user, post=post)
            form.populate_obj(comment)
            comment.save()

            flash(_('COMMENT_SAVE_SUCESS'))

            if comment.parent_comment:
                send_email('reply_comment', comment)
            else:
                send_email('comment', post, comment)

            return redirect(url_for('stamp.show',
                                    id=post.id,
                                    _anchor='comment-%s' % comment.id))

        except Exception as e:
            flash(e.message, 'error')

    return render_template('main/stamp/show.html',
                           post=post,
                           form=form)
Esempio n. 4
0
def project_issue(num):
    issue = Issue.objects(number=num)[0]
    child_issues = Issue.objects(base_issue=num)
    comment = Comment()
    form = CommentForm(request.form, comment)
    if form.validate_on_submit():
        form.populate_obj(comment)
        comment.author = session['user_id']
        issue.comments.append(comment)
        issue.save()
        return redirect('/projects/issues/' + num)
    return render_template('projects_issue.html',
                           issue=issue,
                           child_issues=child_issues,
                           form=form)
Esempio n. 5
0
def project_issue(num):
    issue = Issue.objects(number=num)[0]
    child_issues = Issue.objects(base_issue=num)
    comment = Comment()
    form = CommentForm(request.form, comment)
    if form.validate_on_submit():
        form.populate_obj(comment)
        comment.author = session['user_id']
        issue.comments.append(comment)
        issue.save()
        return redirect('/projects/issues/' + num)
    return render_template('projects_issue.html',
                           issue=issue,
                           child_issues=child_issues,
                           form=form)
Esempio n. 6
0
def post(slug):
    p=Post.objects.get_or_404(slug=slug)
    tags=Post.objects.distinct('tags')
    print request.form
    form = CommentForm(request.form)
    print form.data
    print form.validate()
    if form.validate():
        comment = Comment()
        form.populate_obj(comment)
        p.comments.append(comment)
        p.save()
        return redirect(url_for('post', slug=slug))

    return render_template("post.html", title = p.title, p=p, tags=tags, form=form)
Esempio n. 7
0
def post_comment():
    from models import Post, Comment

    form = CommentForm(request.form)
    if form.validate():
        model = Comment()
        form.populate_obj(model)
        model.post = Post.query.filter_by(id=model.post_id).first()

        db.session.add(model)
        db.session.commit()

        comment = model.post.comments.order_by(Comment.id.desc()).first()

        return jsonify(comment.serialize)
    else:
        abort(500)