0001-wcs-add-new-card-cell-model-68140.patch
combo/apps/wcs/migrations/0051_new_card_cell.py | ||
---|---|---|
1 |
import django.contrib.postgres.fields.jsonb |
|
2 |
import django.db.models.deletion |
|
3 |
from django.db import migrations, models |
|
4 | ||
5 |
import combo.apps.wcs.models |
|
6 | ||
7 | ||
8 |
class Migration(migrations.Migration): |
|
9 | ||
10 |
dependencies = [ |
|
11 |
('auth', '0011_update_proxy_permissions'), |
|
12 |
('data', '0057_pagesnapshot_label'), |
|
13 |
('wcs', '0050_card_display_mode'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
migrations.CreateModel( |
|
18 |
name='WcsCardCell', |
|
19 |
fields=[ |
|
20 |
( |
|
21 |
'id', |
|
22 |
models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), |
|
23 |
), |
|
24 |
('placeholder', models.CharField(max_length=20)), |
|
25 |
('order', models.PositiveIntegerField()), |
|
26 |
('slug', models.SlugField(blank=True, verbose_name='Slug')), |
|
27 |
( |
|
28 |
'extra_css_class', |
|
29 |
models.CharField( |
|
30 |
blank=True, max_length=100, verbose_name='Extra classes for CSS styling' |
|
31 |
), |
|
32 |
), |
|
33 |
( |
|
34 |
'template_name', |
|
35 |
models.CharField(blank=True, max_length=50, null=True, verbose_name='Cell Template'), |
|
36 |
), |
|
37 |
( |
|
38 |
'condition', |
|
39 |
models.CharField( |
|
40 |
blank=True, max_length=1000, null=True, verbose_name='Display condition' |
|
41 |
), |
|
42 |
), |
|
43 |
('public', models.BooleanField(default=True, verbose_name='Public')), |
|
44 |
( |
|
45 |
'restricted_to_unlogged', |
|
46 |
models.BooleanField(default=False, verbose_name='Restrict to unlogged users'), |
|
47 |
), |
|
48 |
('last_update_timestamp', models.DateTimeField(auto_now=True)), |
|
49 |
('carddef_reference', models.CharField(max_length=150, verbose_name='Card Model')), |
|
50 |
( |
|
51 |
'related_card_path', |
|
52 |
models.CharField(blank=True, max_length=1000, verbose_name='Card Identifier'), |
|
53 |
), |
|
54 |
( |
|
55 |
'card_ids', |
|
56 |
models.CharField(blank=True, max_length=1000, verbose_name='Other Card Identifiers'), |
|
57 |
), |
|
58 |
( |
|
59 |
'only_for_user', |
|
60 |
models.BooleanField( |
|
61 |
default=False, verbose_name='Limit to cards linked to the logged-in user' |
|
62 |
), |
|
63 |
), |
|
64 |
( |
|
65 |
'without_user', |
|
66 |
models.BooleanField(default=False, verbose_name='Ignore the logged-in user'), |
|
67 |
), |
|
68 |
( |
|
69 |
'limit', |
|
70 |
models.PositiveSmallIntegerField( |
|
71 |
blank=True, null=True, verbose_name='Number of cards per page (default 10)' |
|
72 |
), |
|
73 |
), |
|
74 |
('custom_schema', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict)), |
|
75 |
( |
|
76 |
'display_mode', |
|
77 |
models.CharField( |
|
78 |
choices=[('card', 'Card'), ('table', 'Table')], |
|
79 |
default='card', |
|
80 |
max_length=10, |
|
81 |
verbose_name='Display mode', |
|
82 |
), |
|
83 |
), |
|
84 |
( |
|
85 |
'title_type', |
|
86 |
models.CharField( |
|
87 |
choices=[ |
|
88 |
('auto', 'Default Title (Card Label)'), |
|
89 |
('manual', 'Custom Title'), |
|
90 |
('empty', 'No Title'), |
|
91 |
], |
|
92 |
default='auto', |
|
93 |
max_length=20, |
|
94 |
verbose_name='Title', |
|
95 |
), |
|
96 |
), |
|
97 |
('custom_title', models.CharField(blank=True, max_length=150, verbose_name='Custom Title')), |
|
98 |
('cached_title', models.CharField(max_length=150, verbose_name='Title')), |
|
99 |
('cached_json', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict)), |
|
100 |
('groups', models.ManyToManyField(blank=True, to='auth.Group', verbose_name='Groups')), |
|
101 |
('page', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='data.Page')), |
|
102 |
], |
|
103 |
options={ |
|
104 |
'verbose_name': 'Card(s)', |
|
105 |
}, |
|
106 |
bases=(combo.apps.wcs.models.CardMixin, models.Model), |
|
107 |
), |
|
108 |
] |
combo/apps/wcs/models.py | ||
---|---|---|
935 | 935 |
return '' |
936 | 936 | |
937 | 937 | |
938 |
@register_cell_class |
|
939 |
class WcsCardCell(CardMixin, CellBase): |
|
940 |
carddef_reference = models.CharField(_('Card Model'), max_length=150) |
|
941 |
related_card_path = models.CharField(_('Card Identifier'), max_length=1000, blank=True) |
|
942 |
card_ids = models.CharField(_('Other Card Identifiers'), max_length=1000, blank=True) |
|
943 |
only_for_user = models.BooleanField(_('Limit to cards linked to the logged-in user'), default=False) |
|
944 |
without_user = models.BooleanField(_('Ignore the logged-in user'), default=False) |
|
945 |
limit = models.PositiveSmallIntegerField( |
|
946 |
_('Number of cards per page (default 10)'), null=True, blank=True |
|
947 |
) |
|
948 |
custom_schema = JSONField(blank=True, default=dict) |
|
949 |
display_mode = models.CharField( |
|
950 |
_('Display mode'), |
|
951 |
max_length=10, |
|
952 |
default='card', |
|
953 |
choices=[ |
|
954 |
('card', _('Card')), |
|
955 |
('table', _('Table')), |
|
956 |
], |
|
957 |
) |
|
958 | ||
959 |
title_type = models.CharField( |
|
960 |
_('Title'), |
|
961 |
max_length=20, |
|
962 |
default='auto', |
|
963 |
blank=False, |
|
964 |
choices=[ |
|
965 |
('auto', _('Default Title (Card Label)')), |
|
966 |
('manual', _('Custom Title')), |
|
967 |
('empty', _('No Title')), |
|
968 |
], |
|
969 |
) |
|
970 |
custom_title = models.CharField(_('Custom Title'), max_length=150, blank=True) |
|
971 | ||
972 |
cached_title = models.CharField(_('Title'), max_length=150) |
|
973 |
cached_json = JSONField(blank=True, default=dict) |
|
974 | ||
975 |
class Meta: |
|
976 |
verbose_name = _('Card(s)') |
|
977 | ||
978 | ||
938 | 979 |
@register_cell_class |
939 | 980 |
class WcsCardInfosCell(CardMixin, CellBase): |
940 | 981 |
carddef_reference = models.CharField(_('Card Model'), max_length=150) |
tests/test_manager.py | ||
---|---|---|
1040 | 1040 |
resp.form['site_file'] = Upload('site-export.json', site_export, 'application/json') |
1041 | 1041 |
with CaptureQueriesContext(connection) as ctx: |
1042 | 1042 |
resp = resp.form.submit() |
1043 |
assert len(ctx.captured_queries) in [309, 310]
|
|
1043 |
assert len(ctx.captured_queries) in [314, 315]
|
|
1044 | 1044 |
assert Page.objects.count() == 4 |
1045 | 1045 |
assert PageSnapshot.objects.all().count() == 4 |
1046 | 1046 | |
... | ... | |
1051 | 1051 |
resp.form['site_file'] = Upload('site-export.json', site_export, 'application/json') |
1052 | 1052 |
with CaptureQueriesContext(connection) as ctx: |
1053 | 1053 |
resp = resp.form.submit() |
1054 |
assert len(ctx.captured_queries) == 278
|
|
1054 |
assert len(ctx.captured_queries) == 282
|
|
1055 | 1055 |
assert set(Page.objects.get(slug='one').related_cells['cell_types']) == {'data_textcell', 'data_linkcell'} |
1056 | 1056 |
assert Page.objects.count() == 4 |
1057 | 1057 |
assert LinkCell.objects.count() == 2 |
... | ... | |
2447 | 2447 | |
2448 | 2448 |
with CaptureQueriesContext(connection) as ctx: |
2449 | 2449 |
resp2 = resp.click('view', index=1) |
2450 |
assert len(ctx.captured_queries) == 71
|
|
2450 |
assert len(ctx.captured_queries) == 72
|
|
2451 | 2451 |
assert Page.snapshots.latest('pk').related_cells == {'cell_types': ['data_textcell']} |
2452 | 2452 |
assert resp2.text.index('Hello world') < resp2.text.index('Foobar3') |
2453 | 2453 | |
... | ... | |
2508 | 2508 |
resp = resp.click('restore', index=6) |
2509 | 2509 |
with CaptureQueriesContext(connection) as ctx: |
2510 | 2510 |
resp = resp.form.submit().follow() |
2511 |
assert len(ctx.captured_queries) == 155
|
|
2511 |
assert len(ctx.captured_queries) == 157
|
|
2512 | 2512 | |
2513 | 2513 |
resp2 = resp.click('See online') |
2514 | 2514 |
assert resp2.text.index('Foobar1') < resp2.text.index('Foobar2') < resp2.text.index('Foobar3') |
tests/test_search.py | ||
---|---|---|
1432 | 1432 |
assert IndexedCell.objects.count() == 50 |
1433 | 1433 |
with CaptureQueriesContext(connection) as ctx: |
1434 | 1434 |
index_site() |
1435 |
assert len(ctx.captured_queries) in (175, 225) # (3.2, 2.2)
|
|
1435 |
assert len(ctx.captured_queries) in (176, 226) # (3.2, 2.2)
|
|
1436 | 1436 | |
1437 | 1437 |
SearchCell.objects.create( |
1438 | 1438 |
page=page, placeholder='content', order=0, _search_services={'data': ['search1']} |
1439 |
- |