{
+ const resp = await sithfileSearchFiles({ query: { search: query } });
+ if (resp.data) {
+ return resp.data.results;
+ }
+ return [];
+ }
+
+ protected renderOption(item: SithFileSchema, sanitize: typeof escape_html) {
+ return `
+ ${sanitize(item.path)}
+
`;
+ }
+
+ protected renderItem(item: SithFileSchema, sanitize: typeof escape_html) {
+ return `${sanitize(item.path)}`;
+ }
+}
diff --git a/core/views/files.py b/core/views/files.py
index 3df5c014..d70991b7 100644
--- a/core/views/files.py
+++ b/core/views/files.py
@@ -18,7 +18,6 @@ from urllib.parse import quote, urljoin
# This file contains all the views that concern the page model
from wsgiref.util import FileWrapper
-from ajax_select import make_ajax_field
from django import forms
from django.conf import settings
from django.core.exceptions import PermissionDenied
@@ -39,6 +38,11 @@ from core.views import (
CanViewMixin,
can_view,
)
+from core.views.widgets.select import (
+ AutoCompleteSelectMultipleGroup,
+ AutoCompleteSelectSithFile,
+ AutoCompleteSelectUser,
+)
from counter.utils import is_logged_in_counter
@@ -217,14 +221,13 @@ class FileEditPropForm(forms.ModelForm):
class Meta:
model = SithFile
fields = ["parent", "owner", "edit_groups", "view_groups"]
+ widgets = {
+ "parent": AutoCompleteSelectSithFile,
+ "owner": AutoCompleteSelectUser,
+ "edit_groups": AutoCompleteSelectMultipleGroup,
+ "view_groups": AutoCompleteSelectMultipleGroup,
+ }
- parent = make_ajax_field(SithFile, "parent", "files", help_text="")
- edit_groups = make_ajax_field(
- SithFile, "edit_groups", "groups", help_text="", label=_("edit group")
- )
- view_groups = make_ajax_field(
- SithFile, "view_groups", "groups", help_text="", label=_("view group")
- )
recursive = forms.BooleanField(label=_("Apply rights recursively"), required=False)
diff --git a/core/views/widgets/select.py b/core/views/widgets/select.py
index cd951940..a02df82d 100644
--- a/core/views/widgets/select.py
+++ b/core/views/widgets/select.py
@@ -3,8 +3,8 @@ from django.db.models import Model
from django.forms import Select, SelectMultiple
from ninja import ModelSchema
-from core.models import Group, User
-from core.schemas import GroupSchema, UserProfileSchema
+from core.models import Group, SithFile, User
+from core.schemas import GroupSchema, SithFileSchema, UserProfileSchema
class AutoCompleteSelectMixin:
@@ -91,3 +91,15 @@ class AutoCompleteSelectMultipleGroup(AutoCompleteSelectMixin, SelectMultiple):
component_name = "group-ajax-select"
model = Group
schema = GroupSchema
+
+
+class AutoCompleteSelectSithFile(AutoCompleteSelectMixin, Select):
+ component_name = "sith-file-ajax-select"
+ model = SithFile
+ schema = SithFileSchema
+
+
+class AutoCompleteSelectMultipleSithFile(AutoCompleteSelectMixin, SelectMultiple):
+ component_name = "sith-file-ajax-select"
+ model = SithFile
+ schema = SithFileSchema