meeb/django-distill

Feature: Propagate view_name to distill_func

Closed this issue · 0 comments

I want to make my distill_func to be aware of given view_name.
Use case:

  • Generate multiple distill_paths in a for loop:
views = [("name", View), ("name2", View2)]
urlpatterns += [
    distill_path(
        f"{name}_url/",
        view.as_view(),
        name=name,
        distill_func=get_params
    )
    for name, view in views
]
  • get different params depending on view name:
def get_params(view_name):
     if view_name == "name":
         return 1
     else:
         return 2

This is very usefull for me. Maybe for others too?
Will provide PR if you want to merge...