From 4817f63ad311614520b46ae01d0f3e5074e1fe27 Mon Sep 17 00:00:00 2001 From: Samih Ibrahim Date: Sat, 18 Sep 2021 16:52:37 -0400 Subject: [PATCH] Add flatpages and ckeditor for a light cms experience --- requirements.txt | 3 +++ website/public/admin.py | 14 ++++++++++++-- website/templates/flatpages/default.html | 9 +++++++++ website/website/settings.py | 2 ++ website/website/urls.py | 1 + 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 website/templates/flatpages/default.html diff --git a/requirements.txt b/requirements.txt index 52e1d69..5fb79a9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -55,3 +55,6 @@ html2text==2020.1.16 # Allows us to work with geojson files and perform geographic analysis geojson==2.5.0 Shapely==1.7.1 + +# wysiwyg editor for flatpages +django-ckeditor==6.1.0 \ No newline at end of file diff --git a/website/public/admin.py b/website/public/admin.py index 4185d36..e6c7a57 100644 --- a/website/public/admin.py +++ b/website/public/admin.py @@ -1,3 +1,13 @@ -# from django.contrib import admin +from django.contrib import admin +from django.contrib.flatpages.admin import FlatPageAdmin +from django.contrib.flatpages.models import FlatPage +from django.db import models +from ckeditor.widgets import CKEditorWidget -# Register your models here. +class FlatPageCustom(FlatPageAdmin): + formfield_overrides = { + models.TextField: {'widget': CKEditorWidget} + } + +admin.site.unregister(FlatPage) +admin.site.register(FlatPage, FlatPageCustom) \ No newline at end of file diff --git a/website/templates/flatpages/default.html b/website/templates/flatpages/default.html new file mode 100644 index 0000000..2f89a0a --- /dev/null +++ b/website/templates/flatpages/default.html @@ -0,0 +1,9 @@ +{% extends 'base.html' %} + +{% block title %} +{{ flatpage.title }} +{% endblock %} + +{% block content %} + {{ flatpage.content }} +{% endblock %} \ No newline at end of file diff --git a/website/website/settings.py b/website/website/settings.py index 19d128f..7554892 100644 --- a/website/website/settings.py +++ b/website/website/settings.py @@ -63,6 +63,8 @@ def getenv_bool(key, default=False): 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', + 'django.contrib.flatpages', + 'ckeditor', 'django_extensions', 'bootstrap4', 'django_filters', diff --git a/website/website/urls.py b/website/website/urls.py index e4e390d..190a70a 100644 --- a/website/website/urls.py +++ b/website/website/urls.py @@ -30,6 +30,7 @@ # login redirects to accounts/profile on successful login path('accounts/profile/', UserProfileView.as_view(), name='profile'), path('admin/', admin.site.urls), + path('pages/', include('django.contrib.flatpages.urls')), path('recipients/', include('recipients.urls')), path('volunteers/', include('volunteers.urls')), ]