<s> from django . core . urlresolvers import reverse <EOL> from django . utils . translation import ugettext as _ <EOL> from datetime import datetime <EOL> from google . appengine . api . labs import taskqueue <EOL> from google . appengine . ext import db <EOL> from appengine_django . auth . models import User <EOL> from userstorage . utils import get_user <EOL> from app . base import Base <EOL> from app . utils import break_url , trunc_string <EOL> from projects . models import Project , ProjectURL <EOL> from error . models import Group <EOL> from issues import signals <EOL> class Issue ( Base ) : <EOL> timestamp = db . DateTimeProperty ( ) <EOL> title = db . StringProperty ( required = False ) <EOL> description = db . TextProperty ( required = False ) <EOL> priority = db . IntegerProperty ( ) <EOL> raw = db . StringProperty ( ) <EOL> domain = db . StringProperty ( ) <EOL> query = db . StringProperty ( ) <EOL> protocol = db . StringProperty ( ) <EOL> project = db . ReferenceProperty ( Project , required = False ) <EOL> creator = db . ReferenceProperty ( User , required = False , collection_name = "<STR_LIT>" ) <EOL> assigned = db . ReferenceProperty ( User , required = False , collection_name = "<STR_LIT>" ) <EOL> status = db . StringProperty ( ) <EOL> number = db . IntegerProperty ( ) <EOL> def get_absolute_url ( self ) : <EOL> return reverse ( "<STR_LIT>" , args = [ self . number , ] ) <EOL> def get_log_set ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . log_set . order ( "<STR_LIT>" ) <EOL> def get_comment_set ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . comment_set . order ( "<STR_LIT>" ) <EOL> def add_log ( self , text ) : <EOL> """<STR_LIT>""" <EOL> log = Log ( creator = get_user ( ) , timestamp = datetime . now ( ) , text = text , issue = self ) <EOL> log . save ( ) <EOL> return log <EOL> def add_group ( self , group ) : <EOL> """<STR_LIT>""" <EOL> issue_group = IssueGroup ( issue = self , group = group ) <EOL> issue_group . save ( ) <EOL> return issue_group <EOL> def __str__ ( self ) : <EOL> return self . title <EOL> def save ( self , * args , ** kw ) : <EOL> if self . raw : <EOL> for k , v in break_url ( self . raw ) . items ( ) : <EOL> setattr ( self , k , v ) <EOL> if not self . title : <EOL> self . title = trunc_string ( self . description , <NUM_LIT:50> ) <EOL> created = not getattr ( self , "<STR_LIT:id>" , None ) <EOL> old = None <EOL> if created : <EOL> try : <EOL> self . number = Issue . all ( ) . order ( "<STR_LIT>" ) [ <NUM_LIT:0> ] . number + <NUM_LIT:1> <EOL> except IndexError : <EOL> self . number = <NUM_LIT:1> <EOL> self . timestamp = datetime . now ( ) <EOL> else : <EOL> old = Issue . get ( self . id ) <EOL> self . put ( ) <EOL> if created : <EOL> signals . issue_created . send ( sender = self . __class__ , instance = self ) <EOL> else : <EOL> for key in [ "<STR_LIT:status>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> new_value = getattr ( self , key ) <EOL> old_value = getattr ( old , key ) <EOL> if new_value != old_value : <EOL> signal = getattr ( signals , "<STR_LIT>" % key ) <EOL> signal . send ( sender = self . __class__ , instance = self , old = old_value , new = new_value ) <EOL> signals . issue_changed . send ( sender = self . __class__ , instance = self , old = old ) <EOL> class Comment ( Base ) : <EOL> timestamp = db . DateTimeProperty ( ) <EOL> issue = db . ReferenceProperty ( Issue ) <EOL> text = db . TextProperty ( ) <EOL> creator = db . ReferenceProperty ( User ) <EOL> def save ( self , * args , ** kw ) : <EOL> created = not getattr ( self , "<STR_LIT:id>" , None ) <EOL> if created : <EOL> self . timestamp = datetime . now ( ) <EOL> self . put ( ) <EOL> if created : <EOL> signals . comment_created . send ( sender = self . __class__ , instance = self ) <EOL> class IssueGroup ( Base ) : <EOL> issue = db . ReferenceProperty ( Issue ) <EOL> group = db . ReferenceProperty ( Group ) <EOL> class IssueProjectURL ( Base ) : <EOL> issue = db . ReferenceProperty ( Issue ) <EOL> project_url = db . ReferenceProperty ( ProjectURL ) <EOL> status = db . StringProperty ( required = False ) <EOL> def get_status_image ( self ) : <EOL> return { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } . get ( self . status , "<STR_LIT>" ) <EOL> def get_status_display ( self ) : <EOL> from issues . forms import issue_project_url_statuses <EOL> return dict ( issue_project_url_statuses ) . get ( self . status ) <EOL> def __str__ ( self ) : <EOL> return str ( self . project_url ) <EOL> class Log ( Base ) : <EOL> timestamp = db . DateTimeProperty ( ) <EOL> issue = db . ReferenceProperty ( Issue ) <EOL> text = db . TextProperty ( ) <EOL> creator = db . ReferenceProperty ( User ) <EOL> from notifications import registry <EOL> registry . register ( Issue , "<STR_LIT>" ) </s>
