Skip to content

Commit

Permalink
News
Browse files Browse the repository at this point in the history
  • Loading branch information
Merlin Buczek committed May 28, 2019
1 parent 1706e9a commit 9975f22
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 80 deletions.
17 changes: 17 additions & 0 deletions mpicms/base/migrations/0007_remove_wikipage_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.2.1 on 2019-05-28 14:00

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('base', '0006_contacts_position'),
]

operations = [
migrations.RemoveField(
model_name='wikipage',
name='date',
),
]
13 changes: 4 additions & 9 deletions mpicms/base/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.apps import apps
from django.db import models
from django.utils.translation import gettext as _

Expand All @@ -11,7 +12,7 @@
from wagtail.images.blocks import ImageChooserBlock
from wagtail.snippets.edit_handlers import SnippetChooserPanel

from mpicms.news.models import NewsPage
from mpicms.news.mixins import NewsMixin


Page.show_in_menus_default = True
Expand Down Expand Up @@ -45,22 +46,17 @@ class Meta: # noqa
abstract = True


class HomePage(Page):
class HomePage(NewsMixin, Page):
parent_page_types = ['wagtailcore.Page'] # Restrict parent to be root

content_panels = Page.content_panels

def get_context(self, request):
context = super().get_context(request)
context['news'] = NewsPage.objects.first()
return context

class Meta: # noqa
verbose_name = _("homepage")
verbose_name_plural = _("homepages")


class CategoryPage(Page):
class CategoryPage(NewsMixin, Page):
body = RichTextField(_("content"), blank=True)
side_content = RichTextField(
_("sidebar content"), blank=True,
Expand Down Expand Up @@ -94,7 +90,6 @@ class WikiPage(CategoryMixin, Page):
('image', ImageChooserBlock()),
('url', blocks.URLBlock())
], blank=True)
date = models.DateField("Post date", auto_now_add=True)

search_fields = Page.search_fields + [
index.SearchField('body'),
Expand Down
20 changes: 20 additions & 0 deletions mpicms/news/migrations/0004_newsentry_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.2.1 on 2019-05-28 14:00

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('news', '0003_auto_20190525_1616'),
]

operations = [
migrations.AddField(
model_name='newsentry',
name='date',
field=models.DateField(auto_now_add=True, default=datetime.date(2019, 5, 28), verbose_name='Post date'),
preserve_default=False,
),
]
13 changes: 13 additions & 0 deletions mpicms/news/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.apps import apps
from django.db import models


class NewsMixin(models.Model):

@property
def news(self):
news_page = apps.get_model('news', 'NewsPage')
return self.get_children().type(news_page)

class Meta: # noqa
abstract = True
7 changes: 5 additions & 2 deletions mpicms/news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel

from mpicms.base.models import CategoryMixin

class NewsPage(Page):

class NewsPage(CategoryMixin, Page):
content_panels = Page.content_panels

parent_page_types = ['base.CategoryPage', 'base.HomePage']
Expand All @@ -18,9 +20,10 @@ class Meta: # noqa
verbose_name_plural = _("news Blogs")


class NewsEntry(Page):
class NewsEntry(CategoryMixin, Page):
preview = models.TextField(_("preview"), blank=True)
body = RichTextField(_("content"))
date = models.DateField("Post date", auto_now_add=True)

content_panels = Page.content_panels + [
FieldPanel('preview'),
Expand Down
23 changes: 20 additions & 3 deletions mpicms/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ select, input {
padding-left: 2rem;
padding-bottom: 2rem;
margin-top: 3rem;
align-content: flex-start;
}

.sidebar ul {
Expand Down Expand Up @@ -116,6 +117,18 @@ select, input {
flex: 0 0 100%;
}

.sidebar time {
color: black;
font-size: 85%;
text-align: end;
flex-basis: 100%;
}

.event-button {
display: flex !important;
flex-wrap: wrap;
}

.contact {
padding-bottom: 1em;
line-height: 90%;
Expand Down Expand Up @@ -166,21 +179,21 @@ select, input {
.card {
margin: 1rem;
flex-grow: 1;
flex-basis: auto;
flex-basis: 18rem;
width: inherit;
flex-shrink: 0;
}

.flex-align {
display: flex !important;
flex-wrap: nowrap;
align-items: center;
justify-content: space-between;
width: 100%;
}

.flex-base {
display: flex !important;
flex-wrap: nowrap;
flex-wrap: wrap;
align-items: stretch;
width: 100%;
}
Expand Down Expand Up @@ -224,4 +237,8 @@ select, input {

.fa-chevron-right {
padding-left: 0.8rem;
}

.select:not(.is-multiple):not(.is-loading)::after {
border-color: #006c66;
}
3 changes: 3 additions & 0 deletions mpicms/templates/base/category_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ <h2 class="title is-2">{{ page.title }}</h2>
{{ page.body|richtext }}
</p>
</div>

{% include 'news/components/news_preview.html' with news=page.news %}

{% for child in page.get_children.live %}
<a href="{% pageurl child %}">
<div class="card">
Expand Down
2 changes: 1 addition & 1 deletion mpicms/templates/base/home_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

{% block content %}
<section class="section">
{% include 'news/components/news_preview.html' with news=news %}
{% include 'news/components/news_preview.html' with news=page.news %}
</section>
{% endblock %}
2 changes: 1 addition & 1 deletion mpicms/templates/base/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
<div class="columns" style="flex-direction: row-reverse;">
<div class="column">
<div class="section contains-breadcrumb">
<div class="contains-breadcrumb">
<div class="container is-fluid">
{% include 'base/components/breadcrumb.html' %}
{% block page_content %}
Expand Down
89 changes: 47 additions & 42 deletions mpicms/templates/menus/side.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,55 @@


{% with page.category as category %}
{% with category.get_children.live.in_menu as children %}

{% if children %}

<div class="menu" style="padding-top: 2rem;">
<a href="{% pageurl category %}" class="menu-label">
{{ category }}
</a>
<ul class="menu-list">
{% for menu_page in children %}
<li>
{% include 'menus/components/menu_item.html' with menu_page=menu_page is_root=True %}
</li>
{% endfor %}
</ul>
</div>


{% endif %}
{% endwith %}

<div class="content" style="padding-top: 2rem;">
{{ category.specific.side_content|richtext }}
</div>


{% with category.specific.contacts.all as contacts %}
{% if contacts %}
<div class="content">
<h4 class="">{% trans 'Contact' %}</h4>
<ul>
{% for contact in contacts %}
<li>
<ul class="contact">
<li style="font-weight: 400;">{{ contact.person.first_name }} {{ contact.person.last_name }}</li>
<li>{{ contact.position }}</li>
<li><i class="fas fa-at"></i> <a href="mailto:{{ contact.person.email }}">{{ contact.person.email }}</a></li>
<li><i class="fas fa-phone"></i> {{ contact.person.phone }}</li>
</ul>
</li>

{% with category.get_children.live.in_menu as children %}

{% if children %}

<div class="menu" style="padding-top: 2rem;">
<a href="{% pageurl category %}" class="menu-label">
{{ category }}
</a>
<ul class="menu-list">
{% for menu_page in children %}
<li>
{% include 'menus/components/menu_item.html' with menu_page=menu_page is_root=True %}
</li>
{% endfor %}
</ul>
</ul>
</div>


{% endif %}
{% endwith %}
{% endwith %}

<div class="content" style="padding-top: 2rem;">
{% include 'news/components/news_list.html' with news=category.specific.news %}
</div>

<div class="content" style="padding-top: 2rem;">
{{ category.specific.side_content|richtext }}
</div>


{% with category.specific.contacts.all as contacts %}
{% if contacts %}
<div class="content">
<h4 class="">{% trans 'Contact' %}</h4>
<ul>
{% for contact in contacts %}
<li>
<ul class="contact">
<li style="font-weight: 400;">{{ contact.person.first_name }} {{ contact.person.last_name }}</li>
<li>{{ contact.position }}</li>
<li><i class="fas fa-at"></i> <a href="mailto:{{ contact.person.email }}">{{ contact.person.email }}</a></li>
<li><i class="fas fa-phone"></i> {{ contact.person.phone }}</li>
</ul>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endwith %}

{% endwith %}
20 changes: 20 additions & 0 deletions mpicms/templates/news/components/news_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% load i18n %}
{% load wagtailcore_tags %}

{% for news_page in news %}
{% with news_page.get_children.live as news_entries %}
{% if news_entries %}
<h4>{{ news_page.title }}</h4>
<ul class="menu-list">
{% for child in news_entries|slice:3 %}
<li>
<a class="menu-item event-button" href="{% pageurl child %}">{{ child.title }}
<time datetime="{{ child.specific.date }}">{{ child.specific.date }}</time>
</a>
</li>
{% endfor %}
</ul>
<a href="{% pageurl news_page %}">{% trans 'See all' %}<i class="fas fa-chevron-right"></i></a>
{% endif %}
{% endwith %}
{% endfor %}
38 changes: 22 additions & 16 deletions mpicms/templates/news/components/news_preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
{% load wagtailcore_tags %}


<h3 class="title is-3">News</h3>
<div class="flex-base">
{% for child in news.get_children.live|slice:3 %}
<div class="card">
<div class="card-content">
<a href="{% pageurl child %}" class="title is-4">{{ child.title }}</a>
<time datetime="2016-1-1">1 Jan 2016</time>
<div class="content">
{{ child.specific.preview }}
{% for news_page in news %}
{% with news_page.get_children.live as news_entries %}
{% if news_entries %}
<h3 class="title is-3">{{ news_page.title }}</h3>
<div class="flex-base">
{% for child in news_entries|slice:3 %}
<div class="card">
<div class="card-content">
<a href="{% pageurl child %}" class="title is-4">{{ child.title }}</a>
<time datetime="{{ child.specific.date }}">{{ child.specific.date }}</time>
<div class="content">
{{ child.specific.preview }}
</div>
</div>
<a href="{% pageurl child %}" class="card-footer-item card-link"><i class="fas fa-chevron-right"></i></a>
</div>
</div>
<a href="{% pageurl child %}" class="card-footer-item card-link"><i class="fas fa-chevron-right"></i></a>
{% endfor %}
</div>
{% endfor %}
</div>
<div class="section-button">
<a href="{% pageurl news %}"><button class="button">{% trans 'All news' %}<i class="fas fa-chevron-right"></i></button></a>
</div>
<div class="section-button">
<a href="{% pageurl news_page %}"><button class="button">{% trans 'All news' %}<i class="fas fa-chevron-right"></i></button></a>
</div>
{% endif %}
{% endwith %}
{% endfor %}
6 changes: 3 additions & 3 deletions mpicms/templates/news/news_entry.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% extends 'base.html' %}
{% extends 'base/page.html' %}

{% load wagtailcore_tags %}

{% block content %}
{% include 'base/components/breadcrumb.html' %}
{% block page_content %}
<section class="section">
<h1 class="title">{{ page.title }}</h1>
{{ page.date }}
<div class="content">
<p>
{{ page.body|richtext }}
Expand Down
Loading

0 comments on commit 9975f22

Please sign in to comment.