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
2023-10-19 22:52:39 +00:00
from django . db import models
2023-10-19 22:44:24 +00:00
from . . . import bsoup
from . . staff . models import Person
2010-09-26 21:32:53 +00:00
class EntryTag ( models . Model ) :
""" Tagging for blog entries """
label = models . CharField ( max_length = 100 )
slug = models . SlugField ( )
2023-09-07 13:15:48 +00:00
class Meta :
2010-09-26 21:32:53 +00:00
db_table = ' techblog_entrytag ' # legacy
2022-01-10 22:13:46 +00:00
def __str__ ( self ) :
2010-09-26 21:32:53 +00:00
return self . label
def get_absolute_url ( self ) :
2023-09-07 13:15:48 +00:00
return " /blog/?tag= %s " % self . slug
2010-09-26 21:32:53 +00:00
2017-11-07 16:17:33 +00:00
class Entry ( models . Model , bsoup . SoupModelMixin ) :
2010-09-26 21:32:53 +00:00
""" Blog entry """
headline = models . CharField ( max_length = 200 )
slug = models . SlugField ( unique_for_date = ' pub_date ' )
summary = models . TextField ( help_text = " Use raw HTML. Unlike in the press release model, this summary is not included at the beginning of the body when the entry is displayed. " )
body = models . TextField ( help_text = " Use raw HTML. Include the full body of the post. " )
pub_date = models . DateTimeField ( )
2023-09-12 00:55:30 +00:00
author = models . ForeignKey ( Person , on_delete = models . PROTECT )
2021-12-17 06:25:38 +00:00
tags = models . ManyToManyField ( EntryTag , blank = True )
2010-09-26 21:32:53 +00:00
date_created = models . DateTimeField ( auto_now_add = True )
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
db_table = ' techblog_entries ' # legacy
verbose_name_plural = ' entries '
ordering = ( ' -pub_date ' , )
get_latest_by = ' pub_date '
2017-11-07 16:17:33 +00:00
SOUP_ATTRS = [ ' 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 ( " /blog/ %s / %s / "
2010-09-26 21:32:53 +00:00
% ( self . pub_date . strftime ( " % Y/ % b/ %d " ) . lower ( ) ,
self . slug ) )
def is_recent ( self ) :
2012-02-15 23:13:30 +00:00
return self . pub_date > ( datetime . now ( ) - timedelta ( days = 30 ) )
2010-09-26 21:32:53 +00:00
# question: does datetime.now() do a syscall each time is it called?
# Ping google blogs and technorati. Taken from
# http://blog.foozia.com/blog/2007/apr/21/ping-technorati-your-django-blog-using-xml-rpc/
def save ( self ) :
2010-09-26 21:54:29 +00:00
if settings . CONSERVANCY_DEVEL or True : # "or True" means it is disabled always
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 Blog '
blog_url = ' http://www.sfconservancy.org/blog/ '
post_url = ( ' http://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 ( )