0001-backoffice-style-formdefs-and-cards-index-pages-5965.patch
tests/admin_pages/test_card.py | ||
---|---|---|
43 | 43 |
def test_cards_list(pub): |
44 | 44 |
create_superuser(pub) |
45 | 45 | |
46 |
role = pub.role_class(name='foobar') |
|
47 |
role.store() |
|
48 | ||
46 | 49 |
CardDef.wipe() |
47 | 50 |
carddef = CardDef() |
48 | 51 |
carddef.name = 'card title' |
wcs/admin/forms.py | ||
---|---|---|
1682 | 1682 | |
1683 | 1683 |
section = 'forms' |
1684 | 1684 |
top_title = _('Forms') |
1685 |
index_template_name = 'wcs/backoffice/forms.html' |
|
1685 | 1686 |
import_title = _('Import Form') |
1686 | 1687 |
import_submit_label = _('Import Form') |
1687 | 1688 |
import_paragraph = _('You can install a new form by uploading a file ' 'or by pointing to the form URL.') |
... | ... | |
1717 | 1718 | |
1718 | 1719 |
def _q_index(self): |
1719 | 1720 |
self.html_top(title=self.top_title) |
1720 |
r = TemplateIO(html=True) |
|
1721 | 1721 |
get_response().add_javascript(['jquery.js', 'widget_list.js']) |
1722 |
r += self.form_actions() |
|
1723 | 1722 | |
1724 | 1723 |
global_access = is_global_accessible(self.section) |
1725 | 1724 | |
1726 |
cats = self.category_class.select() |
|
1727 |
self.category_class.sort_by_position(cats) |
|
1728 |
one = False |
|
1725 |
categories = self.category_class.select() |
|
1726 |
self.category_class.sort_by_position(categories) |
|
1727 |
categories.append(self.category_class(_('Misc'))) |
|
1728 | ||
1729 | 1729 |
formdefs = self.formdef_class.select(order_by='name', ignore_errors=True, lightweight=True) |
1730 |
for c in cats: |
|
1730 |
has_form_with_category_set = False |
|
1731 |
for category in categories: |
|
1731 | 1732 |
if not global_access: |
1732 | 1733 |
user_roles = set(get_request().user.get_roles()) |
1733 |
management_roles = {x.id for x in getattr(c, 'management_roles') or []} |
|
1734 |
management_roles = {x.id for x in getattr(category, 'management_roles') or []}
|
|
1734 | 1735 |
if not user_roles.intersection(management_roles): |
1735 | 1736 |
continue |
1736 |
l2 = [x for x in formdefs if str(x.category_id) == str(c.id)] |
|
1737 |
l2 = [x for x in formdefs if str(x.category_id) == str(category.id)]
|
|
1737 | 1738 |
l2 = [x for x in l2 if not x.disabled or (x.disabled and x.disabled_redirection)] + [ |
1738 | 1739 |
x for x in l2 if x.disabled and not x.disabled_redirection |
1739 | 1740 |
] |
1740 |
if l2: |
|
1741 |
r += self.form_list(l2, title=c.name) |
|
1742 |
one = True |
|
1743 | ||
1744 |
if global_access: |
|
1745 |
l2 = [x for x in formdefs if not x.category] |
|
1746 |
if l2: |
|
1747 |
if one: |
|
1748 |
title = _('Misc') |
|
1749 |
else: |
|
1750 |
title = None |
|
1751 |
l2 = [x for x in l2 if not x.disabled or (x.disabled and x.disabled_redirection)] + [ |
|
1752 |
x for x in l2 if x.disabled and not x.disabled_redirection |
|
1753 |
] |
|
1754 |
r += self.form_list(l2, title=title) |
|
1755 |
return r.getvalue() |
|
1756 | ||
1757 |
def form_actions(self): |
|
1758 |
r = TemplateIO(html=True) |
|
1759 |
has_roles = bool(get_publisher().role_class.count()) |
|
1760 |
r += htmltext('<div id="appbar">') |
|
1761 |
r += htmltext('<h2>%s</h2>') % _('Forms') |
|
1762 |
if has_roles: |
|
1763 |
r += htmltext('<span class="actions">') |
|
1764 |
if is_global_accessible('forms'): |
|
1765 |
r += htmltext('<a href="data-sources/">%s</a>') % _('Data sources') |
|
1766 |
r += htmltext('<a href="blocks/">%s</a>') % _('Fields blocks') |
|
1767 |
if get_publisher().get_backoffice_root().is_accessible('categories'): |
|
1768 |
r += htmltext('<a href="categories/">%s</a>') % _('Categories') |
|
1769 |
r += htmltext('<a href="import" rel="popup">%s</a>') % _('Import') |
|
1770 |
r += htmltext('<a class="new-item" href="new" rel="popup">%s</a>') % _('New Form') |
|
1771 |
r += htmltext('</span>') |
|
1772 |
r += htmltext('</div>') |
|
1773 | ||
1774 |
if not has_roles: |
|
1775 |
r += htmltext('<p>%s</p>') % _('You first have to define roles.') |
|
1776 |
return r.getvalue() |
|
1777 | ||
1778 |
def form_list(self, formdefs, title): |
|
1779 |
r = TemplateIO(html=True) |
|
1780 |
if title: |
|
1781 |
r += htmltext('<h2>%s</h2>') % title |
|
1782 | ||
1783 |
r += htmltext('<ul class="biglist">') |
|
1784 |
for formdef in formdefs: |
|
1785 |
if formdef.disabled: |
|
1786 |
r += htmltext('<li class="disabled">') |
|
1787 |
else: |
|
1788 |
r += htmltext('<li>') |
|
1789 |
r += htmltext('<strong class="label"><a href="%s/">%s</a></strong>') % (formdef.id, formdef.name) |
|
1790 |
if formdef.disabled and formdef.disabled_redirection: |
|
1791 |
r += htmltext('<a class="redirection" href="%s">(') % formdef.disabled_redirection |
|
1792 |
r += _('redirection') |
|
1793 |
r += htmltext(')</a>') |
|
1794 |
r += htmltext('</li>') |
|
1795 |
r += htmltext('</ul>') |
|
1796 |
return r.getvalue() |
|
1741 |
category.objects = l2 |
|
1742 |
if category.objects and category.id: |
|
1743 |
has_form_with_category_set = True |
|
1744 | ||
1745 |
if not has_form_with_category_set: |
|
1746 |
# no form with a category set, do not display "Misc" title |
|
1747 |
categories[-1].name = None |
|
1748 | ||
1749 |
context = { |
|
1750 |
'view': self, |
|
1751 |
'objects': formdefs, |
|
1752 |
'categories': categories, |
|
1753 |
'has_roles': bool(get_publisher().role_class.count()), |
|
1754 |
} |
|
1755 |
context.update(self.get_extra_index_context_data()) |
|
1756 | ||
1757 |
return template.QommonTemplateResponse(templates=[self.index_template_name], context=context) |
|
1758 | ||
1759 |
def get_extra_index_context_data(self): |
|
1760 |
return { |
|
1761 |
'is_global_accessible_forms': is_global_accessible('forms'), |
|
1762 |
'is_global_accessible_categories': get_publisher() |
|
1763 |
.get_backoffice_root() |
|
1764 |
.is_accessible('categories'), |
|
1765 |
} |
|
1797 | 1766 | |
1798 | 1767 |
def new(self): |
1799 | 1768 |
get_response().breadcrumb.append(('new', _('New'))) |
wcs/backoffice/cards.py | ||
---|---|---|
229 | 229 | |
230 | 230 |
section = 'cards' |
231 | 231 |
top_title = _('Card Models') |
232 |
index_template_name = 'wcs/backoffice/cards.html' |
|
232 | 233 |
import_title = _('Import Card Model') |
233 | 234 |
import_submit_label = _('Import Card Model') |
234 | 235 |
import_paragraph = _( |
... | ... | |
241 | 242 |
'you should nevertheless check everything is ok. ' |
242 | 243 |
) |
243 | 244 | |
244 |
def form_actions(self): |
|
245 |
r = TemplateIO(html=True) |
|
246 |
r += htmltext('<div id="appbar">') |
|
247 |
r += htmltext('<h2>%s</h2>') % _('Card Models') |
|
248 |
r += htmltext('<span class="actions">') |
|
249 |
if get_publisher().get_backoffice_root().is_global_accessible('forms'): |
|
250 |
r += htmltext('<a href="../forms/data-sources/">%s</a>') % _('Data sources') |
|
251 |
r += htmltext('<a href="../forms/blocks/">%s</a>') % _('Fields blocks') |
|
252 |
if get_publisher().get_backoffice_root().is_global_accessible('cards'): |
|
253 |
r += htmltext('<a href="categories/">%s</a>') % _('Categories') |
|
254 |
r += htmltext('<a href="import" rel="popup">%s</a>') % _('Import') |
|
255 |
r += htmltext('<a class="new-item" href="new" rel="popup">%s</a>') % _('New Card Model') |
|
256 |
r += htmltext('</span>') |
|
257 |
r += htmltext('</div>') |
|
258 |
return r.getvalue() |
|
245 |
def get_extra_index_context_data(self): |
|
246 |
context = super().get_extra_index_context_data() |
|
247 |
context['is_global_accessible_cards'] = ( |
|
248 |
get_publisher().get_backoffice_root().is_global_accessible('cards') |
|
249 |
) |
|
250 |
return context |
|
259 | 251 | |
260 | 252 |
def new(self): |
261 | 253 |
get_response().breadcrumb.append(('new', _('New'))) |
wcs/templates/wcs/backoffice/cards.html | ||
---|---|---|
1 |
{% extends "wcs/backoffice/forms.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block appbar-title %}{% trans "Card Models" %}{% endblock %} |
|
5 | ||
6 |
{% block appbar-actions %} |
|
7 |
{% if is_global_accessible_forms %} |
|
8 |
<a href="../forms/data-sources/">{% trans "Data sources" %}</a> |
|
9 |
<a href="../forms/blocks/">{% trans "Fields blocks" %}</a> |
|
10 |
{% endif %} |
|
11 |
{% if is_global_accessible_cards %} |
|
12 |
<a href="categories/">{% trans "Categories" %}</a> |
|
13 |
{% endif %} |
|
14 |
<a rel="popup" href="import">{% trans "Import" %}</a> |
|
15 |
<a rel="popup" href="new">{% trans "New Card Model" %}</a> |
|
16 |
{% endblock %} |
|
17 | ||
18 |
{% block no-objects %} |
|
19 |
{% trans "There are no card models defined." %} |
|
20 |
{% endblock %} |
wcs/templates/wcs/backoffice/forms.html | ||
---|---|---|
1 |
{% extends "wcs/backoffice/base.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block appbar-title %}{% trans "Forms" %}{% endblock %} |
|
5 | ||
6 |
{% block appbar-actions %} |
|
7 |
{% if has_roles %} |
|
8 |
{% if is_global_accessible_forms %} |
|
9 |
<a href="data-sources/">{% trans "Data sources" %}</a> |
|
10 |
<a href="blocks/">{% trans "Fields blocks" %}</a> |
|
11 |
{% if is_global_accessible_categories %} |
|
12 |
<a href="categories/">{% trans "Categories" %}</a> |
|
13 |
{% endif %} |
|
14 |
{% endif %} |
|
15 |
<a rel="popup" href="import">{% trans "Import" %}</a> |
|
16 |
<a rel="popup" href="new">{% trans "New Form" %}</a> |
|
17 |
{% endif %} |
|
18 |
{% endblock %} |
|
19 | ||
20 |
{% block content %} |
|
21 |
{% if not has_roles %} |
|
22 |
<p>{% trans "You first have to define roles." %}</p> |
|
23 |
{% elif objects %} |
|
24 |
{% for category in categories %} |
|
25 |
{% if category.objects %} |
|
26 |
<div class="section"> |
|
27 |
{% if category.name %}<h2>{{ category.name }}</h2>{% endif %} |
|
28 |
<ul class="objects-list single-links"> |
|
29 |
{% for item in category.objects %} |
|
30 |
<li {% if item.disabled %}class="disabled"{% endif %}><a href="{{ item.id }}/">{{ item.name }} |
|
31 |
{% if item.disabled and item.disabled_redirection %} |
|
32 |
<span class="extra-info">- {% trans "redirection" %}</span> |
|
33 |
{% endif %} |
|
34 |
</a> |
|
35 |
</li> |
|
36 |
{% endfor %} |
|
37 |
</ul> |
|
38 |
</div> |
|
39 |
{% endif %} |
|
40 |
{% endfor %} |
|
41 |
{% else %} |
|
42 |
<div class="infonotice"> |
|
43 |
{% block no-objects %} |
|
44 |
{% trans "There are no forms defined." %} |
|
45 |
{% endblock %} |
|
46 |
</div> |
|
47 |
{% endif %} |
|
48 |
{% endblock %} |
|
0 |
- |