2023-10-19 22:44:24 +00:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
2010-09-26 21:32:53 +00:00
|
|
|
from django.conf import settings
|
|
|
|
from django.contrib.sites.models import Site
|
2023-10-19 22:52:39 +00:00
|
|
|
from django.db import models
|
2023-10-19 22:44:24 +00:00
|
|
|
|
2023-10-20 07:25:55 +00:00
|
|
|
from .. import bsoup
|
2023-10-19 22:44:24 +00:00
|
|
|
from ..events.models import Event
|
2023-10-19 22:52:39 +00:00
|
|
|
from ..staff.models import Person
|
2023-10-19 22:44:24 +00:00
|
|
|
|
2010-09-26 21:32:53 +00:00
|
|
|
|
2017-11-07 16:17:33 +00:00
|
|
|
class PressRelease(models.Model, bsoup.SoupModelMixin):
|
2010-09-26 21:32:53 +00:00
|
|
|
"""News release model"""
|
|
|
|
|
|
|
|
headline = models.CharField(max_length=300)
|
|
|
|
subhead = models.CharField(max_length=300, blank=True)
|
|
|
|
slug = models.SlugField(unique_for_date="pub_date",
|
|
|
|
help_text=("automatically built from headline"))
|
|
|
|
summary = models.TextField(help_text="First paragraph (raw HTML)")
|
|
|
|
body = models.TextField(help_text="Remainder of post (raw HTML)",
|
|
|
|
blank=True)
|
|
|
|
pub_date = models.DateTimeField("date [to be] published")
|
|
|
|
sites = models.ManyToManyField(Site)
|
|
|
|
|
|
|
|
date_last_modified = models.DateTimeField(auto_now=True)
|
|
|
|
|
2023-09-07 13:15:48 +00:00
|
|
|
class Meta:
|
2010-09-26 21:32:53 +00:00
|
|
|
ordering = ("-pub_date",)
|
|
|
|
get_latest_by = "pub_date"
|
|
|
|
|
2017-11-07 16:17:33 +00:00
|
|
|
SOUP_ATTRS = ['summary', 'body']
|
|
|
|
|
2022-01-10 22:13:46 +00:00
|
|
|
def __str__(self):
|
2010-09-26 21:32:53 +00:00
|
|
|
return self.headline
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2023-09-07 13:15:48 +00:00
|
|
|
return "/news/{}/{}/".format(self.pub_date.strftime("%Y/%b/%d").lower(),
|
2010-09-26 21:32:53 +00:00
|
|
|
self.slug)
|
|
|
|
|
|
|
|
def is_recent(self):
|
|
|
|
return self.pub_date > (datetime.now() - timedelta(days=5))
|
|
|
|
# question: does datetime.now() do a syscall each time is it called?
|
|
|
|
|
|
|
|
def is_in_past_month(self):
|
|
|
|
# This function is deprecated. Use the date_within template
|
2010-09-26 21:54:29 +00:00
|
|
|
# filter instead (example in conservancy/templates/frontpage.html)
|
2010-09-26 21:32:53 +00:00
|
|
|
return self.pub_date > (datetime.now() - timedelta(days=30))
|
|
|
|
|
|
|
|
def save(self):
|
2023-10-26 01:28:29 +00:00
|
|
|
if settings.DEBUG or True:
|
2023-09-07 13:15:48 +00:00
|
|
|
super().save()
|
2010-09-26 21:32:53 +00:00
|
|
|
return
|
|
|
|
|
2020-01-24 17:26:59 +00:00
|
|
|
blog_name = 'Software Freedom Conservancy News'
|
2023-02-11 06:21:33 +00:00
|
|
|
blog_url = 'https://www.sfconservancy.org/news/'
|
2020-01-24 17:26:59 +00:00
|
|
|
post_url = ('https://www.sfconservancy.org'
|
2010-09-26 21:32:53 +00:00
|
|
|
+ self.get_absolute_url())
|
|
|
|
|
2021-11-29 20:55:45 +00:00
|
|
|
import xmlrpc.client
|
2010-09-26 21:32:53 +00:00
|
|
|
|
|
|
|
# Ping Technorati
|
2021-11-29 20:55:45 +00:00
|
|
|
j = xmlrpc.client.Server('http://rpc.technorati.com/rpc/ping')
|
2010-09-26 21:32:53 +00:00
|
|
|
reply = j.weblogUpdates.ping(blog_name, blog_url)
|
|
|
|
|
|
|
|
# Ping Google Blog Search
|
2021-11-29 20:55:45 +00:00
|
|
|
j = xmlrpc.client.Server('http://blogsearch.google.com/ping/RPC2')
|
2010-09-26 21:32:53 +00:00
|
|
|
reply = j.weblogUpdates.ping(blog_name, blog_url, post_url)
|
|
|
|
|
|
|
|
# Call any superclass's method
|
2023-09-07 13:15:48 +00:00
|
|
|
super().save()
|
2010-09-26 21:32:53 +00:00
|
|
|
|
|
|
|
class ExternalArticleTag(models.Model):
|
|
|
|
"""A way to tag external articles"""
|
|
|
|
|
|
|
|
label = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
date_created = models.DateField(auto_now_add=True)
|
|
|
|
|
2022-01-10 22:13:46 +00:00
|
|
|
def __str__(self):
|
2010-09-26 21:32:53 +00:00
|
|
|
return self.label
|
|
|
|
|
|
|
|
class PublicExternalArticleManager(models.Manager):
|
2015-03-03 18:40:18 +00:00
|
|
|
def get_queryset(self):
|
2023-09-07 13:15:48 +00:00
|
|
|
return super().get_queryset().filter(visible=True)
|
2010-09-26 21:32:53 +00:00
|
|
|
|
|
|
|
class ExternalArticle(models.Model):
|
2010-09-26 21:54:29 +00:00
|
|
|
"""A system for displaying Conservancy news mentions on the site.
|
2010-09-26 21:32:53 +00:00
|
|
|
|
|
|
|
(Currently unused)
|
|
|
|
"""
|
|
|
|
|
|
|
|
title = models.CharField(max_length=400)
|
|
|
|
info = models.CharField(help_text="subscribers only? audio? pdf warning?",
|
|
|
|
blank=True, max_length=300)
|
|
|
|
publication = models.CharField("source of article", max_length=300)
|
2015-03-03 18:40:18 +00:00
|
|
|
# verify_exists removed https://docs.djangoproject.com/en/1.7/releases/1.4/
|
|
|
|
url = models.URLField(blank=True)
|
2010-09-26 21:32:53 +00:00
|
|
|
date = models.DateField()
|
2015-03-09 01:00:50 +00:00
|
|
|
visible = models.BooleanField(help_text="Whether to display on website", default=True)
|
2010-09-26 21:32:53 +00:00
|
|
|
|
2021-12-17 06:25:38 +00:00
|
|
|
tags = models.ManyToManyField(ExternalArticleTag, blank=True)
|
|
|
|
people = models.ManyToManyField(Person, blank=True)
|
2023-09-12 00:55:30 +00:00
|
|
|
event = models.ForeignKey(Event, null=True, blank=True, on_delete=models.CASCADE)
|
|
|
|
press_release = models.ForeignKey(PressRelease, null=True, blank=True, on_delete=models.CASCADE)
|
2010-09-26 21:32:53 +00:00
|
|
|
|
|
|
|
date_created = models.DateField(auto_now_add=True)
|
|
|
|
|
2023-09-07 13:15:48 +00:00
|
|
|
class Meta:
|
2010-09-26 21:32:53 +00:00
|
|
|
ordering = ("-date_created",)
|
|
|
|
get_latest_by = "date_created"
|
|
|
|
|
2022-01-10 22:13:46 +00:00
|
|
|
def __str__(self):
|
2023-09-07 13:15:48 +00:00
|
|
|
return "{} ({})".format(self.title, self.publication)
|
2010-09-26 21:32:53 +00:00
|
|
|
|
|
|
|
objects = models.Manager()
|
|
|
|
public = PublicExternalArticleManager()
|
|
|
|
|