Skip to content

Commit a751e78

Browse files
authored
Merge pull request #35 from raagin/dev
to 2.0
2 parents ae7a056 + ae953cf commit a751e78

42 files changed

Lines changed: 1251 additions & 13052 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
*.pyc
2-
.idea
32
.DS_Store
4-
dist/*
53
build/*
64
django_streamfield.egg-info/*
75
test_project/db.sqlite3
86
package-lock.json
9-
node_modules/*
7+
frontend/node_modules/*
8+
streamfield/static/streamfield/index.html
9+
streamfield/static/streamfield/streamfield_widget.js.LICENSE.txt

README.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Django StreamField
22

33
This is a simple realisation of StreamField's idea of Wagtail CMS for plain Django admin or with Grappelli skin.
4-
Stable version: 1.4.5
4+
Stable version: 2.0.0
5+
6+
[Major changes (1.4.5 > 2.0.0)](changes2.0.md)
57

68
## Highlights
79
You can build your page with different kind of blocks.
@@ -15,7 +17,7 @@ without any additional settings.
1517

1618
Module also working with [Grappelli Interface](https://github.com/sehmaschine/django-grappelli) (Optional)
1719

18-
![django-streamfield demo screenshot](https://raagin.ru/media/uploads/django-streamfield.png)
20+
![django-streamfield demo screenshot](https://raagin.ru/media/uploads/django-streamfield-2.jpg)
1921

2022
## Contents
2123

@@ -39,7 +41,7 @@ Module also working with [Grappelli Interface](https://github.com/sehmaschine/dj
3941

4042
## Installation
4143

42-
Requirements: `django>=2.*`
44+
Requirements: `django>=3.1`
4345

4446
`pip install django-streamfield`
4547

@@ -63,6 +65,11 @@ For example:
6365
# one object
6466
class RichText(models.Model):
6567
text = models.TextField(blank=True, null=True)
68+
69+
def __str__(self):
70+
# This text will be added to block title name.
71+
# For better navigation when block is collapsed.
72+
return self.text[:30]
6673

6774
class Meta:
6875
# This will use as name of block in admin
@@ -75,6 +82,10 @@ class ImageWithText(models.Model):
7582

7683
# StreamField option for list of objects
7784
as_list = True
85+
86+
def __str__(self):
87+
# This text will be added to block title name. For better navigation when block is collapsed.
88+
return self.text[:30]
7889

7990
class Meta:
8091
verbose_name="Image with text"
@@ -377,6 +388,7 @@ class EmptyBlock(models.Model):
377388
verbose_name='Empty space'
378389
```
379390
and use `streamblocks/templates/streamblocks/emptyblock.html` for your content.
391+
For admin `streamblocks/templates/streamblocks/admin/emptyblock.html`
380392
> Note: Don't forget to register a block in STREAMBLOCKS_MODELS
381393

382394
### Add extra context to blocks
@@ -455,18 +467,17 @@ page.save()
455467
# settings.py
456468
```
457469

458-
### STREAMFIELD_SHOW_ADMIN_COLLAPSE
459-
If you want to hide "Collapse" link in admin.
460-
Set:
470+
### STREAMFIELD_SHOW_ADMIN_HELP_TEXT
471+
If you want to show "Help" link in admin.
472+
Set:
461473
```python
462-
STREAMFIELD_SHOW_ADMIN_COLLAPSE = False
474+
STREAMFIELD_SHOW_ADMIN_HELP_TEXT = True
463475
```
464476

465-
### STREAMFIELD_SHOW_ADMIN_HELP_TEXT
466-
If you want to hide "Help" link in admin.
467-
Set:
477+
### STREAMFIELD_ADMIN_HELP_TEXT
478+
You can setup custom help text in settings
468479
```python
469-
STREAMFIELD_SHOW_ADMIN_HELP_TEXT = False
480+
STREAMFIELD_ADMIN_HELP_TEXT = '<p>Text</p>'
470481
```
471482

472483
### STREAMFIELD_DELETE_BLOCKS_FROM_DB

changes2.0.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# django-streamfield. Changes 2.0
2+
## Major changes
3+
1. Removed string escaping in the database. Now StreamField is stored in the database as a native JSON, since version 3.1 Django supports JSON in all databases. When resaving the object, escaping in the new version will be automatically removed.
4+
2. Added new frontend features: You can open/collapse blocks by one or all together. You can add new block between the others blocks.
5+
3. For better blocks navigation you can add name of the block by using `__str__` method in block definition code.
6+
4. For development. Webpack 5 is used to build frontend part. JS scripts is divided into components. SASS is used for styling.
7+
5. JS libraries are join to one bundle including streamfield.
8+
9+
## Minor changes
10+
1. StreamBlocksAdminMixin now using for StreamBlocksAdmin class (#21)
11+
2. Icons changed from png to svg
12+
3. STREAMFIELD_SHOW_ADMIN_HELP_TEXT bug fixed (#27)
13+
4. STREAMFIELD_SHOW_ADMIN_HELP_TEXT now is False by default. And you can add your own text by using STREAMFIELD_ADMIN_HELP_TEXT in settings.
14+
5. Removed STREAMFIELD_SHOW_ADMIN_COLLAPSE from settings.
15+
6. Fixed migrate_stream_options method.

frontend/babel.config.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"modules": false,
7+
"targets": {
8+
"browsers": [
9+
"> 1%",
10+
"last 2 versions",
11+
"not dead",
12+
"ie > 11"
13+
]
14+
}
15+
}
16+
]
17+
]
18+
}

frontend/images/icons.svg

Lines changed: 1 addition & 0 deletions
Loading

frontend/package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "streamfield_widget.js",
3+
"version": "2.0.0",
4+
"description": "",
5+
"private": true,
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"dev": "webpack --mode development --watch",
9+
"build": "webpack --mode production --progress"
10+
},
11+
"author": "Yury Lapshinov <y.raagin@gmail.com>",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@babel/preset-env": "^7.20.2",
15+
"axios": "^1.3.4",
16+
"babel-loader": "^9.1.2",
17+
"clean-webpack-plugin": "^4.0.0",
18+
"css-loader": "^6.7.3",
19+
"css-minimizer-webpack-plugin": "^4.2.2",
20+
"file-loader": "^6.2.0",
21+
"html-webpack-plugin": "^5.5.0",
22+
"js-cookie": "^3.0.1",
23+
"lodash": "^4.17.21",
24+
"mini-css-extract-plugin": "^2.7.5",
25+
"sass": "^1.60.0",
26+
"sass-loader": "^13.2.1",
27+
"sortablejs": "^1.15.0",
28+
"style-loader": "^3.3.2",
29+
"terser-webpack-plugin": "^5.3.7",
30+
"vue-loader": "^17.0.1",
31+
"vuedraggable": "^4.1.0",
32+
"webpack-cli": "^5.0.1"
33+
}
34+
}

streamfield/static/streamfield/js/admin_popup_response.js renamed to frontend/src/admin_popup_response.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
(function() {
33
'use strict';
44
var initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse);
5-
65
switch(initData.action) {
76
case 'change':
87
opener.streamapps[initData.app_id].updateBlock(initData.block_id, initData.instance_id);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<script>
2+
import BlockHeader from '@/components/BlockHeader.vue'
3+
import BlockOptions from '@/components/BlockOptions.vue'
4+
import AddBlockHere from '@/components/AddBlockHere.vue'
5+
6+
export default {
7+
props: ['block'],
8+
data () {
9+
return {
10+
model_name_lower: this.block.model_name.toLowerCase()
11+
}
12+
},
13+
components: { BlockOptions, BlockHeader, AddBlockHere },
14+
beforeMount: function() {
15+
this.getContent();
16+
},
17+
methods: {
18+
render_url: function(block) {
19+
return '/streamfield/abstract-block/' + this.model_name_lower + '/';
20+
},
21+
getContent() {
22+
let block = _.find(this.$root.stream, ['unique_id', this.block.unique_id]);
23+
window.ax.get(this.render_url(this.block)).then((response) => {
24+
this.$root.blocks[this.block.model_name] = response.data;
25+
});
26+
}
27+
}
28+
}
29+
</script>
30+
<template>
31+
<div class="stream-model-block" :class="{ 'collapsed': block.collapsed }">
32+
<div class="stream-model-block__inner">
33+
<BlockHeader :block="block" />
34+
<div class="stream-model-block__content no-subblocks abstract-block"
35+
:class="model_name_lower">
36+
<span v-html="$root.blocks[this.block.model_name]"></span>
37+
</div>
38+
<BlockOptions :block="block" />
39+
</div>
40+
<AddBlockHere :block="block" />
41+
</div>
42+
</template>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<script>
2+
import BlockList from '@/components/BlockList.vue'
3+
4+
let st;
5+
export default {
6+
props: ['block'],
7+
components: { BlockList },
8+
data () {
9+
return {
10+
hover: false,
11+
show_add_block: false
12+
}
13+
},
14+
methods: {
15+
show () {
16+
st = setTimeout( () => {
17+
this.hover = true
18+
}, 500)
19+
},
20+
hide () {
21+
clearTimeout(st)
22+
this.hover = false
23+
},
24+
get_index () {
25+
let [idx] = this.$root.getBlockIndex(this.block.unique_id)
26+
return idx + 1
27+
},
28+
hideAddBlock () {
29+
this.show_add_block = false
30+
this.hide()
31+
}
32+
}
33+
}
34+
</script>
35+
<template>
36+
<div class="add_here" :class="{'show': hover, show_add_block }" @mouseover="show" @mouseout="hide" @click="show_add_block=!show_add_block">
37+
<BlockList v-if="show_add_block" :idx="get_index()" @hide_add_block="hideAddBlock"/>
38+
</div>
39+
</template>

0 commit comments

Comments
 (0)