<s> import datetime <EOL> import copy <EOL> from django . db import models <EOL> from django . db . models import Q <EOL> from stacktach import datetime_to_decimal as dt <EOL> def routing_key_type ( key ) : <EOL> if key . endswith ( '<STR_LIT:error>' ) : <EOL> return '<STR_LIT:E>' <EOL> return '<STR_LIT:U+0020>' <EOL> class Deployment ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:50> ) <EOL> def __repr__ ( self ) : <EOL> return self . name <EOL> class GenericRawData ( models . Model ) : <EOL> result_titles = [ [ "<STR_LIT:#>" , "<STR_LIT:?>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] ] <EOL> deployment = models . ForeignKey ( Deployment ) <EOL> tenant = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True , <EOL> db_index = True ) <EOL> json = models . TextField ( ) <EOL> routing_key = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> when = models . DecimalField ( max_digits = <NUM_LIT:20> , decimal_places = <NUM_LIT:6> , <EOL> db_index = True ) <EOL> publisher = models . CharField ( max_length = <NUM_LIT:100> , null = True , <EOL> blank = True , db_index = True ) <EOL> event = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> service = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> host = models . CharField ( max_length = <NUM_LIT:100> , null = True , <EOL> blank = True , db_index = True ) <EOL> instance = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> request_id = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> message_id = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> @ staticmethod <EOL> def get_name ( ) : <EOL> return GenericRawData . __name__ <EOL> @ property <EOL> def uuid ( self ) : <EOL> return self . instance <EOL> def search_results ( self , results , when , routing_key_status ) : <EOL> if not results : <EOL> results = copy . deepcopy ( self . result_titles ) <EOL> results . append ( [ self . id , routing_key_status , str ( when ) , <EOL> self . deployment . name , self . event , self . host , <EOL> self . instance , self . request_id ] ) <EOL> return results <EOL> class RawData ( models . Model ) : <EOL> result_titles = [ [ "<STR_LIT:#>" , "<STR_LIT:?>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ] <EOL> deployment = models . ForeignKey ( Deployment ) <EOL> tenant = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True , <EOL> db_index = True ) <EOL> json = models . TextField ( ) <EOL> routing_key = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> state = models . CharField ( max_length = <NUM_LIT:20> , null = True , <EOL> blank = True , db_index = True ) <EOL> old_state = models . CharField ( max_length = <NUM_LIT:20> , null = True , <EOL> blank = True , db_index = True ) <EOL> old_task = models . CharField ( max_length = <NUM_LIT:30> , null = True , <EOL> blank = True , db_index = True ) <EOL> task = models . CharField ( max_length = <NUM_LIT:30> , null = True , <EOL> blank = True , db_index = True ) <EOL> image_type = models . IntegerField ( null = True , default = <NUM_LIT:0> , db_index = True ) <EOL> when = models . DecimalField ( max_digits = <NUM_LIT:20> , decimal_places = <NUM_LIT:6> , <EOL> db_index = True ) <EOL> publisher = models . CharField ( max_length = <NUM_LIT:100> , null = True , <EOL> blank = True , db_index = True ) <EOL> event = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> service = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> host = models . CharField ( max_length = <NUM_LIT:100> , null = True , <EOL> blank = True , db_index = True ) <EOL> instance = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> request_id = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . event , self . instance , self . state ) <EOL> @ property <EOL> def uuid ( self ) : <EOL> return self . instance <EOL> @ staticmethod <EOL> def get_name ( ) : <EOL> return RawData . __name__ <EOL> def search_results ( self , results , when , routing_key_status ) : <EOL> if not results : <EOL> results = copy . deepcopy ( self . result_titles ) <EOL> results . append ( [ self . id , routing_key_status , str ( when ) , <EOL> self . deployment . name , self . event , self . host , self . state , <EOL> self . old_state , self . old_task ] ) <EOL> return results <EOL> class RawDataImageMeta ( models . Model ) : <EOL> raw = models . ForeignKey ( RawData , null = False ) <EOL> os_architecture = models . TextField ( null = True , blank = True ) <EOL> os_distro = models . TextField ( null = True , blank = True ) <EOL> os_version = models . TextField ( null = True , blank = True ) <EOL> rax_options = models . TextField ( null = True , blank = True ) <EOL> class Lifecycle ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> instance = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> last_state = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> last_task_state = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> last_raw = models . ForeignKey ( RawData , null = True ) <EOL> class InstanceUsage ( models . Model ) : <EOL> instance = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> launched_at = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> request_id = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> instance_type_id = models . CharField ( max_length = <NUM_LIT:50> , <EOL> null = True , <EOL> blank = True , <EOL> db_index = True ) <EOL> instance_flavor_id = models . CharField ( max_length = <NUM_LIT:100> , null = True , <EOL> blank = True , db_index = True ) <EOL> tenant = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True , <EOL> db_index = True ) <EOL> os_architecture = models . TextField ( null = True , blank = True ) <EOL> os_distro = models . TextField ( null = True , blank = True ) <EOL> os_version = models . TextField ( null = True , blank = True ) <EOL> rax_options = models . TextField ( null = True , blank = True ) <EOL> def deployment ( self ) : <EOL> raws = RawData . objects . filter ( request_id = self . request_id ) <EOL> return raws and raws [ <NUM_LIT:0> ] . deployment <EOL> def latest_deployment_for_request_id ( self ) : <EOL> raw = self . latest_raw_for_request_id ( ) <EOL> return raw and raw . deployment <EOL> def latest_raw_for_request_id ( self ) : <EOL> raw = [ ] <EOL> if self . request_id : <EOL> raw = RawData . objects . filter ( request_id = self . request_id ) . order_by ( '<STR_LIT>' ) <EOL> return ( len ( raw ) > <NUM_LIT:0> and raw [ <NUM_LIT:0> ] ) or None <EOL> def host ( self ) : <EOL> raw = self . latest_raw_for_request_id ( ) <EOL> return raw and raw . host <EOL> @ staticmethod <EOL> def find ( instance , launched_at ) : <EOL> start = launched_at - datetime . timedelta ( <EOL> microseconds = launched_at . microsecond ) <EOL> end = start + datetime . timedelta ( microseconds = <NUM_LIT> ) <EOL> params = { '<STR_LIT>' : instance , <EOL> '<STR_LIT>' : dt . dt_to_decimal ( start ) , <EOL> '<STR_LIT>' : dt . dt_to_decimal ( end ) } <EOL> return InstanceUsage . objects . filter ( ** params ) <EOL> class InstanceDeletes ( models . Model ) : <EOL> instance = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> launched_at = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> deleted_at = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> raw = models . ForeignKey ( RawData , null = True ) <EOL> def deployment ( self ) : <EOL> return self . raw . deployment <EOL> @ staticmethod <EOL> def find ( instance , launched , deleted_max = None ) : <EOL> start = launched - datetime . timedelta ( microseconds = launched . microsecond ) <EOL> end = start + datetime . timedelta ( microseconds = <NUM_LIT> ) <EOL> params = { '<STR_LIT>' : instance , <EOL> '<STR_LIT>' : dt . dt_to_decimal ( start ) , <EOL> '<STR_LIT>' : dt . dt_to_decimal ( end ) } <EOL> if deleted_max : <EOL> params [ '<STR_LIT>' ] = dt . dt_to_decimal ( deleted_max ) <EOL> return InstanceDeletes . objects . filter ( ** params ) <EOL> class InstanceReconcile ( models . Model ) : <EOL> row_created = models . DateTimeField ( auto_now_add = True ) <EOL> row_updated = models . DateTimeField ( auto_now = True ) <EOL> instance = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> launched_at = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> deleted_at = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> instance_type_id = models . CharField ( max_length = <NUM_LIT:50> , <EOL> null = True , <EOL> blank = True , <EOL> db_index = True ) <EOL> instance_flavor_id = models . CharField ( max_length = <NUM_LIT:100> , null = True , <EOL> blank = True , db_index = True ) <EOL> tenant = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True , <EOL> db_index = True ) <EOL> os_architecture = models . TextField ( null = True , blank = True ) <EOL> os_distro = models . TextField ( null = True , blank = True ) <EOL> os_version = models . TextField ( null = True , blank = True ) <EOL> rax_options = models . TextField ( null = True , blank = True ) <EOL> source = models . CharField ( max_length = <NUM_LIT> , null = True , <EOL> blank = True , db_index = True ) <EOL> @ staticmethod <EOL> def find ( instance , launched ) : <EOL> start = launched - datetime . timedelta ( microseconds = launched . microsecond ) <EOL> end = start + datetime . timedelta ( microseconds = <NUM_LIT> ) <EOL> params = { '<STR_LIT>' : instance , <EOL> '<STR_LIT>' : dt . dt_to_decimal ( start ) , <EOL> '<STR_LIT>' : dt . dt_to_decimal ( end ) } <EOL> return InstanceReconcile . objects . filter ( ** params ) <EOL> class InstanceExists ( models . Model ) : <EOL> PENDING = '<STR_LIT>' <EOL> VERIFYING = '<STR_LIT>' <EOL> VERIFIED = '<STR_LIT>' <EOL> RECONCILED = '<STR_LIT>' <EOL> FAILED = '<STR_LIT>' <EOL> SENT_UNVERIFIED = '<STR_LIT>' <EOL> SENT_FAILED = '<STR_LIT>' <EOL> SENT_VERIFYING = '<STR_LIT>' <EOL> STATUS_CHOICES = [ <EOL> ( PENDING , '<STR_LIT>' ) , <EOL> ( VERIFYING , '<STR_LIT>' ) , <EOL> ( VERIFIED , '<STR_LIT>' ) , <EOL> ( RECONCILED , '<STR_LIT>' ) , <EOL> ( FAILED , '<STR_LIT>' ) , <EOL> ( SENT_UNVERIFIED , '<STR_LIT>' ) , <EOL> ( SENT_FAILED , '<STR_LIT>' ) , <EOL> ( SENT_VERIFYING , '<STR_LIT>' ) <EOL> ] <EOL> instance = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> launched_at = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> deleted_at = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> audit_period_beginning = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , <EOL> db_index = True ) <EOL> audit_period_ending = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> message_id = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> instance_type_id = models . CharField ( max_length = <NUM_LIT:50> , <EOL> null = True , <EOL> blank = True , <EOL> db_index = True ) <EOL> status = models . CharField ( max_length = <NUM_LIT:50> , db_index = True , <EOL> choices = STATUS_CHOICES , <EOL> default = PENDING ) <EOL> fail_reason = models . CharField ( max_length = <NUM_LIT> , null = True , <EOL> blank = True , db_index = True ) <EOL> raw = models . ForeignKey ( RawData , related_name = '<STR_LIT:+>' , null = True ) <EOL> usage = models . ForeignKey ( InstanceUsage , related_name = '<STR_LIT:+>' , null = True ) <EOL> delete = models . ForeignKey ( InstanceDeletes , related_name = '<STR_LIT:+>' , null = True ) <EOL> send_status = models . IntegerField ( null = True , default = <NUM_LIT:0> , db_index = True ) <EOL> tenant = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True , <EOL> db_index = True ) <EOL> os_architecture = models . TextField ( null = True , blank = True ) <EOL> os_distro = models . TextField ( null = True , blank = True ) <EOL> os_version = models . TextField ( null = True , blank = True ) <EOL> rax_options = models . TextField ( null = True , blank = True ) <EOL> bandwidth_public_out = models . BigIntegerField ( default = <NUM_LIT:0> ) <EOL> instance_flavor_id = models . CharField ( max_length = <NUM_LIT:100> , null = True , <EOL> blank = True , db_index = True ) <EOL> event_id = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True ) <EOL> def deployment ( self ) : <EOL> return self . raw . deployment <EOL> @ staticmethod <EOL> def find ( ending_max , status ) : <EOL> params = { '<STR_LIT>' : dt . dt_to_decimal ( ending_max ) , <EOL> '<STR_LIT:status>' : status } <EOL> return InstanceExists . objects . select_related ( ) . filter ( ** params ) . order_by ( '<STR_LIT:id>' ) <EOL> def mark_verified ( self , reconciled = False , reason = None ) : <EOL> if not reconciled : <EOL> self . status = InstanceExists . VERIFIED <EOL> else : <EOL> self . status = InstanceExists . RECONCILED <EOL> if reason is not None : <EOL> self . fail_reason = reason <EOL> self . save ( ) <EOL> def mark_failed ( self , reason = None ) : <EOL> if self . status == InstanceExists . SENT_VERIFYING : <EOL> self . status = InstanceExists . SENT_FAILED <EOL> else : <EOL> self . status = InstanceExists . FAILED <EOL> if reason : <EOL> self . fail_reason = reason <EOL> self . save ( ) <EOL> def update_status ( self , new_status ) : <EOL> self . status = new_status <EOL> def is_image_type_import ( self ) : <EOL> return ( self . raw . image_type & <NUM_LIT> ) == <NUM_LIT:3> <EOL> @ staticmethod <EOL> def mark_exists_as_sent_unverified ( message_ids ) : <EOL> absent_exists = [ ] <EOL> exists_not_pending = [ ] <EOL> for message_id in message_ids : <EOL> try : <EOL> exists = InstanceExists . objects . get ( message_id = message_id ) <EOL> if exists . status == InstanceExists . PENDING : <EOL> exists . status = InstanceExists . SENT_UNVERIFIED <EOL> exists . send_status = '<STR_LIT>' <EOL> exists . save ( ) <EOL> else : <EOL> exists_not_pending . append ( message_id ) <EOL> except Exception : <EOL> absent_exists . append ( message_id ) <EOL> return absent_exists , exists_not_pending <EOL> class Timing ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( max_length = <NUM_LIT:50> , db_index = True ) <EOL> lifecycle = models . ForeignKey ( Lifecycle ) <EOL> start_raw = models . ForeignKey ( RawData , related_name = '<STR_LIT:+>' , null = True ) <EOL> end_raw = models . ForeignKey ( RawData , related_name = '<STR_LIT:+>' , null = True ) <EOL> start_when = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> ) <EOL> end_when = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , decimal_places = <NUM_LIT:6> ) <EOL> diff = models . DecimalField ( null = True , max_digits = <NUM_LIT:20> , decimal_places = <NUM_LIT:6> , <EOL> db_index = True ) <EOL> class RequestTracker ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> request_id = models . CharField ( max_length = <NUM_LIT:50> , db_index = True ) <EOL> lifecycle = models . ForeignKey ( Lifecycle ) <EOL> last_timing = models . ForeignKey ( Timing , null = True , db_index = True ) <EOL> start = models . DecimalField ( max_digits = <NUM_LIT:20> , decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> duration = models . DecimalField ( max_digits = <NUM_LIT:20> , decimal_places = <NUM_LIT:6> , <EOL> db_index = True ) <EOL> completed = models . BooleanField ( default = False , db_index = True ) <EOL> class JsonReport ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> period_start = models . DateTimeField ( db_index = True ) <EOL> period_end = models . DateTimeField ( db_index = True ) <EOL> created = models . DecimalField ( max_digits = <NUM_LIT:20> , decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> name = models . CharField ( max_length = <NUM_LIT:50> , db_index = True ) <EOL> version = models . IntegerField ( default = <NUM_LIT:1> ) <EOL> json = models . TextField ( ) <EOL> class TenantType ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:50> , db_index = True ) <EOL> value = models . CharField ( max_length = <NUM_LIT:50> , db_index = True ) <EOL> class TenantInfo ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> tenant = models . CharField ( max_length = <NUM_LIT:50> , db_index = True , unique = True ) <EOL> name = models . CharField ( max_length = <NUM_LIT:100> , null = True , <EOL> blank = True , db_index = True ) <EOL> types = models . ManyToManyField ( TenantType ) <EOL> last_updated = models . DateTimeField ( db_index = True ) <EOL> class GlanceRawData ( models . Model ) : <EOL> result_titles = [ [ "<STR_LIT:#>" , "<STR_LIT:?>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] ] <EOL> ACTIVE = '<STR_LIT>' <EOL> DELETED = '<STR_LIT>' <EOL> KILLED = '<STR_LIT>' <EOL> PENDING_DELETE = '<STR_LIT>' <EOL> QUEUED = '<STR_LIT>' <EOL> SAVING = '<STR_LIT>' <EOL> STATUS_CHOICES = [ <EOL> ( ACTIVE , '<STR_LIT>' ) , <EOL> ( DELETED , '<STR_LIT>' ) , <EOL> ( KILLED , '<STR_LIT>' ) , <EOL> ( PENDING_DELETE , '<STR_LIT>' ) , <EOL> ( QUEUED , '<STR_LIT>' ) , <EOL> ( SAVING , '<STR_LIT>' ) , <EOL> ] <EOL> deployment = models . ForeignKey ( Deployment ) <EOL> owner = models . CharField ( max_length = <NUM_LIT:255> , null = True , blank = True , <EOL> db_index = True ) <EOL> json = models . TextField ( ) <EOL> routing_key = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True , <EOL> db_index = True ) <EOL> when = models . DecimalField ( max_digits = <NUM_LIT:20> , decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> publisher = models . CharField ( max_length = <NUM_LIT:100> , null = True , <EOL> blank = True , db_index = True ) <EOL> event = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True , <EOL> db_index = True ) <EOL> service = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True , <EOL> db_index = True ) <EOL> host = models . CharField ( max_length = <NUM_LIT:100> , null = True , blank = True , <EOL> db_index = True ) <EOL> instance = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True , <EOL> db_index = True ) <EOL> request_id = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True , <EOL> db_index = True ) <EOL> uuid = models . CharField ( max_length = <NUM_LIT> , null = True , blank = True , <EOL> db_index = True ) <EOL> status = models . CharField ( max_length = <NUM_LIT:30> , db_index = True , <EOL> choices = STATUS_CHOICES , null = True ) <EOL> image_type = models . IntegerField ( null = True , default = <NUM_LIT:0> , db_index = True ) <EOL> @ staticmethod <EOL> def get_name ( ) : <EOL> return GlanceRawData . __name__ <EOL> def search_results ( self , results , when , routing_key_status ) : <EOL> if not results : <EOL> results = copy . deepcopy ( self . result_titles ) <EOL> results . append ( [ self . id , routing_key_status , str ( when ) , <EOL> self . deployment . name , self . event , self . host , <EOL> self . status ] ) <EOL> return results <EOL> class ImageUsage ( models . Model ) : <EOL> uuid = models . CharField ( max_length = <NUM_LIT:50> , db_index = True ) <EOL> created_at = models . DecimalField ( max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> owner = models . CharField ( max_length = <NUM_LIT:50> , db_index = True , null = True ) <EOL> size = models . BigIntegerField ( max_length = <NUM_LIT:20> ) <EOL> last_raw = models . ForeignKey ( GlanceRawData , null = True ) <EOL> class ImageDeletes ( models . Model ) : <EOL> uuid = models . CharField ( max_length = <NUM_LIT:50> , db_index = True ) <EOL> deleted_at = models . DecimalField ( max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True , <EOL> null = True ) <EOL> raw = models . ForeignKey ( GlanceRawData , null = True ) <EOL> @ staticmethod <EOL> def find ( uuid , deleted_max = None ) : <EOL> params = { '<STR_LIT>' : uuid } <EOL> if deleted_max : <EOL> params [ '<STR_LIT>' ] = dt . dt_to_decimal ( deleted_max ) <EOL> return ImageDeletes . objects . filter ( ** params ) <EOL> class ImageExists ( models . Model ) : <EOL> PENDING = '<STR_LIT>' <EOL> VERIFYING = '<STR_LIT>' <EOL> VERIFIED = '<STR_LIT>' <EOL> FAILED = '<STR_LIT>' <EOL> SENT_UNVERIFIED = '<STR_LIT>' <EOL> SENT_FAILED = '<STR_LIT>' <EOL> SENT_VERIFYING = '<STR_LIT>' <EOL> STATUS_CHOICES = [ <EOL> ( PENDING , '<STR_LIT>' ) , <EOL> ( VERIFYING , '<STR_LIT>' ) , <EOL> ( VERIFIED , '<STR_LIT>' ) , <EOL> ( FAILED , '<STR_LIT>' ) , <EOL> ( SENT_UNVERIFIED , '<STR_LIT>' ) , <EOL> ( SENT_FAILED , '<STR_LIT>' ) , <EOL> ( SENT_VERIFYING , '<STR_LIT>' ) <EOL> ] <EOL> uuid = models . CharField ( max_length = <NUM_LIT:50> , db_index = True , null = True ) <EOL> created_at = models . DecimalField ( max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True , <EOL> null = True ) <EOL> deleted_at = models . DecimalField ( max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True , <EOL> null = True ) <EOL> audit_period_beginning = models . DecimalField ( max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , <EOL> db_index = True ) <EOL> audit_period_ending = models . DecimalField ( max_digits = <NUM_LIT:20> , <EOL> decimal_places = <NUM_LIT:6> , db_index = True ) <EOL> status = models . CharField ( max_length = <NUM_LIT:50> , db_index = True , <EOL> choices = STATUS_CHOICES , <EOL> default = PENDING ) <EOL> fail_reason = models . CharField ( max_length = <NUM_LIT> , null = True ) <EOL> raw = models . ForeignKey ( GlanceRawData , related_name = '<STR_LIT:+>' ) <EOL> usage = models . ForeignKey ( ImageUsage , related_name = '<STR_LIT:+>' , null = True ) <EOL> delete = models . ForeignKey ( ImageDeletes , related_name = '<STR_LIT:+>' , null = True ) <EOL> send_status = models . IntegerField ( default = <NUM_LIT:0> , db_index = True ) <EOL> owner = models . CharField ( max_length = <NUM_LIT:255> , db_index = True , null = True ) <EOL> size = models . BigIntegerField ( max_length = <NUM_LIT:20> ) <EOL> message_id = models . CharField ( max_length = <NUM_LIT:50> , null = True , <EOL> blank = True , db_index = True ) <EOL> event_id = models . CharField ( max_length = <NUM_LIT:50> , null = True , blank = True ) <EOL> def update_status ( self , new_status ) : <EOL> self . status = new_status <EOL> @ staticmethod <EOL> def find_and_group_by_owner_and_raw_id ( ending_max , status ) : <EOL> params = { '<STR_LIT>' : dt . dt_to_decimal ( ending_max ) , <EOL> '<STR_LIT:status>' : status } <EOL> ordered_exists = ImageExists . objects . select_related ( ) . filter ( ** params ) . order_by ( '<STR_LIT>' ) <EOL> result = { } <EOL> for exist in ordered_exists : <EOL> key = "<STR_LIT>" % ( exist . owner , exist . raw_id ) <EOL> if key in result : <EOL> result [ key ] . append ( exist ) <EOL> else : <EOL> result [ key ] = [ exist ] <EOL> return result <EOL> def mark_verified ( self ) : <EOL> self . status = InstanceExists . VERIFIED <EOL> self . save ( ) <EOL> def mark_failed ( self , reason = None ) : <EOL> if self . status == ImageExists . SENT_VERIFYING : <EOL> self . status = ImageExists . SENT_FAILED <EOL> else : <EOL> self . status = ImageExists . FAILED <EOL> if reason : <EOL> self . fail_reason = reason <EOL> self . save ( ) <EOL> @ staticmethod <EOL> def mark_exists_as_sent_unverified ( message_ids ) : <EOL> absent_exists = [ ] <EOL> exists_not_pending = [ ] <EOL> for message_id in message_ids : <EOL> exists_list = ImageExists . objects . filter ( message_id = message_id ) <EOL> if exists_list : <EOL> for exists in exists_list : <EOL> if exists . status == ImageExists . PENDING : <EOL> exists . status = ImageExists . SENT_UNVERIFIED <EOL> exists . send_status = '<STR_LIT>' <EOL> exists . save ( ) <EOL> else : <EOL> exists_not_pending . append ( message_id ) <EOL> else : <EOL> absent_exists . append ( message_id ) <EOL> return absent_exists , exists_not_pending <EOL> def get_model_fields ( model ) : <EOL> return model . _meta . fields </s>
