From 47d166203304f971ed2fb7a5deccdd9352778570 Mon Sep 17 00:00:00 2001 From: Martin Green Date: Sun, 26 Jun 2022 21:29:46 +0100 Subject: [PATCH] Added help writing HTML in the cave editing form. Made the HTML previews optional --- core/forms.py | 23 +++++++++++----- core/views/editor_helpers.py | 4 +-- core/views/expo.py | 5 ++-- templates/editcave.html | 4 +-- templates/html_editor_scripts_css.html | 36 ++++++++++++++++++++------ templates/widgets/HTMLarea.html | 4 ++- 6 files changed, 54 insertions(+), 22 deletions(-) diff --git a/core/forms.py b/core/forms.py index cd40822..19a3b1b 100644 --- a/core/forms.py +++ b/core/forms.py @@ -11,6 +11,8 @@ from django.contrib.admin.widgets import AdminDateWidget from troggle.core.models.troggle import Person, PersonExpedition, Expedition from troggle.core.models.caves import Cave, LogbookEntry, QM, Entrance, CaveAndEntrance +from troggle.core.views.editor_helpers import HTMLarea + '''These are all the class-based Forms used by troggle. There are other, simpler, upload forms in view/uploads.py Some are not used and need renovating or destroying. @@ -24,15 +26,22 @@ class CaveForm(ModelForm): the other fields are present on the form, but use the default presentation style ''' official_name = forms.CharField(required = False, widget=forms.TextInput(attrs={'size': '45'})) - underground_description = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':9})) - explorers = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2})) - equipment = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2})) - survey = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2})) + underground_description = forms.CharField(required = False, widget=HTMLarea( + attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"})) + explorers = forms.CharField(required = False, widget=HTMLarea( + attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"})) + equipment = forms.CharField(required = False, widget=HTMLarea( + attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"})) + survey = forms.CharField(required = False, widget=HTMLarea( + attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"})) #survey = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) kataster_status = forms.CharField(required = False) - underground_centre_line = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2})) - notes = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2})) - references = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':1})) + underground_centre_line = forms.CharField(required = False, widget=HTMLarea( + attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"})) + notes = forms.CharField(required = False, widget=HTMLarea( + attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"})) + references = forms.CharField(required = False, widget=HTMLarea( + attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"})) description_file = forms.CharField(required = False, widget=forms.TextInput(attrs={'size': '45'})) survex_file = forms.CharField(required = False, label="Survex file [caves-1623/000/000.svx]", widget=forms.TextInput(attrs={'size': '45'})) url = forms.CharField(required = True, label="URL [1623/000/000]", widget=forms.TextInput(attrs={'size': '45'})) diff --git a/core/views/editor_helpers.py b/core/views/editor_helpers.py index 0051138..8eb2591 100644 --- a/core/views/editor_helpers.py +++ b/core/views/editor_helpers.py @@ -134,10 +134,10 @@ class NewWebImageForm(forms.Form): class HTMLarea(forms.Textarea): template_name = "widgets/HTMLarea.html" def __init__(self, *args, **kwargs): - self.iframeattrs = kwargs.pop('iframeattrs') + self.preview = kwargs.pop('preview', False) super(forms.Textarea, self).__init__(*args, **kwargs) def get_context(self, name, value, attrs): c = super(forms.Textarea, self).get_context(name, value, attrs) - c["iframe"] = {"attrs": self.iframeattrs} + c["preview"] = self.preview return c diff --git a/core/views/expo.py b/core/views/expo.py index 1d07d6b..7b0d283 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -382,6 +382,7 @@ class ExpoPageForm(forms.Form): '''The form used by the editexpopage function ''' title = forms.CharField(widget=forms.TextInput(attrs={'size':'60', 'placeholder': "Enter title (displayed in tab)"})) - html = forms.CharField(widget=HTMLarea(iframeattrs = {"height": "80%"}, - attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"})) + html = forms.CharField(widget=HTMLarea(attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}, + preview = True + )) change_message = forms.CharField(widget=forms.Textarea(attrs={"cols":80, "rows":3, 'placeholder': "Descibe the change made (for git)"})) diff --git a/templates/editcave.html b/templates/editcave.html index 49aa767..64c2f97 100644 --- a/templates/editcave.html +++ b/templates/editcave.html @@ -1,11 +1,11 @@ {% extends "cavebase.html" %} {% block title %}Edit Cave - {{cave.official_name|safe}} - {{cave.kataster_number}}{% endblock %} {% block extraheaders %} - - +{% include 'html_editor_scripts_css.html' %} {% endblock %} {% block content %}

Edit Cave - {{cave.official_name|safe}} - {{cave.kataster_number}}

+{% include 'html_editor_pop_ups.html' %}

{{message}}

{% csrf_token %} {{ form }}{{caveAndEntranceFormSet}}
diff --git a/templates/html_editor_scripts_css.html b/templates/html_editor_scripts_css.html index 78dad9f..8634958 100644 --- a/templates/html_editor_scripts_css.html +++ b/templates/html_editor_scripts_css.html @@ -8,7 +8,6 @@ - "); preview.write(HTMLarea.data("editor").getValue()); @@ -158,7 +173,12 @@ function add_image_popup(editor) { $('.add-image-popup').addClass('active'); window.current_editor = editor; - $('#image_popup_content').load("{% url 'image_selector' path %}", function() { + {% if not path %} + var path = $("#id_url").val(); + {% else %} + var path = ""; + {% endif %} + $('#image_popup_content').load("{% url 'image_selector' path %}" + path, function() { $('.thumbnail').click(function(){ $(".add-image-popup").removeClass("active"); addStr(window.current_editor, $( this ).attr("data-html")) diff --git a/templates/widgets/HTMLarea.html b/templates/widgets/HTMLarea.html index 1f1c99a..50a332c 100644 --- a/templates/widgets/HTMLarea.html +++ b/templates/widgets/HTMLarea.html @@ -1,6 +1,8 @@
{% include "django/forms/widgets/textarea.html" %} - +{% if preview %} + +{% endif %}