0001-assets-make-it-possible-to-qualify-assets-as-not-bei.patch
combo/apps/assets/views.py | ||
---|---|---|
65 | 65 | |
66 | 66 | |
67 | 67 |
class SlotAsset(object): |
68 |
def __init__(self, key=None, name=None, asset=None): |
|
68 |
def __init__(self, key=None, name=None, asset_type='image', asset=None):
|
|
69 | 69 |
self.key = key |
70 | 70 |
self.name = name |
71 |
self.asset_type = asset_type |
|
71 | 72 |
self.asset = asset |
72 | 73 | |
73 | 74 |
def is_image(self): |
74 |
return bool(self.asset) |
|
75 |
return self.asset_type == 'image' and bool(self.asset)
|
|
75 | 76 | |
76 | 77 |
def size(self): |
77 | 78 |
if self.asset: |
... | ... | |
95 | 96 |
for cell in CellBase.get_cells(cell_filter=lambda x: bool(x.get_asset_slots)): |
96 | 97 |
uniq_slots.update(cell.get_asset_slots()) |
97 | 98 |
for key, value in uniq_slots.items(): |
98 |
yield cls(key, name=value.get('label'), asset=assets.get(key)) |
|
99 |
yield cls(key, |
|
100 |
name=value.get('label'), |
|
101 |
asset_type=value.get('asset-type', 'image'), |
|
102 |
asset=assets.get(key)) |
|
99 | 103 | |
100 | 104 | |
101 | 105 |
class Assets(ListView): |
combo/apps/wcs/models.py | ||
---|---|---|
107 | 107 |
suffix = '' |
108 | 108 |
if slot_template_data.get('suffix'): |
109 | 109 |
suffix = ' (%s)' % slot_template_data['suffix'] |
110 |
slots['wcs:form:%s:%s' % (slot_template_key, self.formdef_reference)] = { |
|
110 |
slot_key = 'wcs:form:%s:%s' % (slot_template_key, self.formdef_reference) |
|
111 |
slots[slot_key] = { |
|
111 | 112 |
'label': u'%(prefix)s — %(label)s%(suffix)s' % { |
112 | 113 |
'prefix': slot_template_data['prefix'], |
113 | 114 |
'label': self.cached_title, |
114 | 115 |
'suffix': suffix}} |
116 |
slots[slot_key].update(slot_template_data) |
|
115 | 117 |
return slots |
116 | 118 | |
117 | 119 | |
... | ... | |
150 | 152 |
suffix = '' |
151 | 153 |
if slot_template_data.get('suffix'): |
152 | 154 |
suffix = ' (%s)' % slot_template_data['suffix'] |
153 |
slots['wcs:category:%s:%s' % (slot_template_key, self.category_reference)] = { |
|
155 |
slot_key = 'wcs:category:%s:%s' % (slot_template_key, self.category_reference) |
|
156 |
slots[slot_key] = { |
|
154 | 157 |
'label': u'%(prefix)s — %(label)s%(suffix)s' % { |
155 | 158 |
'prefix': slot_template_data['prefix'], |
156 | 159 |
'label': self.cached_title, |
157 | 160 |
'suffix': suffix}} |
161 |
slots[slot_key].update(slot_template_data) |
|
158 | 162 |
return slots |
159 | 163 | |
160 | 164 |
tests/test_manager.py | ||
---|---|---|
762 | 762 |
'image/png') |
763 | 763 |
resp = resp.form.submit().follow() |
764 | 764 |
assert 'test2.png' in resp.text |
765 |
assert '<img data-href' in resp.text # thumbnail |
|
765 | 766 |
assert '>Delete<' in resp.text |
766 | 767 |
assert Asset.objects.filter(key='collectivity:banner').count() == 1 |
767 | 768 | |
... | ... | |
773 | 774 | |
774 | 775 |
resp = app.get('/assets/collectivity:banner', status=404) |
775 | 776 | |
777 |
with override_settings(COMBO_ASSET_SLOTS={'collectivity:cgu': {'label': 'CGU', 'asset-type': 'document'}}): |
|
778 |
resp = app.get('/manage/assets/') |
|
779 |
assert '>CGU<' in resp.text |
|
780 |
assert '>Delete<' not in resp.text |
|
781 | ||
782 |
resp = resp.click('Overwrite') |
|
783 |
resp.form['upload'] = Upload('test.pdf', 'PDF-1.4 ...', 'application.pdf') |
|
784 |
resp = resp.form.submit().follow() |
|
785 |
assert 'test.pdf' in resp.text |
|
786 |
assert '<img data-href' not in resp.text # no thumbnail |
|
787 |
assert '>Delete<' in resp.text |
|
788 |
assert Asset.objects.filter(key='collectivity:cgu').count() == 1 |
|
789 | ||
776 | 790 |
def test_menu_json(app, admin_user): |
777 | 791 |
app.get('/manage/menu.json', status=302) |
778 | 792 | |
779 |
- |