0002-assets-compatibility-for-wcs-assets-40223.patch
combo/apps/wcs/models.py | ||
---|---|---|
144 | 144 |
'text': text, |
145 | 145 |
}] |
146 | 146 | |
147 |
def get_asset_slots(self): |
|
148 |
slots = {} |
|
149 |
for slot_template_key, slot_template_data in settings.WCS_FORM_ASSET_SLOTS.items(): |
|
150 |
suffix = '' |
|
151 |
if slot_template_data.get('suffix'): |
|
152 |
suffix = ' (%s)' % slot_template_data['suffix'] |
|
153 |
slot_key = 'wcs:form:%s:%s' % (slot_template_key, self.formdef_reference) |
|
154 |
slots[slot_key] = { |
|
155 |
'label': u'%(prefix)s — %(label)s%(suffix)s' % { |
|
156 |
'prefix': slot_template_data['prefix'], |
|
157 |
'label': self.cached_title, |
|
158 |
'suffix': suffix}} |
|
159 |
slots[slot_key].update(slot_template_data) |
|
160 |
return slots |
|
147 |
def get_slug_for_asset(self): |
|
148 |
return self.formdef_reference |
|
149 | ||
150 |
def get_label_for_asset(self): |
|
151 |
return str(self) |
|
152 | ||
153 |
def get_asset_slot_key(self, key): |
|
154 |
# for legacy |
|
155 |
return 'wcs:form:%s:%s' % ( |
|
156 |
key, |
|
157 |
self.get_slug_for_asset()) |
|
158 | ||
159 |
def get_asset_slot_templates(self): |
|
160 |
# for legacy |
|
161 |
if settings.WCS_FORM_ASSET_SLOTS: |
|
162 |
return settings.WCS_FORM_ASSET_SLOTS |
|
163 |
return super().get_asset_slot_templates() |
|
161 | 164 | |
162 | 165 | |
163 | 166 |
class WcsCommonCategoryCell(CellBase): |
... | ... | |
219 | 222 |
return |
220 | 223 |
return self.cached_title |
221 | 224 | |
222 |
def get_asset_slots(self): |
|
223 |
slots = {} |
|
224 |
for slot_template_key, slot_template_data in settings.WCS_CATEGORY_ASSET_SLOTS.items(): |
|
225 |
suffix = '' |
|
226 |
if slot_template_data.get('suffix'): |
|
227 |
suffix = ' (%s)' % slot_template_data['suffix'] |
|
228 |
slot_key = 'wcs:category:%s:%s' % (slot_template_key, self.category_reference) |
|
229 |
slots[slot_key] = { |
|
230 |
'label': u'%(prefix)s — %(label)s%(suffix)s' % { |
|
231 |
'prefix': slot_template_data['prefix'], |
|
232 |
'label': self.cached_title, |
|
233 |
'suffix': suffix}} |
|
234 |
slots[slot_key].update(slot_template_data) |
|
235 |
return slots |
|
225 |
def get_slug_for_asset(self): |
|
226 |
return self.category_reference |
|
227 | ||
228 |
def get_label_for_asset(self): |
|
229 |
return str(self) |
|
230 | ||
231 |
def get_asset_slot_key(self, key): |
|
232 |
# for legacy |
|
233 |
return 'wcs:category:%s:%s' % ( |
|
234 |
key, |
|
235 |
self.get_slug_for_asset()) |
|
236 | ||
237 |
def get_asset_slot_templates(self): |
|
238 |
# for legacy |
|
239 |
if settings.WCS_CATEGORY_ASSET_SLOTS: |
|
240 |
return settings.WCS_CATEGORY_ASSET_SLOTS |
|
241 |
return super().get_asset_slot_templates() |
|
236 | 242 | |
237 | 243 | |
238 | 244 |
@register_cell_class |
combo/apps/wcs/templates/combo/wcs/forms_of_category.html | ||
---|---|---|
3 | 3 | |
4 | 4 |
{% block cell-header %} |
5 | 5 |
<h2>{{ title }}</h2> |
6 |
{% get_asset "wcs:category:picture:"|add:cell.category_reference as asset %} |
|
7 |
{% if asset %} |
|
8 |
<picture> |
|
9 |
<img src="{% asset_url asset size="660x360" crop="center" upscale=False %}" alt=""> |
|
10 |
</picture> |
|
11 |
{% endif %} |
|
6 |
{% include "combo/asset_picture_fragment.html" %} |
|
12 | 7 |
{% if description %} |
13 | 8 |
<div class="intro"> |
14 | 9 |
{{ description|safe }} |
combo/settings.py | ||
---|---|---|
316 | 316 | |
317 | 317 |
# dynamic slots created for wcs category/form cells |
318 | 318 |
# example: {'picture': {'prefix': 'Picture'}} |
319 |
WCS_CATEGORY_ASSET_SLOTS = { |
|
320 |
'picture': { |
|
321 |
'prefix': _('Picture'), |
|
322 |
}, |
|
323 |
} |
|
319 |
# XXX deprecated |
|
320 |
WCS_CATEGORY_ASSET_SLOTS = {} |
|
324 | 321 | |
322 |
# XXX deprecated |
|
325 | 323 |
WCS_FORM_ASSET_SLOTS = {} |
326 | 324 | |
327 | 325 |
COMBO_CELL_ASSET_SLOTS = { |
... | ... | |
335 | 333 |
'prefix': _('Picture'), |
336 | 334 |
}, |
337 | 335 |
}, |
336 |
'wcs_wcsformsofcategorycell': { |
|
337 |
'picture': { |
|
338 |
'prefix': _('Picture'), |
|
339 |
}, |
|
340 |
} |
|
338 | 341 |
} |
339 | 342 | |
340 | 343 |
# known services |
tests/test_wcs.py | ||
---|---|---|
1009 | 1009 | |
1010 | 1010 |
resp = app.post(reverse('wcs-tracking-code'), params={'cell': cell.id}, status=400) |
1011 | 1011 | |
1012 | ||
1012 | 1013 |
@wcs_present |
1013 |
def test_cell_assets(app, admin_user): |
|
1014 |
page = Page(title='xxx', slug='test_cell_assets', template_name='standard') |
|
1015 |
page.save() |
|
1016 |
cell = WcsFormCell(page=page, placeholder='content', order=0) |
|
1017 |
cell.formdef_reference = u'default:form-title' |
|
1018 |
cell.save() |
|
1014 |
def test_cell_assets(settings, app, admin_user): |
|
1015 |
page = Page.objects.create(title='xxx', slug='test_cell_assets', template_name='standard') |
|
1016 |
cell1 = WcsFormCell.objects.create(page=page, placeholder='content', order=0, formdef_reference=u'default:form-title') |
|
1019 | 1017 | |
1020 |
cell = WcsFormsOfCategoryCell(page=page, placeholder='content', order=0)
|
|
1021 |
cell.category_reference = 'default:test-9'
|
|
1022 |
cell.ordering = 'alpha'
|
|
1023 |
cell.save()
|
|
1018 |
cell2 = WcsFormsOfCategoryCell.objects.create(
|
|
1019 |
page=page, placeholder='content', order=0,
|
|
1020 |
category_reference='default:test-9',
|
|
1021 |
ordering='alpha')
|
|
1024 | 1022 | |
1025 | 1023 |
app = login(app) |
1026 |
with override_settings(WCS_CATEGORY_ASSET_SLOTS={}): |
|
1027 |
resp = app.get('/manage/assets/') |
|
1028 |
assert 'have any asset yet.' in resp.text |
|
1029 | ||
1030 |
with override_settings( |
|
1031 |
WCS_CATEGORY_ASSET_SLOTS={'logo': {'prefix': 'Logo'}}, |
|
1032 |
WCS_FORM_ASSET_SLOTS={'picture': {'prefix': 'Picture'}}): |
|
1033 |
resp = app.get('/manage/assets/') |
|
1034 |
assert u'>Logo — Test 9<' in resp.text |
|
1035 |
assert u'>Picture — form title<' in resp.text |
|
1036 | ||
1037 |
with override_settings( |
|
1038 |
WCS_CATEGORY_ASSET_SLOTS={'logo': {'prefix': 'Logo', 'suffix': 'test'}}, |
|
1039 |
WCS_FORM_ASSET_SLOTS={'picture': {'prefix': 'Picture', 'suffix': 'test'}}): |
|
1040 |
resp = app.get('/manage/assets/') |
|
1041 |
assert u'>Logo — Test 9 (test)<' in resp.text |
|
1042 |
assert u'>Picture — form title (test)<' in resp.text |
|
1024 |
settings.WCS_CATEGORY_ASSET_SLOTS = {} |
|
1025 |
settings.WCS_FORM_ASSET_SLOTS = {} |
|
1026 |
settings.COMBO_CELL_ASSET_SLOTS = {} |
|
1027 |
resp = app.get('/manage/assets/') |
|
1028 |
assert 'have any asset yet.' in resp.text |
|
1029 | ||
1030 |
# Old settings have priority |
|
1031 |
settings.WCS_CATEGORY_ASSET_SLOTS = {'logo': {'prefix': 'Logo'}} |
|
1032 |
settings.WCS_FORM_ASSET_SLOTS = {'picture': {'prefix': 'Picture'}} |
|
1033 |
settings.COMBO_CELL_ASSET_SLOTS = { |
|
1034 |
'wcs_wcsformcell': {'picture': {'prefix': 'Picture blabla', 'suffix': 'test'}}, |
|
1035 |
'wcs_wcsformsofcategorycell': {'logo': {'prefix': 'Logo blabla', 'suffix': 'test'}}, |
|
1036 |
} |
|
1037 |
resp = app.get('/manage/assets/') |
|
1038 |
assert u'>Logo — %s<' % cell2.get_label_for_asset() in resp.text |
|
1039 |
assert u'>Logo blabla — %s<' % cell2.get_label_for_asset() not in resp.text |
|
1040 |
assert u'>Picture — %s<' % cell1.get_label_for_asset() in resp.text |
|
1041 |
assert u'>Picture blabla — %s<' % cell1.get_label_for_asset() not in resp.text |
|
1042 |
# New settings |
|
1043 |
settings.WCS_CATEGORY_ASSET_SLOTS = {} |
|
1044 |
settings.WCS_FORM_ASSET_SLOTS = {} |
|
1045 |
settings.COMBO_CELL_ASSET_SLOTS = { |
|
1046 |
'wcs_wcsformcell': {'picture': {'prefix': 'Picture'}}, |
|
1047 |
'wcs_wcsformsofcategorycell': {'logo': {'prefix': 'Logo'}}, |
|
1048 |
} |
|
1049 |
resp = app.get('/manage/assets/') |
|
1050 |
assert u'>Logo — %s<' % cell2.get_label_for_asset() in resp.text |
|
1051 |
assert u'>Picture — %s<' % cell1.get_label_for_asset() in resp.text |
|
1052 | ||
1053 |
# test suffix |
|
1054 |
settings.COMBO_CELL_ASSET_SLOTS = { |
|
1055 |
'wcs_wcsformcell': {'picture': {'prefix': 'Picture', 'suffix': 'test'}}, |
|
1056 |
'wcs_wcsformsofcategorycell': {'logo': {'prefix': 'Logo', 'suffix': 'test'}}, |
|
1057 |
} |
|
1058 |
resp = app.get('/manage/assets/') |
|
1059 |
assert u'>Logo — %s (test)<' % cell2.get_label_for_asset() in resp.text |
|
1060 |
assert u'>Picture — %s (test)<' % cell1.get_label_for_asset() in resp.text |
|
1061 | ||
1043 | 1062 | |
1044 | 1063 |
@wcs_present |
1045 | 1064 |
def test_tracking_code_search(app, nocache): |
1046 |
- |