<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_lazy as _ <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . contenttypes import generic <EOL> from tagging . fields import TagField <EOL> from disciplines . models import Discipline <EOL> from people . models import Institution <EOL> from papers . models import Paper <EOL> import object_feeds <EOL> class Issue ( models . Model ) : <EOL> title = models . CharField ( _ ( "<STR_LIT:title>" ) , max_length = <NUM_LIT:255> , unique = True ) <EOL> slug = models . SlugField ( _ ( "<STR_LIT>" ) , unique = True ) <EOL> creator = models . ForeignKey ( User , verbose_name = _ ( "<STR_LIT>" ) , related_name = "<STR_LIT>" ) <EOL> created = models . DateTimeField ( _ ( "<STR_LIT>" ) , default = datetime . now ) <EOL> description = models . TextField ( _ ( "<STR_LIT:description>" ) ) <EOL> private = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> sandbox = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> model_project = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> disciplines = models . ManyToManyField ( Discipline , blank = True ) <EOL> tags = TagField ( ) <EOL> resolved = models . BooleanField ( default = False ) <EOL> resolution = models . ForeignKey ( Paper , null = True , blank = True , related_name = '<STR_LIT>' ) <EOL> contributor_users = models . ManyToManyField ( User , <EOL> through = "<STR_LIT>" , <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> ) <EOL> institutions = models . ManyToManyField ( Institution , blank = True ) <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:1> , 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> @ property <EOL> def papers ( self ) : <EOL> return Paper . objects . filter ( content_type = ContentType . objects . get_for_model ( self ) , object_id = self . id ) <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<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> def user_can_read ( self , user ) : <EOL> if self . private and not self . user_is_contributor ( user ) : <EOL> return False <EOL> return True <EOL> def resolve ( self , resolution_paper ) : <EOL> if resolution_paper in self . papers : <EOL> self . resolution = resolution_paper <EOL> self . resolved = True <EOL> self . save ( ) <EOL> return resolution_paper <EOL> return False <EOL> object_feeds . register ( Issue ) <EOL> class IssueContributor ( models . Model ) : <EOL> issue = models . ForeignKey ( Issue , 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 issue_feed_title_update ( sender , instance , created , ** kwargs ) : <EOL> instance . feed . title = instance . title <EOL> instance . feed . save ( ) <EOL> post_save . connect ( issue_feed_title_update , sender = Issue ) </s>
