Feed page module
This commit is contained in:
parent
11bcb50f72
commit
b0c1d6ba1e
4 changed files with 112 additions and 1 deletions
30
feedler/migrations/0002_feedpage.py
Normal file
30
feedler/migrations/0002_feedpage.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.3 on 2017-07-03 15:21
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import wagtail.wagtailcore.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0040_merge_20170703_1238'),
|
||||
('feedler', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='FeedPage',
|
||||
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')),
|
||||
('intro', wagtail.wagtailcore.fields.RichTextField(blank=True, default='')),
|
||||
('stream', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='feedler.Stream', verbose_name='Filter to stream (optional)')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Feeds',
|
||||
},
|
||||
bases=('wagtailcore.page',),
|
||||
),
|
||||
]
|
|
@ -4,6 +4,10 @@ from datetime import datetime
|
|||
|
||||
from django.db import models
|
||||
|
||||
from wagtail.wagtailcore.models import Page, Orderable
|
||||
from wagtail.wagtailadmin.edit_handlers import FieldPanel
|
||||
from wagtail.wagtailcore.fields import RichTextField
|
||||
|
||||
class Stream(models.Model):
|
||||
title = models.CharField(max_length=255)
|
||||
ident = models.CharField(max_length=255)
|
||||
|
@ -80,3 +84,33 @@ class Entry(models.Model):
|
|||
if len(label) > 3 and not label in tags:
|
||||
tags.append(label)
|
||||
self.tags = ','.join(tags)
|
||||
|
||||
class FeedPage(Page):
|
||||
intro = RichTextField(default='', blank=True)
|
||||
stream = models.ForeignKey(Stream, on_delete=models.PROTECT,
|
||||
null=True, blank=True, verbose_name='Filter to stream (optional)')
|
||||
|
||||
content_panels = [
|
||||
FieldPanel('title'),
|
||||
FieldPanel('intro'),
|
||||
FieldPanel('stream'),
|
||||
]
|
||||
|
||||
@property
|
||||
def feedentries(self):
|
||||
if self.stream:
|
||||
entries = Entry.objects.filter(stream=self.stream)
|
||||
else:
|
||||
entries = Entry.objects.all()
|
||||
# Order by most recent date first
|
||||
entries = entries.order_by('-published')
|
||||
return entries[:10]
|
||||
|
||||
def get_context(self, request):
|
||||
# Update template context
|
||||
context = super(FeedPage, self).get_context(request)
|
||||
context['feedentries'] = self.feedentries
|
||||
return context
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Feeds"
|
||||
|
|
47
feedler/templates/feedler/feed_page.html
Normal file
47
feedler/templates/feedler/feed_page.html
Normal file
|
@ -0,0 +1,47 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static wagtailcore_tags %}
|
||||
|
||||
{% block body_class %}template-{{ self.get_verbose_name|slugify }}{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
{% endblock %}
|
||||
|
||||
{% block title %}Feeds{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<section id="article-index" class="article-index-page">
|
||||
<div class="container">
|
||||
<h2>{{ page.title }}</h2>
|
||||
<p class="lead">{{ page.intro|richtext }}</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Page body -->
|
||||
<section id="news" class="feedpage-body">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
{% for entry in feedentries %}
|
||||
<div class="col-md-4 col-sm-6 col-xs-12">
|
||||
<div class="panel panel-default">
|
||||
{% if entry.visual %}
|
||||
<img src="{{ entry.visual }}" width="360">
|
||||
{% endif %}
|
||||
<div class="panel-body">
|
||||
<h3><span>{{ entry.title }}</span></h3>
|
||||
<p>
|
||||
{{ entry.content|striptags|truncatewords_html:40 }}
|
||||
<br><em><small><span>{{ entry.author }}</span></small></em>
|
||||
</p>
|
||||
</div>
|
||||
<a href="{{ entry.link }}" target="_blank" class="fill"></a>
|
||||
</div>
|
||||
</div>
|
||||
{% empty %}
|
||||
<!-- No news today -->
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{% endblock %}
|
|
@ -15,7 +15,7 @@
|
|||
{% if entry.excerpt %}
|
||||
{{ entry.excerpt|striptags }}
|
||||
{% else %}
|
||||
{{ entry.body|striptags|truncatewords_html:70 }}
|
||||
{{ entry.body|striptags|truncatewords_html:40 }}
|
||||
{% endif %}
|
||||
</p>
|
||||
<a href="{% pageurl entry %}" class="btn btn-default btn-xs">Mehr erfahren</a>
|
||||
|
|
Loading…
Reference in a new issue