applications: add support for combo (#78738)

This commit is contained in:
Frédéric Péters 2023-06-19 21:39:16 +02:00
parent aa50d4e71b
commit 8efc84a7e1
3 changed files with 11 additions and 5 deletions

View File

@ -78,7 +78,7 @@ class UnlinkError(ApplicationError):
class Application(models.Model):
SUPPORTED_MODULES = ('wcs',)
SUPPORTED_MODULES = ('wcs', 'combo')
name = models.CharField(max_length=100, verbose_name=_('Name'))
slug = models.SlugField(max_length=100)

View File

@ -11,9 +11,11 @@
<div class="application-elements">
{% for category in categories %}
<div>
<h4>{{ category.name }}</h4>
{% if category.name %}<h4>{{ category.name }}</h4>{% endif %}
{% for element in category.elements %}
<label data-slugged-text="{{ element.text|slugify }}"><input type="checkbox" name="elements" value="{{ element.id }}">{{ element.text }}</label>
<label data-slugged-text="{{ element.text|slugify }}"><input
type="checkbox" name="elements" value="{{ element.id }}">
{{ element.indentation }}{{ element.text }}</label>
{% endfor %}
</div>
{% endfor %}

View File

@ -162,13 +162,15 @@ class AppAddElementView(TemplateView):
url = object_type['urls']['list']
response = requests.get(url)
elements = response.json()['data']
for element in elements:
element['indentation'] = '\u00a0' * 2 * int(element.get('indent', '0'))
category_names = {el.get('category') or '' for el in elements}
categories = [
Category(
name=c,
elements=sorted(
[el for el in elements if el.get('category') == c],
key=lambda a: slugify(a['text']),
key=lambda a: a.get('order', slugify(a['text'])),
),
)
for c in sorted(list(category_names))
@ -179,11 +181,13 @@ class AppAddElementView(TemplateView):
name=_('Uncategorized'),
elements=sorted(
[el for el in elements if not el.get('category')],
key=lambda a: slugify(a['text']),
key=lambda a: a.get('order', slugify(a['text'])),
),
)
)
context['categories'] = categories
if len(categories) == 1:
categories[0].name = ''
break
return context