Commit f9f707e8dc23d4d9c5f389c680c193ccf4953bf9

Authored by filipecmedeiros
1 parent 4e06051e

Adding WYSIWYG editor Summernote [Issue #232]

amadeus/settings.py
... ... @@ -46,6 +46,7 @@ INSTALLED_APPS = [
46 46 'rest_framework',
47 47 'django_bootstrap_breadcrumbs',
48 48 's3direct',
  49 + 'django_summernote',
49 50  
50 51 'users',
51 52 'core',
... ... @@ -225,7 +226,59 @@ S3DIRECT_DESTINATIONS = {
225 226 # FILE UPLOAD
226 227 MAX_UPLOAD_SIZE = 10485760
227 228  
  229 +SUMMERNOTE_CONFIG = {
  230 + # Using SummernoteWidget - iframe mode
  231 + 'iframe': True, # or set False to use SummernoteInplaceWidget - no iframe mode
  232 +
  233 + # Using Summernote Air-mode
  234 + 'airMode': False,
  235 +
  236 + # Use native HTML tags (`<b>`, `<i>`, ...) instead of style attributes
  237 + # (Firefox, Chrome only)
  238 + 'styleWithTags': True,
  239 +
  240 + # Set text direction : 'left to right' is default.
  241 + 'direction': 'ltr',
  242 +
  243 + # Change editor size
  244 + 'width': '100%',
  245 + 'height': '480',
  246 +
  247 + # Use proper language setting automatically (default)
  248 + 'lang': None,
  249 +
  250 + # Or, set editor language/locale forcely
  251 + 'lang_matches': {
  252 + 'pt': 'pt-BR',
  253 + },
  254 +
  255 + # Customize toolbar buttons
  256 + 'toolbar': [
  257 + ['style', ['style']],
  258 + ['font', ['bold', 'italic', 'underline', 'superscript', 'subscript',
  259 + 'strikethrough', 'clear']],
  260 + ['fontname', ['fontname']],
  261 + ['fontsize', ['fontsize']],
  262 + ['color', ['color']],
  263 + ['para', ['ul', 'ol', 'paragraph']],
  264 + ['height', ['height']],
  265 + ['table', ['table']],
  266 + ['insert', ['link', 'picture', 'video', 'hr']],
  267 + ['view', ['fullscreen', 'codeview']],
  268 + ['help', ['help']],
  269 + ],
  270 +
  271 + # Need authentication while uploading attachments.
  272 + 'attachment_require_authentication': True,
  273 +
  274 + # Set `upload_to` function for attachments.
  275 + #'attachment_upload_to': my_custom_upload_to_func(),
  276 +
  277 +
  278 +
  279 +}
  280 +
228 281 try:
229 282 from .local_settings import *
230 283 except ImportError:
231 284 - pass
  285 + pass
232 286 \ No newline at end of file
... ...
amadeus/urls.py
... ... @@ -28,6 +28,7 @@ urlpatterns = [
28 28  
29 29 #S3Direct
30 30 url(r'^s3direct/', include('s3direct.urls')),
  31 + url(r'^summernote/', include('django_summernote.urls')),
31 32 ]
32 33  
33 34 urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
... ...
courses/forms.py
... ... @@ -2,7 +2,7 @@ from django import forms
2 2 from django.utils.translation import ugettext_lazy as _
3 3 from .models import CourseCategory, Course, Subject, Topic, ActivityFile, Activity, FileMaterial, LinkMaterial
4 4 from s3direct.widgets import S3DirectWidget
5   -
  5 +from django_summernote.widgets import SummernoteWidget
6 6  
7 7 class CategoryCourseForm(forms.ModelForm):
8 8  
... ... @@ -79,8 +79,8 @@ class CourseForm(forms.ModelForm):
79 79  
80 80 widgets = {
81 81 'categoy': forms.Select(),
82   - 'objectivies': forms.Textarea(attrs={'cols': 80, 'rows': 5}),
83   - 'content': forms.Textarea(attrs={'cols': 80, 'rows': 5}),
  82 + 'objectivies': SummernoteWidget(attrs={'cols': 80, 'rows': 5}),
  83 + 'content': SummernoteWidget(attrs={'cols': 80, 'rows': 5}),
84 84 }
85 85  
86 86 class UpdateCourseForm(CourseForm):
... ... @@ -120,8 +120,8 @@ class UpdateCourseForm(CourseForm):
120 120 }
121 121 widgets = {
122 122 'categoy': forms.Select(),
123   - 'objectivies': forms.Textarea(attrs={'cols': 80, 'rows': 5}),
124   - 'content': forms.Textarea(attrs={'cols': 80, 'rows': 5}),
  123 + 'objectivies': SummernoteWidget(attrs={'cols': 80, 'rows': 5}),
  124 + 'content': SummernoteWidget(attrs={'cols': 80, 'rows': 5}),
125 125 }
126 126  
127 127 class SubjectForm(forms.ModelForm):
... ... @@ -143,6 +143,9 @@ class SubjectForm(forms.ModelForm):
143 143 'end_date': _('End date of the subject'),
144 144 'visible': _('Is the subject visible?'),
145 145 }
  146 + widgets = {
  147 + 'description':SummernoteWidget(),
  148 + }
146 149  
147 150 class TopicForm(forms.ModelForm):
148 151  
... ... @@ -157,6 +160,9 @@ class TopicForm(forms.ModelForm):
157 160 'name': _("Topic's name"),
158 161 'description': _("Topic's description"),
159 162 }
  163 + widgets = {
  164 + 'description':SummernoteWidget(),
  165 + }
160 166  
161 167 class ActivityFileForm(forms.ModelForm):
162 168 name = forms.CharField(
... ...
requirements.txt
  1 +beautifulsoup4==4.5.1
1 2 click==6.6
2 3 decorator==4.0.10
3 4 deps==0.1.0
... ... @@ -10,18 +11,22 @@ django-floppyforms==1.7.0
10 11 django-modalview==0.1.5
11 12 django-role-permissions==1.2.1
12 13 django-s3direct==0.4.2
  14 +django-summernote==0.8.6
13 15 django-widget-tweaks==1.4.1
  16 +django-wysiwyg==0.8.0
14 17 djangorestframework==3.4.6
15 18 gunicorn==19.6.0
  19 +itsdangerous==0.24
16 20 Jinja2==2.8
  21 +lxml==3.6.4
17 22 MarkupSafe==0.23
18 23 Pillow==3.3.1
19 24 psycopg2==2.6.2
20 25 pycpfcnpj==1.0.2
  26 +requests==2.11.1
21 27 six==1.10.0
  28 +slugify==0.0.1
22 29 validators==0.11.0
  30 +virtualenv==15.0.3
23 31 Werkzeug==0.11.11
24 32 whitenoise==3.2.2
25   -beautifulsoup4==4.5.1
26   -lxml==3.6.4
27   -requests==2.11.1
... ...