summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauréline Guérin <zebuline@entrouvert.com>2019-11-12 10:28:13 (GMT)
committerLauréline Guérin <zebuline@entrouvert.com>2019-12-06 09:12:22 (GMT)
commit850bab5600f072e3643fba8302d14173eb59b786 (patch)
tree46e5b2686b8d48eadc15ccb577ef2b8be6fa07ae
parentff792192d88ab09dd26d9e40fb0928c81bf4fc7c (diff)
downloadcombo-wip/20231-drafts-in-current-forms.zip
combo-wip/20231-drafts-in-current-forms.tar.gz
combo-wip/20231-drafts-in-current-forms.tar.bz2
wcs: include drafts or not in current forms cell (#20231)wip/20231-drafts-in-current-forms
-rw-r--r--combo/apps/wcs/forms.py2
-rw-r--r--combo/apps/wcs/migrations/0019_wcscurrentformscell_include_drafts.py19
-rw-r--r--combo/apps/wcs/models.py27
-rw-r--r--combo/apps/wcs/templates/combo/wcs/list_of_forms.html5
-rw-r--r--tests/test_wcs.py13
5 files changed, 58 insertions, 8 deletions
diff --git a/combo/apps/wcs/forms.py b/combo/apps/wcs/forms.py
index 120006d..09ebb75 100644
--- a/combo/apps/wcs/forms.py
+++ b/combo/apps/wcs/forms.py
@@ -107,7 +107,7 @@ class WcsFormsMixin(object):
class WcsCurrentFormsCellForm(WcsFormsMixin, forms.ModelForm):
class Meta:
model = WcsCurrentFormsCell
- fields = ['wcs_site', 'categories', 'current_forms', 'done_forms']
+ fields = ['wcs_site', 'categories', 'current_forms', 'done_forms', 'include_drafts']
def __init__(self, *args, **kwargs):
super(WcsCurrentFormsCellForm, self).__init__(*args, **kwargs)
diff --git a/combo/apps/wcs/migrations/0019_wcscurrentformscell_include_drafts.py b/combo/apps/wcs/migrations/0019_wcscurrentformscell_include_drafts.py
new file mode 100644
index 0000000..cc1ad16
--- /dev/null
+++ b/combo/apps/wcs/migrations/0019_wcscurrentformscell_include_drafts.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('wcs', '0018_wcscurrentdraftscell_categories'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='wcscurrentformscell',
+ name='include_drafts',
+ field=models.BooleanField(default=False, verbose_name='Include drafts'),
+ ),
+ ]
diff --git a/combo/apps/wcs/models.py b/combo/apps/wcs/models.py
index 7995fc1..e183070 100644
--- a/combo/apps/wcs/models.py
+++ b/combo/apps/wcs/models.py
@@ -307,6 +307,7 @@ class WcsCurrentFormsCell(WcsUserDataBaseCell):
categories = JSONField(_('Categories'), blank=True)
current_forms = models.BooleanField(_('Current Forms'), default=True)
done_forms = models.BooleanField(_('Done Forms'), default=False)
+ include_drafts = models.BooleanField(_('Include drafts'), default=False)
class Meta:
verbose_name = _('User Forms')
@@ -317,11 +318,15 @@ class WcsCurrentFormsCell(WcsUserDataBaseCell):
def get_api_url(self, context):
user = self.get_concerned_user(context)
+ base_url = '/api/user/forms'
if user:
user_name_id = user.get_name_id()
if user_name_id:
- return '/api/users/%s/forms?limit=100&sort=desc' % user_name_id
- return '/api/user/forms?limit=100&sort=desc'
+ base_url = '/api/users/%s/forms' % user_name_id
+ url = base_url + '?limit=100&sort=desc'
+ if self.include_drafts:
+ url += '&include-drafts=on'
+ return url
@property
def template_name(self):
@@ -333,12 +338,20 @@ class WcsCurrentFormsCell(WcsUserDataBaseCell):
def get_additional_label(self):
initial_label = super(WcsCurrentFormsCell, self).get_additional_label()
- if self.current_forms and self.done_forms:
- label = _('All Forms')
- elif self.done_forms:
- label = _('Done Forms')
+ if self.include_drafts:
+ if self.current_forms and self.done_forms:
+ label = _('All Forms and Drafts')
+ elif self.done_forms:
+ label = _('Done Forms and Drafts')
+ else:
+ label = _('Current Forms and Drafts')
else:
- label = _('Current Forms')
+ if self.current_forms and self.done_forms:
+ label = _('All Forms')
+ elif self.done_forms:
+ label = _('Done Forms')
+ else:
+ label = _('Current Forms')
if initial_label:
return '%s - %s' % (initial_label, label)
return label
diff --git a/combo/apps/wcs/templates/combo/wcs/list_of_forms.html b/combo/apps/wcs/templates/combo/wcs/list_of_forms.html
index 5d1099c..752860b 100644
--- a/combo/apps/wcs/templates/combo/wcs/list_of_forms.html
+++ b/combo/apps/wcs/templates/combo/wcs/list_of_forms.html
@@ -1,3 +1,4 @@
+{% load combo %}
{% block cell-content %}
{% if forms %}
<ul>
@@ -5,9 +6,13 @@
{% if data.url and data.title %}
<li class="{{data.status_css_class}} {% if data.form_status_is_endpoint %}done{% endif %}"><a
{% if data.readable %}href="{{ data.url }}"{% endif %}><span class="form-title">{{data.name}}</span>
+ {% if data.draft %}
+ <span class="form-number">{{data.datetime|strptime:"%Y-%m-%d %H:%M:%S"}}</span>
+ {% else %}
<span class="form-number">{{data.form_number}}
{% if data.form_digest %}<span class="form-digest">({{data.form_digest}})</span>{% endif %}
</span>
+ {% endif %}
<span class="form-status">{{data.status}}</span></a></li>
{% endif %}
{% endfor %}
diff --git a/tests/test_wcs.py b/tests/test_wcs.py
index 23dc02b..ef556e6 100644
--- a/tests/test_wcs.py
+++ b/tests/test_wcs.py
@@ -387,6 +387,7 @@ def test_current_forms_cell_render(context):
# done forms
cell.current_forms = False
cell.done_forms = True
+ cell.include_drafts = False
cell.save()
result = cell.render(context)
assert not 'http://127.0.0.1:8999/form-title/1/' in result
@@ -422,6 +423,18 @@ def test_current_forms_cell_render(context):
extra_context = cell.get_cell_extra_context(context)
assert len(extra_context['forms']) == 0
+ # check include drafts
+ cell.include_drafts = False
+ with mock.patch('combo.apps.wcs.models.requests.get') as requests_get:
+ cell.get_cell_extra_context(context)
+ assert requests_get.call_args_list[0][0][0] == '/api/user/forms?limit=100&sort=desc'
+
+ cell.include_drafts = True
+ with mock.patch('combo.apps.wcs.models.requests.get') as requests_get:
+ cell.get_cell_extra_context(context)
+ assert requests_get.call_args_list[0][0][0] == '/api/user/forms?limit=100&sort=desc&include-drafts=on'
+
+
@wcs_present
def test_current_forms_cell_render_single_site(context):
page = Page(title='xxx', slug='test_current_forms_cell_render', template_name='standard')