misc: add a |with_drafts filter (#46718) #857

Merged
fpeters merged 1 commits from wip/46718-with-drafts-filter into main 2023-11-24 09:13:25 +01:00
3 changed files with 14 additions and 0 deletions

View File

@ -1626,6 +1626,11 @@ def test_lazy_formdata_queryset_filter(pub, variable_test_data):
tmpl = Template('{{form_objects|done|count}}')
assert tmpl.render(context) == '4'
# test |with_drafts
context = pub.substitutions.get_context_variables(mode='lazy')
tmpl = Template('{{form_objects|with_drafts|count}}')
assert tmpl.render(context) == '12'
# test |filter_by_internal_id
context = pub.substitutions.get_context_variables(mode='lazy')
for tpl in ['filter_by_internal_id', 'filter_by:"internal_id"|filter_value']:

View File

@ -789,6 +789,11 @@ def with_custom_view(queryset, custom_view_slug):
return queryset.with_custom_view(custom_view_slug)
@register.filter
def with_drafts(queryset):
return queryset.with_drafts()
@register.filter
def order_by(queryset, attribute):
return queryset.order_by(unlazy(attribute))

View File

@ -200,6 +200,10 @@ class LazyFormDefObjectsManager:
criterias = [x for x in self._criterias if not getattr(x, 'exclude_anonymised', True)]
return self._clone(criterias)
def with_drafts(self):
criterias = [x for x in self._criterias if not getattr(x, 'exclude_drafts', False)]
return self._clone(criterias)
def done(self):
status_filters = ['wf-%s' % x.id for x in self._formdef.workflow.get_endpoint_status()]
criterias = [Contains('status', status_filters)]