finetune Form presentation
Ease the development of future forms Adapt tenant and user forms
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
.form-control {
|
||||||
|
border: 1px solid #d2d6da;
|
||||||
|
padding: 0.625rem 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-control:focus {
|
||||||
|
color: #495057;
|
||||||
|
background-color: transparent;
|
||||||
|
border-color: #d2d6da;
|
||||||
|
outline: 0;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons+Round" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons+Round" rel="stylesheet">
|
||||||
<!-- CSS Files -->
|
<!-- CSS Files -->
|
||||||
<link id="pagestyle" href="{{url_for('static', filename='/assets/css/material-kit-pro.css')}}" rel="stylesheet" />
|
<link id="pagestyle" href="{{url_for('static', filename='/assets/css/material-kit-pro.css')}}" rel="stylesheet" />
|
||||||
|
<link id="pagestyle" href="{{url_for('static', filename='/assets/css/eveai.css')}}" rel="stylesheet" />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="presentation-page bg-gray-200">
|
<body class="presentation-page bg-gray-200">
|
||||||
|
|||||||
24
eveai_app/templates/macros.html
Normal file
24
eveai_app/templates/macros.html
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{% macro render_field(field, disabled_fields=[], exclude_fields=[]) %}
|
||||||
|
{% set disabled = field.name in disabled_fields %}
|
||||||
|
{% set exclude_fields = exclude_fields + ['csrf_token', 'submit'] %}
|
||||||
|
{% if field.name not in exclude_fields %}
|
||||||
|
{% if field.type == 'BooleanField' %}
|
||||||
|
<div class="form-check">
|
||||||
|
{{ field(class="form-check-input", type="checkbox", id="flexSwitchCheckDefault") }}
|
||||||
|
{{ field.label(class="form-check-label", for="flexSwitchCheckDefault", disabled=disabled) }}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="form-group">
|
||||||
|
{{ field.label(class="form-label") }}
|
||||||
|
{{ field(class="form-control", disabled=disabled) }}
|
||||||
|
{% if field.errors %}
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{% for error in field.errors %}
|
||||||
|
{{ error }}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
21
eveai_app/templates/user/edit_tenant.html
Normal file
21
eveai_app/templates/user/edit_tenant.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
{% from "macros.html" import render_field %}
|
||||||
|
|
||||||
|
{% block title %}Update Tenant{% endblock %}
|
||||||
|
|
||||||
|
{% block content_title %}Update Tenant{% endblock %}
|
||||||
|
{% block content_description %}Update given tenant{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form method="post">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
{% set disabled_fields = ['name'] %}
|
||||||
|
{% set exclude_fields = [] %}
|
||||||
|
{% for field in form %}
|
||||||
|
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||||
|
{% endfor %}
|
||||||
|
<button type="submit" class="btn btn-primary">Update Tenant</button>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content_footer %} {% endblock %}
|
||||||
@@ -1,25 +1,18 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% from "macros.html" import render_field %}
|
||||||
{% block title %}Update User{% endblock %}
|
{% block title %}Update User{% endblock %}
|
||||||
|
|
||||||
{% block content_title %}Update User{% endblock %}
|
{% block content_title %}Update User{% endblock %}
|
||||||
{% block content_description %}Update given user account{% endblock %}
|
{% block content_description %}Update given user account{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
{% for field in form %}
|
{% set disabled_fields = ['email', 'user_name'] %}
|
||||||
<div class="form-group">
|
{% set exclude_fields = ['password', 'confirm_password'] %}
|
||||||
{{ field.label }}
|
{% for field in form %}
|
||||||
{{ field(class="form-control", disabled=true) if field.name in ['email', 'user_name'] else field(class="form-control") }}
|
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||||
{% if field.errors %}
|
{% endfor %}
|
||||||
<div class="alert alert-danger">
|
<button type="submit" class="btn btn-primary">Update User</button>
|
||||||
{% for error in field.errors %}
|
</form>
|
||||||
<p>{{ error }}</p>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
<button type="submit" class="btn btn-primary">Update User</button>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -1,29 +1,21 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
{% from "macros.html" import render_field %}
|
||||||
|
|
||||||
{% block title %}Tenant Details{% endblock %}
|
{% block title %}Tenant Registration{% endblock %}
|
||||||
|
|
||||||
|
{% block content_title %}Register Tenant{% endblock %}
|
||||||
|
{% block content_description %}Add a new tenant to EveAI{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form action="" method="post" novalidate>
|
<form method="post">
|
||||||
<p>
|
{{ form.hidden_tag() }}
|
||||||
{{ form.name.label }}<br>
|
{% set disabled_fields = [] %}
|
||||||
{{ form.name(size=80) }}
|
{% set exclude_fields = [] %}
|
||||||
</p>
|
{% for field in form %}
|
||||||
<p>
|
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||||
{{ form.website.label }}<br>
|
{% endfor %}
|
||||||
{{ form.website(size=80) }}
|
<button type="submit" class="btn btn-primary">Register Tenant</button>
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.license_start_date.label }}<br>
|
|
||||||
{{ form.license_start_date(size=20) }}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.license_end_date.label }}<br>
|
|
||||||
{{ form.license_end_date(size=20) }}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.allowed_monthly_interactions.label }}<br>
|
|
||||||
{{ form.allowed_monthly_interactions(size=20) }}
|
|
||||||
</p>
|
|
||||||
<p>{{ form.submit() }}</p>
|
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content_footer %} {% endblock %}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
{% from "macros.html" import render_field %}
|
||||||
|
|
||||||
{% block title %}User Registration{% endblock %}
|
{% block title %}User Registration{% endblock %}
|
||||||
|
|
||||||
@@ -6,45 +7,14 @@
|
|||||||
{% block content_description %}Make a new user account{% endblock %}
|
{% block content_description %}Make a new user account{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form action="" method="post">
|
<form method="post">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
<p>
|
{% set disabled_fields = [] %}
|
||||||
{{ form.user_name.label }}<br>
|
{% set exclude_fields = [] %}
|
||||||
{{ form.user_name(size=80) }}
|
{% for field in form %}
|
||||||
</p>
|
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||||
<p>
|
{% endfor %}
|
||||||
{{ form.email.label }}<br>
|
<button type="submit" class="btn btn-primary">Register User</button>
|
||||||
{{ form.email(size=80) }}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.password.label }}<br>
|
|
||||||
{{ form.password(size=80) }}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.confirm_password.label }}<br>
|
|
||||||
{{ form.confirm_password(size=80) }}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.first_name.label }}<br>
|
|
||||||
{{ form.first_name(size=80) }}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.last_name.label }}<br>
|
|
||||||
{{ form.last_name(size=80) }}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.is_active.label }}<br>
|
|
||||||
{{ form.is_active() }}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.valid_to.label }}<br>
|
|
||||||
{{ form.valid_to() }}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.tenant_id.label }}<br>
|
|
||||||
{{ form.tenant_id() }}
|
|
||||||
</p>
|
|
||||||
<p>{{ form.submit() }}</p>
|
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class UserForm(FlaskForm):
|
|||||||
confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), Length(min=8)])
|
confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), Length(min=8)])
|
||||||
first_name = StringField('First Name', validators=[DataRequired(), Length(max=80)])
|
first_name = StringField('First Name', validators=[DataRequired(), Length(max=80)])
|
||||||
last_name = StringField('Last Name', validators=[DataRequired(), Length(max=80)])
|
last_name = StringField('Last Name', validators=[DataRequired(), Length(max=80)])
|
||||||
is_active = BooleanField('Is Active')
|
is_active = BooleanField('Is Active', id='flexSwitchCheckDefault')
|
||||||
valid_to = DateField('Valid to', id='datepicker')
|
valid_to = DateField('Valid to', id='datepicker')
|
||||||
tenant_id = IntegerField('Tenant ID', validators=[NumberRange(min=0)])
|
tenant_id = IntegerField('Tenant ID', validators=[NumberRange(min=0)])
|
||||||
submit = SubmitField('Submit')
|
submit = SubmitField('Submit')
|
||||||
|
|||||||
@@ -64,6 +64,20 @@ def tenant():
|
|||||||
return render_template('user/tenant.html', form=form)
|
return render_template('user/tenant.html', form=form)
|
||||||
|
|
||||||
|
|
||||||
|
@user_bp.route('/tenant/<int:tenant_id>', methods=['GET', 'POST'])
|
||||||
|
def edit_tenant(tenant_id):
|
||||||
|
tenant = Tenant.query.get_or_404(tenant_id) # This will return a 404 if no tenant is found
|
||||||
|
form = TenantForm(obj=tenant)
|
||||||
|
|
||||||
|
if request.method == 'POST' and form.validate_on_submit():
|
||||||
|
# Populate the tenant with form data
|
||||||
|
form.populate_obj(tenant)
|
||||||
|
db.session.commit()
|
||||||
|
flash('User updated successfully.', 'success')
|
||||||
|
return redirect(url_for(f"user/tenant/tenant_id"))
|
||||||
|
|
||||||
|
return render_template('user/edit_tenant.html', form=form, tenant_id=tenant_id)
|
||||||
|
|
||||||
@user_bp.route('/user', methods=['GET', 'POST'])
|
@user_bp.route('/user', methods=['GET', 'POST'])
|
||||||
def user():
|
def user():
|
||||||
form = UserForm()
|
form = UserForm()
|
||||||
|
|||||||
Reference in New Issue
Block a user