Added commenting system
Needs some styling, but it works ok.
This commit is contained in:
@@ -1,16 +1,13 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from application import db
|
from application import db
|
||||||
|
from application.forms import CommentForm
|
||||||
from application.models.users import *
|
from application.models.users import *
|
||||||
from application.models.applications import Application, Skill, ReviewersApplications
|
from application.models.applications import Application, Skill, ReviewersApplications, Comment
|
||||||
|
|
||||||
from flask import render_template, redirect, url_for, request, Blueprint
|
from flask import render_template, redirect, url_for, request, Blueprint
|
||||||
from flask.ext.security import login_required, roles_accepted
|
from flask.ext.security import login_required, roles_accepted
|
||||||
from flask.ext.security.core import current_user
|
from flask.ext.security.core import current_user
|
||||||
from flask_wtf import Form
|
|
||||||
from wtforms import TextField, TextAreaField, BooleanField, SelectMultipleField
|
|
||||||
from wtforms.validators import DataRequired
|
|
||||||
from wtforms.fields.html5 import URLField
|
|
||||||
from wtforms.validators import url
|
|
||||||
|
|
||||||
applications = Blueprint('applications', __name__)
|
applications = Blueprint('applications', __name__)
|
||||||
|
|
||||||
@@ -24,6 +21,9 @@ def index():
|
|||||||
@applications.route('/view/<int:id>')
|
@applications.route('/view/<int:id>')
|
||||||
@roles_accepted('bfct_board', 'bfct_manager', 'admin')
|
@roles_accepted('bfct_board', 'bfct_manager', 'admin')
|
||||||
def view(id):
|
def view(id):
|
||||||
|
|
||||||
|
comment_form = CommentForm()
|
||||||
|
|
||||||
review = ReviewersApplications.query.\
|
review = ReviewersApplications.query.\
|
||||||
filter_by(application_id=id).\
|
filter_by(application_id=id).\
|
||||||
filter_by(reviewer_blender_id=current_user.id).\
|
filter_by(reviewer_blender_id=current_user.id).\
|
||||||
@@ -37,7 +37,8 @@ def view(id):
|
|||||||
title='applications',
|
title='applications',
|
||||||
application=Application.query.get_or_404(id),
|
application=Application.query.get_or_404(id),
|
||||||
review=review,
|
review=review,
|
||||||
reviews=reviews)
|
reviews=reviews,
|
||||||
|
comment_form=comment_form)
|
||||||
|
|
||||||
@applications.route('/vote/<int:approved>/<int:id>')
|
@applications.route('/vote/<int:approved>/<int:id>')
|
||||||
@roles_accepted('bfct_board', 'bfct_manager', 'admin')
|
@roles_accepted('bfct_board', 'bfct_manager', 'admin')
|
||||||
@@ -92,3 +93,19 @@ def final_review(approved, id):
|
|||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(url_for('.view', id=id))
|
return redirect(url_for('.view', id=id))
|
||||||
|
|
||||||
|
|
||||||
|
@applications.route('/comment/<int:application_id>', methods=['POST'])
|
||||||
|
@roles_accepted('bfct_board', 'bfct_manager', 'admin')
|
||||||
|
def comment(application_id):
|
||||||
|
comment_form = CommentForm()
|
||||||
|
if comment_form.validate_on_submit():
|
||||||
|
comment = Comment(
|
||||||
|
blender_id=current_user.id,
|
||||||
|
application_id=application_id,
|
||||||
|
text=comment_form.text.data)
|
||||||
|
|
||||||
|
db.session.add(comment)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for('.view', id=application_id))
|
||||||
|
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
from application import app, db
|
from application import app, db
|
||||||
|
from application.forms import ApplicationForm
|
||||||
from application.emails import send_email_notification_new_submission
|
from application.emails import send_email_notification_new_submission
|
||||||
from application.models.users import *
|
from application.models.users import *
|
||||||
from application.models.applications import Application, Skill
|
from application.models.applications import Application, Skill
|
||||||
@@ -7,24 +8,6 @@ from flask import render_template, redirect, url_for, request, flash
|
|||||||
from flask.ext.security import login_required
|
from flask.ext.security import login_required
|
||||||
from flask.ext.security.core import current_user
|
from flask.ext.security.core import current_user
|
||||||
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
||||||
from flask_wtf import Form
|
|
||||||
from wtforms import TextField, TextAreaField, BooleanField, SelectMultipleField
|
|
||||||
from wtforms.validators import DataRequired
|
|
||||||
from wtforms.fields.html5 import URLField
|
|
||||||
from wtforms.validators import url
|
|
||||||
|
|
||||||
|
|
||||||
class ApplicationForm(Form):
|
|
||||||
network_profile = TextField('Blender Network Profile')
|
|
||||||
website = URLField(validators=[url(), DataRequired()])
|
|
||||||
city_country = TextField('City and Country', validators=[DataRequired()])
|
|
||||||
teaching = BooleanField('Teaching')
|
|
||||||
institution_name = TextField('School or institution name')
|
|
||||||
skills = SelectMultipleField('Areas of expertise', coerce=int)
|
|
||||||
video_example = URLField(validators=[url(), DataRequired()])
|
|
||||||
written_example = URLField(validators=[url(), DataRequired()])
|
|
||||||
portfolio_cv = URLField(validators=[url(), DataRequired()])
|
|
||||||
bio_message = TextAreaField('Your message for the board', validators=[DataRequired()])
|
|
||||||
|
|
||||||
|
|
||||||
# Views
|
# Views
|
||||||
|
20
blender-bfct/application/forms.py
Normal file
20
blender-bfct/application/forms.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from flask_wtf import Form
|
||||||
|
from wtforms import TextField, TextAreaField, BooleanField, SelectMultipleField
|
||||||
|
from wtforms.validators import DataRequired
|
||||||
|
from wtforms.fields.html5 import URLField
|
||||||
|
from wtforms.validators import url
|
||||||
|
|
||||||
|
class ApplicationForm(Form):
|
||||||
|
network_profile = TextField('Blender Network Profile')
|
||||||
|
website = URLField(validators=[url(), DataRequired()])
|
||||||
|
city_country = TextField('City and Country', validators=[DataRequired()])
|
||||||
|
teaching = BooleanField('Teaching')
|
||||||
|
institution_name = TextField('School or institution name')
|
||||||
|
skills = SelectMultipleField('Areas of expertise', coerce=int)
|
||||||
|
video_example = URLField(validators=[url(), DataRequired()])
|
||||||
|
written_example = URLField(validators=[url(), DataRequired()])
|
||||||
|
portfolio_cv = URLField(validators=[url(), DataRequired()])
|
||||||
|
bio_message = TextAreaField('Your message for the board', validators=[DataRequired()])
|
||||||
|
|
||||||
|
class CommentForm(Form):
|
||||||
|
text = TextAreaField('Your comment', validators=[DataRequired()])
|
@@ -1,6 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from application import app
|
from application import app, db
|
||||||
from application import db
|
|
||||||
from application.helpers import pretty_date
|
from application.helpers import pretty_date
|
||||||
from users import User
|
from users import User
|
||||||
|
|
||||||
@@ -83,3 +82,26 @@ class ReviewersApplications(db.Model):
|
|||||||
@property
|
@property
|
||||||
def reviewer(self):
|
def reviewer(self):
|
||||||
return User.query.get_or_404(self.reviewer_blender_id)
|
return User.query.get_or_404(self.reviewer_blender_id)
|
||||||
|
|
||||||
|
|
||||||
|
class Comment(db.Model):
|
||||||
|
"""Comments to an application. Only BFCT board members can add comments
|
||||||
|
via the applications review inferface"""
|
||||||
|
|
||||||
|
id = db.Column(db.Integer(), primary_key=True)
|
||||||
|
|
||||||
|
application_id = db.Column(db.Integer(), db.ForeignKey(Application.id), nullable=False)
|
||||||
|
application = db.relationship('Application', backref='comments')
|
||||||
|
|
||||||
|
blender_id = db.Column(db.Integer(), nullable=False)
|
||||||
|
text = db.Column(db.Text())
|
||||||
|
creation_date = db.Column(db.DateTime(), default=datetime.datetime.now)
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pretty_creation_date(self):
|
||||||
|
return pretty_date(self.creation_date)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user(self):
|
||||||
|
return User.query.get_or_404(self.blender_id)
|
||||||
|
@@ -133,6 +133,26 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<h2>Comments</h2>
|
||||||
|
{% for comment in application.comments %}
|
||||||
|
<p>{{comment.pretty_creation_date}}
|
||||||
|
<p>{{comment.user.first_name}} {{comment.user.last_name}}</p>
|
||||||
|
<p>{{comment.text}}</p>
|
||||||
|
<hr>
|
||||||
|
{% endfor %}
|
||||||
|
<form class="form-horizontal" method="POST" action="{{url_for('applications.comment', application_id=application.id)}}">
|
||||||
|
<fieldset>
|
||||||
|
{{ comment_form.hidden_tag() }}
|
||||||
|
{{ comment_form.text(class="form-controllo") }}
|
||||||
|
<button class="btn btn-default btn-squishy width-half pull-right offset-top-2" type="submit" value="Go">
|
||||||
|
Comment
|
||||||
|
</button>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if current_user.has_role('admin') %}
|
{% if current_user.has_role('admin') %}
|
||||||
{% if not application.review_end_date %}
|
{% if not application.review_end_date %}
|
||||||
|
Reference in New Issue
Block a user