mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
rework news form
This commit is contained in:
@ -894,6 +894,7 @@ Welcome to the wiki page!
|
||||
public_group = Group.objects.create(name="Public")
|
||||
|
||||
subscribers = Group.objects.create(name="Subscribers")
|
||||
subscribers.permissions.add(*list(perms.filter(codename__in=["add_news"])))
|
||||
old_subscribers = Group.objects.create(name="Old subscribers")
|
||||
old_subscribers.permissions.add(
|
||||
*list(
|
||||
|
@ -665,7 +665,9 @@ form {
|
||||
}
|
||||
|
||||
&:checked {
|
||||
background: var(--nf-input-focus-border-color) none initial;
|
||||
background: none;
|
||||
background-position: 0 0;
|
||||
background-color: var(--nf-input-focus-border-color);
|
||||
|
||||
&::after {
|
||||
transform: translateY(-50%) translateX(
|
||||
|
@ -436,8 +436,8 @@ body {
|
||||
$row-gap: 0.5rem;
|
||||
|
||||
&.gap {
|
||||
column-gap: var($col-gap);
|
||||
row-gap: var($row-gap);
|
||||
column-gap: $col-gap;
|
||||
row-gap: $row-gap;
|
||||
}
|
||||
|
||||
@for $i from 2 through 5 {
|
||||
|
@ -26,6 +26,7 @@ import datetime
|
||||
|
||||
import phonenumbers
|
||||
from django import template
|
||||
from django.forms import BoundField
|
||||
from django.template.defaultfilters import stringfilter
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ngettext
|
||||
@ -80,3 +81,43 @@ def format_timedelta(value: datetime.timedelta) -> str:
|
||||
return ngettext(
|
||||
"%(nb_days)d day, %(remainder)s", "%(nb_days)d days, %(remainder)s", days
|
||||
) % {"nb_days": days, "remainder": str(remainder)}
|
||||
|
||||
|
||||
@register.filter(name="add_attr")
|
||||
def add_attr(field: BoundField, attr: str):
|
||||
"""Add attributes to a form field directly in the template.
|
||||
|
||||
Attributes are `key=value` pairs, separated by commas.
|
||||
|
||||
Example:
|
||||
```jinja
|
||||
<form x-data="{alpineField: null}">
|
||||
{{ form.field|add_attr("x-model=alpineField") }}
|
||||
</form>
|
||||
```
|
||||
|
||||
will render :
|
||||
```html
|
||||
<form x-data="{alpineField: null}">
|
||||
<input type="..." x-model="alpineField">
|
||||
</form>
|
||||
```
|
||||
|
||||
Notes:
|
||||
Doing this gives the same result as setting the attribute
|
||||
directly in the python code.
|
||||
However, sometimes there are attributes that are tightly
|
||||
coupled to the frontend logic (like Alpine variables)
|
||||
and that shouldn't be declared outside of it.
|
||||
"""
|
||||
attrs = {}
|
||||
definition = attr.split(",")
|
||||
|
||||
for d in definition:
|
||||
if "=" not in d:
|
||||
attrs["class"] = d
|
||||
else:
|
||||
key, val = d.split("=")
|
||||
attrs[key] = val
|
||||
|
||||
return field.as_widget(attrs=attrs)
|
||||
|
Reference in New Issue
Block a user