0001-wcs-add-a-cell-forms-in-your-care-31989.patch
combo/apps/wcs/migrations/0017_wcscareformscell.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2019-10-18 13:48 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
import combo.apps.wcs.models |
|
6 |
from django.db import migrations, models |
|
7 |
import django.db.models.deletion |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('auth', '0008_alter_user_username_max_length'), |
|
14 |
('data', '0037_auto_20190701_2118'), |
|
15 |
('wcs', '0016_backofficesubmissioncell'), |
|
16 |
] |
|
17 | ||
18 |
operations = [ |
|
19 |
migrations.CreateModel( |
|
20 |
name='WcsCareFormsCell', |
|
21 |
fields=[ |
|
22 |
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|
23 |
('placeholder', models.CharField(max_length=20)), |
|
24 |
('order', models.PositiveIntegerField()), |
|
25 |
('slug', models.SlugField(blank=True, verbose_name='Slug')), |
|
26 |
('extra_css_class', models.CharField(blank=True, max_length=100, verbose_name='Extra classes for CSS styling')), |
|
27 |
('public', models.BooleanField(default=True, verbose_name='Public')), |
|
28 |
('restricted_to_unlogged', models.BooleanField(default=False, verbose_name='Restrict to unlogged users')), |
|
29 |
('last_update_timestamp', models.DateTimeField(auto_now=True)), |
|
30 |
('wcs_site', models.CharField(blank=True, max_length=50, verbose_name='Site')), |
|
31 |
('groups', models.ManyToManyField(blank=True, to='auth.Group', verbose_name='Groups')), |
|
32 |
('page', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='data.Page')), |
|
33 |
], |
|
34 |
options={ |
|
35 |
'verbose_name': 'Forms in your care', |
|
36 |
}, |
|
37 |
bases=(models.Model, combo.apps.wcs.models.WcsBlurpMixin), |
|
38 |
), |
|
39 |
] |
combo/apps/wcs/models.py | ||
---|---|---|
504 | 504 |
'text': text} |
505 | 505 | |
506 | 506 | |
507 |
@register_cell_class |
|
508 |
class WcsCareFormsCell(WcsDataBaseCell): |
|
509 |
api_url = '/api/forms/?limit=10' |
|
510 |
variable_name = 'care_forms' |
|
511 |
template_name = 'combo/wcs/care_forms.html' |
|
512 |
cache_duration = 600 |
|
513 | ||
514 |
class Meta: |
|
515 |
verbose_name = _('Forms in your care') |
|
516 | ||
517 | ||
507 | 518 |
@register_cell_class |
508 | 519 |
class CategoriesCell(WcsDataBaseCell): |
509 | 520 |
api_url = '/api/categories/?full=on' |
combo/apps/wcs/templates/combo/wcs/care_forms.html | ||
---|---|---|
1 |
{% load i18n combo %} |
|
2 |
{% block cell-content %} |
|
3 |
{% for slug, forms in care_forms.items %} |
|
4 |
<h2>{% trans "Forms in your care" %} - {{ forms.title }}</h2> |
|
5 |
{% if forms.data %} |
|
6 |
<table id="listing" class="main"> |
|
7 |
<thead> |
|
8 |
<tr> |
|
9 |
<th><span>{% trans "Form" %}</span></th> |
|
10 |
<th><span>{% trans "Reference" %}</span></th> |
|
11 |
<th><span>{% trans "Created" %}</span></th> |
|
12 |
<th><span>{% trans "Last Modified" %}</span></th> |
|
13 |
<th><span>{% trans "Status" %}</span></th> |
|
14 |
</tr> |
|
15 |
</thead> |
|
16 |
<tbody> |
|
17 |
{% for data in forms.data|dictsortreversed:"form_receipt_datetime" %} |
|
18 |
<tr> |
|
19 |
<td>{{ data.name }}</td> |
|
20 |
<td><a href="{{ data.form_url_backoffice }}">{{ data.form_number }}</a></td> |
|
21 |
<td>{{ data.datetime|strptime:"%Y-%m-%d %H:%M:%S" }}</td> |
|
22 |
<td>{{ data.last_update_time|strptime:"%Y-%m-%d %H:%M:%S" }}</td> |
|
23 |
<td>{{ data.status }}</td> |
|
24 |
</tr> |
|
25 |
{% endfor %} |
|
26 |
</tbody> |
|
27 |
</table> |
|
28 |
{% endif %} |
|
29 |
<a href="{{ forms.url }}backoffice/management/">{% trans "See all forms" %}</a> |
|
30 |
{% endfor %} |
|
31 |
{% endblock %} |
tests/test_wcs.py | ||
---|---|---|
24 | 24 |
from combo.apps.search.engines import engines |
25 | 25 |
from combo.apps.wcs.models import (WcsFormCell, WcsCurrentFormsCell, |
26 | 26 |
WcsFormsOfCategoryCell, WcsCurrentDraftsCell, WcsCategoryCell, |
27 |
TrackingCodeInputCell, BackofficeSubmissionCell) |
|
27 |
TrackingCodeInputCell, BackofficeSubmissionCell, WcsCareFormsCell)
|
|
28 | 28 | |
29 | 29 |
from combo.utils import NothingInCacheException |
30 | 30 | |
... | ... | |
464 | 464 |
assert 'http://127.0.0.1:8999/' not in result |
465 | 465 |
assert len(caplog.records) == 0 |
466 | 466 | |
467 | ||
468 |
@wcs_present |
|
469 |
def test_care_forms_cell_setup(): |
|
470 |
cell = WcsCareFormsCell() |
|
471 |
form_class = cell.get_default_form_class() |
|
472 |
form = form_class() |
|
473 |
assert form.fields['wcs_site'].widget.choices == [ |
|
474 |
('', 'All'), (u'default', u'test'), (u'other', u'test2')] |
|
475 |
assert cell.get_additional_label() == 'All Sites' |
|
476 |
cell.wcs_site = 'default' |
|
477 |
assert cell.get_additional_label() == 'test' |
|
478 | ||
479 | ||
480 |
@wcs_present |
|
481 |
def test_care_forms_cell_render(context): |
|
482 |
page = Page(title='xxx', slug='test_care_forms_cell_render', template_name='standard') |
|
483 |
page.save() |
|
484 |
cell = WcsCareFormsCell(page=page, placeholder='content', order=0) |
|
485 |
cell.save() |
|
486 | ||
487 |
context['request'].user = MockUser() |
|
488 | ||
489 |
# query should fail as nothing is cached |
|
490 |
cache.clear() |
|
491 |
with pytest.raises(NothingInCacheException): |
|
492 |
result = cell.render(context) |
|
493 | ||
494 |
context['synchronous'] = True # to get fresh content |
|
495 | ||
496 |
result = cell.render(context) |
|
497 |
assert '"http://127.0.0.1:8999/backoffice/management/"' in result |
|
498 |
assert '"http://127.0.0.2:8999/backoffice/management/"' in result |
|
499 | ||
500 |
data = cell.get_data(context) |
|
501 |
assert 'default' in data |
|
502 |
assert 'other' in data |
|
503 | ||
504 |
# XXX calls to /api/forms return 404: how to test this ? |
|
505 | ||
506 | ||
507 |
@wcs_present |
|
508 |
def test_care_forms_cell_render_single_site(context): |
|
509 |
page = Page(title='xxx', slug='test_care_forms_cell_render', template_name='standard') |
|
510 |
page.save() |
|
511 |
cell = WcsCareFormsCell(page=page, placeholder='content', order=0) |
|
512 |
cell.wcs_site = 'default' |
|
513 |
cell.save() |
|
514 | ||
515 |
context['request'].user = MockUser() |
|
516 | ||
517 |
# query should fail as nothing is cached |
|
518 |
cache.clear() |
|
519 |
with pytest.raises(NothingInCacheException): |
|
520 |
result = cell.render(context) |
|
521 | ||
522 |
context['synchronous'] = True # to get fresh content |
|
523 | ||
524 |
result = cell.render(context) |
|
525 |
assert '"http://127.0.0.1:8999/backoffice/management/"' in result |
|
526 |
assert '"http://127.0.0.2:8999/backoffice/management/"' not in result |
|
527 | ||
528 |
data = cell.get_data(context) |
|
529 |
assert 'default' in data |
|
530 |
assert 'other' not in data |
|
531 | ||
532 | ||
467 | 533 |
@wcs_present |
468 | 534 |
def test_forms_of_category_cell_setup(): |
469 | 535 |
cell = WcsFormsOfCategoryCell() |
470 |
- |