parent
f22b4dd02f
commit
3e7a4d30a2
@ -63,7 +63,6 @@ class EventFilter(django_filters.FilterSet):
|
||||
label="À proximité de",
|
||||
method="no_filter",
|
||||
empty_label=_("Select a location"),
|
||||
field_name='attr__slug',
|
||||
to_field_name='slug',
|
||||
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"]
|
||||
|
||||
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)
|
||||
if not kwargs["request"].user.is_authenticated:
|
||||
self.form.fields.pop("status")
|
||||
@ -314,7 +320,7 @@ class EventFilter(django_filters.FilterSet):
|
||||
|
||||
def get_url_add_suggested_position(self, location):
|
||||
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):
|
||||
|
@ -25,4 +25,8 @@ class Migration(migrations.Migration):
|
||||
name='slug',
|
||||
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