<s> from django . db . models import Q <EOL> from orchestra . core . errors import ModelSaveError <EOL> class WorkflowMixin ( object ) : <EOL> def __str__ ( self ) : <EOL> return self . slug <EOL> class WorkflowVersionMixin ( object ) : <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . workflow . slug , self . slug ) <EOL> class CertificationMixin ( object ) : <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . slug , self . workflow . slug ) <EOL> class StepMixin ( object ) : <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . slug , self . workflow_version . slug , <EOL> self . workflow_version . workflow . slug ) <EOL> class WorkerMixin ( object ) : <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( <EOL> self . user . username , <EOL> self . slack_username , <EOL> self . phone <EOL> ) <EOL> class WorkerCertificationMixin ( object ) : <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( <EOL> self . worker . user . username , self . certification . slug , <EOL> self . certification . workflow . slug , <EOL> dict ( self . TASK_CLASS_CHOICES ) [ self . task_class ] , <EOL> dict ( self . ROLE_CHOICES ) [ self . role ] ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> if self . role == self . Role . REVIEWER : <EOL> if not ( type ( self ) . objects <EOL> . filter ( worker = self . worker , task_class = self . task_class , <EOL> certification = self . certification , <EOL> role = self . Role . ENTRY_LEVEL ) <EOL> . exists ( ) ) : <EOL> raise ModelSaveError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self ) ) <EOL> super ( ) . save ( * args , ** kwargs ) <EOL> class ProjectMixin ( object ) : <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( str ( self . workflow_version . slug ) , <EOL> self . short_description ) <EOL> class TaskMixin ( object ) : <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( str ( self . project ) , str ( self . step . slug ) ) <EOL> class TaskAssignmentMixin ( object ) : <EOL> def save ( self , * args , ** kwargs ) : <EOL> if self . task . step . is_human : <EOL> if self . worker is None : <EOL> raise ModelSaveError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> if self . worker is not None : <EOL> raise ModelSaveError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> super ( ) . save ( * args , ** kwargs ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( <EOL> str ( self . task ) , self . assignment_counter , str ( self . worker ) ) <EOL> class PayRateMixin ( object ) : <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( <EOL> self . worker , self . start_date , self . end_date or '<STR_LIT>' ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> if self . end_date and self . end_date < self . start_date : <EOL> raise ModelSaveError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if self . end_date is None : <EOL> if type ( self ) . objects . exclude ( id = self . id ) . filter ( <EOL> ( Q ( end_date__gte = self . start_date ) | <EOL> Q ( end_date__isnull = True ) ) , <EOL> worker = self . worker ) . exists ( ) : <EOL> raise ModelSaveError ( <EOL> '<STR_LIT>' ) <EOL> else : <EOL> if ( type ( self ) . objects . exclude ( id = self . id ) . filter ( <EOL> start_date__lte = self . end_date , <EOL> end_date__isnull = True , <EOL> worker = self . worker ) . exists ( ) or <EOL> type ( self ) . objects . exclude ( id = self . id ) . filter ( <EOL> ( Q ( start_date__lte = self . end_date ) & <EOL> Q ( end_date__gte = self . start_date ) ) , <EOL> worker = self . worker ) . exists ( ) ) : <EOL> raise ModelSaveError ( <EOL> '<STR_LIT>' ) <EOL> super ( ) . save ( * args , ** kwargs ) </s>
