From f9f707e8dc23d4d9c5f389c680c193ccf4953bf9 Mon Sep 17 00:00:00 2001 From: filipecmedeiros Date: Thu, 3 Nov 2016 02:42:09 -0300 Subject: [PATCH] Adding WYSIWYG editor Summernote [Issue #232] --- amadeus/settings.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- amadeus/urls.py | 1 + courses/forms.py | 16 +++++++++++----- requirements.txt | 11 ++++++++--- 4 files changed, 74 insertions(+), 9 deletions(-) diff --git a/amadeus/settings.py b/amadeus/settings.py index 438c378..e733a04 100644 --- a/amadeus/settings.py +++ b/amadeus/settings.py @@ -46,6 +46,7 @@ INSTALLED_APPS = [ 'rest_framework', 'django_bootstrap_breadcrumbs', 's3direct', + 'django_summernote', 'users', 'core', @@ -225,7 +226,59 @@ S3DIRECT_DESTINATIONS = { # FILE UPLOAD MAX_UPLOAD_SIZE = 10485760 +SUMMERNOTE_CONFIG = { + # Using SummernoteWidget - iframe mode + 'iframe': True, # or set False to use SummernoteInplaceWidget - no iframe mode + + # Using Summernote Air-mode + 'airMode': False, + + # Use native HTML tags (``, ``, ...) instead of style attributes + # (Firefox, Chrome only) + 'styleWithTags': True, + + # Set text direction : 'left to right' is default. + 'direction': 'ltr', + + # Change editor size + 'width': '100%', + 'height': '480', + + # Use proper language setting automatically (default) + 'lang': None, + + # Or, set editor language/locale forcely + 'lang_matches': { + 'pt': 'pt-BR', + }, + + # Customize toolbar buttons + 'toolbar': [ + ['style', ['style']], + ['font', ['bold', 'italic', 'underline', 'superscript', 'subscript', + 'strikethrough', 'clear']], + ['fontname', ['fontname']], + ['fontsize', ['fontsize']], + ['color', ['color']], + ['para', ['ul', 'ol', 'paragraph']], + ['height', ['height']], + ['table', ['table']], + ['insert', ['link', 'picture', 'video', 'hr']], + ['view', ['fullscreen', 'codeview']], + ['help', ['help']], + ], + + # Need authentication while uploading attachments. + 'attachment_require_authentication': True, + + # Set `upload_to` function for attachments. + #'attachment_upload_to': my_custom_upload_to_func(), + + + +} + try: from .local_settings import * except ImportError: - pass + pass \ No newline at end of file diff --git a/amadeus/urls.py b/amadeus/urls.py index 52845ec..2f3745e 100644 --- a/amadeus/urls.py +++ b/amadeus/urls.py @@ -28,6 +28,7 @@ urlpatterns = [ #S3Direct url(r'^s3direct/', include('s3direct.urls')), + url(r'^summernote/', include('django_summernote.urls')), ] urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT) diff --git a/courses/forms.py b/courses/forms.py index 4f32ac2..ae3a796 100644 --- a/courses/forms.py +++ b/courses/forms.py @@ -2,7 +2,7 @@ from django import forms from django.utils.translation import ugettext_lazy as _ from .models import CourseCategory, Course, Subject, Topic, ActivityFile, Activity, FileMaterial, LinkMaterial from s3direct.widgets import S3DirectWidget - +from django_summernote.widgets import SummernoteWidget class CategoryCourseForm(forms.ModelForm): @@ -79,8 +79,8 @@ class CourseForm(forms.ModelForm): widgets = { 'categoy': forms.Select(), - 'objectivies': forms.Textarea(attrs={'cols': 80, 'rows': 5}), - 'content': forms.Textarea(attrs={'cols': 80, 'rows': 5}), + 'objectivies': SummernoteWidget(attrs={'cols': 80, 'rows': 5}), + 'content': SummernoteWidget(attrs={'cols': 80, 'rows': 5}), } class UpdateCourseForm(CourseForm): @@ -120,8 +120,8 @@ class UpdateCourseForm(CourseForm): } widgets = { 'categoy': forms.Select(), - 'objectivies': forms.Textarea(attrs={'cols': 80, 'rows': 5}), - 'content': forms.Textarea(attrs={'cols': 80, 'rows': 5}), + 'objectivies': SummernoteWidget(attrs={'cols': 80, 'rows': 5}), + 'content': SummernoteWidget(attrs={'cols': 80, 'rows': 5}), } class SubjectForm(forms.ModelForm): @@ -143,6 +143,9 @@ class SubjectForm(forms.ModelForm): 'end_date': _('End date of the subject'), 'visible': _('Is the subject visible?'), } + widgets = { + 'description':SummernoteWidget(), + } class TopicForm(forms.ModelForm): @@ -157,6 +160,9 @@ class TopicForm(forms.ModelForm): 'name': _("Topic's name"), 'description': _("Topic's description"), } + widgets = { + 'description':SummernoteWidget(), + } class ActivityFileForm(forms.ModelForm): name = forms.CharField( diff --git a/requirements.txt b/requirements.txt index 1eeb137..d7aa162 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +beautifulsoup4==4.5.1 click==6.6 decorator==4.0.10 deps==0.1.0 @@ -10,18 +11,22 @@ django-floppyforms==1.7.0 django-modalview==0.1.5 django-role-permissions==1.2.1 django-s3direct==0.4.2 +django-summernote==0.8.6 django-widget-tweaks==1.4.1 +django-wysiwyg==0.8.0 djangorestframework==3.4.6 gunicorn==19.6.0 +itsdangerous==0.24 Jinja2==2.8 +lxml==3.6.4 MarkupSafe==0.23 Pillow==3.3.1 psycopg2==2.6.2 pycpfcnpj==1.0.2 +requests==2.11.1 six==1.10.0 +slugify==0.0.1 validators==0.11.0 +virtualenv==15.0.3 Werkzeug==0.11.11 whitenoise==3.2.2 -beautifulsoup4==4.5.1 -lxml==3.6.4 -requests==2.11.1 -- libgit2 0.21.2