Skip to content

Commit

Permalink
Fix non-alphanumeric characters in flag names
Browse files Browse the repository at this point in the history
As @chosak notes in #73, the admin URL patterns prevented creating flags that didn't match `[\w\-]`. This change fixes that by switching from `re_path` to `path` for those patterns, simplifying them and making them more readable.

Fixes #73
  • Loading branch information
willbarton committed Jul 5, 2024
1 parent 1fd58c7 commit c7f9edc
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions wagtailflags/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import django
from django.templatetags.static import static
from django.urls import include, re_path, reverse
from django.urls import include, path, reverse
from django.utils.html import format_html

from wagtail import hooks
Expand All @@ -22,47 +21,37 @@ def register_flags_menu():
@hooks.register("register_admin_urls")
def register_flag_admin_urls():
flagpatterns = [
re_path(r"^$", views.index, name="list"),
re_path(r"^create/$", views.create_flag, name="create_flag"),
re_path(r"^(?P<name>[\w\-]+)/$", views.flag_index, name="flag_index"),
re_path(
r"^(?P<name>[\w\-]+)/delete/$",
path("", views.index, name="list"),
path("create/", views.create_flag, name="create_flag"),
path("<name>/", views.flag_index, name="flag_index"),
path(
"<name>/delete/",
views.delete_flag,
name="delete_flag",
),
re_path(
r"^(?P<name>[\w\-]+)/create/$",
path(
"<name>/create/",
views.edit_condition,
name="create_condition",
),
re_path(
r"^(?P<name>[\w\-]+)/(?P<condition_pk>\d+)/$",
path(
"<name>/<int:condition_pk>/",
views.edit_condition,
name="edit_condition",
),
re_path(
r"^(?P<name>[\w\-]+)/(?P<condition_pk>\d+)/delete/$",
path(
"<name>/<int:condition_pk>/delete/",
views.delete_condition,
name="delete_condition",
),
]

if django.VERSION >= (1, 10): # pragma: no cover
urlpatterns = [
re_path(
r"^flags/",
include(
(flagpatterns, "wagtailflags"), namespace="wagtailflags"
),
)
]
else: # pragma: no cover; fallback for Django < 1.10
urlpatterns = [
re_path(
r"^flags/",
include((flagpatterns, "wagtailflags", "wagtailflags")),
)
]
urlpatterns = [
path(
"flags/",
include((flagpatterns, "wagtailflags"), namespace="wagtailflags"),
)
]

return urlpatterns

Expand Down

0 comments on commit c7f9edc

Please sign in to comment.