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

[WIP] Add flatpages and ckeditor for a light cms experience #492

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 14 additions & 2 deletions website/public/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# from django.contrib import admin
from django.contrib import admin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a good place for this or should I have used another admin.py file? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, we're using the public app as a source of things that should be accessible to the public without logging into the website so FlatPages-related stuff seems like it should fit well here (the "admin" stuff is never accessible to the public anyways)

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)
9 changes: 9 additions & 0 deletions website/templates/flatpages/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'base.html' %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also tweak the base.html template if you need to include other sections from flatpages (not sure if there's more needed beyond the title/content)


{% block title %}
{{ flatpage.title }}
{% endblock %}

{% block content %}
{{ flatpage.content }}
{% endblock %}
2 changes: 2 additions & 0 deletions website/website/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions website/website/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
]