class Border(models.Model): exit_country = country_fields.CountryField(blank=False, null=True, verbose_name=_('Exit Country')) enter_country = country_fields.CountryField( blank=False, null=True, verbose_name=_('Entry Country')) open_to_others = models.BooleanField(default=True) class Meta: verbose_name_plural = _("Borders") def __unicode__(self): return "{} -> {}".format(self.exit_country, self.enter_country)
class Publisher(models.Model): name = models.CharField(max_length=100, blank=False, help_text="Publisher Name") country = fields.CountryField(blank_label="(select country)") website = models.URLField() def __str__(self): return self.name
class RegIncident(models.Model): CompleteDate = models.DateField(verbose_name="Date") Application = models.CharField(verbose_name="Application Name", max_length=30) SealID = models.CharField(verbose_name="SealID", max_length=10) Severity = models.CharField(verbose_name="Severity", max_length=4) TicketNum = models.CharField(verbose_name="Ticket", unique=True, max_length=13) StartTime = models.TimeField(verbose_name="Start Hour") EndTime = models.TimeField(verbose_name="End Hour") IssueDesc = ck.RichTextField(verbose_name="Issue description") ReportTo = models.CharField(verbose_name="Report to regulator?", max_length=3) Impact = ck.RichTextField(verbose_name="Impact") RegBy = models.ForeignKey(User, verbose_name="Registered by", on_delete=models.PROTECT) ReportedBy = models.CharField(verbose_name="Reported by") Country = countries.CountryField(verbose_name="Country") Extras = models.FileField(verbose_name="Another extras", upload_to="ExtrasEv") #Checar si se necesita relación de muchos a muchos entre la tabla de usuarios default y esta tabla. class Meta(): verbose_name = "Incident" verbose_name_plural = "Incidents" def __str__(self): return self.TicketNum
class Profile(models.Model): GENDER_CHOICES = (('M', 'Male'), ('F', 'Female'), ('O', 'Other'), ('P', 'I prefer not to say')) user = models.OneToOneField(User, on_delete=models.CASCADE) following = models.ManyToManyField('self', related_name='followers', symmetrical=False, blank=True) slug = models.SlugField(unique=True) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) image = models.ImageField(default='media/default.jpg', upload_to='profile_pics', blank=True) city = models.CharField(max_length=20, blank=True) country = fields.CountryField(blank=True) linkedin = models.URLField(blank=True) gender = models.CharField(max_length=1, choices=GENDER_CHOICES, blank=True) class Meta: ordering = ('-created', ) def __repr__(self): return ("<Profile: " f"user='******', " f"image='{self.image}', " f"city='{self.city}', " f"country='{self.country}', " f"linkedin='{self.linkedin}', " f"gender='{self.gender}'>") def __str__(self): return f'{self.user} Profile' def display_gender(self): if self.gender: return dict(self.GENDER_CHOICES)[self.gender] else: return None def save(self, *args, **kwargs): slug_str = f'{self.user}' unique_slugify(self, slug_str) super().save(*args, **kwargs) # This is commented for now because it will cause issues # when storing our files in AWS S3 # if self.image: # img = Image.open(self.image.path) # if img.height > 300 or img.width > 300: # output_size = (300, 300) # img.thumbnail(output_size) # img.save(self.image.path) def image_url(self): if (self.image and hasattr(self.image, 'url')): return self.image.url
class Company(models.Model): company_id = models.UUIDField( default=uuid.uuid4, editable=False, primary_key=True, ) name = models.TextField( db_index=True, default=None, unique=True, editable=False, ) industry = models.TextField( db_index=True, default=None, editable=False, ) description = models.TextField( default=None, editable=False, ) exchange = models.TextField( db_index=True, default=None, editable=False, ) country = fields.CountryField( db_index=True, default=None, editable=False, ) class Meta: db_table = 'app_companies'
class Nationality(models.Model): name = models.CharField(max_length=200, blank=False, null=False) country_iso = country_fields.CountryField(blank=True, null=True) class Meta: verbose_name_plural = _("Nationalities") def __unicode__(self): return self.name
class JobApplication(models.Model): name = models.CharField(max_length=35) last_name = models.CharField(max_length=35) birth_date = models.DateTimeField(auto_now=False, auto_now_add=False) sex_list = (('M', 'Male'), ('F', 'Female')) sex = models.CharField(max_length=1, choices=sex_list) country = country_fields.CountryField() phone_number = phonenumber_fields.PhoneNumberField() about = models.CharField(max_length=250) def __str__(self): return "{0} {1}".format(self.name, self.last_name)
class Pen(models.Model): product = models.OneToOneField(Product, related_name='pen', on_delete=models.CASCADE) year = models.IntegerField(validators=[validate_year]) country = countries.CountryField(blank=True, null=True) cap_color = models.CharField(max_length=25) body_color = models.CharField(max_length=25) nib_description = models.CharField(max_length=55) nib_make = models.CharField(max_length=25) nib_grade = models.CharField(max_length=25) nib_material = models.CharField(max_length=25) nib_flexibility = models.CharField(max_length=25) nib_alternative = models.BooleanField()
class Organisation(base.TimeStampedModel, TranslatableModel): name = models.CharField(max_length=512, unique=True) slug = models.SlugField(max_length=512, unique=True) translations = TranslatedFields( title=models.CharField(max_length=512), description_why=models.TextField(), description_how=models.TextField(), description=models.TextField(), ) initiators = models.ManyToManyField(settings.AUTH_USER_MODEL) image = fields.ConfiguredImageField( 'heroimage', upload_to='organisations/images', blank=True, verbose_name=_('Header image'), help_prefix=_( 'The image sets the atmosphere for your organisation page.'), ) logo = fields.ConfiguredImageField( 'logo', upload_to='organisations/logos', blank=True, help_prefix=_('The official logo of your organisation.'), ) twitter_handle = models.CharField(max_length=200, blank=True) facebook_handle = models.CharField(max_length=200, blank=True) instagram_handle = models.CharField(max_length=200, blank=True) webpage = models.URLField(blank=True) country = countries_fields.CountryField() place = models.CharField(max_length=200) objects = OrganisationManager() def __str__(self): return self.name def has_social_share(self): return (self.twitter_handle or self.facebook_handle or self.instagram_handle or self.webpage) def has_initiator(self, user): return user in self.initiators.all() def get_absolute_url(self): from django.core.urlresolvers import reverse return reverse('organisation-detail', args=[str(self.slug)])
class Address(models.Model): def __str__(self): return "{} \n{} {} \n{}, {} {} \n{}".format(self.addressee, self.street, self.apt, self.city, self.state, self.zip_code, self.country) addressee = models.CharField(max_length=255) street = models.CharField(max_length=255) apt = models.CharField(max_length=12, null=True, blank=True) city = models.CharField(max_length=255) state = models.CharField(max_length=255) zip_code = models.CharField(max_length=12) country = countries.CountryField(blank_label="Select Country") phone = phonenumber.PhoneNumberField(null=True, blank=True) email = models.EmailField(max_length=254)
class AbstractPoliticalInformation(Model): """ This model holds political information about a person """ person = models.OneToOneField( to=swapper.get_model_name('kernel', 'Person'), on_delete=models.CASCADE, ) nationality = django_countries_fields.CountryField( blank_label='Nationality', ) religion = models.CharField( max_length=63, blank=True, ) passport_number = models.CharField( max_length=15, blank=True, ) driving_license_number = models.CharField( max_length=31, blank=True, ) class Meta: """ Meta class for AbstractPoliticalInformation """ abstract = True def __str__(self): """ Return the string representation of the model :return: the string representation of the model """ person = self.person nationality = self.nationality return f'{person} - {nationality}'
class CheckoutForm(forms.Form): street_adress =forms.CharField(widget=forms.TextInput(attrs={ 'placeholder':'1234 Main St', 'class':"form-control" })) appartement_adress = forms.CharField(required = True, widget=forms.TextInput(attrs={ 'placeholder':"Apartment or suite", 'class':"form-control" })) country = fields.CountryField(blank_label= "(select country)").formfield( widget = CountrySelectWidget(attrs = { 'class' :"custom-select d-block w-100" })) zip = forms.CharField(widget= forms.TextInput(attrs = { 'class':"form-control", 'id':"zip" })) same_shipping_adress =forms.BooleanField(required= False) save_info =forms.BooleanField(required= False) payment_option = forms.ChoiceField(widget = forms.RadioSelect , choices= PAYENT_CHOICE)
class Movie(models.Model): title = models.CharField(max_length=50) director = models.ForeignKey(Director, on_delete=models.CASCADE) actors = models.ManyToManyField(Actor) genres = models.ManyToManyField(Genre) year = models.IntegerField() image = models.CharField(max_length=250) rated = models.ForeignKey(Rating, on_delete=models.CASCADE) country = fields.CountryField() language = LanguageField() plot = models.CharField(max_length=250, default="Any Plot, We shall add here later") writer = models.ForeignKey(Writer, on_delete=models.CASCADE, null=True, blank=True) awards = models.ManyToManyField(Awards, related_name='awards', blank=True) runtime = models.IntegerField() def __str__(self): return self.title
class AbstractPoliticalInformation(AbstractPersonalInformation): """ This model holds political information about a person """ nationality = django_countries_fields.CountryField( blank_label='Nationality', ) religion = models.CharField( max_length=63, blank=True, ) passport_number = models.CharField( max_length=15, blank=True, ) driving_license_number = models.CharField( max_length=31, blank=True, ) class Meta: """ Meta class for AbstractPoliticalInformation """ abstract = True def __str__(self): """ Return the string representation of the model :return: the string representation of the model """ person = self.person nationality = self.nationality return f'{person} - {nationality}'
class UserDetail(db.Model): """Additional user detail.""" user = db.OneToOneField( settings.AUTH_USER_MODEL, on_delete=db.CASCADE, related_name="details", related_query_name="details" ) is_public = db.BooleanField(default=False) gender = db.CharField( max_length=2, choices=( ("MM", "Male"), ("FF", "Female"), ("MF", "My body is male, but my soul is female"), ("FM", "My body is female, but my soul is male"), ) ) address1 = db.CharField(max_length=140) address2 = db.CharField(max_length=140) city = db.CharField(max_length=20) region = db.CharField(max_length=20) country = ct.CountryField(blank_label=_("Select Country"))
class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) profile_picture = models.ImageField( upload_to='img/profilepictures/', default='img/profilepictures/default-profile-picture.png') header_picture = models.ImageField( upload_to='img/headerpictures/', default='img/headerpictures/default-header-picture.png') country = country_fields.CountryField() birth_date = models.DateField(auto_now=False, auto_now_add=False, null=True) gender_list = (('M', 'Male'), ('F', 'Female')) gender = models.CharField(max_length=1, choices=gender_list, null=True) follows = models.ManyToManyField('Profile', related_name='followed_by') def get_full_name(self): return f'{self.user.first_name} {self.user.last_name}' def get_short_name(self): last_name = self.user.last_name[0] return f'{self.user.first_name} {last_name}.' def get_friend_requests(self): query = self.friend_requests.order_by('-pk') return query def has_friend_requests(self): return True if len(self.friend_requests.all()) > 0 else False def has_friends(self): return True if len( Friendship.objects.filter(Q(creator=self) | Q(friend=self))) > 0 else False def is_friends_with(self, friend_profile): profiles = [self, friend_profile] friend = Friendship.objects.filter(creator__in=profiles, friend__in=profiles) return True if friend.exists() else False def get_friends(self): friends = [] for f in list( Friendship.objects.filter(Q(creator=self) | Q(friend=self))): friends.append(f.creator if f.creator != self else f.friend) return friends def get_online_friends(self): friends = [] for f in self.get_friends(): if f.online: friends.append(f) return friends def get_offline_friends(self): friends = [] for f in self.get_friends(): if not f.online: friends.append(f) return friends def last_seen(self): return cache.get('seen_%s' % self.user.username) def online(self): if self.last_seen(): now = datetime.datetime.now() if now > self.last_seen() + datetime.timedelta( seconds=settings.USER_ONLINE_TIMEOUT): return False else: return True else: return False def __str__(self): return self.get_short_name()
class GroundStation(models.Model): """ This class models the configuration required for managing a generic ground station, in terms of communication channels and pass simulations. """ class Meta: app_label = 'configuration' objects = GroundStationsManager() user = models.ForeignKey( account_models.UserProfile, verbose_name='User to which this GroundStation belongs to') identifier = models.CharField( 'Unique alphanumeric identifier for this GroundStation', max_length=30, unique=True, validators=[ validators.RegexValidator(regex='^[a-zA-Z0-9.\-_]*$', message="Alphanumeric or '.-_' required", code='invalid_spacecraft_identifier') ]) callsign = models.CharField( 'Radio amateur callsign for this GroundStation', max_length=10, validators=[ validators.RegexValidator(regex='^[a-zA-Z0-9.\-_]*$', message="Alphanumeric or '.-_' required", code='invalid_callsign') ]) contact_elevation = models.FloatField( 'Minimum elevation for contact(degrees)') latitude = models.FloatField('Latitude of the Ground Station') longitude = models.FloatField('Longitude of the Ground Station') altitude = models.FloatField('Altitude of the Ground Station') # Necessary for matching this information with the IARU database for band # regulations. country = fields.CountryField('Country where the GroundStation is located') IARU_region = models.SmallIntegerField('IARU region identifier') is_automatic = models.BooleanField( 'Flag that defines this GroundStation as a fully automated one,' 'so that it will automatically accept any operation request from a ' 'remote Spacecraft operator', default=False) def update(self, callsign=None, contact_elevation=None, latitude=None, longitude=None, is_automatic=None): """ Updates the configuration for the given GroundStation object. It is not necessary to provide all the parameters for this function, since only those that are not null will be updated. :param callsign: CALLSIGN for this GS :param contact_elevation: Minimum contact elevation :param latitude: GS's latitude :param longitude: GS's longitude :param is_automatic: Flag that defines whether the station is automatic """ changes = False change_altitude = False update_fields = [] if callsign and self.callsign != callsign: self.callsign = callsign update_fields.append('callsign') changes = True if contact_elevation is not None and\ self.contact_elevation != contact_elevation: self.contact_elevation = contact_elevation update_fields.append('contact_elevation') changes = True if is_automatic and self.is_automatic != is_automatic: self.is_automatic = is_automatic update_fields.append('is_automatic') changes = True if latitude and self.latitude != latitude: self.latitude = latitude update_fields.append('latitude') changes = True change_altitude = True if longitude and self.longitude != longitude: self.longitude = longitude update_fields.append('longitude') changes = True change_altitude = True if change_altitude: self.altitude = gis.get_altitude(self.latitude, self.longitude)[0] update_fields.append('altitude') if changes: self.save(update_fields=update_fields) def __str__(self): """ Prints in a unicode string the most remarkable data for this spacecraft object. """ return ' >>> GS, id = ' + str(self.identifier) + ', callsign = ' + str( self.callsign)
class LocationInformation(Model): """ This model holds information about how to locate 'any' locatable entity """ address = models.TextField() city = models.CharField(max_length=127, ) state = models.CharField(max_length=127, ) country = django_countries_fields.CountryField(blank_label='Country', ) postal_code = models.IntegerField( validators=[ RegexValidator(r'^[0-9]{3,9}$'), MinValueValidator(0), ], blank=True, null=True, ) latitude = models.DecimalField( max_digits=12, decimal_places=8, validators=[ MinValueValidator(-90), MaxValueValidator(90), ], blank=True, null=True, ) longitude = models.DecimalField( max_digits=12, decimal_places=8, validators=[ MinValueValidator(-180), MaxValueValidator(180), ], blank=True, null=True, ) # Relationship with the locatable entity entity_content_type = models.ForeignKey( to=contenttypes_models.ContentType, on_delete=models.CASCADE, ) entity_object_id = models.PositiveIntegerField() entity = contenttypes_fields.GenericForeignKey( ct_field='entity_content_type', fk_field='entity_object_id', ) class Meta: """ Meta class for LocationInformation """ verbose_name_plural = 'location information' def __str__(self): """ Return the string representation of the model :return: the string representation of the model """ city = self.city state = self.state country = self.country postal_code = self.postal_code return f'{city}, {state}, {country} - {postal_code}'
class User(auth_models.AbstractBaseUser, auth_models.PermissionsMixin): username = models.CharField(_('username'), max_length=60, unique=True, help_text=USERNAME_HELP, validators=[USERNAME_VALIDATOR], error_messages={ 'unique': _(USERNAME_NOT_UNIQUE), }) email = models.EmailField(_('email address'), unique=True, error_messages={ 'unique': EMAIL_NOT_UNIQUE, }) is_staff = models.BooleanField(_('staff status'), default=False, help_text=IS_STAFF_HELP) is_active = models.BooleanField(_('active'), default=True, help_text=IS_ACTIVE_HELP) date_joined = models.DateTimeField(editable=False, default=timezone.now) get_notifications = models.BooleanField( verbose_name=_('Send me email notifications'), default=True, help_text=GET_NOTIFICATIONS_HELP) _avatar = fields.ConfiguredImageField( 'avatar', upload_to='users/images', blank=True, verbose_name=_('Avatar picture'), ) description = models.CharField( blank=True, max_length=250, verbose_name=_('Short description about yourself'), help_text=_('Write a little bit about yourself. ' '(max. 250 characters)')) twitter_handle = models.CharField( blank=True, max_length=15, verbose_name=_('Twitter name'), ) facebook_handle = models.CharField( blank=True, max_length=50, verbose_name=_('Facebook name'), ) instagram_handle = models.CharField( blank=True, max_length=30, verbose_name=_('Instagram name'), ) country = countries_fields.CountryField( blank=True, verbose_name=_('Country of residence'), ) city = models.CharField( blank=True, max_length=80, verbose_name=_('City of residence'), ) birthdate = models.DateField( blank=True, null=True, verbose_name=_('Date of birth'), ) gender = models.CharField( blank=True, verbose_name=_('Gender'), max_length=2, choices=[ ('M', _('Male')), ('F', _('Female')), ('T', _('Transgender')), ('TF', _('Transgender Female')), ('TM', _('Transgender Male')), ('I', _('Intersex')), ('GF', _('Gender Fluid')), ('O', _('Other')), ], ) languages = models.CharField( blank=True, verbose_name=_('Languages'), max_length=150, help_text=_('Enter the languages you’re speaking.')) timezone = models.CharField(blank=True, verbose_name=_('Time zone'), max_length=100, choices=[(t, t) for t in common_timezones]) objects = auth_models.UserManager() USERNAME_FIELD = 'email' REQUIRED_FIELDS = ['username'] class Meta: verbose_name = _("User") verbose_name_plural = _("Users") def get_absolute_url(self): from django.core.urlresolvers import reverse return reverse('profile', kwargs={'slug': str(self.username)}) def __str__(self): return self.get_full_name() @property def has_social_share(self): return (self.twitter_handle or self.facebook_handle or self.instagram_handle) @property def organisations(self): return self.organisation_set.all() @property def avatar(self): if self._avatar: return self._avatar @property def default_avatar(self): id = self.pk % 6 return static('images/penguin_{}.png'.format(id)) @property def age(self): today = date.today() years_difference = today.year - self.birthdate.year is_before_birthday = (today.month, today.day) < (self.birthdate.month, self.birthdate.day) elapsed_years = years_difference - int(is_before_birthday) return elapsed_years def get_full_name(self): """ Returns the first_name plus the last_name, with a space in between. """ full_name = '%s <%s>' % (self.username, self.email) return full_name.strip() def get_short_name(self): "Returns the short name for the user." return self.username def signup(self, username, email, timezone, commit=True): """Update the fields required for sign-up.""" self.username = username self.email = email self.timezone = timezone if commit: self.save()
class MultiNullCountryNoBlank(models.Model): countries = fields.CountryField(multiple=True, null=True)
def test_db_collation(self): # test fix for issue 338 country = fields.CountryField() self.assertTrue(hasattr(country, "db_collation"))