HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //proc/thread-self/root/home/arjun/projects/buyercall/buyercall/templates/macros/form.jinja2
{# Render a form field's label with visual aid to see if it's required. #}
{%- macro field_label(field) -%}
    <label for="{{ field.id }}" class="control-label">
      {%- if field.flags and field.flags.required -%}
          {{ field.label.text }}
      {%- elif field.label %}
        {{ field.label.text }}
      {%- endif %}
    </label>
{%- endmacro -%}


{# Render a form field's errors. #}
{%- macro field_errors(f) -%}
  {% if f.errors %}
      <ul class="list-unstyled text-danger field-error">
        {% for error in f.errors %}
            <li>{{ error | e }}</li>
        {% endfor %}
      </ul>
  {% endif %}
{%- endmacro -%}


{# Render a form field. #}
{%- macro field(f, css_class='form-control') -%}
  {{ f(class=css_class, **kwargs) }}
{%- endmacro -%}

{# Render a password form field. #}
{%- macro password_field(f, css_class='form-control') -%}
<div class="input-group" style="display:block;">
    {{ f(class=css_class, **kwargs) }}
    <a href="#" class="toggle_hide_password">
        <i class="fa fa-eye-slash field-icon" aria-hidden="true"></i>
    </a>
  </div>
{%- endmacro -%}

{# Render a checkbox field. #}
{%- macro checkbox_field(f) -%}
  {{ f(type='checkbox', **kwargs) }} {{ f.label }}
{%- endmacro -%}


{# Render a file field. #}
{%- macro file_field(f, css_class='') -%}
  {{ f(class=css_class, **kwargs) }}
{%- endmacro -%}


{# Render a Bootstrap 3 form group with errors for various field types. #}
{%- macro password_form_group(f, css_class='') -%}
{% if f.errors %}
    {% set css_class = css_class + ' has-error ' + kwargs.pop('class', '') %}
  {% endif %}
    <div>
    {{ field_label(f) }}
    {{ password_field(f, **kwargs) }}
    </div>
{%- endmacro -%}


{%- macro form_group(f, css_class='') -%}
  {% if f.errors %}
    {% set css_class = css_class + ' has-error ' + kwargs.pop('class', '') %}
  {% endif %}

  {% if f.type == 'BooleanField' %}
  <div class="checkbox">
    <label>
    {{ checkbox_field(f, **kwargs) }}
  </div>
  {% elif f.type == 'FileField' %}
  <span class="btn btn-warning btn-round btn-file">
    <span class="fileinput-new"> Select Image </span>
    {{ file_field(f, **kwargs) }}
  </span>
  {% else %}
    {% if 'value' in kwargs.keys() %}
      {% if not kwargs['value'] %}
        {% set a = kwargs.pop('value') %}
        <div>
          {{ field_label(f) }}
          {{ field(f, value='', **kwargs) }}
        </div>
      {% else %}
        <div>
          {{ field_label(f) }}
          {{ field(f, **kwargs) }}
        </div>
      {% endif %}
    {% else %}
      <div>
        {{ field_label(f) }}
        {{ field(f, **kwargs) }}
      </div>
    {% endif %}
  {% endif %}
  <div>
    {{ field_errors(f) }}
    {{ caller () }}
  </div>
{%- endmacro %}

{# Render a form tag that contains a CSRF token and all hidden fields, it also
   properly supports all HTTP version, simply pass in method='delete', etc.. #}
{%- macro form_tag(endpoint, fid='', class='', method='post') -%}
  {% set method = method | lower %}
  {% set browser_method = 'post' %}
  {% set real_method = 'post' %}

  {% if method == 'get' %}
    {% set browser_method = 'get' %}
    {% set real_method = 'get' %}
  {% elif method not in ('get', 'post') %}
    {% set browser_method = 'post' %}
    {% set real_method = method %}
  {% endif %}

    <form action="{{ url_for(endpoint, **kwargs) }}"
          method="{{ browser_method }}"
          id="{{ fid }}" class="{{ class }}" role="form">
      {{ form.hidden_tag() }}
      {{ caller () }}
    </form>
{%- endmacro -%}


{# Render a form for searching. #}
{%- macro search(endpoint) -%}
  {% call form_tag(endpoint, class='top-margin', method='get') %}
      <div class="input-group sm-margin-bottom">
          <input type="text" class="form-control"
                 id="q" name="q" value="{{ request.args.get('q', '') }}"
                 placeholder="Search by typing, then press enter...">
      <span class="input-group-addon">
       <i class="material-icons">search</i>    <label for="password" class="control-label">Password
    </label>
      </span>
      </div>
  {% endcall %}
{%- endmacro -%}

{# Render a passoword field with many attributes #}
{%- macro password_form_group(f, css_class='') -%}
  {% if f.errors %}
    {% set css_class = css_class + ' has-error ' + kwargs.pop('class', '') %}
  {% endif %}
  {{ field_label(f) }}
  <div class="input-group auth-pass-inputgroup">
      {{ field(f, **kwargs) }}
      <button class="btn btn-light" type="button" id="password-addon">
      <iconify-icon id="pass-button" icon="ion:eye-off-outline" class="pt-1"></iconify-icon>
      </button>
  </div>
{% endmacro %}

{# Form checkbox custom #}
{%- macro form_group_checkbox(f, label='') -%}
  <div class="form-check">
    {{ field(f, **kwargs) }}
    <label for="{{ f.id }}" class="form-check-label">{{ label }}</label>
  </div>
{% endmacro %}

{# Select tag for dropdowns. Parameter iterator is dict type with key:value as value:label in jinja #}
{%- macro form_select(f, iterator, select_class='', option_class='', selected='en') -%}
  <select class="{{ select_class }}" **kwargs>
    {% for key,value in iterator.items() %}
      <option class="{{ option_class }}" value="{{ key }}" > {{ value }} </option>
    {% endfor %}
  </select>
{% endmacro %}}

{# Render a form tag that contains a CSRF token and all hidden fields, it also
   properly supports all HTTP version, simply pass in method='delete', etc.. #}
{%- macro form_tag_custom(endpoint, fid='', class='', method='post', form='', enctype='', name='') -%}
  {% set method = method | lower %}
  {% set browser_method = 'post' %}
  {% set real_method = 'post' %}

  {% if method == 'get' %}
    {% set browser_method = 'get' %}
    {% set real_method = 'get' %}
  {% elif method not in ('get', 'post') %}
    {% set browser_method = 'post' %}
    {% set real_method = method %}
  {% endif %}

  <form action="{{ url_for(endpoint) }}" id="{{ fid }}" class="{{ class }}" method="{{ browser_method }}" role="form", enctype="{{ enctype }}", name="{{ name }}">
    {{ form.hidden_tag() }}
    {{ caller () }}
  </form>
{%- endmacro -%}