Skip to content

Commit

Permalink
Move common blocks from pages to common, add edition page, minor tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
apardyl committed Feb 25, 2021
1 parent 3a12dc0 commit f80a15b
Show file tree
Hide file tree
Showing 27 changed files with 195 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ assets/webpack_bundles/
assets/bundles/
node_modules/
webpack-stats.json
*.old
4 changes: 2 additions & 2 deletions agenda/blocks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from wagtail.core.blocks import StructBlock, PageChooserBlock, IntegerBlock

from agenda.models import Event
import agenda.models


class AgendaBlock(StructBlock):
Expand All @@ -16,7 +16,7 @@ class EventIndexBlock(StructBlock):

def get_context(self, value, parent_context=None):
context = super().get_context(value, parent_context)
context['posts'] = Event.objects.live().public().descendant_of(value['index']).order_by('-date')[
context['posts'] = agenda.models.Event.objects.live().public().descendant_of(value['index']).order_by('-date')[
:value['shown_posts']]
return context

Expand Down
22 changes: 22 additions & 0 deletions agenda/migrations/0010_edition_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.1.4 on 2021-02-25 09:41

import common.blocks
from django.db import migrations
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks


class Migration(migrations.Migration):

dependencies = [
('agenda', '0009_auto_20210112_1356'),
]

operations = [
migrations.AddField(
model_name='edition',
name='content',
field=wagtail.core.fields.StreamField([('paragraph', wagtail.core.blocks.RichTextBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('event_index', wagtail.core.blocks.StructBlock([('index', wagtail.core.blocks.PageChooserBlock(page_type=['agenda.EventIndex'])), ('shown_posts', wagtail.core.blocks.IntegerBlock(min_value=1))])), ('header', wagtail.core.blocks.StructBlock([('content', wagtail.core.blocks.RichTextBlock(features=['h1', 'h2', 'h3', 'h4', 'bold', 'italic', 'ol', 'ul', 'link', 'document-link'])), ('buttons', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('name', wagtail.core.blocks.CharBlock(max_length=100)), ('link_page', wagtail.core.blocks.PageChooserBlock(required=False)), ('link_url', wagtail.core.blocks.URLBlock(required=False))]), default=[], required=False))])), ('section_title', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock())])), ('section_subtitle', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock())])), ('section_divider', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock())])), ('dropdown', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock()), ('content', wagtail.core.blocks.RichTextBlock())])), ('photo_gallery', wagtail.core.blocks.StructBlock([('image_height', wagtail.core.blocks.IntegerBlock(default=200, max_value=2000, min_value=0)), ('image_width', wagtail.core.blocks.IntegerBlock(default=200, max_value=2000, min_value=0)), ('crop_to_fit', wagtail.core.blocks.BooleanBlock(default=False, required=False)), ('photos', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock(required=False)), ('photo', wagtail.images.blocks.ImageChooserBlock()), ('link', wagtail.core.blocks.URLBlock(required=False))])))])), ('map', wagtail.core.blocks.StructBlock([('center_longitude', wagtail.core.blocks.FloatBlock()), ('center_latitude', wagtail.core.blocks.FloatBlock()), ('zoom', wagtail.core.blocks.FloatBlock()), ('bearing', wagtail.core.blocks.FloatBlock()), ('pitch', wagtail.core.blocks.FloatBlock()), ('markers', wagtail.core.blocks.ListBlock(common.blocks.MapMarker)), ('placeholder', wagtail.images.blocks.ImageChooserBlock(help_text='Insert a screenshot of the map here'))])), ('raw_html', wagtail.core.blocks.RawHTMLBlock())], blank=True, null=True, verbose_name='content'),
),
]
27 changes: 27 additions & 0 deletions agenda/migrations/0011_auto_20210225_1101.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.1.4 on 2021-02-25 10:01

import common.blocks
from django.db import migrations
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks


class Migration(migrations.Migration):

dependencies = [
('agenda', '0010_edition_content'),
]

operations = [
migrations.AddField(
model_name='edition',
name='content_en',
field=wagtail.core.fields.StreamField([('paragraph', wagtail.core.blocks.RichTextBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('event_index', wagtail.core.blocks.StructBlock([('index', wagtail.core.blocks.PageChooserBlock(page_type=['agenda.EventIndex'])), ('shown_posts', wagtail.core.blocks.IntegerBlock(min_value=1))])), ('header', wagtail.core.blocks.StructBlock([('content', wagtail.core.blocks.RichTextBlock(features=['h1', 'h2', 'h3', 'h4', 'bold', 'italic', 'ol', 'ul', 'link', 'document-link'])), ('buttons', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('name', wagtail.core.blocks.CharBlock(max_length=100)), ('link_page', wagtail.core.blocks.PageChooserBlock(required=False)), ('link_url', wagtail.core.blocks.URLBlock(required=False))]), default=[], required=False))])), ('section_title', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock())])), ('section_subtitle', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock())])), ('section_divider', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock())])), ('dropdown', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock()), ('content', wagtail.core.blocks.RichTextBlock())])), ('photo_gallery', wagtail.core.blocks.StructBlock([('image_height', wagtail.core.blocks.IntegerBlock(default=200, max_value=2000, min_value=0)), ('image_width', wagtail.core.blocks.IntegerBlock(default=200, max_value=2000, min_value=0)), ('crop_to_fit', wagtail.core.blocks.BooleanBlock(default=False, required=False)), ('photos', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock(required=False)), ('photo', wagtail.images.blocks.ImageChooserBlock()), ('link', wagtail.core.blocks.URLBlock(required=False))])))])), ('map', wagtail.core.blocks.StructBlock([('center_longitude', wagtail.core.blocks.FloatBlock()), ('center_latitude', wagtail.core.blocks.FloatBlock()), ('zoom', wagtail.core.blocks.FloatBlock()), ('bearing', wagtail.core.blocks.FloatBlock()), ('pitch', wagtail.core.blocks.FloatBlock()), ('markers', wagtail.core.blocks.ListBlock(common.blocks.MapMarker)), ('placeholder', wagtail.images.blocks.ImageChooserBlock(help_text='Insert a screenshot of the map here'))])), ('raw_html', wagtail.core.blocks.RawHTMLBlock())], blank=True, null=True, verbose_name='content'),
),
migrations.AddField(
model_name='edition',
name='content_pl',
field=wagtail.core.fields.StreamField([('paragraph', wagtail.core.blocks.RichTextBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('event_index', wagtail.core.blocks.StructBlock([('index', wagtail.core.blocks.PageChooserBlock(page_type=['agenda.EventIndex'])), ('shown_posts', wagtail.core.blocks.IntegerBlock(min_value=1))])), ('header', wagtail.core.blocks.StructBlock([('content', wagtail.core.blocks.RichTextBlock(features=['h1', 'h2', 'h3', 'h4', 'bold', 'italic', 'ol', 'ul', 'link', 'document-link'])), ('buttons', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('name', wagtail.core.blocks.CharBlock(max_length=100)), ('link_page', wagtail.core.blocks.PageChooserBlock(required=False)), ('link_url', wagtail.core.blocks.URLBlock(required=False))]), default=[], required=False))])), ('section_title', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock())])), ('section_subtitle', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock())])), ('section_divider', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock())])), ('dropdown', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock()), ('content', wagtail.core.blocks.RichTextBlock())])), ('photo_gallery', wagtail.core.blocks.StructBlock([('image_height', wagtail.core.blocks.IntegerBlock(default=200, max_value=2000, min_value=0)), ('image_width', wagtail.core.blocks.IntegerBlock(default=200, max_value=2000, min_value=0)), ('crop_to_fit', wagtail.core.blocks.BooleanBlock(default=False, required=False)), ('photos', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock(required=False)), ('photo', wagtail.images.blocks.ImageChooserBlock()), ('link', wagtail.core.blocks.URLBlock(required=False))])))])), ('map', wagtail.core.blocks.StructBlock([('center_longitude', wagtail.core.blocks.FloatBlock()), ('center_latitude', wagtail.core.blocks.FloatBlock()), ('zoom', wagtail.core.blocks.FloatBlock()), ('bearing', wagtail.core.blocks.FloatBlock()), ('pitch', wagtail.core.blocks.FloatBlock()), ('markers', wagtail.core.blocks.ListBlock(common.blocks.MapMarker)), ('placeholder', wagtail.images.blocks.ImageChooserBlock(help_text='Insert a screenshot of the map here'))])), ('raw_html', wagtail.core.blocks.RawHTMLBlock())], blank=True, null=True, verbose_name='content'),
),
]
35 changes: 29 additions & 6 deletions agenda/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from modelcluster.fields import ParentalKey
from wagtail.admin.edit_handlers import FieldPanel, PageChooserPanel, InlinePanel, StreamFieldPanel
from wagtail.core import blocks
from wagtail.core.blocks import RawHTMLBlock
from wagtail.core.fields import RichTextField, StreamField
from wagtail.core.models import Page
from wagtail.embeds.models import Embed
Expand All @@ -17,10 +18,12 @@
from wagtail.snippets.edit_handlers import SnippetChooserPanel
from wagtail.snippets.models import register_snippet

from agenda.blocks import EventIndexBlock
from common.blocks import SectionTitleBlock, SectionSubtitleBlock, SectionDividerBlock, DropdownBlock, PhotoGallery, \
MapBlock
from common.cache import InvalidateCacheMixin
from common.models import SFIPage
from common.utils import paginate, with_context
from pages.blocks import SectionTitleBlock, SectionSubtitleBlock, SectionDividerBlock, DropdownBlock, PhotoGallery


@register_snippet
Expand Down Expand Up @@ -53,7 +56,7 @@ class Meta:
class SpeakerIndex(SFIPage):
subpage_types = ['Speaker']

SPEAKERS_PER_PAGE = 10
SPEAKERS_PER_PAGE = 25

def get_context(self, request, *args, **kwargs):
context = super().get_context(request, *args, **kwargs)
Expand Down Expand Up @@ -83,7 +86,8 @@ class Speaker(SFIPage):
def get_all_events_by_edition(self):
by_edition = defaultdict(list)
for event_speaker in self.event_speakers.all():
by_edition[event_speaker.event.get_edition()].append(event_speaker.event)
if event_speaker.event.live:
by_edition[event_speaker.event.get_edition()].append(event_speaker.event)
return sorted(by_edition.items(), key=lambda x: x[0].start_date if x[0].start_date else timezone.now(),
reverse=True)

Expand Down Expand Up @@ -126,11 +130,11 @@ def icon(self):
class EditionIndex(SFIPage):
subpage_types = ['Edition']

EDITIONS_PER_PAGE = 10
EDITIONS_PER_PAGE = 25

def get_context(self, request, *args, **kwargs):
context = super().get_context(request, *args, **kwargs)
context['posts'] = Edition.objects.live().public().descendant_of(self).order_by("title")
context['posts'] = Edition.objects.live().public().descendant_of(self).order_by('-start_date', 'title')
return context

class Meta:
Expand All @@ -141,6 +145,20 @@ class Meta:
class Edition(SFIPage):
start_date = models.DateTimeField(null=True, blank=True, verbose_name=_('edition start date'))
end_date = models.DateTimeField(null=True, blank=True, verbose_name=_('edition end date'))

content = StreamField([
('paragraph', blocks.RichTextBlock()),
('image', ImageChooserBlock()),
('event_index', EventIndexBlock()),
('section_title', SectionTitleBlock()),
('section_subtitle', SectionSubtitleBlock()),
('section_divider', SectionDividerBlock()),
('dropdown', DropdownBlock()),
('photo_gallery', PhotoGallery()),
('map', MapBlock()),
('raw_html', RawHTMLBlock()),
], null=True, blank=True, verbose_name=_('content'))

default_featured_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
Expand All @@ -166,6 +184,7 @@ def get_edition_footer(self):
content_panels = SFIPage.content_panels + [
FieldPanel('start_date'),
FieldPanel('end_date'),
StreamFieldPanel('content'),
ImageChooserPanel('default_featured_image'),
InlinePanel('event_categories', label='Event categories'),
StreamFieldPanel('edition_footer'),
Expand Down Expand Up @@ -227,7 +246,7 @@ class EventIndex(EditionSubpage):
parent_page_types = ['Edition']
subpage_types = ['Event']

EVENTS_PER_PAGE = 10
EVENTS_PER_PAGE = 25

color = models.CharField(max_length=7,
default='#23211f',
Expand Down Expand Up @@ -317,6 +336,10 @@ class EventSpeaker(InvalidateCacheMixin, models.Model):
PageChooserPanel('speaker'),
]

@property
def live(self):
return self.event.live and self.speaker.live

class Meta:
verbose_name = _('event speaker')
verbose_name_plural = _('event speakers')
10 changes: 10 additions & 0 deletions agenda/templates/agenda/edition.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "common/page.html" %}
{% load wagtailcore_tags %}

{% block content %}
{% include 'agenda/partials/edition_header.html' %}

{% if page.content %}
{% include_block page.content %}
{% endif %}
{% endblock content %}
5 changes: 5 additions & 0 deletions agenda/templates/agenda/edition_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends 'common/post_index_base.html' %}

{% block single_post %}
{% include 'agenda/partials/edition_index_single.html' with edition=post %}
{% endblock %}
8 changes: 5 additions & 3 deletions agenda/templates/agenda/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
</div>
<div class="event-info__content">
{% for event_speaker in page.event_speakers.all %}
<a href="{% pageurl event_speaker.speaker %}"
class="event-header_details_value event-header_details_value--link">
{{ event_speaker.speaker.title }}</a>{% if not forloop.last %},{% endif %}
{% if event_speaker.live %}
<a href="{% pageurl event_speaker.speaker %}"
class="event-header_details_value event-header_details_value--link">
{{ event_speaker.speaker.title }}</a>{% if not forloop.last %},{% endif %}
{% endif %}
{% endfor %}
</div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions agenda/templates/agenda/partials/edition_header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends 'common/partials/post_base_header.html' %}
{% load i18n %}
{% load wagtailcore_tags %}


{% block details %}
<div class="event-header_details">
{% if page.start_date %}
<p>{% trans 'Date' %}: <span class="event-header_details_value">{{ page.start_date }}{% if page.end_date %}
- {{ page.end_date }}{% endif %}</span></p>
{% endif %}
</div>
{% endblock details %}
13 changes: 13 additions & 0 deletions agenda/templates/agenda/partials/edition_index_single.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% load i18n %}
{% load common_tags %}

<a href="{{ edition.url }}" class="post_base-list__single-post">
{% responsive_img edition.get_featured_image 'fill-350x350' 'post_base-list__image' %}
<div class="post_base-list__post-info">
<div class="post_base-list__info-container">
<p class="post_base-list__title">{{ edition.title }}</p>
<p class="post_base-list__post-content">{% get_description edition %}</p>
</div>
<p class="post_base-list__read-more">{% trans 'Read more...' %}</p>
</div>
</a>
2 changes: 1 addition & 1 deletion agenda/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EditionIndexTR(TranslationOptions):

@register(Edition)
class EditionTR(TranslationOptions):
fields = ('edition_footer',)
fields = ('content', 'edition_footer')


@register(Category)
Expand Down
4 changes: 4 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ function submitContactForm(e) {
}

contactForm.addEventListener('submit', submitContactForm);

const btn = document.createElement('button');
btn.innerText = '{% trans "Send" %}';
document.querySelector('.footer-contact__form').appendChild(btn);
17 changes: 16 additions & 1 deletion assets/sass/components/_map.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
.block-map {
}

.map-container {
}

.page-map {
position: relative;
width: 100%;
min-height: 475px;
max-height: 700px;
height: 50vh;
//border-radius: 30px 0 0 30px;

&__marker {
background: url("../img/sfi-marker.png") no-repeat center center;
Expand All @@ -21,12 +29,13 @@
width: 100%;
position: relative;
cursor: pointer;

& img {
height: 100%;
width: 100%;
object-fit: cover;
filter: brightness(80%);
//border-radius: 30px 0 0 30px;
}

&__text {
Expand All @@ -50,6 +59,12 @@
animation: spin 1s linear infinite;
display: none;
}

& .mapboxgl-popup-content {
color: $page_color_2;
font-weight: bold;
font-size: 1rem;
}
}

@keyframes spin {
Expand Down
1 change: 0 additions & 1 deletion assets/sass/pages/_event.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@

&--image-link {
transition: 0.3s;
margin: 0 15px;
display: block;

&:hover {
Expand Down
15 changes: 8 additions & 7 deletions pages/blocks.py → common/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@ class HeadingBlock(StructBlock):
buttons = ListBlock(MenuItem(), required=False, default=[])

class Meta:
template = 'pages/heading_block.html'
template = 'common/blocks/heading_block.html'


class SectionTitleBlock(StructBlock):
title = TextBlock()

class Meta:
template = 'pages/section_title_block.html'
template = 'common/blocks/section_title_block.html'


class SectionSubtitleBlock(StructBlock):
title = TextBlock()

class Meta:
template = 'pages/section_subtitle_block.html'
template = 'common/blocks/section_subtitle_block.html'


class SectionDividerBlock(StructBlock):
title = TextBlock()

class Meta:
template = 'pages/section_divider_block.html'
template = 'common/blocks/section_divider_block.html'


class DropdownBlock(StructBlock):
title = TextBlock()
content = RichTextBlock()

class Meta:
template = 'pages/dropdown_block.html'
template = 'common/blocks/dropdown_block.html'


class PhotoGalleryItem(StructBlock):
Expand Down Expand Up @@ -75,10 +75,11 @@ def get_context(self, value, parent_context=None):
return context

class Meta:
template = 'pages/photo_gallery_block.html'
template = 'common/blocks/photo_gallery_block.html'


class MapMarker(StructBlock):
name = TextBlock()
longitude = FloatBlock()
latitude = FloatBlock()

Expand All @@ -98,4 +99,4 @@ def get_context(self, value, parent_context=None):
return context

class Meta:
template = 'pages/map_block.html'
template = 'common/blocks/map_block.html'
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit f80a15b

Please sign in to comment.