Skip to content

Commit

Permalink
Added basic and minimal editor configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
gulliverbms committed Jun 5, 2018
1 parent 40b50a7 commit 1e45a8d
Show file tree
Hide file tree
Showing 33 changed files with 52,599 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ target/

db.*
TODO.*
example/static/

3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ include README.rst
include CHANGELOG.rst
include LICENSE
include requirements.txt
recursive-include django_grapesjs/templates *
recursive-include django_grapesjs/templates *
recursive-include django_grapesjs/static *
17 changes: 15 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ Just import the field and add to your model
# default_html - path to the html file to display the default value
# for the field when the form page is received
html = GrapesJsHtmlField(default_html='default.html')
...
# or default - if the page is simply static
html = GrapesJsHtmlField(default=render_to_string('default.html'))
...
# use the redactor_config argument to select the configuration of the editor
# Available:
# - redactor_config='base' - basic setting, most widgets are used
# - redactor_config='min' - minimum setting, only the most necessary
html = GrapesJsHtmlField(redactor_config='base')
Custom Settings
===============
Expand All @@ -69,7 +75,14 @@ Custom Settings
GRAPESJS_DEFAULT_MODELS_DATA = True # default value
# redefine the path to the html file, the markup from this file will be used by default
GRAPESJS_DEFAULT_HTML = 'default.html' # default value
GRAPESJS_DEFAULT_HTML = 'django_grapesjs/default.html' # default value
# Add or redefine the configuration of the editor
REDACTOR_CONFIG = {'base': 'django_grapesjs/redactor_config/base.html'} # default value
Warning
===============
the library does not work in "inlines"

Reference
===============
Expand Down
20 changes: 15 additions & 5 deletions django_grapesjs/forms/widgets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django_grapesjs.settings import GRAPESJS_TEMPLATE
from django_grapesjs.settings import GRAPESJS_TEMPLATE, STATIC_URL
from django.template.loader import render_to_string
from django import forms

Expand All @@ -18,13 +18,22 @@ class GrapesJsWidget(forms.Textarea):
class Media:
css = {
'all': (
'https://unpkg.com/grapesjs/dist/css/grapes.min.css',
'https://unpkg.com/grapesjs-preset-newsletter/dist/grapesjs-preset-newsletter.css',
STATIC_URL + 'css/django_grapesjs/grapes.min.css',
STATIC_URL + 'css/django_grapesjs/grapesjs-preset-newsletter.css',
STATIC_URL + 'css/django_grapesjs/grapesjs-preset-webpage.min.css',
STATIC_URL + 'css/django_grapesjs/grapesjs-plugin-filestack.css',
)
}
js = [
'https://unpkg.com/grapesjs',
'https://unpkg.com/grapesjs-preset-newsletter',
'//static.filestackapi.com/v3/filestack.js',
'//feather.aviary.com/imaging/v3/editor.js',
STATIC_URL + 'js/django_grapesjs/grapes.js',
STATIC_URL + 'js/django_grapesjs/grapesjs-aviary.min.js',
STATIC_URL + 'js/django_grapesjs/grapesjs-preset-newsletter.min.js',
STATIC_URL + 'js/django_grapesjs/grapesjs-preset-webpage.min.js',
STATIC_URL + 'js/django_grapesjs/grapesjs-lory-slider.min.js',
STATIC_URL + 'js/django_grapesjs/grapesjs-tabs.min.js',
STATIC_URL + 'js/django_grapesjs/grapesjs-plugin-filestack.min.js',
]

def get_formated_value_id(self, value_id):
Expand All @@ -35,6 +44,7 @@ def get_context(self, name, value, attrs):

context['widget']['attrs']['id'] = self.get_formated_value_id(context['widget']['attrs']['id'])
context['widget'].update({'get_render_html_value': self.get_render_html_value(self.default_html)})
context['widget'].update({'html_name_init_data': self.html_name_init_data})

return context

Expand Down
9 changes: 6 additions & 3 deletions django_grapesjs/models/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from django_grapesjs.settings import GRAPESJS_DEFAULT_HTML
from django_grapesjs.forms.widgets import GrapesJsWidget
from django_grapesjs.forms.fields import GrapesJsField
from django_grapesjs.settings import BASE, GRAPESJS_DEFAULT_HTML, REDACTOR_CONFIG

__all__ = (
'GrapesJsHtmlField',
Expand All @@ -14,15 +14,18 @@ class GrapesJsHtmlField(models.TextField):
"""
def __init__(self, verbose_name=None, name=None, auto_now=False,
auto_now_add=False, **kwargs):
self.default_html = kwargs.pop('default_html', GRAPESJS_DEFAULT_HTML)
auto_now_add=False, default_html=GRAPESJS_DEFAULT_HTML,
redactor_config=BASE, **kwargs):
self.default_html = default_html
self.html_name_init_data = REDACTOR_CONFIG[redactor_config]

super().__init__(verbose_name, name, **kwargs)

def formfield(self, **kwargs):
kwargs['form_class'] = GrapesJsField
kwargs['widget'] = GrapesJsWidget
setattr(kwargs['widget'], 'default_html', self.default_html)
setattr(kwargs['widget'], 'html_name_init_data', self.html_name_init_data)

return super().formfield(**kwargs)

17 changes: 15 additions & 2 deletions django_grapesjs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


# path to the html file of the form field. Enter your value for the override
GRAPESJS_TEMPLATE = getattr(settings, 'GRAPESJS_TEMPLATE', 'textarea.html')
GRAPESJS_TEMPLATE = getattr(settings, 'GRAPESJS_TEMPLATE', 'django_grapesjs/textarea.html')

# True if you want to save html and css
GRAPESJS_SAVE_CSS = int(getattr(settings, 'GRAPESJS_SAVE_CSS', False))
Expand All @@ -11,5 +11,18 @@
GRAPESJS_DEFAULT_MODELS_DATA = int(getattr(settings, 'GRAPESJS_DEFAULT_MODELS_DATA', True))

# redefine the path to the html file, the markup from this file will be used by default
GRAPESJS_DEFAULT_HTML = getattr(settings, 'GRAPESJS_DEFAULT_HTML', 'default.html')
GRAPESJS_DEFAULT_HTML = getattr(settings, 'GRAPESJS_DEFAULT_HTML', 'django_grapesjs/default.html')


MIN = 'min'
BASE = 'base'

# Use this dictionary to override or add editor configurations
REDACTOR_CONFIG = {
MIN: 'django_grapesjs/redactor_config/min.html',
BASE: 'django_grapesjs/redactor_config/base.html',
**getattr(settings, 'REDACTOR_CONFIG', {})
}

STATIC_URL = getattr(settings, 'STATIC_URL', '/static/')

31 changes: 31 additions & 0 deletions django_grapesjs/static/css/django_grapesjs/grapes.min.css

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright (c) 2016, Artur Arseniev
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
- Neither the name "GrapesJS" nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
.gjs-am-assets-cont .gjs-am-asset-image {
border-bottom: none;
float: left;
width: 20%;
height: 150px;
box-sizing: border-box;
border-radius: 3px;
overflow: hidden; }

.gjs-am-preview-cont,
.gjs-am-assets-cont #gjs-am-meta,
.gjs-am-assets-cont #gjs-am-preview-cont {
width: 100%; }

.gjs-am-assets-cont #gjs-am-preview-cont {
height: 100px; }

.gjs-am-assets-cont #gjs-am-close {
right: 10px;
top: 10px;
z-index: 1;
line-height: 0; }

.gjs-btn-filestack {
margin-bottom: 10px; }

.gjs-am-assets-cont {
height: 400px; }

.gjs-am-assets {
height: 345px;
background-color: rgba(0, 0, 0, 0.1);
padding: 5px;
margin: 0 -10px; }
Loading

0 comments on commit 1e45a8d

Please sign in to comment.