Projet

Général

Profil

0001-backoffice-use-a-template-to-render-category-page-53.patch

Frédéric Péters, 18 mai 2021 16:13

Télécharger (6,49 ko)

Voir les différences:

Subject: [PATCH 1/3] backoffice: use a template to render category page
 (#53667)

 tests/admin_pages/test_carddefcategory.py  |  4 +--
 tests/admin_pages/test_category.py         |  4 +--
 wcs/admin/categories.py                    | 41 ++++++----------------
 wcs/templates/wcs/backoffice/category.html | 32 +++++++++++++++++
 4 files changed, 47 insertions(+), 34 deletions(-)
 create mode 100644 wcs/templates/wcs/backoffice/category.html
tests/admin_pages/test_carddefcategory.py
75 75

  
76 76
    app = login(get_app(pub))
77 77
    resp = app.get('/backoffice/cards/categories/1/')
78
    assert 'no card model associated to this category' in resp.text
78
    assert 'No card model associated to this category' in resp.text
79 79

  
80 80
    resp = resp.click(href='edit')
81 81
    assert resp.forms[0]['name'].value == 'foobar'
......
127 127

  
128 128
    resp = app.get('/backoffice/cards/categories/1/')
129 129
    assert 'form bar' in resp.text
130
    assert 'no card model associated to this category' not in resp.text
130
    assert 'No card model associated to this category' not in resp.text
131 131

  
132 132

  
133 133
def test_categories_delete(pub):
tests/admin_pages/test_category.py
86 86

  
87 87
    app = login(get_app(pub))
88 88
    resp = app.get('/backoffice/forms/categories/1/')
89
    assert 'no form associated to this category' in resp.text
89
    assert 'No form associated to this category' in resp.text
90 90

  
91 91
    resp = resp.click(href='edit')
92 92
    assert resp.forms[0]['name'].value == 'foobar'
......
138 138

  
139 139
    resp = app.get('/backoffice/forms/categories/1/')
140 140
    assert 'form bar' in resp.text
141
    assert 'no form associated to this category' not in resp.text
141
    assert 'No form associated to this category' not in resp.text
142 142

  
143 143

  
144 144
def test_categories_delete(pub):
wcs/admin/categories.py
21 21
from wcs.carddef import CardDef
22 22
from wcs.categories import CardDefCategory, Category
23 23
from wcs.formdef import FormDef
24
from wcs.qommon import _
24
from wcs.qommon import _, template
25 25
from wcs.qommon.backoffice.menu import html_top
26 26
from wcs.qommon.form import Form, HtmlWidget, StringWidget, WysiwygTextWidget
27 27

  
......
84 84
    category_ui_class = CategoryUI
85 85
    formdef_class = FormDef
86 86
    usage_title = _('Forms in this category')
87
    empty_message = _('no form associated to this category')
87
    empty_message = _('No form associated to this category.')
88 88
    _q_exports = ['', 'edit', 'delete', 'description']
89
    do_not_call_in_templates = True
89 90

  
90 91
    def __init__(self, component):
91 92
        self.category = self.category_class.get(component)
......
94 95

  
95 96
    def _q_index(self):
96 97
        html_top('categories', title=self.category.name)
97
        r = TemplateIO(html=True)
98

  
99
        r += htmltext('<div id="appbar">')
100
        r += htmltext('<h2>%s</h2>') % self.category.name
101
        r += htmltext('<span class="actions">')
102
        r += htmltext('<a href="delete" rel="popup">%s</a>') % _('Delete')
103
        r += htmltext('<a href="edit">%s</a>') % _('Edit')
104
        r += htmltext('</span>')
105
        r += htmltext('</div>')
106

  
107
        if self.category.description:
108
            r += htmltext('<div class="bo-block">')
109
            r += self.category.get_description_html_text()
110
            r += htmltext('</div>')
98
        return template.QommonTemplateResponse(
99
            templates=['wcs/backoffice/category.html'],
100
            context={'view': self, 'category': self.category},
101
            is_django_native=True,
102
        )
111 103

  
104
    def get_formdefs(self):
112 105
        formdefs = self.formdef_class.select(order_by='name')
113
        formdefs = [x for x in formdefs if x.category_id == self.category.id]
114
        r += htmltext('<div class="bo-block">')
115
        r += htmltext('<h3>%s</h3>') % self.usage_title
116
        r += htmltext('<ul>')
117
        for formdef in formdefs:
118
            r += htmltext('<li><a href="../../%s/">') % str(formdef.id)
119
            r += formdef.name
120
            r += htmltext('</a></li>')
121
        if not formdefs:
122
            r += htmltext('<li>%s</li>') % self.empty_message
123
        r += htmltext('</ul>')
124
        r += htmltext('</div>')
125
        return r.getvalue()
106
        return [x for x in formdefs if x.category_id == self.category.id]
126 107

  
127 108
    def edit(self):
128 109
        form = self.category_ui.get_form()
......
193 174
    category_ui_class = CardDefCategoryUI
194 175
    formdef_class = CardDef
195 176
    usage_title = _('Card models in this category')
196
    empty_message = _('no card model associated to this category')
177
    empty_message = _('No card model associated to this category.')
197 178

  
198 179

  
199 180
class CategoriesDirectory(Directory):
wcs/templates/wcs/backoffice/category.html
1
{% extends "wcs/backoffice.html" %}
2
{% load i18n %}
3

  
4
{% block appbar-title %}{{ category.name }}{% endblock %}
5

  
6
{% block appbar-actions %}
7
<a href="delete" rel="popup">{% trans "Delete" %}</a>
8
<a href="edit">{% trans "Edit" %}</a>
9
{% endblock %}
10

  
11
{% block content %}
12
{{ block.super }}
13

  
14
{% if category.description %}
15
<div class="bo-block">{{ category.get_description_html_text|safe }}</div>
16
{% endif %}
17

  
18
<div class="section">
19
<h3>{% trans view.usage_title %}</h3>
20
{% with view.get_formdefs as formdefs %}
21
  {% if formdefs %}
22
  <ul class="objects-list single-links">
23
  {% for formdef in formdefs %}
24
  <li><a href="{{ formdef.get_admin_url }}">{{ formdef.name }}</a></li>
25
  {% endfor %}
26
  </ul>
27
  {% else %}
28
  <div><p>{% trans view.empty_message %}</p></div>
29
  {% endif %}
30
{% endwith %}
31
</div>
32
{% endblock %}
0
-