class NYC311Statistics(models.Model): zipcode = us_models.USZipCodeField(db_index=True) complaint_type = models.CharField(max_length=255) complaint_level = models.IntegerField() total_complaints_query_zip = models.IntegerField() closed_complaints_query_zip = models.IntegerField() percentage_complaints_closed = models.FloatField() max_complaints = models.IntegerField() max_complaints_zip = us_models.USZipCodeField() last_updated = models.DateTimeField(auto_now=True) @classmethod def from_statistics(cls, zipcode, stat): return cls( zipcode=zipcode, complaint_type=stat.complaint_type, complaint_level=stat.complaint_level, total_complaints_query_zip=stat.total_complaints_query_zip, closed_complaints_query_zip=stat.closed_complaints_query_zip, percentage_complaints_closed=stat.percentage_complaints_closed, max_complaints=stat.max_complaints, max_complaints_zip=stat.max_complaints_zip, )
class RegistrationForm(BaseModel): user = models.OneToOneField(User, models.CASCADE) address = models.CharField(max_length=300) address_2 = models.CharField(max_length=300, blank=True) city = models.CharField(max_length=100) state = us_model.USStateField() zip_code = us_model.USZipCodeField() phone_1 = PhoneNumberField() phone_2 = PhoneNumberField(blank=True) date_of_birth = models.DateField() gender = models.CharField(max_length=1, choices=GENDER_CHOICES) pronouns = models.CharField(max_length=30, blank=True) emergency_contact_name = models.CharField(max_length=200) emergency_contact_relationship_to_you = models.CharField(max_length=200) emergency_contact_phone_number = PhoneNumberField() physical_fitness = models.TextField() medical_condition_description = models.TextField(blank=True) allergy_condition_description = models.TextField(blank=True) medications_descriptions = models.TextField(blank=True) medical_insurance = models.BooleanField() name_of_policy_holder = models.CharField(max_length=200) relation_of_policy_holder = models.CharField(max_length=100) signature = models.CharField(max_length=3) todays_date = models.DateField() def __str__(self): return f"{self.user.first_name} {self.user.last_name} " f"registration form"
class AttorneyOrganization(models.Model): date_created = models.DateTimeField( help_text="The time when this item was created", auto_now_add=True, db_index=True, ) date_modified = models.DateTimeField( help_text="The last moment when the item was modified.", auto_now=True, db_index=True, ) lookup_key = models.TextField( help_text="A trimmed version of the address for duplicate matching.", db_index=True, unique=True, ) name = models.TextField( help_text="The name of the organization.", db_index=True, ) address1 = models.TextField( help_text="The normalized address1 of the organization", db_index=True, ) address2 = models.TextField( help_text="The normalized address2 of the organization", db_index=True, ) city = models.TextField( help_text="The normalized city of the organization", db_index=True, ) state = local_models.USPostalCodeField( help_text="The two-letter USPS postal abbreviation for the " "organization", db_index=True, ) zip_code = local_models.USZipCodeField( help_text="The zip code for the organization, XXXXX or XXXXX-XXXX " "work.", db_index=True, ) class Meta: unique_together = ('name', 'address1', 'address2', 'city', 'state', 'zip_code') def __unicode__(self): return "%s: %s, %s, %s, %s, %s, %s" % ( self.pk, self.name, self.address1, self.address2, self.city, self.state, self.zip_code, )
class Location(models.Model): city = models.CharField(max_length=100) # locality is for certain places (such as queens) where the google # locality and neighborhood are different locality = models.CharField(max_length=100, default="") state = us_models.USStateField() address = models.CharField(max_length=255) zipcode = us_models.USZipCodeField() latitude = models.DecimalField( max_digits=9, decimal_places=6, blank=True, null=True ) longitude = models.DecimalField( max_digits=9, decimal_places=6, blank=True, null=True ) last_fetched_zillow = models.DateTimeField(blank=True, null=True) @property def full_address(self): addr_components = map(str, [self.address, self.city, self.state, self.zipcode]) return ", ".join(addr_components) @property def url_encoded_full_address(self): return quote(self.full_address) @property def google_map_url(self): return f"https://www.google.com/maps/search/?api=1&query={self.url_encoded_full_address}" def avg_rate(self): review_sum = 0 for review in self.review_set.all(): review_sum += review.rating if self.review_set.count() != 0: avg = review_sum / self.review_set.count() return float("%.2f" % round(avg, 2)) else: return 0 def check_tenant(self, user): return self.apartment_set.filter(tenant=user).exists() def check_landlord(self, user): return self.apartment_set.filter(landlord=user).exists()
class Contact(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, null=True) firstName = models.CharField(max_length=30, default='') lastName = models.CharField(max_length=30, default='') phone = usmodels.PhoneNumberField(default='') email = models.EmailField(default='') street = models.CharField(max_length=255, default='') city = models.CharField(max_length=90, default='Fairview') state = usmodels.USStateField(default='TX') zipCode = usmodels.USZipCodeField(default='75069') ''' This model will then not be used to create any database table. Instead, when it is used as a base class for other models, its fields will be added to those of the child class. ''' class Meta: abstract = True def __unicode__(self): return '%s, %s' % (self.lastName, self.firstName)
class Location(models.Model): city = models.CharField(max_length=100) # locality is for certain places (such as queens) where the google # locality and neighborhood are different locality = models.CharField(max_length=100, default="") state = us_models.USStateField() address = models.CharField(max_length=255) zipcode = us_models.USZipCodeField() latitude = models.DecimalField( max_digits=9, decimal_places=6, blank=True, null=True ) longitude = models.DecimalField( max_digits=9, decimal_places=6, blank=True, null=True ) last_fetched_zillow = models.DateTimeField(blank=True, null=True) @property def full_address(self): addr_components = map(str, [self.address, self.city, self.state, self.zipcode]) return ", ".join(addr_components) @property def url_encoded_full_address(self): return quote(self.full_address) @property def google_map_url(self): return f"https://www.google.com/maps/search/?api=1&query={self.url_encoded_full_address}" @property def representative_image(self): return self.apartment_set.exclude(image=None).first().picture_url @property def representative_image_or_placeholder(self): image = self.representative_image return image if image is not None else "/static/img/no_img.png" @property def rent_price_for_display(self): count = self.apartment_set.count() if count == 0: return None elif count == 1: return self.apartment_set.first().rent_price_for_display else: minimum = f"{self.apartment_set.order_by('rent_price')[0].rent_price:.0f}" maximum = f"{self.apartment_set.order_by('-rent_price')[0].rent_price:.0f}" return f"${minimum} - {maximum}" def avg_rate(self): review_sum = 0 for review in self.review_set.all(): review_sum += review.rating if self.review_set.count() != 0: avg = review_sum / self.review_set.count() return float("%.2f" % round(avg, 2)) else: return 0 def check_tenant(self, user): return self.apartment_set.filter(tenant=user).exists() def check_landlord(self, user): return self.apartment_set.filter(landlord=user).exists()
class Account(AbstractBaseUser): """Returns a new Account object inherited from AbstractBaseUser. AbstractBaseUser: The parent class of users Note: email, businessname, zipcode, city, state, phone are required """ email = models.EmailField(max_length=255, unique=True) businessname = models.CharField(max_length=35, blank=False, default='buname') spaceId = models.CharField(max_length=10, unique=True, blank=True, null=True) zipcode = usmodels.USZipCodeField(blank=False, default='00000') city = models.CharField(max_length=50, blank=False, default='--------') state = usmodels.USStateField(choices=US_STATES, blank=False, default='--------') phone = usmodels.PhoneNumberField(blank=False, default='000-000-0000') SHIRT_SIZES = ( ('1', 'Silver'), ('2', 'Gold'), ('3', 'Platinum'), ) tierlist = models.CharField(blank=True, null=True, max_length=1, choices=SHIRT_SIZES) is_admin = models.BooleanField(default=False) is_staff = models.BooleanField(default=False) is_superuser = models.BooleanField(default=False) is_active = models.BooleanField(default=False) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) objects = AccountManager() USERNAME_FIELD = 'email' REQUIRED_FIELDS = ['businessname', 'zipcode', 'city', 'state', 'phone'] def __unicode__(self): return self.email def get_full_name(self): return ' '.join([self.email, self.businessname]) def get_short_name(self): return self.email def has_module_perms(self, app_label): return self.is_admin def has_perm(self, perm, obj=None): return self.is_admin
class CandidateProfile(models.Model): # Demographic GENDER_CHOICE_FEMALE = "F" GENDER_CHOICE_MALE = "M" GENDER_CHOICE_NON_BINARY = "X" ETHNICITY_HISPANIC_LATINO = "HL" ETHNICITY_OTHER = "OT" RACE_AMERICAN_INDIAN_ALASKA_NATIVE = "NATIVE" RACE_ASIAN = "ASIAN" RACE_BLACK_AFRICA = "BLACK" RACE_NATIVE_HAWAIIAN_PACIFIC_ISLANDER = "PACIFIC" RACE_WHITE = "WHITE" DISABILITY_HEALTH_CONDITIONS_POSITIVE = "POSITIVE" DISABILITY_HEALTH_CONDITIONS_NEGATIVE = "NEGATIVE" VETERAN_POSITIVE = "POSITIVE" VETERAN_NEGATIVE = "NEGATIVE" DEMOGRAPHIC_CHOICES = [ ( "Gender", ( (GENDER_CHOICE_FEMALE, "Female"), (GENDER_CHOICE_MALE, "Male"), (GENDER_CHOICE_NON_BINARY, "Non Binary"), ), ), ( "Ethnicity", ( (ETHNICITY_HISPANIC_LATINO, "Hispanic or Latino"), (ETHNICITY_OTHER, "Not Hispanic or Latino"), (None, "Prefer not to specify"), ), ), ( "Race", ( ( RACE_AMERICAN_INDIAN_ALASKA_NATIVE, "American indian or Alaska Native", ), (RACE_ASIAN, "Asian"), (RACE_BLACK_AFRICA, "Black or African American"), ( RACE_NATIVE_HAWAIIAN_PACIFIC_ISLANDER, "Native Hawaiian or Pacific Islander", ), (RACE_WHITE, "White"), (None, "Prefer not to specify"), ), ), ( "Disability and Health Conditions", ( ( DISABILITY_HEALTH_CONDITIONS_POSITIVE, "One or more health conditions", ), (DISABILITY_HEALTH_CONDITIONS_NEGATIVE, "None listed apply"), (None, "Prefer not to specify"), ), ), ( "Veteran", ( (VETERAN_POSITIVE, "Veteran"), (VETERAN_NEGATIVE, "Not veteran"), (None, "Prefer not to specify"), ), ), ] first_name = models.CharField(max_length=30, blank=True, null=True) last_name = models.CharField(max_length=30, blank=True, null=True) gender = models.CharField(max_length=1, choices=DEMOGRAPHIC_CHOICES[0][1], blank=True, null=True) ethnicity = models.CharField(max_length=2, choices=DEMOGRAPHIC_CHOICES[1][1], blank=True, null=True) race = models.CharField(max_length=7, choices=DEMOGRAPHIC_CHOICES[2][1], blank=True, null=True) health_conditions = models.CharField(max_length=8, choices=DEMOGRAPHIC_CHOICES[3][1], blank=True, null=True) veteran = models.CharField(max_length=8, choices=DEMOGRAPHIC_CHOICES[4][1], blank=True, null=True) address_line = models.CharField(max_length=100, blank=True, null=True) zip_code = mailing.USZipCodeField(blank=True, null=True) state = mailing.USStateField(blank=True, null=True) phone = PhoneNumberField(blank=True, null=True) email = models.EmailField(blank=True, null=True) portfolio_website = models.URLField(help_text="e.g. http://example.com", blank=True, null=True, max_length=200) # Cover Letter cover_letter = models.FileField( storage=ResumeStorage(), upload_to=upload_to, null=True, blank=True, validators=[file_size], ) # Resume chunks resume = models.FileField( storage=ResumeStorage(), upload_to=upload_to, null=True, blank=True, validators=[file_size], ) additional_info = models.TextField(max_length=10000, blank=True, null=True) def __eq__(self, other): if not other: return False return self.id == other.id def __ne__(self, other): if not other: return False return self.id != other.id
class User(AbstractBaseUser, PermissionsMixin): """ An email based user model """ first_name = models.CharField(_('first name'), max_length=30, blank=True) last_name = models.CharField(_('last name'), max_length=30, blank=True) email = models.EmailField(_('email address'), unique=True) title = models.CharField(max_length=100, blank=True, null=True) is_staff = models.BooleanField( _('staff status'), default=False, help_text=_('Designates whether the user can log into this admin ' 'site.')) is_active = models.BooleanField( _('active'), default=True, help_text=_('Designates whether this user should be treated as ' 'active. Unselect this instead of deleting accounts.')) date_joined = models.DateTimeField(_('date joined'), default=timezone.now) # Profile data primary_phone = localflavor_models.PhoneNumberField(_('Primary Phone'), max_length=160, blank=True) other_phone = localflavor_models.PhoneNumberField(_('Other Phone'), max_length=160, blank=True) fax = localflavor_models.PhoneNumberField(_('Fax'), max_length=160, blank=True) company_name = models.CharField(_('Company Name'), max_length=160, blank=True) address = models.CharField(_('Address'), max_length=160, blank=True) address2 = models.CharField(_('Address 2'), max_length=160, blank=True) city = models.CharField(_('City'), max_length=160, blank=True) state = localflavor_models.USStateField(_('State/Province'), max_length=160, blank=True) code = localflavor_models.USZipCodeField(_('Zip Code'), max_length=160, blank=True) objects = UserManager() USERNAME_FIELD = 'email' class Meta: verbose_name = _('user') verbose_name_plural = _('users') def __unicode__(self): full_name = self.get_full_name() return full_name if full_name else self.email def save(self, *args, **kwargs): """ Always save the email as lowercase. Helps identifying unique email addresses. The de jure standard is that the local component of email addresses is case sensitive however the de facto standard is that they are not. In practice what happens is user confusion over why an email address entered with camel casing one day does not match an email address entered in different casing another day. """ self.email = self.email.lower() return super(User, self).save(*args, **kwargs) def get_username(self): """ Returns the email address Satisifies API needs of other libraries. """ return self.email def get_full_name(self): """ Returns the first_name plus the last_name, with a space in between. """ full_name = '%s %s' % (self.first_name, self.last_name) return full_name.strip() def get_short_name(self): """Returns the short name for the user.""" return self.first_name def email_user(self, subject, message, from_email=None, **kwargs): """Sends an email to this User.""" send_mail(subject, message, from_email, [self.email], **kwargs)