class EntityTypeBase(PolymorphicModel): project = ForeignKey(Project, on_delete=CASCADE, null=True, blank=True) name = CharField(max_length=64) description = CharField(max_length=256, blank=True) visible=BooleanField(default=True) def __str__(self): return f'{self.name} | {self.project}'
class Analysis(Model): project = ForeignKey(Project, on_delete=CASCADE, db_column='project') name = CharField(max_length=64) data_query = CharField(max_length=1024, default='*') def __str__(self): return f"{self.project} | {self.name}"
class Project(Model): name = CharField(max_length=128) creator = ForeignKey(User, on_delete=PROTECT, related_name='creator') created = DateTimeField(auto_now_add=True) size = BigIntegerField(default=0) """Size of all media in project in bytes. """ num_files = IntegerField(default=0) summary = CharField(max_length=1024) filter_autocomplete = JSONField(null=True, blank=True) def has_user(self, user_id): return self.membership_set.filter(user_id=user_id).exists() def user_permission(self, user_id): permission = None qs = self.membership_set.filter(user_id=user_id) if qs.exists(): permission = qs[0].permission return permission def __str__(self): return self.name def delete(self, *args, **kwargs): Version.objects.filter(project=self).delete() MediaType.objects.filter(project=self).delete() LocalizationType.objects.filter(project=self).delete() StateType.objects.filter(project=self).delete() LeafType.objects.filter(project=self).delete() super().delete(*args, **kwargs)
class Project(Model): name = CharField(max_length=128) creator = ForeignKey(User, on_delete=PROTECT, related_name='creator') created = DateTimeField(auto_now_add=True) size = BigIntegerField(default=0) """Size of all media in project in bytes. """ num_files = IntegerField(default=0) summary = CharField(max_length=1024) filter_autocomplete = JSONField(null=True, blank=True) section_order = ArrayField(CharField(max_length=128), default=list) def has_user(self, user_id): return self.membership_set.filter(user_id=user_id).exists() def user_permission(self, user_id): permission = None qs = self.membership_set.filter(user_id=user_id) if qs.exists(): permission = qs[0].permission return permission def __str__(self): return self.name def delete(self, *args, **kwargs): # Delete attribute types AttributeTypeBase.objects.filter(project=self).delete() # Delete entities qs = EntityBase.objects.filter(project=self) delete_polymorphic_qs(qs) # Delete entity types qs = EntityTypeBase.objects.filter(project=self) delete_polymorphic_qs(qs) super().delete(*args, **kwargs)
class Section(Model): """ Stores either a lucene search or raw elasticsearch query. """ project = ForeignKey(Project, on_delete=CASCADE, db_column='project') name = CharField(max_length=128) """ Name of the section. """ lucene_search = CharField(max_length=1024, null=True, blank=True) """ Optional lucene query syntax search string. """ media_bools = JSONField(null=True, blank=True) """ Optional list of elasticsearch boolean queries that should be applied to media. These are applied to the boolean query "filter" list. """ annotation_bools = JSONField(null=True, blank=True) """ Optional list of elasticsearch boolean queries that should be applied to annotations. These are applied to the boolean query "filter" list. """ tator_user_sections = CharField(max_length=128, null=True, blank=True) """ Identifier used to label media that is part of this section via the tator_user_sections attribute. If not set, this search is not scoped to a "folder". """ visible = BooleanField(default=True) """ Whether this section should be displayed in the UI.
class Version(Model): name = CharField(max_length=128) description = CharField(max_length=1024, blank=True) number = PositiveIntegerField() project = ForeignKey(Project, on_delete=CASCADE) created_datetime = DateTimeField(auto_now_add=True, null=True, blank=True) created_by = ForeignKey(User, on_delete=SET_NULL, null=True, blank=True, related_name='version_created_by') show_empty = BooleanField(default=True) """ Tells the UI to show this version even if the current media does not have any annotations. """ bases = ManyToManyField('self', symmetrical=False, blank=True) """ This version is a patch to an existing version. A use-case here is using one version for each generation of a state-based inference algorithm; all referencing localizations in another layer. """ def __str__(self): out = f"{self.name}" if self.description: out += f" | {self.description}" return out
class Bookmark(Model): """ Stores a link saved by a user. """ project = ForeignKey(Project, on_delete=CASCADE, db_column='project') user = ForeignKey(User, on_delete=CASCADE, db_column='user') name = CharField(max_length=128) uri = CharField(max_length=1024)
class Detail(Model): feature = CharField(max_length=30) value = CharField(max_length=60, unique=True) group = CharField(max_length=20) class Meta: db_table = 'details'
class Order(Base): complete = BooleanField(default=False) duration = IntegerField(null=True) # how long it took to process the order edited = BooleanField(default=False) # tells you whether they opened it for editing... not whether any actual edits were made end = DateTimeField(null=True) end_user_timezone = CharField(max_length=20, null=True) map_format = CharField(max_length=20, null=True) open_source = BooleanField(default=False) #is this map open-sourced, such that it can be included in open source training data? start = DateTimeField(auto_now_add=True, null=True) # it will never be null, but have to do this because migration asks for default otherwise style = ForeignKey("MapStyle", null=True, on_delete=SET_NULL) token = CharField(max_length=200, null=True, unique=True) # the random string that's used to find the order in the maps url = URLField(null=True, max_length=1000, unique=True) # URL if started from url or iframe embeded on a webpage def __str__(self): return self.token def d(self): self.delete_map() self.delete() def delete_map(self): rmtree("/home/usrfd/maps/" + self.token) def finish(self): self.complete = True self.end = end = datetime.now().replace(tzinfo=utc) self.duration = (end - self.start).total_seconds() self.save()
class WithSellingPrice(WithPrice, Model): total_price = PositiveIntegerField('preţ total', blank=True, default=None) total_price_currency = CharField('', max_length=4, choices=Currencies.choices, default=Currencies.EUR) util_price = PositiveIntegerField('preţ / mp util sau UM', blank=True, default=None) util_price_currency = CharField('', max_length=4, choices=Currencies.choices, default=Currencies.EUR) class Meta: abstract = True
class MediaType(Model): dtype = CharField(max_length=16, choices=[('image', 'image'), ('video', 'video'), ('multi', 'multi')]) project = ForeignKey(Project, on_delete=CASCADE, null=True, blank=True, db_column='project') name = CharField(max_length=64) description = CharField(max_length=256, blank=True) visible = BooleanField(default=True) """ Whether this type should be displayed in the UI.""" editTriggers = JSONField(null=True, blank=True) file_format = CharField(max_length=4, null=True, blank=True, default=None) keep_original = BooleanField(default=True, null=True, blank=True) default_volume = IntegerField(default=0) """ Default Volume for Videos (default is muted) """ attribute_types = JSONField(default=list, null=True, blank=True) """ User defined attributes. An array of objects, each containing the following fields: name: Name of the attribute. description: (optional) Description of the attribute. order: Order that the attribute should appear in web UI. Negative means do not display. dtype: Data type of the attribute. Valid values are bool, int, float, string, enum, datetime, geopos. default: (optional) Default value. Valid for all dtypes except datetime. The type should correspond to the dtype (string/enum are strings, int/float are numbers, geopos is a [lon, lat] list). minimum: (optional) Minimum value. Valid for int and float dtypes. maximum: (optional) Maximum value. Valid for int and float dtypes. choices: (optional) Available choices for enum dtype. labels: (optional) Labels for available choices for enum dtype. autocomplete: (optional) Object of the form {'serviceUrl': '<url>'} that specifies URL of the autocomplete service. Valid for string dtype only. use_current: (optional) Boolean indicating whether to use the current time as the default for datetime dtype. """ archive_config = JSONField(default=None, null=True, blank=True) streaming_config = JSONField(default=None, null=True, blank=True) overlay_config = JSONField(default=None, null=True, blank=True) """ Overlay configuration provides text overlay on video / image based on configruation examples: Example: {"mode": "constant", "source": "name"} Overlays file name Time example: {"mode": "datetime", "locale": [locale], "options" : [options]} options can contain 'timeZone' which comes from the TZ database name https://en.wikipedia.org/wiki/List_of_tz_database_time_zones Example: America/Los_Angeles or America/New_York """ def __str__(self): return f'{self.name} | {self.project}'
class JobCluster(Model): name = CharField(max_length=128) owner = ForeignKey(User, null=True, blank=True, on_delete=SET_NULL) host = CharField(max_length=1024) port = PositiveIntegerField() token = CharField(max_length=1024) cert = TextField(max_length=2048) def __str__(self): return self.name
class Alert(Base): colors = (("danger", "danger"), ("info", "info"), ("success", "success"), ("warning", "warning")) color = CharField(choices=colors, max_length=200) permanent = BooleanField() text = CharField(max_length=200) user = OneToOneField(User, blank=True, null=True, on_delete=CASCADE) def __str__(self): return self.text
class UsStates(Model): state = CharField(max_length=2) name = CharField(max_length=24) fips = CharField(max_length=2) lon = FloatField() lat = FloatField() geom = MultiPolygonField(srid=4326) # Returns the string representation of the model. def __str__(self): # __unicode__ on Python 2 return self.name
class LayerMeta(Model): """ Immutable state of layer uploading & geoprocessing progress. To maintain an audit trail of each status change for a layer, these records should *not* be mutated. Instead, a new record should be created for each status change. The data in this table will primarily be maintained by the geoprocessing side of things. """ layer = ForeignKey(Layer, related_name='layer_metas') state = CharField(max_length=16) error = TextField(null=True, blank=True) thumb_small = URLField( null=True, blank=True, help_text='80x80 pixels', ) thumb_large = URLField( null=True, blank=True, help_text='400x150 pixels', ) created_at = DateTimeField(auto_now_add=True) # TileJSON fields min_zoom = IntegerField(default=0) max_zoom = IntegerField(default=11) bounds = CharField( null=True, max_length=120, help_text='JSON array', ) center = CharField( null=True, max_length=60, help_text='JSON array', ) def to_json(self): return { 'id': self.id, 'state': self.state, 'error': self.error, 'thumb_small': self.thumb_small, 'thumb_large': self.thumb_large, 'created_at': self.created_at.isoformat(), 'min_zoom': self.min_zoom, 'max_zoom': self.max_zoom, 'bounds': self.bounds, 'center': self.center, }
class StateType(Model): dtype = CharField(max_length=16, choices=[('state', 'state')], default='state') project = ForeignKey(Project, on_delete=CASCADE, null=True, blank=True, db_column='project') name = CharField(max_length=64) description = CharField(max_length=256, blank=True) visible = BooleanField(default=True) """ Whether this type should be displayed in the UI.""" grouping_default = BooleanField(default=True) """ Whether to group elements in the UI by default.""" media = ManyToManyField(MediaType) interpolation = CharField(max_length=16, choices=[('none', 'none'), ('latest', 'latest')], default='latest') association = CharField(max_length=64, choices=AssociationTypes, default=AssociationTypes[0][0]) attribute_types = JSONField(default=list, null=True, blank=True) """ User defined attributes. An array of objects, each containing the following fields: name: Name of the attribute. description: Description of the attribute. order: Order that the attribute should appear in web UI. Negative means do not display. dtype: Data type of the attribute. Valid values are bool, int, float, string, enum, datetime, geopos. default: (optional) Default value. Valid for all dtypes except datetime. The type should correspond to the dtype (string/enum are strings, int/float are numbers, geopos is a [lon, lat] list). minimum: (optional) Minimum value. Valid for int and float dtypes. maximum: (optional) Maximum value. Valid for int and float dtypes. choices: (optional) Available choices for enum dtype. labels: (optional) Labels for available choices for enum dtype. autocomplete: (optional) Object of the form {'serviceUrl': '<url>'} that specifies URL of the autocomplete service. Valid for string dtype only. use_current: (optional) Boolean indicating whether to use the current time as the default for datetime dtype. style: (optional) String of GUI-related styles. """ delete_child_localizations = BooleanField(default=False) """ If enabled, child localizations will be deleted when states of this type are deleted. """ def __str__(self): return f'{self.name} | {self.project}'
class User(AbstractUser): middle_initial = CharField(max_length=1) initials = CharField(max_length=3) organization = ForeignKey(Organization, on_delete=SET_NULL, null=True, blank=True) last_login = DateTimeField(null=True, blank=True) last_failed_login = DateTimeField(null=True, blank=True) failed_login_count = IntegerField(default=0) def __str__(self): if self.first_name or self.last_name: return f"{self.first_name} {self.last_name}" else: return "---"
class WithBuildingInfo(Model): has_basement = BooleanField('are subsol', default=False) has_semi_basement = BooleanField('are demisol', default=False) has_ground_floor = BooleanField('parter', default=True) levels_nr = PositiveIntegerField('nr. niveluri', blank=True, default=None) has_mansard = BooleanField('mansardă', default=False) building_year = PositiveIntegerField('an finalizare construcţie', blank=True, default=None) building_period = CharField('perioada construire', max_length=10, choices=BuildingPeriod.choices, blank=True, default=None) resistance_structure = CharField('structura de rezistenţă', max_length=10, choices=ResistanceStructure.choices, blank=True, default=None) class Meta: abstract = True
class AttributeTypeBase(PolymorphicModel): """ Generic entity in a JSON-B field. """ name = CharField(max_length=64) """ Name refers to the key in the JSON structure """ description = CharField(max_length=256, blank=True) """ Human readable description of the column """ applies_to = ForeignKey(EntityTypeBase, on_delete=CASCADE) """ Pointer to the owner of this type description. Either a media, state or sequence 'owns' this type and combines it into a set with other AttributeTypes to describe an AttributeSet """ project = ForeignKey(Project, on_delete=CASCADE) order = IntegerField(default=0) """ Controls order (lower numbers first, negative is hide) """ def __str__(self): return self.name
class Project(Model): name = CharField(max_length=128) creator = ForeignKey(User, on_delete=PROTECT, related_name='creator', db_column='creator') organization = ForeignKey(Organization, on_delete=SET_NULL, null=True, blank=True, db_column='organization') created = DateTimeField(auto_now_add=True) size = BigIntegerField(default=0) """Size of all media in project in bytes. """ num_files = IntegerField(default=0) duration = BigIntegerField(default=0) """ Duration of all videos in this project. """ summary = CharField(max_length=1024) filter_autocomplete = JSONField(null=True, blank=True) attribute_type_uuids = JSONField(default=dict, null=True, blank=True) enable_downloads = BooleanField(default=True) thumb = CharField(max_length=1024, null=True, blank=True) usernames = ArrayField(CharField(max_length=256), default=list) """ Mapping between attribute type names and UUIDs. Used internally for maintaining elasticsearch field aliases. """ def has_user(self, user_id): return self.membership_set.filter(user_id=user_id).exists() def user_permission(self, user_id): permission = None qs = self.membership_set.filter(user_id=user_id) if qs.exists(): permission = qs[0].permission return permission def __str__(self): return self.name def delete(self, *args, **kwargs): Version.objects.filter(project=self).delete() MediaType.objects.filter(project=self).delete() LocalizationType.objects.filter(project=self).delete() StateType.objects.filter(project=self).delete() LeafType.objects.filter(project=self).delete() super().delete(*args, **kwargs)
class Resource(Model): path = CharField(db_index=True, max_length=256) count = IntegerField(null=True, default=1) @transaction.atomic def add_resource(path_or_link): if os.path.islink(path_or_link): path = os.readlink(path_or_link) else: path = path_or_link obj, created = Resource.objects.get_or_create(path=path) if not created: obj.count += 1 obj.save() @transaction.atomic def delete_resource(path_or_link): if os.path.islink(path_or_link): path = os.readlink(path_or_link) os.remove(path_or_link) else: path = path_or_link try: obj = Resource.objects.get(path=path) obj.count -= 1 if obj.count <= 0: obj.delete() os.remove(path) else: obj.save() except Resource.DoesNotExist as dne: logger.info(f"Removing legacy resource {path}") os.remove(path) except Exception as e: logger.error(f"{e} when lowering resource count of {path}")
class TreeLeaf(EntityBase): parent=ForeignKey('self', on_delete=SET_NULL, blank=True, null=True) path=PathField(unique=True) name = CharField(max_length=255) class Meta: verbose_name_plural = "TreeLeaves" def __str__(self): return str(self.path) def depth(self): return TreeLeaf.objects.annotate(depth=Depth('path')).get(pk=self.pk).depth def subcategories(self, minLevel=1): return TreeLeaf.objects.select_related('parent').filter( path__descendants=self.path, path__depth__gte=self.depth()+minLevel ) def computePath(self): """ Returns the string representing the path element """ pathStr=self.name.replace(" ","_").replace("-","_").replace("(","_").replace(")","_") if self.parent: pathStr=self.parent.computePath()+"."+pathStr elif self.project: projName=self.project.name.replace(" ","_").replace("-","_").replace("(","_").replace(")","_") pathStr=projName+"."+pathStr return pathStr
class WithAdditionalPropertyInfo(Model): building_year = PositiveIntegerField('an finalizare construcţie', blank=True, default=None) building_stage = CharField('stadiu construcţie', max_length=15, choices=BUILDING_STAGE, default=None, blank=True) underground_levels_nr = PositiveIntegerField('nr. niveluri subterane', default=None, blank=True) levels_nr = PositiveIntegerField('nr. niveluri', default=None, blank=True) has_semi_basement = BooleanField('demisol', default=False) has_ground_floor = BooleanField('parter', default=True) has_mansard = BooleanField('mansardă', default=False) has_terrace = BooleanField('terasă', default=False) has_entresol = BooleanField('mezanin', default=False) has_parking_possibility = BooleanField('posibilitate parcare', default=False) parking_spaces_nr = PositiveIntegerField('nr. locuri parcare', default=None, blank=True) building_state = CharField('stare imobil', max_length=15, choices=BUILDING_STATE, default=None, blank=True) class Meta: abstract = True
class WithSpaceSellingPrice(WithPrice, Model): price = PositiveIntegerField('preţ cerut', default=None) price_currency = CharField('', max_length=4, choices=Currencies.choices, default=Currencies.EUR) hide_price = BooleanField('nu doresc să fie afişat vizitatorilor site-ului', default=False) class Meta: abstract = True
class HouseBaseModel(BaseOfferModel, WithRoomsAndAnnexes, WithBuildingInfo, WithOtherDetails, WithDestination, WithExclusivity, WithOtherZoneDetails, WithHeatingSystem, WithConditioning, WithInternetAccess, WithFinishes, WithFeatures, WithServices, WithHouseSurfaces): roof_cover = CharField('învelitoare acoperiş', max_length=10, choices=RoofCover.choices, default=None, blank=True) has_current = BooleanField('curent', default=False) has_three_phase_current = BooleanField('curent trifazic', default=False) has_water = BooleanField('apă', default=False) has_sewerage = BooleanField('canalizare', default=False) has_septic_tank = BooleanField('fosă septică', default=False) has_gas = BooleanField('gaz', default=False) has_catv = BooleanField('CATV', default=False) has_phone = BooleanField('telefon', default=False) has_phone_station = BooleanField('centrală telefonică', default=False) has_international_phone = BooleanField('telefon internaţional', default=False) has_cellar = BooleanField('pivniţă', default=False) has_wine_cellar = BooleanField('cramă', default=False) has_service_wc = BooleanField('WC serviciu', default=False) has_storage_space = BooleanField('spaţiu depozitare', default=False) has_dressing = BooleanField('dressing', default=False) has_annexes = BooleanField('anexe', default=False) has_dependencies = BooleanField('dependinţe', default=False) class Meta: abstract = True
class CalendarDate(CompanyBoundModel): """This is an exception for Calendar """ EXCEPTION_TYPES = ( ('1', 'Add to service'), ('2', 'Remove from service'), ) service = ForeignKey(Calendar) date = DateField('Date') exception_type = CharField('Exception Type', max_length=1, default='2', choices=EXCEPTION_TYPES) class Meta: verbose_name_plural = "Calendar Dates" def __str__(self): return '%s-%s' % (self.pk, self.date) @property def gtfs_header(self): return 'service_id,date,exception_type' def gtfs_format(self): data = [ ('service_id', self.service.service_id), ('date', self.date.strftime('%Y-%m-%d')), ('exception_type', self.exception_type), ] return OrderedDict(data)
class WithHotelRegime(WithRentPrice, Model): hotel_regime = BooleanField('regim hotelier', default=False) hotel_regime_price = DecimalField('chirie / zi', max_digits=6, decimal_places=2, blank=True, default=None) hotel_regime_currency = CharField('', max_length=4, choices=Currencies.choices, default=Currencies.EUR) class Meta: abstract = True
class BaseOfferModel(BaseModel): agent = ForeignKey(UserProfile, on_delete=SET_NULL, null=True) is_published = BooleanField('publicat?', default=False) address = PointField('adresă', max_length=200, null=True) hide_address_on_imobiliare = BooleanField('ascunde adresa în imobiliare.ro', default=False) county = ForeignKey(County, related_name='%(class)ss', related_query_name='%(class)s', on_delete=SET_NULL, null=True, verbose_name='judeţ') locality = ForeignKey(Locality, related_name='%(class)ss', related_query_name='%(class)s', on_delete=SET_NULL, null=True, verbose_name='localitate') sector = CharField('sectorul', max_length=2, blank=True, default=None, choices=Sector.choices) hide_exact_location_on_imobiliare = BooleanField('ascunde localizarea exactă pe imobiliare.ro', default=False) postal_code = CharField('cod poştal', max_length=50, blank=True, default=None) neighborhood = CharField('vecinătăţi', max_length=100, blank=True, default=None) description = TextField('descriere emoţională', default=None, blank=True) class Meta: abstract = True
class WithPropertyInfo(Model): property_name = CharField('nume proprietate', max_length=100, default=None, blank=True) property_description = TextField('descriere proprietate', max_length=100, default=None, blank=True) total_surface = DecimalField('suprafaţă totală (mp)', max_digits=6, decimal_places=2, default=None) terrain_surface = DecimalField('suprafaţă teren (mp)', max_digits=6, decimal_places=2, default=None, blank=True) class Meta: abstract = True
class WithPrice(Model): not_include_vat = BooleanField('nu include TVA', default=False) price_details = TextField('alte detalii preţ', blank=True, default=None) zero_commission = BooleanField('comision 0%', default=False) buyer_commission = CharField('comision cumpărător', max_length=50, blank=True, default=None) class Meta: abstract = True