<s> from django . db import models <EOL> from systems . models import OperatingSystem , ServerModel <EOL> from datetime import datetime , timedelta , date <EOL> from django . db . models . query import QuerySet <EOL> from settings import USER_SYSTEM_ALLOWED_DELETE , FROM_EMAIL_ADDRESS , UNAUTHORIZED_EMAIL_ADDRESS , BUG_URL <EOL> from django . core . exceptions import PermissionDenied <EOL> from django . core . mail import send_mail <EOL> YES_NO_CHOICES = ( <EOL> ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ) <EOL> OS_CHOICES = ( <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ) <EOL> class QuerySetManager ( models . Manager ) : <EOL> def get_query_set ( self ) : <EOL> return self . model . QuerySet ( self . model ) <EOL> def __getattr__ ( self , attr , * args ) : <EOL> return getattr ( self . get_query_set ( ) , attr , * args ) <EOL> class UserOperatingSystem ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT> , blank = False ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> class UnmanagedSystemType ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT> , blank = False ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> class Meta : <EOL> db_table = '<STR_LIT>' <EOL> class CostCenter ( models . Model ) : <EOL> cost_center_number = models . IntegerField ( ) <EOL> name = models . CharField ( max_length = <NUM_LIT:255> , blank = True ) <EOL> def __unicode__ ( self ) : <EOL> return '<STR_LIT>' % ( self . cost_center_number , self . name ) <EOL> class Meta : <EOL> db_table = '<STR_LIT>' <EOL> class UnmanagedSystem ( models . Model ) : <EOL> serial = models . CharField ( max_length = <NUM_LIT:255> , blank = True ) <EOL> asset_tag = models . CharField ( max_length = <NUM_LIT:255> , blank = True ) <EOL> operating_system = models . ForeignKey ( OperatingSystem , blank = True , null = True ) <EOL> owner = models . ForeignKey ( '<STR_LIT>' , blank = True , null = True ) <EOL> system_type = models . ForeignKey ( '<STR_LIT>' , blank = False , null = True ) <EOL> server_model = models . ForeignKey ( ServerModel , blank = True , null = True ) <EOL> created_on = models . DateTimeField ( null = True , blank = True ) <EOL> updated_on = models . DateTimeField ( null = True , blank = True ) <EOL> date_purchased = models . DateField ( null = True , blank = True ) <EOL> cost = models . CharField ( max_length = <NUM_LIT:50> , blank = True ) <EOL> cost_center = models . ForeignKey ( '<STR_LIT>' , null = True , blank = True ) <EOL> bug_number = models . CharField ( max_length = <NUM_LIT:255> , blank = True ) <EOL> notes = models . TextField ( blank = True ) <EOL> is_loaned = models . IntegerField ( choices = YES_NO_CHOICES , blank = True , null = True ) <EOL> is_loaner = models . IntegerField ( choices = YES_NO_CHOICES , blank = True , null = True ) <EOL> loaner_return_date = models . DateTimeField ( null = True , blank = True ) <EOL> objects = QuerySetManager ( ) <EOL> search_fields = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> def delete ( self , * args , ** kwargs ) : <EOL> super ( UnmanagedSystem , self ) . delete ( * args , ** kwargs ) <EOL> def save ( self ) : <EOL> if not self . id : <EOL> self . created_on = datetime . now ( ) <EOL> self . updated_on = datetime . now ( ) <EOL> super ( UnmanagedSystem , self ) . save ( ) <EOL> def __unicode__ ( self ) : <EOL> try : <EOL> server_model = self . server_model <EOL> except ServerModel . DoesNotExist : <EOL> server_model = "<STR_LIT>" <EOL> return "<STR_LIT>" % ( server_model , self . asset_tag , self . serial ) <EOL> class QuerySet ( QuerySet ) : <EOL> def get_all_loaners ( self ) : <EOL> return self . filter ( is_loaner = <NUM_LIT:1> ) <EOL> def get_loaners_due ( self ) : <EOL> return_date = date . today ( ) <EOL> return self . filter ( loaner_return_date__lte = return_date ) <EOL> def get_bug_url ( self ) : <EOL> bug_id = '<STR_LIT>' <EOL> if self . bug_number : <EOL> bug_id = self . bug_number <EOL> return "<STR_LIT>" % ( BUG_URL , bug_id ) <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( '<STR_LIT>' , [ self . id ] ) <EOL> class Meta : <EOL> db_table = u'<STR_LIT>' <EOL> class History ( models . Model ) : <EOL> change = models . CharField ( max_length = <NUM_LIT:1000> ) <EOL> changed_by = models . CharField ( max_length = <NUM_LIT> , null = True , blank = True ) <EOL> system = models . ForeignKey ( UnmanagedSystem ) <EOL> created = models . DateTimeField ( auto_now_add = True ) <EOL> def __unicode__ ( self ) : <EOL> "<STR_LIT>" % ( self . created , self . change ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' ] <EOL> class Owner ( models . Model ) : <EOL> name = models . CharField ( unique = True , max_length = <NUM_LIT:255> , blank = True ) <EOL> address = models . TextField ( blank = True ) <EOL> note = models . TextField ( blank = True ) <EOL> user_location = models . ForeignKey ( '<STR_LIT>' , blank = True , null = True ) <EOL> email = models . CharField ( max_length = <NUM_LIT:255> , blank = True ) <EOL> search_fields = ( <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:email>' , <EOL> ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> def upgradeable_systems ( self ) : <EOL> return self . unmanagedsystem_set . filter ( <EOL> date_purchased__lt = datetime . now ( ) - timedelta ( days = <NUM_LIT> ) ) <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( '<STR_LIT>' , [ self . id ] ) <EOL> def delete ( self ) : <EOL> UserLicense . objects . filter ( owner = self ) . update ( owner = None ) <EOL> UnmanagedSystem . objects . filter ( owner = self ) . update ( owner = None ) <EOL> super ( Owner , self ) . delete ( ) <EOL> class Meta : <EOL> db_table = u'<STR_LIT>' <EOL> ordering = [ '<STR_LIT:name>' ] <EOL> class UserLicense ( models . Model ) : <EOL> username = models . CharField ( max_length = <NUM_LIT:255> , blank = True ) <EOL> version = models . CharField ( max_length = <NUM_LIT:255> , blank = True ) <EOL> license_type = models . CharField ( max_length = <NUM_LIT:255> , blank = True ) <EOL> license_key = models . CharField ( max_length = <NUM_LIT:255> , blank = False ) <EOL> owner = models . ForeignKey ( '<STR_LIT>' , blank = True , null = True ) <EOL> purchase_date = models . DateField ( blank = True , null = True , default = None ) <EOL> user_operating_system = models . ForeignKey ( '<STR_LIT>' , blank = True , null = True ) <EOL> search_fields = ( <EOL> '<STR_LIT:username>' , <EOL> '<STR_LIT:version>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def delete ( self , * args , ** kwargs ) : <EOL> super ( UserLicense , self ) . delete ( * args , ** kwargs ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . license_type , self . license_key ) <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( '<STR_LIT>' , [ self . id ] ) <EOL> class Meta : <EOL> db_table = u'<STR_LIT>' <EOL> ordering = [ '<STR_LIT>' ] <EOL> class UserLocation ( models . Model ) : <EOL> city = models . CharField ( unique = True , max_length = <NUM_LIT:255> , blank = True ) <EOL> country = models . CharField ( unique = True , max_length = <NUM_LIT:255> , blank = True ) <EOL> created_at = models . DateTimeField ( null = True , blank = True ) <EOL> updated_at = models . DateTimeField ( null = True , blank = True ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . city , self . country ) <EOL> class Meta : <EOL> db_table = u'<STR_LIT>' </s>
