diff --git a/eveai_app/static/assets/css/eveai.css b/eveai_app/static/assets/css/eveai.css index e69de29..dfbceb2 100644 --- a/eveai_app/static/assets/css/eveai.css +++ b/eveai_app/static/assets/css/eveai.css @@ -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; +} \ No newline at end of file diff --git a/eveai_app/templates/base.html b/eveai_app/templates/base.html index fe17e51..984bdde 100644 --- a/eveai_app/templates/base.html +++ b/eveai_app/templates/base.html @@ -20,6 +20,7 @@ + diff --git a/eveai_app/templates/macros.html b/eveai_app/templates/macros.html new file mode 100644 index 0000000..bfd73e5 --- /dev/null +++ b/eveai_app/templates/macros.html @@ -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' %} +
+ {{ field(class="form-check-input", type="checkbox", id="flexSwitchCheckDefault") }} + {{ field.label(class="form-check-label", for="flexSwitchCheckDefault", disabled=disabled) }} +
+ {% else %} +
+ {{ field.label(class="form-label") }} + {{ field(class="form-control", disabled=disabled) }} + {% if field.errors %} +
+ {% for error in field.errors %} + {{ error }} + {% endfor %} +
+ {% endif %} +
+ {% endif %} + {% endif %} +{% endmacro %} diff --git a/eveai_app/templates/user/edit_tenant.html b/eveai_app/templates/user/edit_tenant.html new file mode 100644 index 0000000..ec22a31 --- /dev/null +++ b/eveai_app/templates/user/edit_tenant.html @@ -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.hidden_tag() }} + {% set disabled_fields = ['name'] %} + {% set exclude_fields = [] %} + {% for field in form %} + {{ render_field(field, disabled_fields, exclude_fields) }} + {% endfor %} + +
+{% endblock %} + +{% block content_footer %} {% endblock %} diff --git a/eveai_app/templates/user/edit_user.html b/eveai_app/templates/user/edit_user.html index 3241bec..74b47f1 100644 --- a/eveai_app/templates/user/edit_user.html +++ b/eveai_app/templates/user/edit_user.html @@ -1,25 +1,18 @@ {% extends "base.html" %} +{% from "macros.html" import render_field %} {% block title %}Update User{% endblock %} {% block content_title %}Update User{% endblock %} {% block content_description %}Update given user account{% endblock %} {% block content %} -
- {{ form.hidden_tag() }} - {% for field in form %} -
- {{ field.label }} - {{ field(class="form-control", disabled=true) if field.name in ['email', 'user_name'] else field(class="form-control") }} - {% if field.errors %} -
- {% for error in field.errors %} -

{{ error }}

- {% endfor %} -
- {% endif %} -
- {% endfor %} - -
+
+ {{ form.hidden_tag() }} + {% set disabled_fields = ['email', 'user_name'] %} + {% set exclude_fields = ['password', 'confirm_password'] %} + {% for field in form %} + {{ render_field(field, disabled_fields, exclude_fields) }} + {% endfor %} + +
{% endblock %} diff --git a/eveai_app/templates/user/tenant.html b/eveai_app/templates/user/tenant.html index ef64aaa..71f082c 100644 --- a/eveai_app/templates/user/tenant.html +++ b/eveai_app/templates/user/tenant.html @@ -1,29 +1,21 @@ {% 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 %} -
-

- {{ form.name.label }}
- {{ form.name(size=80) }} -

-

- {{ form.website.label }}
- {{ form.website(size=80) }} -

-

- {{ form.license_start_date.label }}
- {{ form.license_start_date(size=20) }} -

-

- {{ form.license_end_date.label }}
- {{ form.license_end_date(size=20) }} -

-

- {{ form.allowed_monthly_interactions.label }}
- {{ form.allowed_monthly_interactions(size=20) }} -

-

{{ form.submit() }}

+ + {{ form.hidden_tag() }} + {% set disabled_fields = [] %} + {% set exclude_fields = [] %} + {% for field in form %} + {{ render_field(field, disabled_fields, exclude_fields) }} + {% endfor %} +
{% endblock %} + +{% block content_footer %} {% endblock %} diff --git a/eveai_app/templates/user/user.html b/eveai_app/templates/user/user.html index 76dc50e..df15128 100644 --- a/eveai_app/templates/user/user.html +++ b/eveai_app/templates/user/user.html @@ -1,4 +1,5 @@ {% extends 'base.html' %} +{% from "macros.html" import render_field %} {% block title %}User Registration{% endblock %} @@ -6,45 +7,14 @@ {% block content_description %}Make a new user account{% endblock %} {% block content %} -
+ {{ form.hidden_tag() }} -

- {{ form.user_name.label }}
- {{ form.user_name(size=80) }} -

-

- {{ form.email.label }}
- {{ form.email(size=80) }} -

-

- {{ form.password.label }}
- {{ form.password(size=80) }} -

-

- {{ form.confirm_password.label }}
- {{ form.confirm_password(size=80) }} -

-

- {{ form.first_name.label }}
- {{ form.first_name(size=80) }} -

-

- {{ form.last_name.label }}
- {{ form.last_name(size=80) }} -

-

- {{ form.is_active.label }}
- {{ form.is_active() }} -

-

- {{ form.valid_to.label }}
- {{ form.valid_to() }} -

-

- {{ form.tenant_id.label }}
- {{ form.tenant_id() }} -

-

{{ form.submit() }}

+ {% set disabled_fields = [] %} + {% set exclude_fields = [] %} + {% for field in form %} + {{ render_field(field, disabled_fields, exclude_fields) }} + {% endfor %} +
{% endblock %} diff --git a/eveai_app/views/user_forms.py b/eveai_app/views/user_forms.py index 1e6e15f..a5c22ea 100644 --- a/eveai_app/views/user_forms.py +++ b/eveai_app/views/user_forms.py @@ -19,7 +19,7 @@ class UserForm(FlaskForm): confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), Length(min=8)]) first_name = StringField('First 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') tenant_id = IntegerField('Tenant ID', validators=[NumberRange(min=0)]) submit = SubmitField('Submit') diff --git a/eveai_app/views/user_views.py b/eveai_app/views/user_views.py index ef4ae31..d6532f1 100644 --- a/eveai_app/views/user_views.py +++ b/eveai_app/views/user_views.py @@ -64,6 +64,20 @@ def tenant(): return render_template('user/tenant.html', form=form) +@user_bp.route('/tenant/', 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']) def user(): form = UserForm()