Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-alphanumeric characters in flag names #78

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wagtailflags/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class NewFlagForm(forms.ModelForm):
name = forms.CharField(label="Name", required=True)
name = forms.SlugField(label="Name", required=True)

def clean_name(self):
name = self.cleaned_data["name"]
Expand Down
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
Loading