Exemplo n.º 1
0
class Company(ParanoidModel, CitixenModel):
    """Company model."""

    nit = models.CharField(max_length=50)
    name = CICharField(max_length=120, unique=True)
    email = models.EmailField(max_length=100)
    country = models.ForeignKey(Country,
                                on_delete=models.PROTECT,
                                related_name='companies')
    image_url = models.ImageField(
        upload_to=RandomFileName('companies/images/'))
    namespace = models.CharField(max_length=60, unique=True)

    is_active = models.BooleanField(default=False)

    uuid = models.UUIDField(default=uuid4, primary_key=True)

    created_by = models.ForeignKey('users.User',
                                   on_delete=models.PROTECT,
                                   related_name='companies')

    default_manager = models.Manager()

    class Meta:
        """Meta options."""
        ordering = ('name', )

    def __str__(self):
        return self.name
Exemplo n.º 2
0
class Country(CitixenModel):
    """Country model."""

    name = models.CharField(max_length=120, unique=True)
    national_flag = models.ImageField(
        upload_to=RandomFileName('country/images/'))

    class Meta:
        """Meta options."""
        ordering = ('name', )

    def __str__(self):
        return self.name
Exemplo n.º 3
0
class City(CitixenModel):
    """location model."""
    class Types(models.TextChoices):
        locality = 'locality', _('Locality')
        administrative_area_level_1 = 'administrative_area_level_1', _(
            'Administrative Area Level 1')
        administrative_area_level_2 = 'administrative_area_level_2', _(
            'Administrative Area Level 2')
        administrative_area_level_3 = 'administrative_area_level_3', _(
            'Administrative Area Level 3')
        administrative_area_level_4 = 'administrative_area_level_4', _(
            'Administrative Area Level 4')
        administrative_area_level_5 = 'administrative_area_level_5', _(
            'Administrative Area Level 5')

    code = models.IntegerField(null=True)
    name = models.CharField(max_length=120)
    flag = models.ImageField(upload_to=RandomFileName('locations/images/'))
    country = models.ForeignKey(Country, on_delete=models.PROTECT)

    type = models.CharField(max_length=60,
                            choices=Types.choices,
                            default=Types.locality)
    bounds = JSONField(
        null=True,
        blank=True,
        validators=[
            JSONSchemaValidator(limit_value=schema_location_area_bound)
        ])

    parent = models.ForeignKey('self',
                               on_delete=models.SET_NULL,
                               null=True,
                               blank=True,
                               related_name='locations')

    # Zoom
    zoom_desktop = models.IntegerField(default=14)
    zoom_mobile = models.IntegerField(default=13)

    # Google data
    google_map_key = CICharField(max_length=150, unique=True)
    geo_code_json = JSONField(null=True, blank=True)

    class Meta:
        """Meta options."""
        ordering = ('name', )
        unique_together = [['country', 'code']]

    def __str__(self):
        return f'{self.name} is a location of {self.country}'
Exemplo n.º 4
0
class City(CitixenModel):
    """City model."""

    name = models.CharField(max_length=120, unique=True)
    flag = models.ImageField(upload_to=RandomFileName('city/images/'))
    country = models.ForeignKey(Country, on_delete=models.PROTECT)
    google_map_key = models.CharField(max_length=150)
    map_bounds = models.OneToOneField(LatLngBounds,
                                      null=True,
                                      blank=True,
                                      on_delete=models.CASCADE)

    class Meta:
        """Meta options."""
        ordering = ('name', )

    def __str__(self):
        return f'{self.name} is a city of {self.country.name}'
Exemplo n.º 5
0
class Headquarter(ParanoidModel, CitixenModel):
    """Headquarter model."""

    uuid = models.UUIDField(default=uuid4, primary_key=True)

    company = models.ForeignKey(Company, on_delete=models.PROTECT)

    description = models.TextField(null=True, blank=True)

    name = CICharField(max_length=120)
    image_url = models.ImageField(
        upload_to=RandomFileName('headquarters/images/'))

    email = models.EmailField(max_length=100, null=True)
    phone = models.CharField(max_length=30, null=True)

    latitude = models.DecimalField(max_digits=18, decimal_places=15, default=0)
    longitude = models.DecimalField(max_digits=18,
                                    decimal_places=15,
                                    default=0)
    address = models.CharField(max_length=120)
    neighborhood = models.CharField(max_length=120, blank=True, null=True)
    city = models.ForeignKey(City,
                             on_delete=models.PROTECT,
                             related_name='headquarters')

    google_key = models.CharField(max_length=120, null=True)

    created_by = models.ForeignKey('users.User',
                                   on_delete=models.PROTECT,
                                   related_name='headquarters')

    default_manager = models.Manager()

    class Meta:
        """Meta options."""
        ordering = ('name', )

    def activate_or_deactivate(self):
        self.is_active = not self.is_active
        self.save()

    def __str__(self):
        return f'{self.name} is a headquarters of {self.company.name}'
Exemplo n.º 6
0
class Headquarter(CitixenModel):
    """Headquarter model."""

    uuid = models.UUIDField(default=uuid4, primary_key=True)

    company = models.ForeignKey(Company, on_delete=models.PROTECT)

    description = models.TextField(null=True, blank=True)

    name = models.CharField(max_length=120, unique=True)
    image_url = models.ImageField(
        upload_to=RandomFileName('headquarters/images/'))

    email = models.EmailField(max_length=100, null=True)
    phone = models.CharField(max_length=30, null=True)

    address = models.CharField(max_length=120)
    neighborhood = models.CharField(max_length=120, blank=True, null=True)
    city = models.ForeignKey(City,
                             on_delete=models.PROTECT,
                             related_name='headquarters')

    is_deleted = models.BooleanField(default=False)

    created_by = models.ForeignKey('users.User',
                                   on_delete=models.PROTECT,
                                   related_name='headquarters')

    class Meta:
        """Meta options."""
        ordering = ('name', )

    def activate_or_deactivate(self):
        self.is_active = not self.is_active
        self.save()

    def mark_as_delete(self):
        self.is_deleted = True
        self.save()

    def __str__(self):
        return f'{self.name} is a headquarters of {self.company.name}'
Exemplo n.º 7
0
class Country(CitixenModel):
    """Country model."""
    class AdministrativeAreaLevel(models.IntegerChoices):
        administrative_area_level_1 = 1
        administrative_area_level_2 = 2
        administrative_area_level_3 = 3
        administrative_area_level_4 = 4
        administrative_area_level_5 = 5

    name = models.CharField(max_length=120, unique=True)
    national_flag = models.ImageField(
        upload_to=RandomFileName('country/images/'))
    administrative_area_level = models.IntegerField(
        choices=AdministrativeAreaLevel.choices,
        default=AdministrativeAreaLevel.administrative_area_level_2)
    administrative_area_level_1_name = models.CharField(max_length=90,
                                                        null=True,
                                                        blank=True)
    administrative_area_level_2_name = models.CharField(max_length=90,
                                                        null=True,
                                                        blank=True)
    administrative_area_level_3_name = models.CharField(max_length=90,
                                                        null=True,
                                                        blank=True)
    administrative_area_level_4_name = models.CharField(max_length=90,
                                                        null=True,
                                                        blank=True)
    administrative_area_level_5_name = models.CharField(max_length=90,
                                                        null=True,
                                                        blank=True)

    calling_code = models.CharField(max_length=9, default='')

    class Meta:
        """Meta options."""
        ordering = ('name', )

    def __str__(self):
        return self.name