Merge pull request '10472/expiry-date-to-entry' (#2) from 10472/expiry-date-to-entry into master
Reviewed-on: #2
This commit is contained in:
commit
1abbc707f3
3 changed files with 33 additions and 3 deletions
18
feedler/migrations/0009_entry_expire_at.py
Normal file
18
feedler/migrations/0009_entry_expire_at.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.13 on 2022-05-03 10:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('feedler', '0008_auto_20171117_1647'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='entry',
|
||||
name='expire_at',
|
||||
field=models.DateTimeField(blank=True, null=True, verbose_name='expiry date/time'),
|
||||
),
|
||||
]
|
|
@ -1,9 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
|
||||
from django.db import models
|
||||
from django.utils import translation
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from wagtail.core.models import Page, Orderable
|
||||
from wagtail.admin.edit_handlers import FieldPanel
|
||||
from wagtail.core.fields import RichTextField
|
||||
|
@ -39,6 +40,11 @@ class Entry(models.Model):
|
|||
lang = models.CharField(max_length=2, blank=True, default='', choices=LANGUAGE_CHOICES)
|
||||
content = models.TextField()
|
||||
tags = models.TextField(blank=True)
|
||||
expire_at = models.DateTimeField(
|
||||
verbose_name=_("expiry date/time"),
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
|
||||
stream = models.ForeignKey(Stream,
|
||||
blank=False, on_delete=models.CASCADE,
|
||||
|
@ -68,7 +74,9 @@ class FeedPage(Page):
|
|||
@property
|
||||
def feedentries(self):
|
||||
if self.stream:
|
||||
entries = Entry.objects.filter(stream=self.stream)
|
||||
entries = Entry.objects.filter(stream=self.stream).filter(
|
||||
models.Q(expire_at__isnull=True) | models.Q(expire_at__gt=datetime.datetime.now())
|
||||
)
|
||||
else:
|
||||
entries = Entry.objects.all()
|
||||
# Filter out by chosen language
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
|
||||
from django.db import models
|
||||
from django.utils import translation
|
||||
from django.conf import settings
|
||||
|
@ -320,7 +322,9 @@ class HomePage(Page):
|
|||
@property
|
||||
def newsentries(self):
|
||||
# Get the last few news entries for the home page
|
||||
entries = Entry.objects.all().order_by('-published')
|
||||
entries = Entry.objects.filter(
|
||||
models.Q(expire_at__isnull=True) | models.Q(expire_at__gt=datetime.datetime.now())
|
||||
).all().order_by('-published')
|
||||
# Filter out by current language
|
||||
curlang = translation.get_language()
|
||||
if curlang in ['de']:
|
||||
|
|
Loading…
Reference in a new issue