evorepo/planet/models.py
Jelle van der Waa 17a12f07fb Introduce planet functionality in archweb
This change introduces a replacment for planet.archlinux.org which uses
a python 2 project to generate static html from multiple RSS feed
sources. For archweb a set of 'static' feeds can be created in the
django admin view for the Arch forums and other static feeds, archweb
users can add their own blog rss feed in their profile which will create
a Feed model.

When running the update_planet command, all Feed models are iterated
over and the rss feed is parsed. The latest FeedItem is queried matching
the current Feed model and every newer entry in the RSS feed is added as
new FeedItem. Since the body is also stored in the FeedItem there is a
limit to the amount of FeedItems per Feed configured in settings.py of
which the default is 25.

When a user is marked as inactive his Feed model and items are
removed automatically to avoid keeping stale data around.

Closes: #261
2020-02-03 21:25:31 +01:00

61 lines
1.6 KiB
Python

from django.db import models
# FeedItem summary field length
FEEDITEM_SUMMARY_LIMIT = 2048
class Feed(models.Model):
title = models.CharField(max_length=255)
website = models.CharField(max_length=200, null=True, blank=True)
website_rss = models.CharField(max_length=200, null=True, blank=True)
def __str__(self):
return self.title
class Meta:
db_table = 'feeds'
verbose_name_plural = 'feeds'
get_latest_by = 'title'
ordering = ('-title',)
class FeedItem(models.Model):
title = models.CharField(max_length=255)
summary = models.CharField(max_length=FEEDITEM_SUMMARY_LIMIT)
feed = models.ForeignKey(Feed, related_name='items',
on_delete=models.CASCADE, null=True)
author = models.CharField(max_length=255)
publishdate = models.DateTimeField("publish date", db_index=True)
url = models.CharField('URL', max_length=255)
def get_absolute_url(self):
return self.url
def __str__(self):
return self.title
class Meta:
db_table = 'feeditems'
verbose_name_plural = 'Feed Items'
get_latest_by = 'publishdate'
ordering = ('-publishdate',)
class Planet(models.Model):
'''
The planet model contains related Arch Linux planet instances.
'''
name = models.CharField(max_length=255)
website = models.CharField(max_length=200, null=True, blank=True)
def __str__(self):
return self.name
class Meta:
db_table = 'planets'
verbose_name_plural = 'Worldwide Planets'
get_latest_by = 'name'
ordering = ('-name',)
# vim: set ts=4 sw=4 et: