diff --git a/blender-bfct/application/controllers/applications.py b/blender-bfct/application/controllers/applications.py index 88f4fba..b64b024 100644 --- a/blender-bfct/application/controllers/applications.py +++ b/blender-bfct/application/controllers/applications.py @@ -1,16 +1,13 @@ import datetime from application import db +from application.forms import CommentForm 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.ext.security import login_required, roles_accepted 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__) @@ -24,6 +21,9 @@ def index(): @applications.route('/view/') @roles_accepted('bfct_board', 'bfct_manager', 'admin') def view(id): + + comment_form = CommentForm() + review = ReviewersApplications.query.\ filter_by(application_id=id).\ filter_by(reviewer_blender_id=current_user.id).\ @@ -37,7 +37,8 @@ def view(id): title='applications', application=Application.query.get_or_404(id), review=review, - reviews=reviews) + reviews=reviews, + comment_form=comment_form) @applications.route('/vote//') @roles_accepted('bfct_board', 'bfct_manager', 'admin') @@ -92,3 +93,19 @@ def final_review(approved, id): db.session.commit() return redirect(url_for('.view', id=id)) + + +@applications.route('/comment/', 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)) + diff --git a/blender-bfct/application/controllers/main.py b/blender-bfct/application/controllers/main.py index 796939f..1e68d17 100644 --- a/blender-bfct/application/controllers/main.py +++ b/blender-bfct/application/controllers/main.py @@ -1,4 +1,5 @@ from application import app, db +from application.forms import ApplicationForm from application.emails import send_email_notification_new_submission from application.models.users import * 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.core import current_user 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 diff --git a/blender-bfct/application/forms.py b/blender-bfct/application/forms.py new file mode 100644 index 0000000..85ddbce --- /dev/null +++ b/blender-bfct/application/forms.py @@ -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()]) diff --git a/blender-bfct/application/models/applications.py b/blender-bfct/application/models/applications.py index e38dfc3..8f925c0 100644 --- a/blender-bfct/application/models/applications.py +++ b/blender-bfct/application/models/applications.py @@ -1,6 +1,5 @@ import datetime -from application import app -from application import db +from application import app, db from application.helpers import pretty_date from users import User @@ -83,3 +82,26 @@ class ReviewersApplications(db.Model): @property def reviewer(self): 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) diff --git a/blender-bfct/application/templates/applications/view.html b/blender-bfct/application/templates/applications/view.html index 12f3682..217c891 100755 --- a/blender-bfct/application/templates/applications/view.html +++ b/blender-bfct/application/templates/applications/view.html @@ -133,6 +133,26 @@ {% endif %} +
+
+

Comments

+ {% for comment in application.comments %} +

{{comment.pretty_creation_date}} +

{{comment.user.first_name}} {{comment.user.last_name}}

+

{{comment.text}}

+
+ {% endfor %} +
+
+ {{ comment_form.hidden_tag() }} + {{ comment_form.text(class="form-controllo") }} + +
+
+
+
{% if current_user.has_role('admin') %} {% if not application.review_end_date %}