<s> from twisted . internet . defer import Deferred <EOL> from droned . entity import Entity <EOL> from droned . context import EntityContext <EOL> class Issue ( Entity ) : <EOL> idCounter = <NUM_LIT:0> <EOL> resolved = property ( lambda self : self . deferred . called ) <EOL> resolution = None <EOL> assignedTo = None <EOL> def __init__ ( self , description ) : <EOL> self . description = description <EOL> self . context = IssueContext ( self ) <EOL> self . deferred = Deferred ( ) <EOL> while Issue . byID ( Issue . idCounter ) : <EOL> Issue . idCounter += <NUM_LIT:1> <EOL> self . id = Issue . idCounter <EOL> Issue . idCounter += <NUM_LIT:1> <EOL> def __getstate__ ( self ) : <EOL> return { <EOL> '<STR_LIT:description>' : self . description , <EOL> '<STR_LIT>' : self . context . data <EOL> } <EOL> @ staticmethod <EOL> def construct ( state ) : <EOL> return Issue ( state [ '<STR_LIT:description>' ] ) . withContext ( state [ '<STR_LIT>' ] ) <EOL> @ staticmethod <EOL> def byID ( id ) : <EOL> for issue in Issue . objects : <EOL> if hasattr ( issue , '<STR_LIT:id>' ) : <EOL> if issue . id == id : <EOL> return issue <EOL> def withContext ( self , context ) : <EOL> self . context . update ( context ) <EOL> return self <EOL> def whenResolved ( self , callback ) : <EOL> self . deferred . addCallback ( callback ) <EOL> return self <EOL> def resolve ( self , resolution = None ) : <EOL> if self . resolved : <EOL> return <EOL> else : <EOL> Issue . delete ( self ) <EOL> self . resolution = resolution <EOL> self . deferred . callback ( self ) <EOL> def assign ( self , who ) : <EOL> if isinstance ( who , str ) : <EOL> if Team . exists ( who ) : <EOL> who = Team ( who ) <EOL> elif Conversation . byName ( who ) : <EOL> who = SupportAgent ( Conversation . byName ( who ) . buddy ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % who ) <EOL> if not isinstance ( who , ( Team , SupportAgent ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> self . assignedTo = who <EOL> if isinstance ( who , SupportAgent ) and who . available : <EOL> who . engage ( self ) <EOL> class IssueContext ( EntityContext ) : <EOL> entityAttr = '<STR_LIT>' <EOL> specialKeys = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def get_issue ( self ) : <EOL> return self . issue <EOL> def get_assignedTo ( self ) : <EOL> return self . issue . assignedTo <EOL> def get_agent ( self ) : <EOL> for agent in SupportAgent . objects : <EOL> if agent . currentIssue is self . issue : <EOL> return agent <EOL> def get_conversation ( self ) : <EOL> if isinstance ( self . issue . assignedTo , SupportAgent ) : <EOL> return self . issue . assignedTo . conversation <EOL> else : <EOL> return None <EOL> def get_sop ( self ) : <EOL> agent = self . issue . assignedTo <EOL> if agent : <EOL> return agent . sop <EOL> from droned . models . team import Team , SupportAgent <EOL> from droned . models . conversation import Conversation </s>
