<s> """<STR_LIT>""" <EOL> import re <EOL> from datetime import datetime <EOL> from django . contrib . sites . models import Site <EOL> from django . contrib . sites . managers import CurrentSiteManager <EOL> from django . conf import settings as site_settings <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . core . urlresolvers import reverse <EOL> from django . db import models <EOL> from django . template . loader import select_template <EOL> from django . template import Context <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . translation import ugettext as _ <EOL> from stories import settings <EOL> class CurrentSitePublishedManager ( CurrentSiteManager ) : <EOL> def get_query_set ( self ) : <EOL> queryset = super ( CurrentSitePublishedManager , self ) . get_query_set ( ) <EOL> return queryset . filter ( <EOL> publish_date__lte = datetime . now ( ) <EOL> ) . filter ( <EOL> status__exact = settings . PUBLISHED_STATUS <EOL> ) <EOL> class AlternateManager ( CurrentSiteManager ) : <EOL> """<STR_LIT>""" <EOL> def unique_slug ( self , publish_date , slug , exclude_id = None ) : <EOL> """<STR_LIT>""" <EOL> query_params = { <EOL> '<STR_LIT>' : slug [ : <NUM_LIT:50> ] , <EOL> '<STR_LIT>' : publish_date , <EOL> } <EOL> qset = self . get_query_set ( ) . filter ( ** query_params ) <EOL> if exclude_id : <EOL> qset = qset . exclude ( id = exclude_id ) <EOL> return qset . count ( ) == <NUM_LIT:0> <EOL> def get_unique_slug ( self , publish_date , slug , story_id = None ) : <EOL> """<STR_LIT>""" <EOL> query_params = { <EOL> '<STR_LIT>' : publish_date . year , <EOL> '<STR_LIT>' : publish_date . month , <EOL> '<STR_LIT>' : publish_date . day <EOL> } <EOL> if not self . unique_slug ( publish_date , slug , story_id ) : <EOL> query_params [ '<STR_LIT>' ] = slug [ : <NUM_LIT> ] <EOL> num = self . get_query_set ( ) . filter ( ** query_params ) . count ( ) <EOL> slug = '<STR_LIT>' % ( slug [ : <NUM_LIT> ] , str ( num + <NUM_LIT:1> ) ) <EOL> return slug <EOL> def published ( self ) : <EOL> queryset = self . get_query_set ( ) <EOL> return queryset . filter ( <EOL> publish_date__lte = datetime . now ( ) <EOL> ) . filter ( <EOL> status__exact = settings . PUBLISHED_STATUS ) <EOL> class Story ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> headline = models . CharField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT:100> ) <EOL> tease_headline = models . CharField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT:100> , <EOL> default = "<STR_LIT>" , <EOL> blank = True ) <EOL> subhead = models . CharField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT:200> , <EOL> blank = True , <EOL> null = True ) <EOL> slug = models . SlugField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> max_length = <NUM_LIT:50> ) <EOL> authors = models . ManyToManyField ( <EOL> settings . AUTHOR_MODEL , <EOL> verbose_name = _ ( '<STR_LIT>' ) , <EOL> blank = True , <EOL> null = True , <EOL> limit_choices_to = settings . AUTHOR_MODEL_LIMIT_CHOICES ) <EOL> non_staff_author = models . CharField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> max_length = <NUM_LIT:200> , <EOL> blank = True , <EOL> null = True , <EOL> help_text = _ ( "<STR_LIT>" ) ) <EOL> publish_date = models . DateField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> blank = True , <EOL> null = True ) <EOL> publish_time = models . TimeField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> blank = True , <EOL> null = True ) <EOL> update_date = models . DateTimeField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> blank = True , <EOL> null = True ) <EOL> modified_date = models . DateTimeField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> auto_now = True , <EOL> blank = True , <EOL> editable = False ) <EOL> print_pub_date = models . DateTimeField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> blank = True , <EOL> null = True ) , <EOL> print_section = models . CharField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> max_length = <NUM_LIT:30> , <EOL> blank = True , <EOL> null = True ) , <EOL> print_page = models . CharField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> max_length = <NUM_LIT:5> , <EOL> blank = True , <EOL> null = True ) , <EOL> comments = models . BooleanField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> default = True ) <EOL> comment_status = models . IntegerField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> choices = settings . COMMENT_STATUSES , <EOL> default = <NUM_LIT:1> <EOL> ) <EOL> status = models . IntegerField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> choices = settings . STATUS_CHOICES , <EOL> default = settings . DEFAULT_STATUS ) <EOL> teaser = models . TextField ( _ ( "<STR_LIT>" ) , blank = True ) <EOL> kicker = models . CharField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> max_length = <NUM_LIT:50> , <EOL> blank = True , <EOL> null = True ) <EOL> body = models . TextField ( _ ( "<STR_LIT>" ) ) <EOL> origin = models . IntegerField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> choices = settings . ORIGIN_CHOICES , <EOL> default = settings . DEFAULT_ORIGIN , ) <EOL> site = models . ForeignKey ( Site , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> objects = AlternateManager ( ) <EOL> published = CurrentSitePublishedManager ( ) <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> ordering = settings . ORDERING <EOL> get_latest_by = '<STR_LIT>' <EOL> unique_together = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def get_absolute_url ( self ) : <EOL> if self . publish_date is None : <EOL> return "<STR_LIT>" <EOL> return reverse ( '<STR_LIT>' , args = tuple ( ) , kwargs = { <EOL> '<STR_LIT>' : self . publish_date . year , <EOL> '<STR_LIT>' : self . publish_date . strftime ( '<STR_LIT>' ) . lower ( ) , <EOL> '<STR_LIT>' : self . publish_date . day , <EOL> '<STR_LIT>' : self . slug <EOL> } ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . status == settings . PUBLISHED_STATUS : <EOL> if not self . publish_date : <EOL> self . publish_date = datetime . now ( ) . date ( ) <EOL> if not self . publish_time : <EOL> self . publish_time = datetime . now ( ) . time ( ) <EOL> self . slug = Story . objects . get_unique_slug ( self . publish_date , self . slug , self . id ) <EOL> super ( Story , self ) . save ( * args , ** kwargs ) <EOL> @ property <EOL> def comments_frozen ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . comment_status == settings . COMMENTS_FROZEN <EOL> @ property <EOL> def author ( self ) : <EOL> """<STR_LIT>""" <EOL> import warnings <EOL> warnings . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' , DeprecationWarning ) <EOL> AuthorModel = models . get_model ( * settings . AUTHOR_MODEL . split ( "<STR_LIT:.>" ) ) <EOL> link = '<STR_LIT>' <EOL> if AuthorModel . __module__ == '<STR_LIT>' : <EOL> authors = [ link % ( <EOL> i . get_profile ( ) . get_absolute_url ( ) , <EOL> i . first_name , <EOL> i . last_name ) for i in self . authors . all ( ) ] <EOL> else : <EOL> authors = [ link % ( i . get_absolute_url ( ) , i . first_name , i . last_name ) <EOL> for i in self . authors . all ( ) ] <EOL> if self . non_staff_author : <EOL> authors . append ( self . non_staff_author ) <EOL> if len ( authors ) > <NUM_LIT:1> : <EOL> author_string = "<STR_LIT>" % ( "<STR_LIT:U+002CU+0020>" . join ( authors [ : - <NUM_LIT:1> ] ) , authors [ - <NUM_LIT:1> ] ) <EOL> elif len ( authors ) == <NUM_LIT:1> : <EOL> author_string = authors [ <NUM_LIT:0> ] <EOL> else : <EOL> author_string = '<STR_LIT>' <EOL> return mark_safe ( author_string ) <EOL> @ property <EOL> def author_display ( self ) : <EOL> """<STR_LIT>""" <EOL> template = "<STR_LIT>" <EOL> ctx = Context ( ) <EOL> ctx . update ( { <EOL> '<STR_LIT>' : self , <EOL> '<STR_LIT>' : self . authors . all ( ) , <EOL> '<STR_LIT>' : self . non_staff_author <EOL> } ) <EOL> t = select_template ( [ template ] ) <EOL> return t . render ( ctx ) <EOL> @ property <EOL> def paragraphs ( self ) : <EOL> """<STR_LIT>""" <EOL> return re . findall ( "<STR_LIT>" , self . body , re . I | re . S ) <EOL> if '<STR_LIT>' in site_settings . INSTALLED_APPS : <EOL> def get_related_content_type ( self , content_type ) : <EOL> """<STR_LIT>""" <EOL> return self . storyrelation_set . filter ( <EOL> content_type__name = content_type ) <EOL> def get_relation_type ( self , relation_type ) : <EOL> """<STR_LIT>""" <EOL> return self . storyrelation_set . filter ( relation_type = relation_type ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . headline , self . publish_date ) <EOL> if settings . USE_REVERSION : <EOL> rev_error_msg = '<STR_LIT>' '<STR_LIT>' <EOL> try : <EOL> import reversion <EOL> if not '<STR_LIT>' in site_settings . INSTALLED_APPS : <EOL> raise ImproperlyConfigured ( rev_error_msg ) <EOL> except ( ImportError , ) : <EOL> raise ImproperlyConfigured ( rev_error_msg ) <EOL> reversion . register ( Story ) <EOL> try : <EOL> if '<STR_LIT>' in site_settings . INSTALLED_APPS and '<STR_LIT>' in site_settings . INSTALLED_APPS : <EOL> import categories <EOL> from distutils . version import LooseVersion <EOL> categories_version = LooseVersion ( categories . __version__ ) <EOL> compare_version = LooseVersion ( '<STR_LIT>' ) <EOL> if categories_version <= compare_version : <EOL> from categories . migration import migrate_app <EOL> from django . db . models . signals import post_syncdb <EOL> post_syncdb . connect ( migrate_app ) <EOL> except ( ImportError , ValueError ) : <EOL> pass </s>
