parent
f22b4dd02f
commit
3e7a4d30a2
@ -63,7 +63,6 @@ class EventFilter(django_filters.FilterSet):
|
|||||||
label="À proximité de",
|
label="À proximité de",
|
||||||
method="no_filter",
|
method="no_filter",
|
||||||
empty_label=_("Select a location"),
|
empty_label=_("Select a location"),
|
||||||
field_name='attr__slug',
|
|
||||||
to_field_name='slug',
|
to_field_name='slug',
|
||||||
queryset=ReferenceLocation.objects.filter(main__gt=0).order_by("-main", "name__unaccent")
|
queryset=ReferenceLocation.objects.filter(main__gt=0).order_by("-main", "name__unaccent")
|
||||||
)
|
)
|
||||||
@ -112,6 +111,13 @@ class EventFilter(django_filters.FilterSet):
|
|||||||
fields = ["tags", "exclude_tags", "status", "recurrences"]
|
fields = ["tags", "exclude_tags", "status", "recurrences"]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
# urls were using pk, now we moved to slug
|
||||||
|
if len(args) > 0 and "position" in args[0] and args[0]["position"].isdigit():
|
||||||
|
args[0]._mutable = True
|
||||||
|
el = ReferenceLocation.objects.filter(pk=int(args[0]["position"])).values("slug").first()
|
||||||
|
args[0]["position"] = None if el is None else el["slug"]
|
||||||
|
args[0]._mutable = False
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
if not kwargs["request"].user.is_authenticated:
|
if not kwargs["request"].user.is_authenticated:
|
||||||
self.form.fields.pop("status")
|
self.form.fields.pop("status")
|
||||||
@ -314,7 +320,7 @@ class EventFilter(django_filters.FilterSet):
|
|||||||
|
|
||||||
def get_url_add_suggested_position(self, location):
|
def get_url_add_suggested_position(self, location):
|
||||||
result = self.request.get_full_path()
|
result = self.request.get_full_path()
|
||||||
return result + ('&' if '?' in result else '?') + 'position=' + str(location.pk) + "&radius=" + str(location.suggested_distance)
|
return result + ('&' if '?' in result else '?') + 'position=' + str(location.slug) + "&radius=" + str(location.suggested_distance)
|
||||||
|
|
||||||
|
|
||||||
class EventFilterAdmin(django_filters.FilterSet):
|
class EventFilterAdmin(django_filters.FilterSet):
|
||||||
|
@ -25,4 +25,8 @@ class Migration(migrations.Migration):
|
|||||||
name='slug',
|
name='slug',
|
||||||
field=autoslug.fields.AutoSlugField(default=None, editable=False, null=True, populate_from='name', unique=True),
|
field=autoslug.fields.AutoSlugField(default=None, editable=False, null=True, populate_from='name', unique=True),
|
||||||
),
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=migrate_data_slug_forward,
|
||||||
|
reverse_code=migrate_data_slug_backward,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user