Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CONCD-610 Use Rich Text editor to Django admin #2200

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bagit = "*"
django-registration = "*"
django-prometheus-metrics = "*"
django-simple-captcha = "*"
django-tinymce = "*"
elasticsearch = "<7.14.0"
django-elasticsearch-dsl = "==7.3"
django-debug-toolbar = "*"
Expand Down
740 changes: 398 additions & 342 deletions Pipfile.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions concordia/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
from .forms import (
AdminItemImportForm,
BleachedDescriptionAdminForm,
CampaignAdminForm,
ProjectAdminForm,
SimpleContentBlockAdminForm,
)

Expand Down Expand Up @@ -182,7 +184,7 @@ def truncated_metadata(self, obj):

@admin.register(Campaign)
class CampaignAdmin(admin.ModelAdmin, CustomListDisplayFieldsMixin):
form = BleachedDescriptionAdminForm
form = CampaignAdminForm

list_display = (
"title",
Expand Down Expand Up @@ -383,7 +385,7 @@ class TopicAdmin(admin.ModelAdmin):

@admin.register(Project)
class ProjectAdmin(admin.ModelAdmin, CustomListDisplayFieldsMixin):
form = BleachedDescriptionAdminForm
form = ProjectAdminForm

# todo: add foreignKey link for campaign
list_display = ("id", "title", "slug", "campaign", "published", "ordering")
Expand Down
22 changes: 22 additions & 0 deletions concordia/admin/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import bleach
from django import forms
from tinymce.widgets import TinyMCE

from ..models import Campaign, Project

FRAGMENT_ALLOWED_TAGS = {"br", "kbd", "span"} | bleach.sanitizer.ALLOWED_TAGS

Expand Down Expand Up @@ -65,6 +68,25 @@ def clean_short_description(self):
)


class CampaignAdminForm(BleachedDescriptionAdminForm):
class Meta:
model = Campaign
widgets = {
"short_description": TinyMCE(),
"description": TinyMCE(),
}
fields = "__all__"


class ProjectAdminForm(BleachedDescriptionAdminForm):
class Meta:
model = Project
widgets = {
"description": TinyMCE(),
}
fields = "__all__"


class SimpleContentBlockAdminForm(forms.ModelForm):
def clean_body(self):
return bleach.clean(
Expand Down
11 changes: 11 additions & 0 deletions concordia/settings_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"flags",
"channels",
"django_admin_multiple_choice_list_filter",
"tinymce",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -388,3 +389,13 @@
},
}
}

SECURE_REFERRER_POLICY = "origin"
TINYMCE_COMPRESSOR = False
TINYMCE_DEFAULT_CONFIG = {
"selector": "textarea.tinymce",
"referrer_policy": "origin",
"skin": "oxide-dark",
"content_css": "dark",
}
TINYMCE_JS_URL = "https://cdn.tiny.cloud/1/rf486i5f1ww9m8191oolczn7f0ry61mzdtfwbu7maiiiv2kv/tinymce/6/tinymce.min.js"
16 changes: 0 additions & 16 deletions concordia/templates/admin/concordia/campaign/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,3 @@
{% endif %}
{{ block.super }}
{% endblock %}

{% block extrahead %}
{{ block.super }}

{% include 'fragments/codemirror.html' %}
{% endblock extrahead %}


{% block content %}
{{ block.super }}

<script>
setupCodeMirror(document.getElementById('id_description'), 'html');
setupCodeMirror(document.getElementById('id_short_description'), 'html');
</script>
{% endblock content %}
15 changes: 0 additions & 15 deletions concordia/templates/admin/concordia/project/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,3 @@
{% endif %}
{{ block.super }}
{% endblock %}

{% block extrahead %}
{{ block.super }}

{% include 'fragments/codemirror.html' %}
{% endblock extrahead %}


{% block content %}
{{ block.super }}

<script>
setupCodeMirror(document.getElementById('id_description'), 'html');
</script>
{% endblock content %}
1 change: 1 addition & 0 deletions concordia/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
path("error/404/", page_not_found, {"exception": Http404()}),
path("error/429/", views.ratelimit_view),
path("error/403/", permission_denied, {"exception": HttpResponseForbidden()}),
path("tinymce/", include("tinymce.urls")),
path("", include("django_prometheus_metrics.urls")),
path("robots.txt", include("robots.urls")),
]
Expand Down