diff --git a/blender-bfct/application/controllers/applications.py b/blender-bfct/application/controllers/applications.py index 2e47a14..044c2e3 100644 --- a/blender-bfct/application/controllers/applications.py +++ b/blender-bfct/application/controllers/applications.py @@ -6,7 +6,7 @@ from application.forms import CommentForm from application.models.users import * 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, abort from flask.ext.security import login_required, roles_accepted from flask.ext.security.core import current_user @@ -113,3 +113,22 @@ def comment(application_id): db.session.commit() return redirect(url_for('.view', id=application_id)) + +@applications.route('/edit//update-bfct-role/') +@roles_accepted('bfct_manager', 'admin') +def update_bfct_role(application_id): + application = Application.query.get_or_404(application_id) + user = User.query.get_or_404(application.blender_id) + applications = Application.query\ + .filter_by(blender_id=user.id)\ + .all() + + for application in applications: + if application.status == 'approved': + # TODO: additional check to see if application is valid + user_datastore.add_role_to_user(user, 'bfct_trainer') + db.session.commit() + else: + user_datastore.remove_role_from_user(user, 'bfct_trainer') + db.session.commit() + return redirect(url_for('.view', id=application_id)) diff --git a/blender-bfct/application/models/users.py b/blender-bfct/application/models/users.py index a2bdbd4..4ba427e 100644 --- a/blender-bfct/application/models/users.py +++ b/blender-bfct/application/models/users.py @@ -7,7 +7,6 @@ from application import db class User(db.Model, UserMixin): __bind_key__ = 'users' - __table_args__ = {'schema': 'blender-id'} id = db.Column(db.Integer(), primary_key=True) first_name = db.Column(db.String(255)) last_name = db.Column(db.String(255)) diff --git a/blender-bfct/application/templates/applications/view.html b/blender-bfct/application/templates/applications/view.html index 949f7c4..d5cc7fb 100755 --- a/blender-bfct/application/templates/applications/view.html +++ b/blender-bfct/application/templates/applications/view.html @@ -138,6 +138,14 @@ {% endif %} +
+
+ +