0003-assets-display-assets-related-to-cell-in-popup-40223.patch
combo/apps/assets/templates/combo/manager_assets.html | ||
---|---|---|
38 | 38 | |
39 | 39 |
<div id="assets-browser"> |
40 | 40 |
<div id="assets-listing"> |
41 |
<table class="main"> |
|
42 |
<thead> |
|
43 |
<tr> |
|
44 |
<th>{% trans "Name" %}</th> |
|
45 |
<th>{% trans "Size" %}</th> |
|
46 |
<th></th> |
|
47 |
<th></th> |
|
48 |
</tr> |
|
49 |
</thead> |
|
50 |
<tbody> |
|
51 |
{% for asset in object_list %} |
|
52 |
<tr class="{{ asset.css_classes }}"> |
|
53 |
<td><a href="{{ asset.src }}">{{ asset.name }}</a></td> |
|
54 |
<td>{% if asset.size %}{{ asset.size|filesizeformat }}{% else %}-{% endif %}</td> |
|
55 |
<td class="image">{% if asset.is_image %}<img data-href="{{ asset.src }}" src="{{ asset.thumb }}"/>{% endif %}</td> |
|
56 |
<td class="actions"> |
|
57 |
{% if asset.key %}{# theme asset #} |
|
58 |
<a href="{% url 'combo-manager-slot-asset-upload' key=asset.key %}" |
|
59 |
class="overwrite" rel="popup">{% trans 'Overwrite' %}</a> |
|
60 |
{% if asset.asset %} |
|
61 |
<a href="{% url 'combo-manager-slot-asset-delete' key=asset.key %}" |
|
62 |
class="delete" rel="popup">{% trans 'Delete' %}</a> |
|
63 |
{% endif %} |
|
64 |
{% else %} |
|
65 |
<a href="{% url 'combo-manager-asset-overwrite' %}?img={{asset.filepath|iriencode}}" |
|
66 |
class="overwrite" rel="popup">{% trans 'Overwrite' %}</a> |
|
67 |
<a href="{% url 'combo-manager-asset-delete' %}?img={{asset.filepath|iriencode}}" |
|
68 |
class="delete" rel="popup">{% trans 'Delete' %}</a> |
|
69 |
{% endif %} |
|
70 |
</td> |
|
71 |
</td> |
|
72 |
</tr> |
|
73 |
{% endfor %} |
|
74 |
</tbody> |
|
75 |
</table> |
|
41 |
{% include "combo/manager_assets_fragment.html" %} |
|
76 | 42 |
</div> |
77 | 43 |
<div id="asset-preview"></div> |
78 | 44 |
</div> |
combo/apps/assets/templates/combo/manager_assets_fragment.html | ||
---|---|---|
1 |
{% load i18n %} |
|
2 |
<table class="main"> |
|
3 |
<thead> |
|
4 |
<tr> |
|
5 |
<th>{% trans "Name" %}</th> |
|
6 |
<th>{% trans "Size" %}</th> |
|
7 |
<th></th> |
|
8 |
<th></th> |
|
9 |
</tr> |
|
10 |
</thead> |
|
11 |
<tbody> |
|
12 |
{% for asset in object_list %} |
|
13 |
<tr class="{{ asset.css_classes }}"> |
|
14 |
<td><a href="{{ asset.src }}">{{ asset.name }}</a></td> |
|
15 |
<td>{% if asset.size %}{{ asset.size|filesizeformat }}{% else %}-{% endif %}</td> |
|
16 |
<td class="image">{% if asset.is_image %}<img data-href="{{ asset.src }}" src="{{ asset.thumb }}"/>{% endif %}</td> |
|
17 |
<td class="actions"> |
|
18 |
{% if asset.key %}{# theme asset #} |
|
19 |
<a href="{% url 'combo-manager-slot-asset-upload' key=asset.key %}{% if cell_reference %}?cell_reference={{ cell_reference }}{% endif %}" |
|
20 |
class="overwrite" rel="popup">{% trans 'Overwrite' %}</a> |
|
21 |
{% if asset.asset %} |
|
22 |
<a href="{% url 'combo-manager-slot-asset-delete' key=asset.key %}{% if cell_reference %}?cell_reference={{ cell_reference }}{% endif %}" |
|
23 |
class="delete" rel="popup">{% trans 'Delete' %}</a> |
|
24 |
{% endif %} |
|
25 |
{% else %} |
|
26 |
<a href="{% url 'combo-manager-asset-overwrite' %}?img={{asset.filepath|iriencode}}" |
|
27 |
class="overwrite" rel="popup">{% trans 'Overwrite' %}</a> |
|
28 |
<a href="{% url 'combo-manager-asset-delete' %}?img={{asset.filepath|iriencode}}" |
|
29 |
class="delete" rel="popup">{% trans 'Delete' %}</a> |
|
30 |
{% endif %} |
|
31 |
</td> |
|
32 |
</tr> |
|
33 |
{% endfor %} |
|
34 |
</tbody> |
|
35 |
</table> |
combo/apps/assets/templates/combo/manager_slot_assets.html | ||
---|---|---|
1 |
{% extends "combo/manager_base.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block appbar %} |
|
5 |
<h2>{% trans 'Assets' %}</h2> |
|
6 |
{% endblock %} |
|
7 | ||
8 |
{% block breadcrumb %} |
|
9 |
{{ block.super }} |
|
10 |
<a href="{% url 'combo-manager-assets' %}">{% trans 'Assets' %}</a> |
|
11 |
{% endblock %} |
|
12 | ||
13 |
{% block content %} |
|
14 | ||
15 |
<div id="assets-listing"> |
|
16 |
{% include "combo/manager_assets_fragment.html" %} |
|
17 |
</div> |
|
18 | ||
19 |
{% endblock %} |
combo/apps/assets/urls.py | ||
---|---|---|
23 | 23 | |
24 | 24 |
assets_manager_urls = [ |
25 | 25 |
url(r'^$', views.assets, name='combo-manager-assets'), |
26 |
url(r'^slots/(?P<cell_reference>[\w_-]+)/$', views.slot_assets, name='combo-manager-slot-assets'), |
|
26 | 27 |
url(r'^delete$', views.asset_delete, name='combo-manager-asset-delete'), |
27 | 28 |
url(r'^overwrite/$', views.asset_overwrite, name='combo-manager-asset-overwrite'), |
28 | 29 |
url(r'^upload/$', views.asset_upload, name='combo-manager-asset-upload'), |
... | ... | |
37 | 38 |
url(r'^manage/assets/', decorated_includes(manager_required, |
38 | 39 |
include(assets_manager_urls))), |
39 | 40 | |
40 |
url('^api/assets/set/(?P<key>[\w_:-]+)/$', api_views.view_set, |
|
41 |
url(r'^api/assets/set/(?P<key>[\w_:-]+)/$', api_views.view_set,
|
|
41 | 42 |
name='api-assets-set'), |
42 | 43 |
] |
combo/apps/assets/views.py | ||
---|---|---|
20 | 20 | |
21 | 21 |
from django.conf import settings |
22 | 22 |
from django.contrib import messages |
23 |
from django.core.exceptions import PermissionDenied |
|
23 |
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
|
24 | 24 |
from django.core.files.storage import default_storage |
25 | 25 |
from django.core.urlresolvers import reverse, reverse_lazy |
26 | 26 |
from django.http import Http404, HttpResponse |
... | ... | |
230 | 230 |
Assets(request=self.request).get_anchored_url( |
231 | 231 |
name=os.path.basename(img_orig))) |
232 | 232 | |
233 | ||
233 | 234 |
asset_delete = AssetDelete.as_view() |
234 | 235 | |
235 | 236 | |
237 |
class SlotAssets(ListView): |
|
238 |
template_name = 'combo/manager_slot_assets.html' |
|
239 | ||
240 |
def get_assets(self, cell): |
|
241 |
asset_slots = cell.get_asset_slots() |
|
242 |
assets = dict([(x.key, x) for x in Asset.objects.filter(key__in=asset_slots.keys())]) |
|
243 |
for key, value in asset_slots.items(): |
|
244 |
yield SlotAsset( |
|
245 |
key, |
|
246 |
name=value.get('label'), |
|
247 |
asset_type=value.get('asset-type', 'image'), |
|
248 |
asset=assets.get(key)) |
|
249 | ||
250 |
def get_queryset(self): |
|
251 |
cell_reference = self.kwargs['cell_reference'] |
|
252 |
try: |
|
253 |
cell = CellBase.get_cell(cell_reference) |
|
254 |
except ObjectDoesNotExist: |
|
255 |
raise Http404() |
|
256 | ||
257 |
return self.get_assets(cell) |
|
258 | ||
259 |
def get_context_data(self, **kwargs): |
|
260 |
context = super().get_context_data(**kwargs) |
|
261 |
context['cell_reference'] = self.kwargs['cell_reference'] |
|
262 |
return context |
|
263 | ||
264 | ||
265 |
slot_assets = SlotAssets.as_view() |
|
266 | ||
267 | ||
236 | 268 |
class SlotAssetUpload(FormView): |
237 | 269 |
form_class = AssetUploadForm |
238 | 270 |
template_name = 'combo/manager_asset_upload.html' |
... | ... | |
248 | 280 |
return super(SlotAssetUpload, self).form_valid(form) |
249 | 281 | |
250 | 282 |
def get_success_url(self): |
283 |
if self.request.GET.get('cell_reference'): |
|
284 |
cell_reference = self.request.GET['cell_reference'] |
|
285 |
try: |
|
286 |
cell = CellBase.get_cell(cell_reference) |
|
287 |
except ObjectDoesNotExist: |
|
288 |
pass |
|
289 |
else: |
|
290 |
return reverse('combo-manager-page-view', kwargs={'pk': cell.page_id}) + '#cell-' + cell_reference |
|
291 | ||
251 | 292 |
return Assets(request=self.request).get_anchored_url(key=self.kwargs['key']) |
252 | 293 | |
294 | ||
253 | 295 |
slot_asset_upload = SlotAssetUpload.as_view() |
254 | 296 | |
255 | 297 | |
... | ... | |
258 | 300 | |
259 | 301 |
def post(self, request, *args, **kwargs): |
260 | 302 |
Asset.objects.filter(key=kwargs['key']).delete() |
303 |
if self.request.GET.get('cell_reference'): |
|
304 |
cell_reference = self.request.GET['cell_reference'] |
|
305 |
try: |
|
306 |
cell = CellBase.get_cell(cell_reference) |
|
307 |
except ObjectDoesNotExist: |
|
308 |
pass |
|
309 |
else: |
|
310 |
return redirect( |
|
311 |
reverse('combo-manager-page-view', kwargs={'pk': cell.page_id}) + '#cell-' + cell_reference) |
|
261 | 312 |
return redirect(Assets(request=self.request).get_anchored_url(key=kwargs['key'])) |
262 | 313 | |
314 | ||
263 | 315 |
slot_asset_delete = SlotAssetDelete.as_view() |
264 | 316 | |
265 | 317 |
combo/manager/static/css/combo.manager.css | ||
---|---|---|
258 | 258 |
width: 80%; |
259 | 259 |
} |
260 | 260 | |
261 |
#assets-browser #assets-listing table th,
|
|
262 |
#assets-browser #assets-listing table td {
|
|
261 |
#assets-listing table th, |
|
262 |
#assets-listing table td { |
|
263 | 263 |
text-align: left; |
264 | 264 |
padding-left: 1ex; |
265 | 265 |
} |
266 | 266 | |
267 |
#assets-browser #assets-listing table td.image {
|
|
267 |
#assets-listing table td.image { |
|
268 | 268 |
padding: 0; |
269 | 269 |
text-align: center; |
270 | 270 |
} |
271 | 271 | |
272 |
#assets-browser #assets-listing table td.actions {
|
|
272 |
#assets-listing table td.actions { |
|
273 | 273 |
width: 80px; |
274 | 274 |
} |
275 | 275 | |
276 |
#assets-browser #assets-listing table td.actions a.overwrite,
|
|
277 |
#assets-browser #assets-listing table td.actions a.delete {
|
|
276 |
#assets-listing table td.actions a.overwrite, |
|
277 |
#assets-listing table td.actions a.delete { |
|
278 | 278 |
display: inline-block; |
279 | 279 |
border: none; |
280 | 280 |
overflow: hidden; |
... | ... | |
283 | 283 |
line-height: 30px; |
284 | 284 |
} |
285 | 285 | |
286 |
#assets-browser #assets-listing table td.actions a.delete::before {
|
|
286 |
#assets-listing table td.actions a.delete::before { |
|
287 | 287 |
text-align: center; |
288 | 288 |
font-family: FontAwesome; |
289 | 289 |
content: "\f057"; /* remove-sign */ |
... | ... | |
291 | 291 |
width: 30px; |
292 | 292 |
} |
293 | 293 | |
294 |
#assets-browser #assets-listing table td.actions a.overwrite::before {
|
|
294 |
#assets-listing table td.actions a.overwrite::before { |
|
295 | 295 |
text-align: center; |
296 | 296 |
font-family: FontAwesome; |
297 | 297 |
content: "\f093"; /* upload */ |
combo/manager/templates/combo/manager_edit_cell_block.html | ||
---|---|---|
17 | 17 |
<a rel="popup" href="{% url 'combo-manager-page-delete-cell' page_pk=page.id cell_reference=cell.get_reference %}">{% trans 'Delete' %}</a> | |
18 | 18 |
<a rel="popup" href="{% url 'combo-manager-page-visibility-cell' page_pk=page.id cell_reference=cell.get_reference %}">{% trans 'Visibility' %}</a> | |
19 | 19 |
<a rel="popup" href="{% url 'combo-manager-page-options-cell' page_pk=page.id cell_reference=cell.get_reference %}">{% trans 'Options' %}</a> | |
20 |
{% if cell.can_have_assets %}<a rel="popup" data-selector="div#assets-listing" href="{% url 'combo-manager-slot-assets' cell_reference=cell.get_reference %}">{% trans 'Assets' %}</a> |{% endif %} |
|
20 | 21 |
<a class="close-button" href="#">{% trans 'Close' %}</a> |
21 | 22 |
{% if form %} |
22 | 23 |
<button class="save submit-button">{% trans 'Save' %}</button> |
tests/test_manager.py | ||
---|---|---|
1136 | 1136 |
resp = resp.form.submit() |
1137 | 1137 |
assert resp.text.count('<tr class="asset') == 2 |
1138 | 1138 | |
1139 | ||
1139 | 1140 |
def test_asset_slots_management(app, admin_user): |
1140 | 1141 |
app = login(app) |
1141 | 1142 |
assert Asset.objects.count() == 0 |
... | ... | |
1198 | 1199 |
assert '>CGU<' in resp.text |
1199 | 1200 | |
1200 | 1201 | |
1202 |
def test_asset_slots_for_cells_management(settings, app, admin_user): |
|
1203 |
app = login(app) |
|
1204 |
assert Asset.objects.count() == 0 |
|
1205 | ||
1206 |
settings.COMBO_CELL_ASSET_SLOTS = {'data_textcell': {'picture': {'prefix': 'Picture'}}} |
|
1207 |
page = Page.objects.create(title='xxx', slug='test_cell_assets', template_name='standard') |
|
1208 |
cell = TextCell.objects.create(page=page, order=0, slug='foo') |
|
1209 | ||
1210 |
resp = app.get('/manage/assets/slots/%s/' % cell.get_reference()) |
|
1211 |
assert '>Overwrite<' in resp.text |
|
1212 |
assert '>Delete<' not in resp.text |
|
1213 | ||
1214 |
resp = resp.click('Overwrite') |
|
1215 |
resp.form['upload'] = Upload( |
|
1216 |
'test.png', |
|
1217 |
base64.decodebytes(b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12NgAgAABAADRWoApgAA\nAABJRU5ErkJggg=='), |
|
1218 |
'image/png') |
|
1219 |
resp = resp.form.submit() |
|
1220 |
assert resp.location.endswith('/manage/pages/%s/#cell-%s' % (page.pk, cell.get_reference())) |
|
1221 |
assert Asset.objects.filter(key=cell.get_asset_slot_key('picture')).count() == 1 |
|
1222 | ||
1223 |
assert app.get('/assets/%s' % cell.get_asset_slot_key('picture'), status=302)['location'].endswith('test.png') |
|
1224 | ||
1225 |
# upload a new version of image |
|
1226 |
resp = app.get('/manage/assets/slots/%s/' % cell.get_reference()) |
|
1227 |
resp = resp.click('Overwrite') |
|
1228 |
resp.form['upload'] = Upload( |
|
1229 |
'test2.png', |
|
1230 |
base64.decodebytes(b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12NgAgAABAADRWoApgAA\nAABJRU5ErkJggg=='), |
|
1231 |
'image/png') |
|
1232 |
resp = resp.form.submit() |
|
1233 |
resp = app.get('/manage/assets/slots/%s/' % cell.get_reference()) |
|
1234 |
assert 'test2.png' in resp.text |
|
1235 |
assert '<img data-href' in resp.text # thumbnail |
|
1236 |
assert '>Delete<' in resp.text |
|
1237 |
assert Asset.objects.filter(key=cell.get_asset_slot_key('picture')).count() == 1 |
|
1238 | ||
1239 |
# delete the image |
|
1240 |
resp = app.get('/manage/assets/slots/%s/' % cell.get_reference()) |
|
1241 |
resp = resp.click('Delete') |
|
1242 |
resp = resp.form.submit() |
|
1243 |
assert resp.location.endswith('/manage/pages/%s/#cell-%s' % (page.pk, cell.get_reference())) |
|
1244 |
resp = app.get('/manage/assets/slots/%s/' % cell.get_reference()) |
|
1245 |
assert '>Overwrite<' in resp.text |
|
1246 |
assert '>Delete<' not in resp.text |
|
1247 |
assert Asset.objects.filter(key=cell.get_asset_slot_key('picture')).count() == 0 |
|
1248 | ||
1249 |
assert app.get('/assets/%s' % cell.get_asset_slot_key('picture'), status=404) |
|
1250 | ||
1251 | ||
1201 | 1252 |
def test_asset_slots_export(app, admin_user): |
1202 | 1253 |
app = login(app) |
1203 | 1254 | |
1204 |
- |