move user edit routes into their own module and blueprint

This commit is contained in:
dandds 2018-10-15 11:06:04 -04:00
parent 8ea99a7aa5
commit e7a117be33
6 changed files with 28 additions and 21 deletions

View File

@ -15,6 +15,7 @@ from atst.routes import bp
from atst.routes.workspaces import bp as workspace_routes
from atst.routes.requests import requests_bp
from atst.routes.dev import bp as dev_routes
from atst.routes.users import bp as user_routes
from atst.routes.errors import make_error_pages
from atst.domain.authnid.crl import CRLCache
from atst.domain.auth import apply_authentication
@ -57,6 +58,7 @@ def make_app(config):
app.register_blueprint(bp)
app.register_blueprint(workspace_routes)
app.register_blueprint(requests_bp)
app.register_blueprint(user_routes)
if ENV != "prod":
app.register_blueprint(dev_routes)

View File

@ -52,3 +52,10 @@ class User(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
self.has_workspaces,
self.id,
)
def to_dictionary(self):
return {
c.name: getattr(self, c.name)
for c in self.__table__.columns
if c.name not in ["id"]
}

View File

@ -10,7 +10,6 @@ from atst.domain.users import Users
from atst.domain.authnid import AuthenticationContext
from atst.domain.audit_log import AuditLog
from atst.domain.auth import logout as _logout
from atst.forms.edit_user import EditUserForm
bp = Blueprint("atst", __name__)
@ -119,19 +118,6 @@ def activity_history():
return render_template("audit_log.html", audit_events=audit_events)
@bp.route("/user")
def user():
form = EditUserForm(request.form)
user = g.current_user
return render_template("user/edit.html", form=form, user=user)
@bp.route("/save_user")
def save_user():
# no op
return redirect(url_for(".home"))
@bp.route("/about")
def about():
return render_template("about.html")

17
atst/routes/users.py Normal file
View File

@ -0,0 +1,17 @@
from flask import Blueprint, render_template, g, redirect, session, url_for, request
from atst.forms.edit_user import EditUserForm
bp = Blueprint("users", __name__)
@bp.route("/user")
def user():
user = g.current_user
form = EditUserForm(data=user.to_dictionary())
return render_template("user/edit.html", form=form, user=user)
@bp.route("/user", methods=["POST"])
def update_user():
return redirect(url_for(".home"))

View File

@ -20,7 +20,7 @@
</a>
{% endif %}
<a href="{{ url_for('atst.user') }}" class="topbar__link">
<a href="{{ url_for('users.user') }}" class="topbar__link">
<span class="topbar__link-label">{{ g.current_user.first_name + " " + g.current_user.last_name }}</span>
{{ Icon('avatar', classes='topbar__link-icon') }}
</a>

View File

@ -1,12 +1,7 @@
{% extends "base.html" %}
{% from "components/alert.html" import Alert %}
{% block content %}
<div class='col'>
{{ Alert('This form does not yet function',
message="<p>Functionality of this form is pending more engineering work. Engineers, please remove this alert when done.</p>",
level='warning'
) }}
<div class='panel'>
<div class='panel__heading'>
@ -17,7 +12,7 @@
</div>
</div>
{% set form_action = url_for('atst.save_user') %}
{% set form_action = url_for('users.user') %}
{% include "fragments/edit_user_form.html" %}
</div>