admin.jinja2 3.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
{% extends "base_user.jinja2" %}
{% block title %}Zoe {{ kind }} admin{% endblock %}

{% block custom_head %}
{% endblock %}

{% block content %}
<h2>Zoe {{ kind }} admin</h2>

<table id="exec_list" class="app_list">
    <thead>
    <tr>
        <th>ID</th>
        {% for h in column_names %}
        <th>{{ h }}</th>
        {% endfor %}
        <th>Actions</th>
    </tr>
    </thead>
    <tbody>
    {% for row in rows|sort(attribute='id') %}
        {% set row_index = loop.index0 %}
        <tr>
            <td><form id="form{{ row_index }}" method="post" action="{{ reverse_url('admin_' + kind) }}"><input type="hidden" name="id" value="{{ row.id }}">{{ row.id }}</form></td>
        {% for key in column_keys %}
            {% if column_types[key] == None %}
                <td>{{ row[key] }}</td>
            {% elif column_types[key] == 'text' %}
                <td><input form="form{{ row_index }}" type="text" name="{{ key }}" value="{{ row[key] }}" title="{{ key }}"></td>
            {% elif column_types[key] == 'number' %}
                <td><input form="form{{ row_index }}" type="number" name="{{ key }}" value="{{ row[key] }}" title="{{ key }}"></td>
            {% elif column_types[key] == 'bytes' %}
                <td><input form="form{{ row_index }}" type="number" name="{{ key }}" value="{{ row[key]/(1024**3) }}" title="{{ key }}"></td>
            {% elif column_types[key] == 'bool' %}
                {% if row[key] %}
                <td><input form="form{{ row_index }}" type="checkbox" name="{{ key }}" checked title="{{ key }}"></td>
                {% else %}
                <td><input form="form{{ row_index }}" type="checkbox" name="{{ key }}" title="{{ key }}"></td>
                {% endif %}
            {% elif column_types[key] == 'list' %}
                <td>
                <select form="form{{ row_index }}" title="{{ key }}" name="{{ key }}">
                    {% for item in lists[key] %}
                        {% if row[key] == item %}
                        <option value="{{ item }}" selected>{{ item }}</option>
                        {% else %}
                        <option value="{{ item }}">{{ item }}</option>
                        {% endif %}
                    {% endfor %}
                </select>
                </td>
            {% endif %}
        {% endfor %}
            <td>
                <button form="form{{ row_index }}" name="action" type="submit" value="update">Update</button>
                <button form="form{{ row_index }}" name="action" type="submit" value="delete">Delete</button>
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    {% if kind != "users" %}
    <h3>Create new {{ kind }}</h3>
    <form method="post" action="{{ reverse_url('admin_' + kind) }}">
    {% for key in column_keys %}
    <label>
        {{ column_names[loop.index0] }}:
        {% if column_types[key] == 'text' or column_types[key] == None %}
            <input type="text" name="{{ key }}" title="{{ key }}">
        {% elif column_types[key] == 'number' %}
            <input type="number" name="{{ key }}" title="{{ key }}">
        {% elif column_types[key] == 'bytes' %}
            <input type="number" name="{{ key }}" title="{{ key }}">
        {% elif column_types[key] == 'bool' %}
            <input type="checkbox" name="{{ key }}" title="{{ key }}">
        {% elif column_types[key] == 'list' %}
            <select title="{{ key }}" name="{{ key }}">
                {% for item in lists[key] %}
                <option value="{{ item }}">{{ item }}</option>
                {% endfor %}
            </select>
        {% endif %}
    </label><br>
    {% endfor %}
    <button name="action" type="submit" value="create">Create</button>
    </form>
    {% endif %}
88
{% endblock %}