Skip to content

Commit

Permalink
Initial wagtail setup (#1071)
Browse files Browse the repository at this point in the history
* Add wagtail

* Wagtail version of homepage model

And add wagtail to requirements.txt

* add google login to the Wagtail login page

* wagtail feature flag ENABLE_WAGTAIL added

* lol flake

* not everything wagtail can be locked away

* wrong env syntax

* proper filtering
  • Loading branch information
Pomax authored and alanmoo committed Feb 26, 2018
1 parent f6759e7 commit 5c21d15
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 24 deletions.
31 changes: 16 additions & 15 deletions env.default
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@ PULSE_API_DOMAIN=network-pulse-api-production.herokuapp.com
PULSE_DOMAIN=www.mozillapulse.org
# Always add a protocol (ex: https://) in front of the NETWORK_SITE_URL, including for localhost
NETWORK_SITE_URL=https://foundation.mozilla.org
TARGET_DOMAIN=foundation.mozilla.org
SHOW_TAKEOVER=false
TARGET_DOMAIN=foundation.mozilla.org

# network-api environment:

DEBUG=True
DJANGO_SECRET_KEY=secret
USE_S3=False
ALLOWED_HOSTS=localhost,127.0.0.1
ASSET_DOMAIN=network.mofoprod.net
AWS_SQS_ACCESS_KEY_ID=
AWS_SQS_SECRET_ACCESS_KEY=
AWS_SQS_REGION=
CONTENT_TYPE_NO_SNIFF=True
CORS_WHITELIST=*
CORS_REGEX_WHITELIST=
XSS_PROTECTION=True
CONTENT_TYPE_NO_SNIFF=True
DEBUG=True
DJANGO_SECRET_KEY=secret
ENABLE_WAGTAIL=False
LOAD_FIXTURE=False
PETITION_SQS_QUEUE_URL=
SET_HSTS=False
SSL_REDIRECT=False
X_FRAME_OPTIONS=DENY
ALLOWED_HOSTS=localhost,127.0.0.1
ASSET_DOMAIN=network.mofoprod.net
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY=
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET=
SOCIAL_AUTH_LOGIN_REDIRECT_URL=http://localhost:5000/soc/complete/google-oauth2/
LOAD_FIXTURE=False
PETITION_SQS_QUEUE_URL=
AWS_SQS_ACCESS_KEY_ID=
AWS_SQS_SECRET_ACCESS_KEY=
AWS_SQS_REGION=
SSL_REDIRECT=False
USE_S3=False
X_FRAME_OPTIONS=DENY
XSS_PROTECTION=True

# CSP config

Expand Down
15 changes: 15 additions & 0 deletions network-api/networkapi/highlights/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from networkapi.highlights.models import Highlight
from networkapi.highlights.forms import HighlightAdminForm
from wagtail.contrib.modeladmin.options import (
ModelAdmin, modeladmin_register)


class HighlightAdmin(SortableAdmin):
Expand All @@ -13,3 +15,16 @@ class HighlightAdmin(SortableAdmin):
)

admin.site.register(Highlight, HighlightAdmin)


# Wagtail admin
class WagtailHighlightAdmin(ModelAdmin):
model = Highlight
menu_icon = 'date' # change as required
menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd)
add_to_settings_menu = False # or True to add your model to the Settings sub-menu
exclude_from_explorer = False # or True to exclude pages of this type from Wagtail's explorer view
list_display = ('title', 'description', 'link_url',)
search_fields = ('title', 'description')

modeladmin_register(WagtailHighlightAdmin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-02-08 22:05
from __future__ import unicode_literals

from django.db import migrations
import wagtail.wagtailcore.fields


class Migration(migrations.Migration):

dependencies = [
('highlights', '0005_remove_highlight_homepage'),
]

operations = [
migrations.AlterField(
model_name='highlight',
name='footer',
field=wagtail.wagtailcore.fields.RichTextField(help_text='Content to appear after description (view more projects link or something similar)', null=True, verbose_name='footer'),
),
]
4 changes: 3 additions & 1 deletion network-api/networkapi/highlights/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from django.db import models
from django.db.models import Q
from adminsortable.models import SortableMixin
from mezzanine.core.fields import RichTextField
from wagtail.wagtailcore.fields import RichTextField
from networkapi.utility.images import get_image_upload_path
from wagtail.wagtailsnippets.models import register_snippet


def get_highlights_image_upload_path(instance, filename):
Expand All @@ -27,6 +28,7 @@ def published(self):
)


@register_snippet
class Highlight(SortableMixin):
"""
An data type to highlight things like pulse
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-02-08 22:05
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0040_page_draft_title'),
('people', '0025_remove_person_homepage'),
('highlights', '0006_auto_20180208_2205'),
('news', '0011_auto_20171012_1326'),
('homepage', '0003_auto_20170919_1838'),
]

operations = [
migrations.CreateModel(
name='HomepageRelatedHighlights',
fields=[
('highlight_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='highlights.Highlight')),
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
('highlights', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='homepage_highlights', to='highlights.Highlight')),
],
options={
'ordering': ['sort_order'],
'abstract': False,
},
bases=('highlights.highlight', models.Model),
),
migrations.CreateModel(
name='HomepageRelatedNews',
fields=[
('news_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='news.News')),
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
('news', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='homepage_news', to='news.News')),
],
options={
'ordering': ['sort_order'],
'abstract': False,
},
bases=('news.news', models.Model),
),
migrations.CreateModel(
name='HomepageRelatedPeople',
fields=[
('person_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='people.Person')),
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
],
options={
'ordering': ['sort_order'],
'abstract': False,
},
bases=('people.person', models.Model),
),
migrations.CreateModel(
name='WagtailHomepage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
migrations.AddField(
model_name='homepagerelatedpeople',
name='page',
field=modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='homepage_people', to='homepage.WagtailHomepage'),
),
migrations.AddField(
model_name='homepagerelatedpeople',
name='people',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='homepage_people', to='people.Person'),
),
migrations.AddField(
model_name='homepagerelatednews',
name='page',
field=modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='homepage_news', to='homepage.WagtailHomepage'),
),
migrations.AddField(
model_name='homepagerelatedhighlights',
name='page',
field=modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='homepage_highlights', to='homepage.WagtailHomepage'),
),
]
50 changes: 50 additions & 0 deletions network-api/networkapi/homepage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
from networkapi.people.models import Person
from networkapi.news.models import News
from networkapi.highlights.models import Highlight
from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.models import Orderable as WagtailOrderable
from wagtail.wagtailadmin.edit_handlers import InlinePanel
from modelcluster.fields import ParentalKey
from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel


# The old homepage
class Homepage(models.Model):
class Meta:
verbose_name_plural = 'homepage'
Expand Down Expand Up @@ -60,3 +66,47 @@ class HomepageHighlights(Orderable):
class Meta:
verbose_name = 'featured highlight'
verbose_name_plural = 'get involved (Highlights)'


# Code for the new wagtail based homepage

class HomepageRelatedPeople(WagtailOrderable, Person):
page = ParentalKey(
'WagtailHomePage',
related_name='homepage_people',
)
people = models.ForeignKey(Person, related_name='homepage_people')
panels = [
SnippetChooserPanel('people'),
]


class HomepageRelatedNews(WagtailOrderable, News):
page = ParentalKey(
'WagtailHomePage',
related_name='homepage_news',
)
news = models.ForeignKey(News, related_name='homepage_news')
panels = [
SnippetChooserPanel('news'),
]


class HomepageRelatedHighlights(WagtailOrderable, Highlight):
page = ParentalKey(
'WagtailHomePage',
related_name='homepage_highlights',
)
highlights = models.ForeignKey(Highlight, related_name='homepage_highlights')
panels = [
SnippetChooserPanel('highlights'),
]


class WagtailHomepage(Page):

content_panels = Page.content_panels + [
InlinePanel('homepage_people', label="People", max_num=3),
InlinePanel('homepage_news', label="News", max_num=3),
InlinePanel('homepage_highlights', label="Highlights", max_num=3),
]
14 changes: 14 additions & 0 deletions network-api/networkapi/news/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

from networkapi.news.models import News
from networkapi.news.forms import NewsAdminForm
from wagtail.contrib.modeladmin.options import (
ModelAdmin, modeladmin_register)


class NewsAdmin(admin.ModelAdmin):
form = NewsAdminForm


admin.site.register(News, NewsAdmin)


class WagtailNewsAdmin(ModelAdmin):
model = News
menu_icon = 'doc-full-inverse' # change as required
menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd)
add_to_settings_menu = False # or True to add your model to the Settings sub-menu
exclude_from_explorer = False # or True to exclude pages of this type from Wagtail's explorer view
list_display = ('headline', 'thumbnail', 'date', 'link',)
search_fields = ('headline',)

modeladmin_register(WagtailNewsAdmin)
2 changes: 2 additions & 0 deletions network-api/networkapi/news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from networkapi.utility.images import get_image_upload_path
from filebrowser_safe.fields import FileBrowseField
from wagtail.wagtailsnippets.models import register_snippet


def get_news_glyph_upload_path(instance, filename):
Expand Down Expand Up @@ -37,6 +38,7 @@ def published(self):
)


@register_snippet
class News(models.Model):
"""
Medium blog posts, articles and other media
Expand Down
16 changes: 16 additions & 0 deletions network-api/networkapi/people/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Affiliation,
)
from networkapi.people.forms import PersonAdminForm
from wagtail.contrib.modeladmin.options import (
ModelAdmin, modeladmin_register)


class AffiliationAdmin(admin.TabularInline):
Expand All @@ -31,3 +33,17 @@ class Media:

admin.site.register(Person, PersonAdmin)
admin.site.register(InternetHealthIssue)


# Wagtail admin
class WagtailPersonAdmin(ModelAdmin):
model = Person
menu_icon = 'user' # change as required
menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd)
add_to_settings_menu = False # or True to add your model to the Settings sub-menu
exclude_from_explorer = True # or True to exclude pages of this type from Wagtail's explorer view
list_display = ('name', 'role', 'location')
list_filter = ('internet_health_issues',)
search_fields = ('name')

modeladmin_register(WagtailPersonAdmin)
2 changes: 2 additions & 0 deletions network-api/networkapi/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from adminsortable.models import SortableMixin

from networkapi.utility.images import get_image_upload_path
from wagtail.wagtailsnippets.models import register_snippet


def get_people_image_upload_path(instance, filename):
Expand Down Expand Up @@ -47,6 +48,7 @@ def __str__(self):
return str(self.name)


@register_snippet
class Person(SortableMixin):
"""
A member of the Network
Expand Down
Loading

0 comments on commit 5c21d15

Please sign in to comment.