mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 14:34:21 +01:00
Extra form.extra rendering into a macro
This commit is contained in:
@@ -40,8 +40,7 @@ def build_custom_user_fields(
|
|||||||
else:
|
else:
|
||||||
form_field.render_kw = {"data-initial": initial}
|
form_field.render_kw = {"data-initial": initial}
|
||||||
|
|
||||||
entry = (field.name, form_field)
|
fields.append(form_field)
|
||||||
fields.append(entry)
|
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
25
CTFd/themes/admin/templates/macros/forms.html
Normal file
25
CTFd/themes/admin/templates/macros/forms.html
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{% macro render_extra_fields(fields, show_labels=True, show_optionals=True, show_descriptions=True) -%}
|
||||||
|
{% for field in fields %}
|
||||||
|
<div class="form-group">
|
||||||
|
{% if show_labels %}
|
||||||
|
<b>{{ field.label }}</b>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if show_optionals %}
|
||||||
|
{% if field.flags.required is false %}
|
||||||
|
<small class="float-right text-muted align-text-bottom">Optional</small>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{{ field(class="form-control") }}
|
||||||
|
|
||||||
|
{% if show_descriptions %}
|
||||||
|
{% if field.description %}
|
||||||
|
<small class="form-text text-muted">
|
||||||
|
{{ field.description }}
|
||||||
|
</small>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{%- endmacro %}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
{% with form = Forms.users.UserCreateForm() %}
|
{% with form = Forms.users.UserCreateForm() %}
|
||||||
|
{% from "admin/macros/forms.html" import render_extra_fields %}
|
||||||
<form id="user-info-create-form" method="POST">
|
<form id="user-info-create-form" method="POST">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{{ form.name.label }}
|
{{ form.name.label }}
|
||||||
@@ -28,20 +29,7 @@
|
|||||||
{{ form.country(class="form-control custom-select") }}
|
{{ form.country(class="form-control custom-select") }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% for k, v in form.extra %}
|
{{ render_extra_fields(form.extra) }}
|
||||||
<div class="form-group">
|
|
||||||
<b>{{ v.label }}</b>
|
|
||||||
{% if v.flags.required is false %}
|
|
||||||
<small class="float-right text-muted align-text-bottom">Optional</small>
|
|
||||||
{% endif %}
|
|
||||||
{{ v(class="form-control") }}
|
|
||||||
{% if v.description %}
|
|
||||||
<small class="form-text text-muted">
|
|
||||||
{{ v.description }}
|
|
||||||
</small>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% with form = Forms.users.UserEditForm(obj=user) %}
|
{% with form = Forms.users.UserEditForm(obj=user) %}
|
||||||
|
{% from "admin/macros/forms.html" import render_extra_fields %}
|
||||||
<form id="user-info-edit-form">
|
<form id="user-info-edit-form">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{{ form.name.label }}
|
{{ form.name.label }}
|
||||||
@@ -25,20 +26,7 @@
|
|||||||
{{ form.country(class="form-control custom-select") }}
|
{{ form.country(class="form-control custom-select") }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% for k, v in form.extra %}
|
{{ render_extra_fields(form.extra) }}
|
||||||
<div class="form-group">
|
|
||||||
<b>{{ v.label }}</b>
|
|
||||||
{% if v.flags.required is false %}
|
|
||||||
<small class="float-right text-muted align-text-bottom">Optional</small>
|
|
||||||
{% endif %}
|
|
||||||
{{ v(class="form-control") }}
|
|
||||||
{% if v.description %}
|
|
||||||
<small class="form-text text-muted">
|
|
||||||
{{ v.description }}
|
|
||||||
</small>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline">
|
||||||
|
|||||||
25
CTFd/themes/core/templates/macros/forms.html
Normal file
25
CTFd/themes/core/templates/macros/forms.html
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{% macro render_extra_fields(fields, show_labels=True, show_optionals=True, show_descriptions=True) -%}
|
||||||
|
{% for field in fields %}
|
||||||
|
<div class="form-group">
|
||||||
|
{% if show_labels %}
|
||||||
|
<b>{{ field.label }}</b>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if show_optionals %}
|
||||||
|
{% if field.flags.required is false %}
|
||||||
|
<small class="float-right text-muted align-text-bottom">Optional</small>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{{ field(class="form-control") }}
|
||||||
|
|
||||||
|
{% if show_descriptions %}
|
||||||
|
{% if field.description %}
|
||||||
|
<small class="form-text text-muted">
|
||||||
|
{{ field.description }}
|
||||||
|
</small>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{%- endmacro %}
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% with form = Forms.auth.RegistrationForm() %}
|
{% with form = Forms.auth.RegistrationForm() %}
|
||||||
|
{% from "macros/forms.html" import render_extra_fields %}
|
||||||
<form method="post" accept-charset="utf-8" autocomplete="off" role="form">
|
<form method="post" accept-charset="utf-8" autocomplete="off" role="form">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<b>{{ form.name.label }}</b>
|
<b>{{ form.name.label }}</b>
|
||||||
@@ -47,20 +48,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{ form.nonce() }}
|
{{ form.nonce() }}
|
||||||
|
|
||||||
{% for k, v in form.extra %}
|
{{ render_extra_fields(form.extra) }}
|
||||||
<div class="form-group">
|
|
||||||
<b>{{ v.label }}</b>
|
|
||||||
{% if v.flags.required is false %}
|
|
||||||
<small class="float-right text-muted align-text-bottom">Optional</small>
|
|
||||||
{% endif %}
|
|
||||||
{{ v(class="form-control") }}
|
|
||||||
{% if v.description %}
|
|
||||||
<small class="form-text text-muted">
|
|
||||||
{{ v.description }}
|
|
||||||
</small>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
<div class="row pt-3">
|
<div class="row pt-3">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
{% include "components/errors.html" %}
|
{% include "components/errors.html" %}
|
||||||
|
|
||||||
{% with form = Forms.self.SettingsForm(country=country) %}
|
{% with form = Forms.self.SettingsForm(country=country) %}
|
||||||
|
{% from "macros/forms.html" import render_extra_fields %}
|
||||||
<form id="user-profile-form" method="post" accept-charset="utf-8" autocomplete="off" role="form"
|
<form id="user-profile-form" method="post" accept-charset="utf-8" autocomplete="off" role="form"
|
||||||
class="form-horizontal">
|
class="form-horizontal">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -62,13 +63,7 @@
|
|||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
{% for k, v in form.extra %}
|
{{ render_extra_fields(form.extra) }}
|
||||||
<div class="form-group">
|
|
||||||
<b>{{ v.label }}</b>
|
|
||||||
{{ v(class="form-control") }}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
|
|
||||||
<div id="results" class="form-group">
|
<div id="results" class="form-group">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user