<s> from datetime import datetime <EOL> from django . core . urlresolvers import reverse <EOL> from django . db import models <EOL> from django . utils . translation import ugettext , ugettext_lazy as _ <EOL> from django . contrib . auth . models import User <EOL> from django . db . models . query import QuerySet <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . contenttypes import generic <EOL> from tagging . fields import TagField <EOL> import object_feeds <EOL> class Paper ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> content_type = models . ForeignKey ( ContentType , null = True , blank = True ) <EOL> object_id = models . PositiveIntegerField ( null = True , blank = True ) <EOL> content_object = generic . GenericForeignKey ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> title = models . CharField ( _ ( "<STR_LIT:title>" ) , max_length = <NUM_LIT:255> , unique = True ) <EOL> slug = models . SlugField ( ) <EOL> creator = models . ForeignKey ( User , verbose_name = _ ( "<STR_LIT>" ) , related_name = "<STR_LIT>" ) <EOL> created = models . DateTimeField ( _ ( "<STR_LIT>" ) , default = datetime . now ) <EOL> last_editor = models . ForeignKey ( User , verbose_name = _ ( "<STR_LIT>" ) , related_name = "<STR_LIT>" ) <EOL> last_edited = models . DateTimeField ( default = datetime . now ) <EOL> tags = TagField ( ) <EOL> contributor_users = models . ManyToManyField ( User , <EOL> through = "<STR_LIT>" , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> yeas = models . PositiveIntegerField ( default = <NUM_LIT:0> , editable = False ) <EOL> nays = models . PositiveIntegerField ( default = <NUM_LIT:0> , editable = False ) <EOL> votes = models . PositiveIntegerField ( default = <NUM_LIT:0> , editable = False ) <EOL> contributors_count = models . PositiveIntegerField ( default = <NUM_LIT:0> , editable = False ) <EOL> comments_count = models . PositiveIntegerField ( default = <NUM_LIT:0> , editable = False ) <EOL> followers_count = models . PositiveIntegerField ( default = <NUM_LIT:0> , editable = False ) <EOL> class Meta : <EOL> app_label = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> ordering = [ '<STR_LIT>' ] <EOL> get_latest_by = '<STR_LIT>' <EOL> def __unicode__ ( self ) : <EOL> return self . title <EOL> def get_absolute_url ( self ) : <EOL> return reverse ( "<STR_LIT>" , kwargs = { "<STR_LIT>" : self . slug } ) <EOL> def user_is_contributor ( self , user ) : <EOL> return self . contributors . filter ( user = user ) . exists ( ) <EOL> @ property <EOL> def current ( self ) : <EOL> return self . revisions . latest ( ) <EOL> @ property <EOL> def revision ( self , rev_number ) : <EOL> return self . revisions . get ( revision = rev_number ) <EOL> object_feeds . register ( Paper ) <EOL> class PaperRevision ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> paper = models . ForeignKey ( Paper , verbose_name = _ ( u'<STR_LIT>' ) , related_name = "<STR_LIT>" ) <EOL> editor = models . ForeignKey ( User , verbose_name = _ ( u'<STR_LIT>' ) , null = True ) <EOL> revision = models . IntegerField ( _ ( u"<STR_LIT>" ) ) <EOL> comment = models . CharField ( _ ( u"<STR_LIT>" ) , max_length = <NUM_LIT:255> , blank = True ) <EOL> content = models . TextField ( _ ( u"<STR_LIT>" ) ) <EOL> created = models . DateTimeField ( _ ( u"<STR_LIT>" ) , default = datetime . now ) <EOL> yeas = models . PositiveIntegerField ( default = <NUM_LIT:0> , editable = False ) <EOL> nays = models . PositiveIntegerField ( default = <NUM_LIT:0> , editable = False ) <EOL> votes = models . PositiveIntegerField ( default = <NUM_LIT:0> , editable = False ) <EOL> class Meta : <EOL> verbose_name = _ ( u'<STR_LIT>' ) <EOL> verbose_name_plural = _ ( u'<STR_LIT>' ) <EOL> get_latest_by = '<STR_LIT>' <EOL> ordering = [ '<STR_LIT>' ] <EOL> def __unicode__ ( self ) : <EOL> return ugettext ( '<STR_LIT>' ) % { <EOL> '<STR_LIT>' : self . created . strftime ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . paper . title , <EOL> } <EOL> def get_absolute_url ( self ) : <EOL> return reverse ( "<STR_LIT>" , kwargs = { "<STR_LIT>" : self . paper . id , "<STR_LIT>" : self . revision } ) <EOL> class PaperContributor ( models . Model ) : <EOL> paper = models . ForeignKey ( Paper , related_name = "<STR_LIT>" , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> user = models . ForeignKey ( User , related_name = "<STR_LIT>" , verbose_name = _ ( "<STR_LIT:user>" ) ) <EOL> contributions = models . PositiveIntegerField ( _ ( "<STR_LIT>" ) , default = <NUM_LIT:1> ) <EOL> away = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> away_message = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT> ) <EOL> away_since = models . DateTimeField ( _ ( "<STR_LIT>" ) , default = datetime . now ) <EOL> class Meta : <EOL> unique_together = [ ( "<STR_LIT:user>" , "<STR_LIT>" ) ] <EOL> from django . db . models . signals import pre_save , post_save <EOL> def paper_feed_title_update ( sender , instance , created , ** kwargs ) : <EOL> instance . feed . title = instance . title <EOL> instance . feed . save ( ) <EOL> post_save . connect ( paper_feed_title_update , sender = Paper ) </s>
