Skip to content

Commit c4e36bf

Browse files
committed
added changes from comments
1 parent 06ad197 commit c4e36bf

File tree

6 files changed

+51
-20
lines changed

6 files changed

+51
-20
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ This addon is compatible with `Aldryn <http://aldryn.com>`_ and is also availabl
1515
`django CMS Marketplace <https://marketplace.django-cms.org/en/addons/browse/djangocms-file/>`_
1616
for easy installation.
1717

18+
.. image:: preview.gif
19+
1820

1921
Contributing
2022
============

aldryn_config.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
11
# -*- coding: utf-8 -*-
22
from aldryn_client import forms
3+
4+
5+
def split_and_strip(string):
6+
return [item.strip() for item in string.split(',') if item]
7+
8+
9+
class Form(forms.BaseForm):
10+
templates = forms.CharField(
11+
'List of additional templates (comma separated)',
12+
required=False,
13+
)
14+
15+
def clean(self):
16+
data = super(Form, self).clean()
17+
18+
# prettify
19+
data['templates'] = ', '.join(split_and_strip(data['templates']))
20+
return data
21+
22+
def to_settings(self, data, settings):
23+
if data['templates']:
24+
settings['DJANGOCMS_FILE_TEMPLATES'] = [
25+
(item, item)
26+
for item in split_and_strip(data['templates'])
27+
]
28+
29+
return settings

djangocms_file/cms_plugins.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class FolderPlugin(CMSPluginBase):
5757
}),
5858
]
5959

60+
def render(self, context, instance, placeholder):
61+
context['folder_files'] = instance.get_files()
62+
63+
return super(FolderPlugin, self).render(context, instance, placeholder)
64+
6065
def get_render_template(self, context, instance, placeholder):
6166
return 'djangocms_file/{}/folder.html'.format(instance.template)
6267

djangocms_file/models.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@
1717

1818

1919
LINK_TARGET = (
20-
('_self', _('Open in same window.')),
21-
('_blank', _('Open in new window.')),
22-
('_parent', _('Delegate to parent.')),
23-
('_top', _('Delegate to top.')),
20+
('_self', _('Open in same window')),
21+
('_blank', _('Open in new window')),
22+
('_parent', _('Delegate to parent')),
23+
('_top', _('Delegate to top')),
2424
)
2525

2626

2727
# Add additional choices through the ``settings.py``.
2828
def get_templates():
29-
choices = getattr(
29+
choices = [
30+
('default', _('Default')),
31+
]
32+
choices += getattr(
3033
settings,
31-
'DJANGOCMS_FILE_TEMPLATES',
34+
'DJANGOCMS_PICTURE_TEMPLATES',
3235
[],
3336
)
3437
return choices
@@ -41,14 +44,10 @@ class File(CMSPlugin):
4144
"""
4245
search_fields = ('name',)
4346

44-
TEMPLATE_CHOICES = [
45-
('default', _('Default')),
46-
]
47-
4847
template = models.CharField(
4948
verbose_name=_('Template'),
50-
choices=TEMPLATE_CHOICES + get_templates(),
51-
default=TEMPLATE_CHOICES[0][0],
49+
choices=get_templates(),
50+
default=get_templates()[0][0],
5251
max_length=255,
5352
)
5453
file_src = FilerFileField(
@@ -104,6 +103,8 @@ def __str__(self):
104103
return str(self.pk)
105104

106105
def get_short_description(self):
106+
if self.file_name:
107+
return self.file_name
107108
if self.file_src and self.file_src.label:
108109
return self.file_src.label
109110
return ugettext('<file is missing>')
@@ -119,14 +120,10 @@ class Folder(CMSPlugin):
119120
"""
120121
Renders a folder plugin to the selected tempalte
121122
"""
122-
TEMPLATE_CHOICES = [
123-
('default', _('Default')),
124-
]
125-
126123
template = models.CharField(
127124
verbose_name=_('Template'),
128-
choices=TEMPLATE_CHOICES + get_templates(),
129-
default=TEMPLATE_CHOICES[0][0],
125+
choices=get_templates(),
126+
default=get_templates()[0][0],
130127
max_length=255,
131128
)
132129
folder_src = FilerFolderField(

djangocms_file/templates/djangocms_file/default/folder.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% load i18n %}
22

3-
{% for file in instance.get_files %}
3+
{% for file in folder_files %}
44
<a href="{{ file.url }}"
55
{% if instance.link_target %} target="{{ instance.link_target }}"{% endif %}
66
{{ instance.attributes_str }}>
@@ -18,7 +18,7 @@
1818
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video
1919
# https://github.com/divio/django-filer/blob/master/filer/models/filemodels.py
2020
{{ instance.folder_src }}
21-
{{ instance.get_files }}
21+
{{ instance.get_files }} or {{ folder_files }}
2222
# Available variables:
2323
{{ instance.template }}
2424
{{ instance.link_target }}

preview.gif

44.4 KB
Loading

0 commit comments

Comments
 (0)