Skip to content

Commit

Permalink
Added news section
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Arnold committed Aug 8, 2019
1 parent f3b954d commit 8b3b631
Show file tree
Hide file tree
Showing 15 changed files with 611 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/collective/frontpage/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@
class=".teaser.TeaserDefaultView"
/>

<!-- News -->

<browser:page
name="news_default"
title="News Default"
menu="plone_displayviews"
for="collective.frontpage.content.news.INews"
permission="zope2.View"
class=".news.NewsDefaultView"
/>

<!-- Search -->

<browser:page
Expand Down
45 changes: 45 additions & 0 deletions src/collective/frontpage/browser/news.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
from collective.frontpage.browser.mixins import SectionsViewMixin
from collective.frontpage.utils import crop
from plone import api
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile


class NewsBase(SectionsViewMixin, BrowserView):
"""TeaserBase base class"""

def get_news(self):
results = []
items = api.content.find(
portal_type='News Item',
sort_on='Date',
sort_order='descending',
Language=api.portal.get_current_language(),
)
if items:
items = [item.getObject() for item in items]
for item in items:
title = item.title
description = crop(item.description, 200)
url = item.absolute_url()
scaled_image = None
if item.image:
images_view = api.content.get_view(
'images', item, self.request)
scaled_image = images_view.scale(
'image', width=640, height=420, direction='down')
data = {
'title': title,
'description': description,
'url': url,
'scaled_image': scaled_image,
}
results.append(data)
return results[:3]


class NewsDefaultView(NewsBase):
"""TeaserDefaultView base class"""

template = ViewPageTemplateFile("templates/sections/news_default.pt")
62 changes: 62 additions & 0 deletions src/collective/frontpage/browser/static/cards.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.cards {
color: inherit;
display: flex;
flex-wrap: wrap;
justify-content: center;
margin: 0 auto;
float: none !important;

.card {
color: inherit;
border: 1px solid #d0d0d0;
box-shadow: 0 2px 4px rgba(3, 27, 78, 0.06);
cursor: pointer;
margin: 15px;
padding: 0;
text-align: center;

&.blank {
border: none !important;
box-shadow: none !important;
}

&.fill {
background-color: white;
}

&.inactive:hover {
box-shadow: 0 2px 4px rgba(3, 27, 78, 0.06);
cursor: default;
}

&:hover {
box-shadow: 0 10px 20px rgba(3, 27, 78, 0.1);
}

a {
color: inherit;
}

.vendor(transition, all 150ms ease-in-out);

.card-graphic {
font-size: 3em;
margin-bottom: 30px;
display: inline-block;
width: 100%;
height: auto;
}

.card-heading {
font-weight: 500;
line-height: 1.5;
margin: 0 20px 20px 20px;
position: relative;
}

.card-description {
font-weight: 400;
margin: 20px;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/collective/frontpage/browser/static/frontpage.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
@{property}: @value;
}

@import './cards.less';

/* Frontpage */
.editable-section {
position: relative;
Expand Down Expand Up @@ -89,12 +91,12 @@
background-position: center;
background-repeat: no-repeat;
background-size: cover;
padding: 180px 60px;
padding: 80px 60px;
text-align: center;
height: 100%;

.section-text {
margin-bottom: 60px;
margin-bottom: 40px;

.section-title {
font-size: 56px;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<html xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="here/main_template/macros/master"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns="http://www.w3.org/1999/xhtml"
i18n:domain="collective.frontpage"
lang="en"
tal:omit-tag="">

<head>
<metal:block fill-slot="style_slot">
<link rel="stylesheet" type="text/css"
href="++resource++collective.frontpage/frontpage-compiled-2019-06-27.css">
</metal:block>
</head>

<body>
<metal:main fill-slot="main">

<div class="frontpage-section" metal:define-macro="static_default">
<div class="section-content container" tal:attributes="style view/get_style">

<div class="section-text col-md-6 col-md-offset-3">
<h2 class="section-title">${context/title}</h2>
<p class="section-description" tal:condition="context/description">${context/description}</p>
</div>

<div class="cards col-md-12" tal:define="news_items view/get_news">
<tal:repeat tal:repeat="news_item news_items">
<div class="card fill col-md-3" style="background-color: ${context/primary_color}; color: ${python: view.button_text_color(context)}">
<a href="${news_item/url}">
<img tal:replace="structure python:news_item.get('scaled_image').tag(css_class='card-graphic')" tal:condition="news_item/scaled_image" />
<h4 class="card-heading">${news_item/title}</h4>
<p class="card-description">${news_item/description}</p>
</a>
</div>

</tal:repeat>
</div>

</div>
</div>

</metal:main>
</body>

</html>
16 changes: 16 additions & 0 deletions src/collective/frontpage/content/news.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from plone.dexterity.content import Container
from plone.supermodel import model


class INews(model.Schema):
"""
Marker interface and Dexterity Python Schema for Static.
"""

pass


class News(Container):

pass
18 changes: 15 additions & 3 deletions src/collective/frontpage/locales/collective.frontpage.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2019-08-01 12:56+0000\n"
"POT-Creation-Date: 2019-08-08 12:22+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -21,6 +21,10 @@ msgstr ""
msgid "A container for Frontpage sections."
msgstr ""

#: collective/frontpage/profiles/default/types/News.xml
msgid "A news section for a Frontpage. Can contain News Items."
msgstr ""

#: collective/frontpage/profiles/default/types/Search.xml
msgid "A search section for a Frontpage."
msgstr ""
Expand Down Expand Up @@ -63,7 +67,7 @@ msgstr ""

#: collective/frontpage/profiles/default/types/Frontpage.xml
#: collective/frontpage/profiles/default/types/Item.xml
#: collective/frontpage/profiles/default/types/Search.xml
#: collective/frontpage/profiles/default/types/News.xml
msgid "Edit"
msgstr ""

Expand Down Expand Up @@ -107,6 +111,14 @@ msgstr ""
msgid "Link URL"
msgstr ""

#: collective/frontpage/profiles/default/types/News.xml
msgid "News"
msgstr ""

#: collective/frontpage/browser/configure.zcml
msgid "News Default"
msgstr ""

#: collective/frontpage/behaviors.py
msgid "Primary Color"
msgstr ""
Expand Down Expand Up @@ -177,7 +189,7 @@ msgstr ""

#: collective/frontpage/profiles/default/types/Frontpage.xml
#: collective/frontpage/profiles/default/types/Item.xml
#: collective/frontpage/profiles/default/types/Search.xml
#: collective/frontpage/profiles/default/types/News.xml
msgid "View"
msgstr ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2019-08-01 12:56+0000\n"
"POT-Creation-Date: 2019-08-08 12:22+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -18,6 +18,10 @@ msgstr ""
msgid "A container for Frontpage sections."
msgstr ""

#: collective/frontpage/profiles/default/types/News.xml
msgid "A news section for a Frontpage. Can contain News Items."
msgstr ""

#: collective/frontpage/profiles/default/types/Search.xml
msgid "A search section for a Frontpage."
msgstr ""
Expand Down Expand Up @@ -60,7 +64,7 @@ msgstr ""

#: collective/frontpage/profiles/default/types/Frontpage.xml
#: collective/frontpage/profiles/default/types/Item.xml
#: collective/frontpage/profiles/default/types/Search.xml
#: collective/frontpage/profiles/default/types/News.xml
msgid "Edit"
msgstr ""

Expand Down Expand Up @@ -104,6 +108,14 @@ msgstr ""
msgid "Link URL"
msgstr ""

#: collective/frontpage/profiles/default/types/News.xml
msgid "News"
msgstr ""

#: collective/frontpage/browser/configure.zcml
msgid "News Default"
msgstr ""

#: collective/frontpage/behaviors.py
msgid "Primary Color"
msgstr ""
Expand Down Expand Up @@ -174,7 +186,7 @@ msgstr ""

#: collective/frontpage/profiles/default/types/Frontpage.xml
#: collective/frontpage/profiles/default/types/Item.xml
#: collective/frontpage/profiles/default/types/Search.xml
#: collective/frontpage/profiles/default/types/News.xml
msgid "View"
msgstr ""

Expand Down
Loading

0 comments on commit 8b3b631

Please sign in to comment.