-
Notifications
You must be signed in to change notification settings - Fork 8
Commit v0.32
Refactor user.user_role value/display constants
+4 -3 M mysql/scripts/seeddata.sql Comments 1
+1 -1 M web/app/decorators.py
+8 -4 M web/app/user/forms.py Comments 1
+3 -3 M web/app/user/templates/user_edit.html Comments 1
+19 -5 M web/app/user/templates/user_list.html Comments 1
+3 -7 M web/app/user/templates/user_profile.html Comments 1
+4 -8 M web/app/user/templates/user_view.html Comments 1
+1 -1 M web/app/user/views.py Comments 1
+7 -1 M web/config.py Comments 1
File mysql/scripts/seeddata.sql MODIFIED
Side-by-side diff View file Comment More
kwmccabe AUTHOR
Create test users for each user_role.
Reply Edit Delete 5 days ago
USE flaskapp;
DELETE FROM user;
-INSERT INTO user (user_role,keyname,user_email) VALUES (4,"admin","[email protected]");
-INSERT INTO user (user_role,keyname,user_email) VALUES (1,"user","[email protected]");
-INSERT INTO user (user_role,keyname,user_email) VALUES (0,"user2","[email protected]");
+INSERT INTO user (user_role,keyname,user_email) VALUES (3,"admin","[email protected]");
+INSERT INTO user (user_role,keyname,user_email) VALUES (2,"edit","[email protected]");
+INSERT INTO user (user_role,keyname,user_email) VALUES (1,"view","[email protected]");
+INSERT INTO user (user_role,keyname,user_email) VALUES (0,"none","[email protected]");
OPTIMIZE TABLE user;
DELETE FROM item;
File web/app/decorators.py MODIFIED
Side-by-side diff View file Comment More
if status in ['all','active','inactive']:
S['status'] = status
-
if user_role in ['-1','0','1','2','4']:
-
if user_role in ['-1','0','1','2','3']: S['user_role'] = int(user_role) if len(sort) > 0 and sort != S['sort']: S['sort'] = sort
File web/app/user/forms.py MODIFIED Side-by-side diff View file Comment More kwmccabe AUTHOR Update the initialization of user_role.choices to use current_app.config['USER_ROLE'] and related values. Reply Edit Delete 5 days ago import re
+from flask import current_app
from flask_wtf import FlaskForm
from wtforms import BooleanField, DecimalField, FloatField, IntegerField,
DateTimeField, DateField,
HiddenField, SubmitField
from wtforms.validators import Email, EqualTo, InputRequired, Length
from wtforms import ValidationError
-#from flask_pagedown.fields import PageDownField
from .models import UserModel
def filter_username(data): return re.sub('[^a-z0-9_-]', '', str(data).lower())
class EditUserForm(FlaskForm): id = HiddenField('id')
- user_role = SelectField('User Role') keyname = StringField('Username', validators=[InputRequired(),Length(2,63),validate_username], filters=[filter_username])
-
user_role = SelectField('User Role') user_email = StringField('Email', validators=[InputRequired(),Length(1,63),Email(),validate_usermail], filters=[filter_useremail]) password = PasswordField('Password', validators=[EqualTo('password2',message="Passwords must match.")]) password2 = PasswordField('Confirm Password')
def init(self, user, *args, **kwargs): super(EditUserForm, self).init(*args, **kwargs)
-
self.user_role.choices = [('4','Administrator'),('2','Editor'),('1','User'),('0','Inactive')]
-
self.user_role.choices = [ -
(str(current_app.config['USER_ROLE_ADMIN']),current_app.config['USER_ROLE'][current_app.config['USER_ROLE_ADMIN']]), -
(str(current_app.config['USER_ROLE_EDIT']), current_app.config['USER_ROLE'][current_app.config['USER_ROLE_EDIT']]), -
(str(current_app.config['USER_ROLE_VIEW']), current_app.config['USER_ROLE'][current_app.config['USER_ROLE_VIEW']]), -
(str(current_app.config['USER_ROLE_NONE']), current_app.config['USER_ROLE'][current_app.config['USER_ROLE_NONE']]), -
] self.user = user
File web/app/user/templates/user_edit.html MODIFIED Side-by-side diff View file Comment More kwmccabe AUTHOR Replace user_role constants with config values. Reply Edit Delete 5 days ago
{% block content %}
File web/app/user/templates/user_list.html MODIFIED Side-by-side diff View file Comment More kwmccabe AUTHOR Replace user_role constants with config values. Translate user_role value to string from config['USER_ROLE']. Reply Edit Delete 5 days ago Role <option value="-1"{% if session[opts_key]['user_role'] == -1 %} selected{% endif %}>All Users
-
<option value="4"{% if session[opts_key]['user_role'] == 4 %} selected{% endif %}>Administrators</option> -
<option value="2"{% if session[opts_key]['user_role'] == 2 %} selected{% endif %}>Editors</option> -
<option value="1"{% if session[opts_key]['user_role'] == 1 %} selected{% endif %}>Users</option> -
<option value="0"{% if session[opts_key]['user_role'] == 0 %} selected{% endif %}>Inactive</option>
-
<option value="{{ config['USER_ROLE_ADMIN'] }}"{% -
if session[opts_key]['user_role'] == config['USER_ROLE_ADMIN'] %} selected{% endif -
%}>{{ config['USER_ROLE'][config['USER_ROLE_ADMIN']] }}</option> -
<option value="{{ config['USER_ROLE_EDIT'] }}"{% -
if session[opts_key]['user_role'] == config['USER_ROLE_EDIT'] %} selected{% endif -
%}>{{ config['USER_ROLE'][config['USER_ROLE_EDIT']] }}</option> -
<option value="{{ config['USER_ROLE_VIEW'] }}"{% -
if session[opts_key]['user_role'] == config['USER_ROLE_VIEW'] %} selected{% endif -
%}>{{ config['USER_ROLE'][config['USER_ROLE_VIEW']] }}</option> -
<option value="{{ config['USER_ROLE_NONE'] }}"{% -
if session[opts_key]['user_role'] == config['USER_ROLE_NONE'] %} selected{% endif -
%}>{{ config['USER_ROLE'][config['USER_ROLE_NONE']] }}</option> </select>
@staticmethod
def init_app(app):
- FlaskApp Tutorial
- Table of Contents
- About
- Application Setup
- Modules, Templates, and Layouts
- Database Items, Forms, and CRUD
- List Filter, Sort, and Paginate
- Users and Login
- Database Relationships
- API Module, HTTPAuth and JSON
- Refactoring User Roles and Item Status
- AJAX and Public Pages