<s> from datetime import date , timedelta <EOL> import uuid <EOL> import phonenumbers <EOL> from django . conf import settings <EOL> from django . db import models <EOL> from django . core . validators import RegexValidator <EOL> from django . utils import timezone <EOL> from django . utils . translation import ugettext as _ <EOL> from . behaviors import TimeStampedModel <EOL> from . import helpers , managers <EOL> class Tag ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> color_regex = RegexValidator ( regex = r'<STR_LIT>' , message = "<STR_LIT>" ) <EOL> name = models . CharField ( max_length = <NUM_LIT:64> , unique = True , help_text = '<STR_LIT>' ) <EOL> color = models . CharField ( max_length = <NUM_LIT:6> , validators = [ color_regex ] , help_text = '<STR_LIT>' ) <EOL> description = models . CharField ( max_length = <NUM_LIT:64> , blank = True , help_text = '<STR_LIT>' ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT:name>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def save ( self , * args , ** kwargs ) : <EOL> self . color = self . color . lower ( ) <EOL> super ( Tag , self ) . save ( * args , ** kwargs ) <EOL> class Person ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> phone_regex = RegexValidator ( regex = r'<STR_LIT>' , message = "<STR_LIT>" ) <EOL> DEVELOPER_ROLE = '<STR_LIT>' <EOL> QUALITY_ASSURANCE_ROLE = '<STR_LIT>' <EOL> OPERATIONS_ROLE = '<STR_LIT>' <EOL> MANAGER_ROLE = '<STR_LIT>' <EOL> SECURITY_OFFICER_ROLE = '<STR_LIT>' <EOL> SECURITY_CHAMPION_ROLE = '<STR_LIT>' <EOL> ROLE_CHOICES = ( <EOL> ( DEVELOPER_ROLE , '<STR_LIT>' ) , <EOL> ( QUALITY_ASSURANCE_ROLE , '<STR_LIT>' ) , <EOL> ( OPERATIONS_ROLE , '<STR_LIT>' ) , <EOL> ( MANAGER_ROLE , '<STR_LIT>' ) , <EOL> ( SECURITY_OFFICER_ROLE , '<STR_LIT>' ) , <EOL> ( SECURITY_CHAMPION_ROLE , '<STR_LIT>' ) , <EOL> ) <EOL> first_name = models . CharField ( max_length = <NUM_LIT:64> ) <EOL> last_name = models . CharField ( max_length = <NUM_LIT:64> ) <EOL> email = models . EmailField ( max_length = <NUM_LIT> , unique = True ) <EOL> role = models . CharField ( max_length = <NUM_LIT> , choices = ROLE_CHOICES ) <EOL> phone_work = models . CharField ( max_length = <NUM_LIT:15> , validators = [ phone_regex ] , blank = True ) <EOL> phone_mobile = models . CharField ( max_length = <NUM_LIT:15> , validators = [ phone_regex ] , blank = True ) <EOL> job_title = models . CharField ( max_length = <NUM_LIT> , blank = True ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' ] <EOL> verbose_name_plural = '<STR_LIT>' <EOL> def __str__ ( self ) : <EOL> return self . first_name + '<STR_LIT:U+0020>' + self . last_name <EOL> def save ( self , * args , ** kwargs ) : <EOL> if self . phone_work : <EOL> self . phone_work = phonenumbers . format_number ( phonenumbers . parse ( self . phone_work , '<STR_LIT>' ) , phonenumbers . PhoneNumberFormat . E164 ) <EOL> if self . phone_mobile : <EOL> self . phone_mobile = phonenumbers . format_number ( phonenumbers . parse ( self . phone_mobile , '<STR_LIT>' ) , phonenumbers . PhoneNumberFormat . E164 ) <EOL> self . email = self . email . lower ( ) <EOL> super ( Person , self ) . save ( * args , ** kwargs ) <EOL> class Organization ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( max_length = <NUM_LIT:32> , unique = True , help_text = '<STR_LIT>' ) <EOL> description = models . TextField ( blank = True , help_text = '<STR_LIT>' ) <EOL> people = models . ManyToManyField ( Person , blank = True ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT:name>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> class DataElement ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> GLOBAL_CATEGORY = '<STR_LIT>' <EOL> PERSONAL_CATEGORY = '<STR_LIT>' <EOL> COMPANY_CATEGORY = '<STR_LIT>' <EOL> STUDENT_CATEGORY = '<STR_LIT>' <EOL> GOVERNMENT_CATEGORY = '<STR_LIT>' <EOL> PCI_CATEGORY = '<STR_LIT>' <EOL> MEDICAL_CATEGORY = '<STR_LIT>' <EOL> CATEGORY_CHOICES = ( <EOL> ( GLOBAL_CATEGORY , '<STR_LIT>' ) , <EOL> ( PERSONAL_CATEGORY , '<STR_LIT>' ) , <EOL> ( COMPANY_CATEGORY , '<STR_LIT>' ) , <EOL> ( STUDENT_CATEGORY , '<STR_LIT>' ) , <EOL> ( GOVERNMENT_CATEGORY , '<STR_LIT>' ) , <EOL> ( PCI_CATEGORY , '<STR_LIT>' ) , <EOL> ( MEDICAL_CATEGORY , '<STR_LIT>' ) , <EOL> ) <EOL> name = models . CharField ( max_length = <NUM_LIT> , unique = True ) <EOL> description = models . TextField ( blank = True ) <EOL> category = models . CharField ( max_length = <NUM_LIT:10> , choices = CATEGORY_CHOICES ) <EOL> weight = models . PositiveIntegerField ( ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT:id>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> class Technology ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> PROGRAMMING_LANGUAGE_CATEGORY = '<STR_LIT>' <EOL> OPERATING_SYSTEM_CATEGORY = '<STR_LIT>' <EOL> DATA_STORE_CATEGORY = '<STR_LIT>' <EOL> FRAMEWORK_CATEGORY = '<STR_LIT>' <EOL> THIRD_PARTY_COMPONENT = '<STR_LIT>' <EOL> WEB_SERVER_CATEGORY = '<STR_LIT>' <EOL> APPLICATION_SERVER_CATEGORY = '<STR_LIT>' <EOL> HOSTING_PROVIDER_CATEGORY = '<STR_LIT>' <EOL> DENIAL_OF_SERVICE_CATEGORY = '<STR_LIT>' <EOL> FIREWALL_CATEGORY = '<STR_LIT>' <EOL> CATEGORY_CHOICES = ( <EOL> ( PROGRAMMING_LANGUAGE_CATEGORY , '<STR_LIT>' ) , <EOL> ( OPERATING_SYSTEM_CATEGORY , '<STR_LIT>' ) , <EOL> ( DATA_STORE_CATEGORY , '<STR_LIT>' ) , <EOL> ( FRAMEWORK_CATEGORY , '<STR_LIT>' ) , <EOL> ( THIRD_PARTY_COMPONENT , '<STR_LIT>' ) , <EOL> ( APPLICATION_SERVER_CATEGORY , '<STR_LIT>' ) , <EOL> ( WEB_SERVER_CATEGORY , '<STR_LIT>' ) , <EOL> ( HOSTING_PROVIDER_CATEGORY , '<STR_LIT>' ) , <EOL> ( DENIAL_OF_SERVICE_CATEGORY , '<STR_LIT>' ) , <EOL> ( FIREWALL_CATEGORY , '<STR_LIT>' ) , <EOL> ) <EOL> name = models . CharField ( max_length = <NUM_LIT:64> , help_text = '<STR_LIT>' ) <EOL> category = models . CharField ( max_length = <NUM_LIT> , choices = CATEGORY_CHOICES , help_text = '<STR_LIT>' ) <EOL> description = models . CharField ( max_length = <NUM_LIT> , blank = True , help_text = '<STR_LIT>' ) <EOL> reference = models . URLField ( blank = True , help_text = '<STR_LIT>' ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' , '<STR_LIT:name>' ] <EOL> verbose_name_plural = '<STR_LIT>' <EOL> def __str__ ( self ) : <EOL> return self . get_category_display ( ) + '<STR_LIT>' + self . name <EOL> class Regulation ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> PRIVACY_CATEGORY = '<STR_LIT>' <EOL> FINANCE_CATEGORY = '<STR_LIT>' <EOL> EDUCATION_CATEGORY = '<STR_LIT>' <EOL> MEDICAL_CATEGORY = '<STR_LIT>' <EOL> OTHER_CATEGORY = '<STR_LIT>' <EOL> CATEGORY_CHOICES = ( <EOL> ( PRIVACY_CATEGORY , '<STR_LIT>' ) , <EOL> ( FINANCE_CATEGORY , '<STR_LIT>' ) , <EOL> ( EDUCATION_CATEGORY , '<STR_LIT>' ) , <EOL> ( MEDICAL_CATEGORY , '<STR_LIT>' ) , <EOL> ( OTHER_CATEGORY , '<STR_LIT>' ) , <EOL> ) <EOL> name = models . CharField ( max_length = <NUM_LIT> , help_text = '<STR_LIT>' ) <EOL> acronym = models . CharField ( max_length = <NUM_LIT:20> , unique = True , help_text = '<STR_LIT>' ) <EOL> category = models . CharField ( max_length = <NUM_LIT:9> , choices = CATEGORY_CHOICES , help_text = '<STR_LIT>' ) <EOL> jurisdiction = models . CharField ( max_length = <NUM_LIT:64> , help_text = '<STR_LIT>' ) <EOL> description = models . TextField ( blank = True , help_text = '<STR_LIT>' ) <EOL> reference = models . URLField ( blank = True , help_text = '<STR_LIT>' ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' ] <EOL> def __str__ ( self ) : <EOL> return self . acronym + '<STR_LIT>' + self . jurisdiction + '<STR_LIT:)>' <EOL> class ServiceLevelAgreement ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( max_length = <NUM_LIT:64> , help_text = '<STR_LIT>' ) <EOL> description = models . CharField ( max_length = <NUM_LIT> , blank = True , help_text = '<STR_LIT>' ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT:name>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> class ThreadFix ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( max_length = <NUM_LIT:32> , unique = True , help_text = '<STR_LIT>' ) <EOL> host = models . URLField ( help_text = '<STR_LIT>' ) <EOL> api_key = models . CharField ( max_length = <NUM_LIT:50> , help_text = '<STR_LIT>' ) <EOL> verify_ssl = models . BooleanField ( default = True , help_text = '<STR_LIT>' ) <EOL> class Meta : <EOL> verbose_name = '<STR_LIT>' <EOL> verbose_name_plural = '<STR_LIT>' <EOL> def __str__ ( self ) : <EOL> return self . name + '<STR_LIT>' + self . host <EOL> class Application ( TimeStampedModel , models . Model ) : <EOL> """<STR_LIT>""" <EOL> WEB_PLATFORM = '<STR_LIT>' <EOL> DESKTOP_PLATFORM = '<STR_LIT>' <EOL> MOBILE_PLATFORM = '<STR_LIT>' <EOL> WEB_SERVICE_PLATFORM = '<STR_LIT>' <EOL> PLATFORM_CHOICES = ( <EOL> ( WEB_PLATFORM , '<STR_LIT>' ) , <EOL> ( DESKTOP_PLATFORM , '<STR_LIT>' ) , <EOL> ( MOBILE_PLATFORM , '<STR_LIT>' ) , <EOL> ( WEB_SERVICE_PLATFORM , '<STR_LIT>' ) , <EOL> ) <EOL> IDEA_LIFECYCLE = '<STR_LIT>' <EOL> EXPLORE_LIFECYCLE = '<STR_LIT>' <EOL> VALIDATE_LIFECYCLE = '<STR_LIT>' <EOL> GROW_LIFECYCLE = '<STR_LIT>' <EOL> SUSTAIN_LIFECYCLE = '<STR_LIT>' <EOL> RETIRE_LIFECYCLE = '<STR_LIT>' <EOL> LIFECYCLE_CHOICES = ( <EOL> ( IDEA_LIFECYCLE , '<STR_LIT>' ) , <EOL> ( EXPLORE_LIFECYCLE , '<STR_LIT>' ) , <EOL> ( VALIDATE_LIFECYCLE , '<STR_LIT>' ) , <EOL> ( GROW_LIFECYCLE , '<STR_LIT>' ) , <EOL> ( SUSTAIN_LIFECYCLE , '<STR_LIT>' ) , <EOL> ( RETIRE_LIFECYCLE , '<STR_LIT>' ) , <EOL> ) <EOL> THIRD_PARTY_LIBRARY_ORIGIN = '<STR_LIT>' <EOL> PURCHASED_ORIGIN = '<STR_LIT>' <EOL> CONTRACTOR_ORIGIN = '<STR_LIT>' <EOL> INTERNALLY_DEVELOPED_ORIGIN = '<STR_LIT>' <EOL> OPEN_SOURCE_ORIGIN = '<STR_LIT>' <EOL> OUTSOURCED_ORIGIN = '<STR_LIT>' <EOL> ORIGIN_CHOICES = ( <EOL> ( THIRD_PARTY_LIBRARY_ORIGIN , '<STR_LIT>' ) , <EOL> ( PURCHASED_ORIGIN , '<STR_LIT>' ) , <EOL> ( CONTRACTOR_ORIGIN , '<STR_LIT>' ) , <EOL> ( INTERNALLY_DEVELOPED_ORIGIN , '<STR_LIT>' ) , <EOL> ( OPEN_SOURCE_ORIGIN , '<STR_LIT>' ) , <EOL> ( OUTSOURCED_ORIGIN , '<STR_LIT>' ) , <EOL> ) <EOL> VERY_HIGH_CRITICALITY = '<STR_LIT>' <EOL> HIGH_CRITICALITY = '<STR_LIT>' <EOL> MEDIUM_CRITICALITY = '<STR_LIT>' <EOL> LOW_CRITICALITY = '<STR_LIT>' <EOL> VERY_LOW_CRITICALITY = '<STR_LIT>' <EOL> NONE_CRITICALITY = '<STR_LIT:none>' <EOL> BUSINESS_CRITICALITY_CHOICES = ( <EOL> ( VERY_HIGH_CRITICALITY , '<STR_LIT>' ) , <EOL> ( HIGH_CRITICALITY , '<STR_LIT>' ) , <EOL> ( MEDIUM_CRITICALITY , '<STR_LIT>' ) , <EOL> ( LOW_CRITICALITY , '<STR_LIT>' ) , <EOL> ( VERY_LOW_CRITICALITY , '<STR_LIT>' ) , <EOL> ( NONE_CRITICALITY , '<STR_LIT:None>' ) , <EOL> ) <EOL> DCL_1 = <NUM_LIT:1> <EOL> DCL_2 = <NUM_LIT:2> <EOL> DCL_3 = <NUM_LIT:3> <EOL> DCL_4 = <NUM_LIT:4> <EOL> DATA_CLASSIFICATION_CHOICES = ( <EOL> ( None , '<STR_LIT>' ) , <EOL> ( DCL_1 , '<STR_LIT>' ) , <EOL> ( DCL_2 , '<STR_LIT>' ) , <EOL> ( DCL_3 , '<STR_LIT>' ) , <EOL> ( DCL_4 , '<STR_LIT>' ) , <EOL> ) <EOL> ASVS_0 = <NUM_LIT:0> <EOL> ASVS_1 = <NUM_LIT:1> <EOL> ASVS_2 = <NUM_LIT:2> <EOL> ASVS_3 = <NUM_LIT:3> <EOL> ASVS_CHOICES = ( <EOL> ( None , '<STR_LIT>' ) , <EOL> ( ASVS_0 , '<STR_LIT:0>' ) , <EOL> ( ASVS_1 , '<STR_LIT:1>' ) , <EOL> ( ASVS_2 , '<STR_LIT:2>' ) , <EOL> ( ASVS_3 , '<STR_LIT:3>' ) , <EOL> ) <EOL> name = models . CharField ( max_length = <NUM_LIT> , unique = True , help_text = '<STR_LIT>' ) <EOL> description = models . TextField ( blank = True , help_text = '<STR_LIT>' ) <EOL> business_criticality = models . CharField ( max_length = <NUM_LIT:9> , choices = BUSINESS_CRITICALITY_CHOICES , blank = True , null = True ) <EOL> platform = models . CharField ( max_length = <NUM_LIT:11> , choices = PLATFORM_CHOICES , blank = True , null = True ) <EOL> lifecycle = models . CharField ( max_length = <NUM_LIT:8> , choices = LIFECYCLE_CHOICES , blank = True , null = True ) <EOL> origin = models . CharField ( max_length = <NUM_LIT> , choices = ORIGIN_CHOICES , blank = True , null = True ) <EOL> user_records = models . PositiveIntegerField ( blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> revenue = models . DecimalField ( max_digits = <NUM_LIT:15> , decimal_places = <NUM_LIT:2> , blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> external_audience = models . BooleanField ( default = False , help_text = '<STR_LIT>' ) <EOL> internet_accessible = models . BooleanField ( default = False , help_text = '<STR_LIT>' ) <EOL> requestable = models . NullBooleanField ( default = True , help_text = _ ( '<STR_LIT>' ) ) <EOL> technologies = models . ManyToManyField ( Technology , blank = True ) <EOL> regulations = models . ManyToManyField ( Regulation , blank = True ) <EOL> service_level_agreements = models . ManyToManyField ( ServiceLevelAgreement , blank = True ) <EOL> data_elements = models . ManyToManyField ( DataElement , blank = True ) <EOL> override_dcl = models . IntegerField ( choices = DATA_CLASSIFICATION_CHOICES , blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> override_reason = models . TextField ( blank = True , help_text = '<STR_LIT>' ) <EOL> threadfix = models . ForeignKey ( ThreadFix , blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> threadfix_team_id = models . PositiveIntegerField ( blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> threadfix_application_id = models . PositiveIntegerField ( blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> asvs_level = models . IntegerField ( choices = ASVS_CHOICES , blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> asvs_level_percent_achieved = models . PositiveIntegerField ( blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> asvs_doc_url = models . URLField ( blank = True , help_text = '<STR_LIT>' ) <EOL> asvs_level_target = models . IntegerField ( choices = ASVS_CHOICES , blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> organization = models . ForeignKey ( Organization , help_text = '<STR_LIT>' ) <EOL> people = models . ManyToManyField ( Person , through = '<STR_LIT>' , blank = True ) <EOL> tags = models . ManyToManyField ( Tag , blank = True ) <EOL> objects = managers . ApplicationManager . from_queryset ( managers . ApplicationQuerySet ) ( ) <EOL> class Meta : <EOL> get_latest_by = '<STR_LIT>' <EOL> ordering = [ '<STR_LIT:name>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def data_classification_level ( self ) : <EOL> """<STR_LIT>""" <EOL> return helpers . data_classification_level ( self . data_sensitivity_value ( ) ) <EOL> def data_sensitivity_value ( self ) : <EOL> """<STR_LIT>""" <EOL> return helpers . data_sensitivity_value ( self . data_elements . all ( ) ) <EOL> def is_new ( self ) : <EOL> """<STR_LIT>""" <EOL> delta = self . created_date - timezone . now ( ) <EOL> return delta >= timedelta ( days = - <NUM_LIT:7> ) <EOL> class ThreadFixMetrics ( TimeStampedModel , models . Model ) : <EOL> """<STR_LIT>""" <EOL> critical_count = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> high_count = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> medium_count = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> low_count = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> informational_count = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> application = models . ForeignKey ( Application ) <EOL> class Meta : <EOL> get_latest_by = '<STR_LIT>' <EOL> verbose_name = '<STR_LIT>' <EOL> verbose_name_plural = '<STR_LIT>' <EOL> def total ( self ) : <EOL> return self . critical_count + self . high_count + self . medium_count + self . low_count + self . informational_count <EOL> class Relation ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> owner = models . BooleanField ( default = False , help_text = '<STR_LIT>' ) <EOL> emergency = models . BooleanField ( default = False , help_text = '<STR_LIT>' ) <EOL> notes = models . TextField ( blank = True , help_text = '<STR_LIT>' ) <EOL> person = models . ForeignKey ( Person , help_text = '<STR_LIT>' ) <EOL> application = models . ForeignKey ( Application ) <EOL> class Meta : <EOL> unique_together = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __str__ ( self ) : <EOL> return self . person . first_name + '<STR_LIT:U+0020>' + self . person . last_name + '<STR_LIT>' + self . application . name <EOL> class Environment ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> DEVELOPMENT_ENVIRONMENT = '<STR_LIT>' <EOL> INTEGRATION_ENVIRONMENT = '<STR_LIT:int>' <EOL> QUALITY_ASSURANCE_ENVIRONMENT = '<STR_LIT>' <EOL> PRE_PRODUCTION_ENVIRONMENT = '<STR_LIT>' <EOL> CUSTOMER_ACCEPTANCE_ENVIRONMENT = '<STR_LIT>' <EOL> PRODUCTION_ENVIRONMENT = '<STR_LIT>' <EOL> ENVIRONMENT_CHOICES = ( <EOL> ( DEVELOPMENT_ENVIRONMENT , '<STR_LIT>' ) , <EOL> ( INTEGRATION_ENVIRONMENT , '<STR_LIT>' ) , <EOL> ( QUALITY_ASSURANCE_ENVIRONMENT , '<STR_LIT>' ) , <EOL> ( PRE_PRODUCTION_ENVIRONMENT , '<STR_LIT>' ) , <EOL> ( CUSTOMER_ACCEPTANCE_ENVIRONMENT , '<STR_LIT>' ) , <EOL> ( PRODUCTION_ENVIRONMENT , '<STR_LIT>' ) , <EOL> ) <EOL> environment_type = models . CharField ( max_length = <NUM_LIT:4> , choices = ENVIRONMENT_CHOICES , help_text = '<STR_LIT>' ) <EOL> description = models . TextField ( blank = True , help_text = '<STR_LIT>' ) <EOL> testing_approved = models . BooleanField ( default = False , help_text = '<STR_LIT>' ) <EOL> application = models . ForeignKey ( Application ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __str__ ( self ) : <EOL> return self . application . name + '<STR_LIT>' + dict ( Environment . ENVIRONMENT_CHOICES ) [ self . environment_type ] + '<STR_LIT:)>' <EOL> class EnvironmentLocation ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> location = models . URLField ( help_text = '<STR_LIT>' ) <EOL> notes = models . TextField ( blank = True , help_text = '<STR_LIT>' ) <EOL> environment = models . ForeignKey ( Environment ) <EOL> def __str__ ( self ) : <EOL> return self . location <EOL> class EnvironmentCredentials ( TimeStampedModel , models . Model ) : <EOL> """<STR_LIT>""" <EOL> username = models . CharField ( max_length = <NUM_LIT> , blank = True ) <EOL> password = models . CharField ( max_length = <NUM_LIT> , blank = True ) <EOL> role_description = models . CharField ( max_length = <NUM_LIT> , blank = True , help_text = '<STR_LIT>' ) <EOL> notes = models . TextField ( blank = True , help_text = '<STR_LIT>' ) <EOL> environment = models . ForeignKey ( Environment ) <EOL> class Meta : <EOL> verbose_name_plural = '<STR_LIT>' <EOL> ordering = [ '<STR_LIT:username>' , '<STR_LIT:password>' ] <EOL> class Engagement ( TimeStampedModel , models . Model ) : <EOL> """<STR_LIT>""" <EOL> PENDING_STATUS = '<STR_LIT>' <EOL> OPEN_STATUS = '<STR_LIT>' <EOL> CLOSED_STATUS = '<STR_LIT>' <EOL> STATUS_CHOICES = ( <EOL> ( PENDING_STATUS , '<STR_LIT>' ) , <EOL> ( OPEN_STATUS , '<STR_LIT>' ) , <EOL> ( CLOSED_STATUS , '<STR_LIT>' ) <EOL> ) <EOL> status = models . CharField ( max_length = <NUM_LIT:7> , choices = STATUS_CHOICES , default = PENDING_STATUS ) <EOL> start_date = models . DateField ( help_text = '<STR_LIT>' ) <EOL> end_date = models . DateField ( help_text = '<STR_LIT>' ) <EOL> description = models . TextField ( blank = True ) <EOL> open_date = models . DateTimeField ( blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> close_date = models . DateTimeField ( blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> duration = models . DurationField ( blank = True , null = True ) <EOL> requestor = models . ForeignKey ( Person , blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> application = models . ForeignKey ( Application ) <EOL> objects = managers . EngagementManager . from_queryset ( managers . EngagementQuerySet ) ( ) <EOL> metrics = managers . EngagementMetrics . from_queryset ( managers . EngagementQuerySet ) ( ) <EOL> class Meta : <EOL> get_latest_by = '<STR_LIT>' <EOL> ordering = [ '<STR_LIT>' ] <EOL> def save ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . pk is not None : <EOL> engagement = Engagement . objects . get ( pk = self . pk ) <EOL> now = timezone . now ( ) <EOL> if engagement . status != self . status : <EOL> if self . status == Engagement . PENDING_STATUS : <EOL> self . open_date = None <EOL> self . close_date = None <EOL> elif self . status == Engagement . OPEN_STATUS : <EOL> self . open_date = now <EOL> self . close_date = None <EOL> elif self . status == Engagement . CLOSED_STATUS : <EOL> if self . open_date is None : <EOL> self . open_date = now <EOL> self . close_date = now <EOL> if self . open_date is not None and self . close_date is not None : <EOL> self . duration = self . close_date - self . open_date <EOL> super ( Engagement , self ) . save ( * args , ** kwargs ) <EOL> def is_pending ( self ) : <EOL> return self . status == Engagement . PENDING_STATUS <EOL> def is_open ( self ) : <EOL> return self . status == Engagement . OPEN_STATUS <EOL> def is_closed ( self ) : <EOL> return self . status == Engagement . CLOSED_STATUS <EOL> def is_ready_for_work ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . status == Engagement . PENDING_STATUS : <EOL> if date . today ( ) >= self . start_date : <EOL> return True <EOL> return False <EOL> def is_past_due ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . status == Engagement . PENDING_STATUS or self . status == Engagement . OPEN_STATUS : <EOL> if date . today ( ) > self . end_date : <EOL> return True <EOL> return False <EOL> class ActivityType ( TimeStampedModel , models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( max_length = <NUM_LIT> , unique = True , help_text = _ ( '<STR_LIT>' ) ) <EOL> documentation = models . TextField ( blank = True , help_text = _ ( '<STR_LIT>' ) ) <EOL> objects = managers . ActivityTypeManager . from_queryset ( managers . ActivityTypeQuerySet ) ( ) <EOL> metrics = managers . ActivityTypeMetrics . from_queryset ( managers . ActivityTypeQuerySet ) ( ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT:name>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> class Activity ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> PENDING_STATUS = '<STR_LIT>' <EOL> OPEN_STATUS = '<STR_LIT>' <EOL> CLOSED_STATUS = '<STR_LIT>' <EOL> STATUS_CHOICES = ( <EOL> ( PENDING_STATUS , '<STR_LIT>' ) , <EOL> ( OPEN_STATUS , '<STR_LIT>' ) , <EOL> ( CLOSED_STATUS , '<STR_LIT>' ) <EOL> ) <EOL> status = models . CharField ( max_length = <NUM_LIT:7> , choices = STATUS_CHOICES , default = PENDING_STATUS ) <EOL> description = models . TextField ( blank = True ) <EOL> open_date = models . DateTimeField ( blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> close_date = models . DateTimeField ( blank = True , null = True , help_text = '<STR_LIT>' ) <EOL> duration = models . DurationField ( blank = True , null = True ) <EOL> activity_type = models . ForeignKey ( ActivityType ) <EOL> engagement = models . ForeignKey ( Engagement ) <EOL> users = models . ManyToManyField ( settings . AUTH_USER_MODEL , blank = True ) <EOL> objects = managers . ActivityManager . from_queryset ( managers . ActivityQuerySet ) ( ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' ] <EOL> verbose_name_plural = '<STR_LIT>' <EOL> def __str__ ( self ) : <EOL> return self . activity_type . name <EOL> def save ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . pk is not None : <EOL> activity = Activity . objects . get ( pk = self . pk ) <EOL> if activity . status != self . status : <EOL> now = timezone . now ( ) <EOL> if self . status == Activity . PENDING_STATUS : <EOL> self . open_date = None <EOL> self . close_date = None <EOL> elif self . status == Activity . OPEN_STATUS : <EOL> self . open_date = now <EOL> self . close_date = None <EOL> if self . engagement . status is not Engagement . OPEN_STATUS : <EOL> self . engagement . status = Engagement . OPEN_STATUS <EOL> self . engagement . save ( ) <EOL> elif self . status == Activity . CLOSED_STATUS : <EOL> if self . open_date is None : <EOL> self . open_date = now <EOL> self . close_date = now <EOL> close = True <EOL> for current_activity in self . engagement . activity_set . exclude ( id = self . id ) : <EOL> if current_activity . status != Activity . CLOSED_STATUS : <EOL> close = False <EOL> break <EOL> if close : <EOL> self . engagement . status = Engagement . CLOSED_STATUS <EOL> self . engagement . save ( ) <EOL> if self . open_date is not None and self . close_date is not None : <EOL> self . duration = self . close_date - self . open_date <EOL> super ( Activity , self ) . save ( * args , ** kwargs ) <EOL> def is_pending ( self ) : <EOL> return self . status == Activity . PENDING_STATUS <EOL> def is_open ( self ) : <EOL> return self . status == Activity . OPEN_STATUS <EOL> def is_closed ( self ) : <EOL> return self . status == Activity . CLOSED_STATUS <EOL> def is_ready_for_work ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . status == Activity . PENDING_STATUS : <EOL> if date . today ( ) >= self . engagement . start_date : <EOL> return True <EOL> return False <EOL> def is_past_due ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . status == Activity . PENDING_STATUS or self . status == Activity . OPEN_STATUS : <EOL> if date . today ( ) > self . engagement . end_date : <EOL> return True <EOL> return False <EOL> class Comment ( TimeStampedModel , models . Model ) : <EOL> """<STR_LIT>""" <EOL> message = models . TextField ( ) <EOL> user = models . ForeignKey ( settings . AUTH_USER_MODEL ) <EOL> def __str__ ( self ) : <EOL> return self . message <EOL> class Meta : <EOL> abstract = True <EOL> class EngagementComment ( Comment ) : <EOL> """<STR_LIT>""" <EOL> engagement = models . ForeignKey ( Engagement ) <EOL> class ActivityComment ( Comment ) : <EOL> """<STR_LIT>""" <EOL> activity = models . ForeignKey ( Activity ) <EOL> class ExternalRequest ( TimeStampedModel , models . Model ) : <EOL> """<STR_LIT>""" <EOL> token = models . UUIDField ( default = uuid . uuid4 , editable = False ) <EOL> requestor = models . ForeignKey ( Person ) <EOL> application = models . ForeignKey ( Application , blank = True ) <EOL> activities = models . ManyToManyField ( ActivityType , limit_choices_to = { '<STR_LIT>' : True } ) <EOL> class FileUpload ( TimeStampedModel , models . Model ) : <EOL> """<STR_LIT>""" <EOL> file = models . FileField ( ) <EOL> user = models . ForeignKey ( settings . AUTH_USER_MODEL ) <EOL> class Meta : <EOL> abstract = True <EOL> class ApplicationFileUpload ( FileUpload ) : <EOL> """<STR_LIT>""" <EOL> REPORT_FILE_TYPE = '<STR_LIT>' <EOL> DOCUMENTATION_FILE_TYPE = '<STR_LIT>' <EOL> FILE_TYPE_CHOICES = ( <EOL> ( REPORT_FILE_TYPE , '<STR_LIT>' ) , <EOL> ( DOCUMENTATION_FILE_TYPE , '<STR_LIT>' ) , <EOL> ) <EOL> file_type = models . CharField ( max_length = <NUM_LIT> , choices = FILE_TYPE_CHOICES ) <EOL> application = models . ForeignKey ( Application ) </s>
