mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-15 02:33:22 +00:00
Convert the whole request to json at once on select widget
This commit is contained in:
parent
3eb3feea49
commit
e583e78a4e
@ -165,9 +165,8 @@ export abstract class AjaxSelect extends AutoCompleteSelectBase {
|
|||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
/* Capture initial values before they get moved to the inner node and overridden by tom-select */
|
/* Capture initial values before they get moved to the inner node and overridden by tom-select */
|
||||||
this.initialValues = Array.from(this.children)
|
const initial = this.querySelector("slot[name='initial']")?.textContent;
|
||||||
.filter((child: Element) => child.tagName.toLowerCase() === "slot")
|
this.initialValues = initial ? JSON.parse(initial) : [];
|
||||||
.map((slot) => JSON.parse(slot.innerHTML));
|
|
||||||
|
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,5 @@
|
|||||||
<optgroup label="{{ group_name }}">{% endif %}{% for widget in group_choices %}
|
<optgroup label="{{ group_name }}">{% endif %}{% for widget in group_choices %}
|
||||||
{% include widget.template_name %}{% endfor %}{% if group_name %}
|
{% include widget.template_name %}{% endfor %}{% if group_name %}
|
||||||
</optgroup>{% endif %}{% endfor %}
|
</optgroup>{% endif %}{% endfor %}
|
||||||
{% for sel in selected %}<slot style="display: none">{{ sel }}</slot>{% endfor %}
|
{% if initial %}<slot style="display:none" name="initial">{{ initial }}</slot>{% endif %}
|
||||||
</{{ component }}>
|
</{{ component }}>
|
@ -2,6 +2,7 @@ from django.contrib.staticfiles.storage import staticfiles_storage
|
|||||||
from django.db.models import Model
|
from django.db.models import Model
|
||||||
from django.forms import Select, SelectMultiple
|
from django.forms import Select, SelectMultiple
|
||||||
from ninja import ModelSchema
|
from ninja import ModelSchema
|
||||||
|
from pydantic import TypeAdapter
|
||||||
|
|
||||||
from core.models import Group, SithFile, User
|
from core.models import Group, SithFile, User
|
||||||
from core.schemas import GroupSchema, SithFileSchema, UserProfileSchema
|
from core.schemas import GroupSchema, SithFileSchema, UserProfileSchema
|
||||||
@ -46,9 +47,10 @@ class AutoCompleteSelectMixin:
|
|||||||
"css": [staticfiles_storage.url(file) for file in self.css],
|
"css": [staticfiles_storage.url(file) for file in self.css],
|
||||||
}
|
}
|
||||||
if self.is_ajax:
|
if self.is_ajax:
|
||||||
context["selected"] = [
|
adapter = TypeAdapter(list[self.schema])
|
||||||
self.schema.from_orm(obj).model_dump_json()
|
context["initial"] = adapter.dump_json(
|
||||||
for obj in self.model.objects.filter(
|
adapter.validate_python(
|
||||||
|
self.model.objects.filter(
|
||||||
**{
|
**{
|
||||||
f"{self.pk}__in": [
|
f"{self.pk}__in": [
|
||||||
pk
|
pk
|
||||||
@ -59,7 +61,8 @@ class AutoCompleteSelectMixin:
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
).all()
|
).all()
|
||||||
]
|
)
|
||||||
|
).decode("utf-8")
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user