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 }} {% if data.form_digest %}<br><small>{{ data.form_digest }}</small>{% endif %}</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 |
<p><a class="pk-button" href="{{ forms.url }}backoffice/management/">{% trans "See all forms" %}</a></p> |
|
30 |
{% endfor %} |
|
31 |
{% endblock %} |
tests/test_wcs.py | ||
---|---|---|
20 | 20 |
from django.test.client import RequestFactory |
21 | 21 |
from django.utils.six.moves.urllib import parse as urlparse |
22 | 22 | |
23 |
import mock |
|
24 | ||
23 | 25 |
from combo.data.models import Page |
24 | 26 |
from combo.apps.search.engines import engines |
25 | 27 |
from combo.apps.wcs.models import (WcsFormCell, WcsCurrentFormsCell, |
26 | 28 |
WcsFormsOfCategoryCell, WcsCurrentDraftsCell, WcsCategoryCell, |
27 |
TrackingCodeInputCell, BackofficeSubmissionCell) |
|
29 |
TrackingCodeInputCell, BackofficeSubmissionCell, WcsCareFormsCell)
|
|
28 | 30 | |
29 | 31 |
from combo.utils import NothingInCacheException |
30 | 32 | |
... | ... | |
464 | 466 |
assert 'http://127.0.0.1:8999/' not in result |
465 | 467 |
assert len(caplog.records) == 0 |
466 | 468 | |
469 | ||
470 |
@wcs_present |
|
471 |
def test_care_forms_cell_setup(): |
|
472 |
cell = WcsCareFormsCell() |
|
473 |
form_class = cell.get_default_form_class() |
|
474 |
form = form_class() |
|
475 |
assert form.fields['wcs_site'].widget.choices == [ |
|
476 |
('', 'All'), (u'default', u'test'), (u'other', u'test2')] |
|
477 |
assert cell.get_additional_label() == 'All Sites' |
|
478 |
cell.wcs_site = 'default' |
|
479 |
assert cell.get_additional_label() == 'test' |
|
480 | ||
481 | ||
482 |
@wcs_present |
|
483 |
def test_care_forms_cell_render(context): |
|
484 |
page = Page(title='xxx', slug='test_care_forms_cell_render', template_name='standard') |
|
485 |
page.save() |
|
486 |
cell = WcsCareFormsCell(page=page, placeholder='content', order=0) |
|
487 |
cell.save() |
|
488 | ||
489 |
context['request'].user = MockUser() |
|
490 | ||
491 |
# query should fail as nothing is cached |
|
492 |
cache.clear() |
|
493 |
with pytest.raises(NothingInCacheException): |
|
494 |
result = cell.render(context) |
|
495 | ||
496 |
context['synchronous'] = True # to get fresh content |
|
497 | ||
498 |
with mock.patch('combo.apps.wcs.models.requests.get') as requests_get: |
|
499 |
response1 = {'err': 0, 'data': [ |
|
500 |
{ |
|
501 |
'form_receipt_datetime': '2019-10-17T16:46:03', |
|
502 |
'form_url_backoffice': 'http://127.0.0.1:8999/backoffice/management/foobar/1/', |
|
503 |
}, |
|
504 |
{ |
|
505 |
'form_receipt_datetime': '2019-10-17T16:46:04', |
|
506 |
'form_url_backoffice': 'http://127.0.0.1:8999/backoffice/management/foobar/2/', |
|
507 |
}, |
|
508 |
]} |
|
509 |
response2 = {'err': 0, 'data': [ |
|
510 |
{ |
|
511 |
'form_receipt_datetime': '2019-10-17T16:46:05', |
|
512 |
'form_url_backoffice': 'http://127.0.0.2:8999/backoffice/management/foobar/42/', |
|
513 |
}, |
|
514 |
]} |
|
515 |
mock_json = mock.Mock(status_code=200) |
|
516 |
mock_json.json.side_effect = [response1, response2] |
|
517 |
requests_get.return_value = mock_json |
|
518 | ||
519 |
result = cell.render(context) |
|
520 | ||
521 |
assert 'http://127.0.0.1:8999/backoffice/management/foobar/1' in result |
|
522 |
assert 'http://127.0.0.1:8999/backoffice/management/foobar/2' in result |
|
523 |
assert '"http://127.0.0.1:8999/backoffice/management/"' in result |
|
524 |
assert 'http://127.0.0.2:8999/backoffice/management/foobar/42' in result |
|
525 |
assert '"http://127.0.0.2:8999/backoffice/management/"' in result |
|
526 | ||
527 |
data = cell.get_data(context) |
|
528 |
assert 'default' in data |
|
529 |
assert 'other' in data |
|
530 | ||
531 | ||
532 |
@wcs_present |
|
533 |
def test_care_forms_cell_render_single_site(context): |
|
534 |
page = Page(title='xxx', slug='test_care_forms_cell_render', template_name='standard') |
|
535 |
page.save() |
|
536 |
cell = WcsCareFormsCell(page=page, placeholder='content', order=0) |
|
537 |
cell.wcs_site = 'default' |
|
538 |
cell.save() |
|
539 | ||
540 |
context['request'].user = MockUser() |
|
541 | ||
542 |
# query should fail as nothing is cached |
|
543 |
cache.clear() |
|
544 |
with pytest.raises(NothingInCacheException): |
|
545 |
result = cell.render(context) |
|
546 | ||
547 |
context['synchronous'] = True # to get fresh content |
|
548 | ||
549 |
result = cell.render(context) |
|
550 |
assert '"http://127.0.0.1:8999/backoffice/management/"' in result |
|
551 |
assert '"http://127.0.0.2:8999/backoffice/management/"' not in result |
|
552 | ||
553 |
data = cell.get_data(context) |
|
554 |
assert 'default' in data |
|
555 |
assert 'other' not in data |
|
556 | ||
557 | ||
467 | 558 |
@wcs_present |
468 | 559 |
def test_forms_of_category_cell_setup(): |
469 | 560 |
cell = WcsFormsOfCategoryCell() |
470 |
- |