Skip to content

Commit dfc4947

Browse files
committed
Add support for custom path pattern
1 parent 3d464a7 commit dfc4947

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

joeflow/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,13 @@ def urls(cls):
154154
route = "{name}/".format(name=name)
155155
else:
156156
route = "{name}/<pk>/".format(name=name)
157-
urls.append(path(route, cls._wrap_view_instance(name, node), name=name))
157+
urls.append(
158+
path(
159+
route + node.path,
160+
cls._wrap_view_instance(name, node),
161+
name=name,
162+
)
163+
)
158164
if cls.detail_view:
159165
urls.append(
160166
path("<pk>/", cls.detail_view.as_view(model=cls), name="detail")

joeflow/views.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ def get_template_names(self):
2626

2727
class TaskViewMixin(ProcessTemplateNameViewMixin, RevisionMixin):
2828
name = None
29+
path = ""
30+
"""
31+
URL pattern postfix for task view.
32+
33+
Should a task require custom arguments via URL, path
34+
can be set to provide a pattern postfix. e.G.::
35+
36+
start = tasks.StartView(path="path/to/<other_pk>")
37+
38+
"""
2939

3040
def __init__(self, **kwargs):
3141
self._instance_kwargs = kwargs

tests/test_models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ def test_urls(self):
238238
"detail",
239239
}
240240

241+
def test_urls__custom_path(self):
242+
patterns, namespace = models.SimpleProcess.urls()
243+
patterns = {pattern.pattern.describe() for pattern in patterns}
244+
assert "'start_view/custom/postfix/' [name='start_view']" in patterns
245+
241246
def test_urls__no_override(self):
242247
class TestProcess(Process):
243248
override_view = None

tests/testapp/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def end(self):
4343

4444

4545
class SimpleProcess(Process):
46-
start_view = views.StartView(fields="__all__")
46+
start_view = views.StartView(fields="__all__", path="custom/postfix/")
4747
start_method = tasks.Start()
4848
save_the_princess = views.TaskView(fields="__all__")
4949

0 commit comments

Comments
 (0)