Skip to content

Commit f6daadd

Browse files
committed
back to template paths as options and block option update options from settings changed to 'extra_options'
1 parent 2395d4a commit f6daadd

6 files changed

Lines changed: 49 additions & 18 deletions

File tree

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ and will be a list of objects if there is.
108108
</ul>
109109
```
110110

111+
> Note: You may use also `block_template` option. For specify a block template file.
112+
113+
```python
114+
class RichText(models.Model):
115+
...
116+
block_template = "streamblocks/richtext.html"
117+
...
118+
```
119+
111120
**4. Add apps to settings.py**
112121

113122
Add to INSTALLED_APPS
@@ -198,6 +207,15 @@ As context use "form":
198207
```html
199208
{{ form.text.value }}
200209
```
210+
211+
You may also specify custom template as option:
212+
```python
213+
class RichText(models.Model):
214+
...
215+
custom_admin_template = "streamblocks/admin/richtext.html"
216+
...
217+
```
218+
201219
### Override how to render block's fields in admin
202220
Create custom template for field with name as lowercased field widget name, and put it inside `.../streamblocks/admin/fields/` folder.
203221

@@ -275,6 +293,22 @@ In page admin you will see it on the bottom of this block.
275293
> Note: Now only "checkbox" and "select" type is working.
276294
You may apply options for all blocks with `STREAMFIELD_BLOCK_OPTIONS` (See [Settings](#settings))
277295

296+
If you want to add block options to options, which was set in django settings, you may use `extra_options`.
297+
```python
298+
class Slide(models.Model):
299+
...
300+
extra_options = {
301+
"autoplay": {
302+
"label": "Autoplay",
303+
"type": "checkbox",
304+
"default": False
305+
}
306+
}
307+
...
308+
```
309+
310+
If you want to switch off options, which set in django settings, for current block. Set `options={}`
311+
278312
## Special cases
279313
### Complex Blocks
280314
You may use StreamField as part of blocks and create with that way complex structure

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="django-streamfield",
8-
version="1.1.4",
8+
version="1.2.0",
99
author="Yury Lapshinov",
1010
author_email="y.raagin@gmail.com",
1111
description="StreamField for native Django Admin or with Grappelli",

streamfield/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
name = "streamfield"
2-
VERSION = '1.1.4'
2+
VERSION = '1.2.0'

streamfield/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ def to_json(self):
118118

119119

120120
def _get_render_data(model_class, model_str, content, ctx):
121-
block_tmpl = 'streamblocks/%s.html' % model_str.lower()
121+
if hasattr(model_class, 'block_template'):
122+
block_tmpl = model_class.block_template
123+
else:
124+
block_tmpl = 'streamblocks/%s.html' % model_str.lower()
125+
print(block_tmpl)
122126
try:
123127
t = loader.get_template(block_tmpl)
124128
except loader.TemplateDoesNotExist:

streamfield/fields.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def __init__(self, attrs=None):
1818
for block in self.model_list:
1919
as_list = hasattr(block, "as_list") and block.as_list
2020

21-
options = BLOCK_OPTIONS
22-
if hasattr(block, "options"):
21+
options = block.options if hasattr(block, "options") else BLOCK_OPTIONS
22+
if hasattr(block, "extra_options"):
2323
options = deepcopy(options)
24-
options.update(block.options)
24+
options.update(block.extra_options)
2525

2626
model_doc = block._meta.verbose_name_plural if as_list else block._meta.verbose_name
2727
model_list_info[block.__name__] = {

streamfield/views.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44
from .forms import get_form_class
55

66
def admin_instance_class(model, base=DetailView):
7-
8-
tmpl = loader.select_template([
9-
'streamblocks/admin/%s.html' % model.__name__.lower(),
10-
'streamfield/admin/change_form_render_template.html'
11-
])
12-
13-
# will be removed in future. use above approach to override admin template.
7+
148
if hasattr(model, 'custom_admin_template'):
159
tmpl_name = model.custom_admin_template
16-
import warnings
17-
warnings.warn(
18-
"'custom_admin_template' will be removed in future. "
19-
"Use override admin template approach instead",
20-
DeprecationWarning, stacklevel=2)
2110
else:
11+
tmpl = loader.select_template([
12+
'streamblocks/admin/%s.html' % model.__name__.lower(),
13+
'streamfield/admin/change_form_render_template.html'
14+
])
2215
tmpl_name = tmpl.template.name
2316

2417
def get_context_data(self, **kwargs):

0 commit comments

Comments
 (0)