class Options(EmbeddedDocument): access_key = fields.StringField() droplets = fields.ListField(fields.StringField()) ssh_pub_keys = fields.ListField(fields.DictField()) size = fields.StringField() region = fields.StringField() image = fields.StringField() state = fields.StringField() service_opts = fields.DictField(blank=True)
class DataSource(EmbeddedDocument): """Data Source class""" name = fields.StringField(blank=False) url_query = fields.StringField(blank=False) query_options = fields.DictField(blank=True) authentication = fields.EmbeddedDocumentField(Authentication) order_by_field = fields.StringField(blank=True, default="") capabilities = fields.DictField(blank=True)
class Profile(Document): #user = fields.ReferenceField('User') user_id = fields.IntField() full_name = fields.StringField(max_length=191, blank=True) location = fields.DictField({}, blank=True) settings = fields.DictField({}, blank=True) has_at_least_one_social_account = fields.BooleanField(default=False) social_accounts = fields.ListField(fields.DictField({}, blank=True), blank=True) associated_platforms = fields.ListField(fields.DictField(), blank=True) channels = fields.ListField(fields.DictField(blank=True), blank=True) authorized_devices = fields.ListField(fields.DictField(blank=True), blank=True) birth_date = fields.DateTimeField(blank=True) roles = fields.ListField(fields.DictField({}, blank=True), blank=True) permissions = fields.ListField(fields.DictField({}, blank=True), blank=True) signed_up_with = fields.StringField(defalut="email") signed_up_ip_address = fields.StringField(blank=True) singed_up_user_agent = fields.StringField(blank=True) logged_in_ip_address = fields.StringField(blank=True) logged_in_user_agent = fields.StringField(blank=True) meta = {"collection": "auth_profile"} def __str__(self): return self.mobile_number def check_otp(self, otp): return check_password(otp, self.otp)
class Device(Document): serialNumberInserv = fields.StringField() system = fields.EmbeddedDocumentField(System) capacity = fields.EmbeddedDocumentField(Capacity) performance = fields.EmbeddedDocumentField(Performance) disks = fields.EmbeddedDocumentField(Disks) nodes = fields.DictField() authorized = fields.EmbeddedDocumentField(Authorized) updated = fields.DateTimeField() date = fields.DateTimeField() def __str__(self): if self.system and self.system.fullModel: return "{} ({})".format(self.system.fullModel, self.serialNumberInserv) return "{}".format(self.serialNumberInserv) @staticmethod def for_user(user_id): tenant = Tenant.id_for_user(user_id) d = Device.objects.filter(authorized__tenants=tenant) d._user_id = user_id return d def has_triggered(self): user_ids = Tenant.objects.filter( tenant_id__in=self.authorized.tenants).values_list('user_id') statuses = Status.objects.filter(device_id=str(self.id), user_id__in=user_ids) for s in statuses: if s.current_check(): return True return False
class AutoKey(Document): """Auto Key keeps track of keys""" root = fields.ReferenceField(DataStructureElement, reverse_delete_rule=CASCADE, unique=True) keys = fields.DictField(default={}, blank=True) @staticmethod def get_by_root(root): """Return the object with the given root. Args: root: Returns: Data (obj): Data object with the given id """ try: return AutoKey.objects.get(root=root) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(str(e)) except Exception as ex: raise exceptions.ModelError(str(ex))
class PerformanceSummary(EmbeddedDocument): """ "readServiceTimeColMillis" : 1.050376296043396, "writeServiceTimeColMillis" : 1.0604130029678345, "totalServiceTimeColMillis" : 1.4903336763381958 """ portInfo = fields.DictField(blank=True)
class DataSource(EmbeddedDocument): """Data Source class """ name = fields.StringField(blank=False) url_query = fields.StringField(blank=False) query_options = fields.DictField(blank=True) authentication = fields.EmbeddedDocumentField(Authentication)
class SchemaElement(Document): tag = fields.StringField() value = fields.StringField(default=None, blank=True) options = fields.DictField(blank=True) children = fields.ListField(fields.ReferenceField('SchemaElement'), blank=True)
class OaiSet(dme_Document): """ A set object """ setSpec = dme_fields.StringField(unique=True) setName = dme_fields.StringField(unique=True) raw = dme_fields.DictField() registry = dme_fields.StringField(blank=True) harvest = dme_fields.BooleanField(blank=True)
class Addon(Document): name = fields.StringField(unique_with=['type', 'version']) type = fields.StringField(choices=('cloud', 'service')) category = fields.StringField() author = fields.StringField() version = fields.StringField() depends = fields.ListField(fields.StringField(), blank=True) clouds = fields.ListField(fields.StringField(), blank=True) fields = fields.ListField(fields.DictField())
class TypeRenderSpec(Document): """ Storage model that specifies how to render the form for a particular XML type. :property byelem dict: a mapping of elements and attribute names to NodeRenderSpec references for the type's contents; any elements not reference will have specs generated dynamically. :property rendmod str: The class that should be used to render this type; if provided, it will be instantiated passing the config data, a label, and the byelem dictionary. :property config dict: a mapping of arbitrary string fields to data values that should be used to configure the module (ignored if module is not set). """ byelem = fields.DictField(default=dict) rendmod = fields.StringField() config = fields.DictField(default=dict)
class Image(Document): uuid = fields.StringField(max_length=255, primary_key=True) content = fields.DictField(verbose_name="Imagens") created_at = fields.DateTimeField(default=datetime.datetime.now, editable=False) @property def url_images(self): for im in self.content['images']: url = list(im.values())[0] yield os.path.join(settings.MEDIA_URL, url)
class Capacity(EmbeddedDocument): """ "dataRateKBPSAvg" : 77135, "dataRateKBPSMax" : 187243, "dataRateKBPSMin" : 582, "iopsAvg" : 1049, "iopsMax" : 2209, "iopsMin" : 145, "ioSizeAvg" : 59.896141052246094, "ioSizeMax" : 178, "ioSizeMin" : 0, "queueLengthAvg" : 0, "queueLengthMax" : 2, "queueLengthMin" : 0, "serviceTimeMSAvg" : 1.4903336763381958, "serviceTimeMSMax" : 4, "serviceTimeMSMin" : 0 """ total = fields.DictField() byType = fields.DictField() arrayType = fields.StringField()
class System(EmbeddedDocument): companyName = fields.StringField(blank=True) model = fields.StringField() fullModel = fields.StringField() osVersion = fields.StringField() patches = fields.ListField(fields.StringField(), blank=True) """ "patches" : [ "P01", "P02", "P04" ], """ sp = fields.DictField(blank=True) """ "sp" : { "spId" : "8094306", "spModel" : "ProLiant DL120 Gen9", "spVersion" : "5.0.0.0-22913 (5.0 GA)" }, """ productSKU = fields.StringField(blank=True, null=True) productFamily = fields.StringField(blank=True, null=True) recommended = fields.DictField(blank=True) """
class OaiMetadataFormat(dme_Document): """ A OaiMetadataFormat object """ metadataPrefix = dme_fields.StringField() schema = dme_fields.StringField() xmlSchema = dme_fields.StringField(blank=True) metadataNamespace = dme_fields.StringField() raw = dme_fields.DictField() template = dme_fields.ReferenceField(Template, reverse_delete_rule=PULL, blank=True) registry = dme_fields.StringField(blank=True) hash = dme_fields.StringField(blank=True) harvest = dme_fields.BooleanField(blank=True) lastUpdate = dme_fields.DateTimeField(blank=True)
class Tmall(DynamicDocument): title = fields.StringField() store_id = fields.StringField() url = fields.URLField() price = fields.FloatField() sale_num = fields.IntField() image_urls = fields.ListField() scrapy_mongodb = fields.DictField(db_field='scrapy-mongodb') def __str__(self): return self.title @property def cover(self): return self.image_urls[0]
class DataStructureElement(Document): """Represents data structure object""" tag = fields.StringField() value = fields.StringField(blank=True) options = fields.DictField(default={}, blank=True) children = fields.ListField(fields.ReferenceField('self'), blank=True) @staticmethod def get_all(): """ Returns: """ return DataStructureElement.objects.all() @staticmethod def get_all_by_child_id(child_id): """ Get Data structure element object which contains the given child id in its children Args: child_id: Returns: """ try: return DataStructureElement.objects(children=ObjectId(child_id)).all() except Exception as ex: raise exceptions.ModelError(ex.message) @staticmethod def get_by_id(data_structure_element_id): """ Returns the object with the given id Args: data_structure_element_id: Returns: DataStructureElement (obj): DataStructureElement object with the given id """ try: return DataStructureElement.objects.get(pk=str(data_structure_element_id)) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(e.message) except Exception as ex: raise exceptions.ModelError(ex.message)
class ItemCategory(Document): #CI 模型定义 name = fields.StringField(max_length=200, required=True) # name = fields.StringField(max_length=200, required=True, unique_with='group') group = fields.ReferenceField('Group') structure = fields.DictField() ctime = fields.DateTimeField(default=datetime.datetime.now()) utime = fields.DateTimeField(default=datetime.datetime.now()) meta = { "collection": "item_category", "indexes": [ "name", # "$name", "ctime", ], }
class LogFile(Document): """ Error reports for administrators """ application = fields.StringField( blank=False) # Django application name concerned by the error code = fields.IntField(blank=True) # Error code message = fields.StringField(blank=False) # Error message additionalInformation = fields.DictField( blank=True) # Dictionary of additional information timestamp = fields.DateTimeField(blank=True) # Error creation date @staticmethod def get_by_id(log_file_id): """Return a LogFile given its id. Args: log_file_id: Returns: """ try: return LogFile.objects.get(pk=str(log_file_id)) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(str(e)) except Exception as ex: raise exceptions.ModelError(str(ex)) @staticmethod def get_all(): """Return all LogFiles. Returns: """ return LogFile.objects().all() def delete_database(self): """ Delete function """ self.delete()
class OaiIdentify(Document): """Represents an identify object for Oai-Pmh Harvester""" admin_email = fields.StringField(blank=True) base_url = fields.URLField(unique=True) repository_name = fields.StringField(blank=True) deleted_record = fields.StringField(blank=True) delimiter = fields.StringField(blank=True) description = fields.StringField(blank=True) earliest_datestamp = fields.StringField(blank=True) granularity = fields.StringField(blank=True) oai_identifier = fields.StringField(blank=True) protocol_version = fields.StringField(blank=True) repository_identifier = fields.StringField(blank=True) sample_identifier = fields.StringField(blank=True) scheme = fields.StringField(blank=True) raw = fields.DictField(blank=True) registry = fields.ReferenceField(OaiRegistry, reverse_delete_rule=CASCADE, unique=True) @staticmethod def get_by_registry_id(registry_id): """Return an OaiIdentify by its registry id. Args: registry_id: The registry id. Returns: OaiIdentify instance. Raises: DoesNotExist: The OaiIdentify doesn't exist. ModelError: Internal error during the process. """ try: return OaiIdentify.objects().get(registry=str(registry_id)) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(str(e)) except Exception as e: raise exceptions.ModelError(str(e))
class OaiHarvesterSet(OaiSet): """Represents a set for Oai-Pmh Harvester""" raw = fields.DictField() registry = fields.ReferenceField( OaiRegistry, reverse_delete_rule=CASCADE, unique_with="set_spec" ) harvest = fields.BooleanField(blank=True) @staticmethod def get_all_by_registry_id(registry_id, order_by_field=None): """Return a list of OaiHarvesterSet by registry id. Possibility to order_by the list Args: registry_id: The registry id. order_by_field: Order by field. Returns: List of OaiHarvesterSet. """ return OaiHarvesterSet.objects(registry=str(registry_id)).order_by( order_by_field ) @staticmethod def get_all_by_registry_id_and_harvest(registry_id, harvest, order_by_field=None): """Return a list of OaiHarvesterSet by registry and harvest. Possibility to order_by the list. Args: registry_id: The registry id. harvest: Harvest (True/False). order_by_field: Order by field. Returns: List of OaiHarvesterSet. """ return OaiHarvesterSet.objects( registry=str(registry_id), harvest=harvest ).order_by(order_by_field) @staticmethod def get_by_set_spec_and_registry_id(set_spec, registry_id): """Return a OaiHarvesterSet by set_spec and registry. Args: set_spec: The set spec registry_id: The registry id. Returns: OaiHarvesterSet instance. Raises: DoesNotExist: The OaiHarvesterSet doesn't exist. ModelError: Internal error during the process. """ try: return OaiHarvesterSet.objects().get( set_spec=set_spec, registry=str(registry_id) ) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(str(e)) except Exception as e: raise exceptions.ModelError(str(e)) @staticmethod def delete_all_by_registry_id(registry_id): """Delete all OaiHarvesterSet used by a registry. Args: registry_id: The registry id. """ OaiHarvesterSet.get_all_by_registry_id(registry_id).delete() @staticmethod def update_for_all_harvest_by_registry_id(registry_id, harvest): """Update the harvest for all OaiHarvesterSet used by the registry. Args: registry_id: The registry id. harvest: Harvest (True/False). """ OaiHarvesterSet.get_all_by_registry_id(registry_id).update(set__harvest=harvest) @staticmethod def update_for_all_harvest_by_list_ids(list_oai_set_ids, harvest): """Update the harvest for all OaiHarvesterSet by a list of ids. Args: list_oai_set_ids: List of OaiHarvesterSet ids. harvest: Harvest (True/False) """ OaiHarvesterSet.get_all_by_list_ids(list_oai_set_ids).update( set__harvest=harvest )
class Music(Post): url = fields.StringField(max_length=100, verbose_name="Music Url") music_parameters = fields.DictField(verbose_name="Music Parameters")
class SwachhToilet(Document): qci_id = fields.StringField(max_length=100, unique=True) toilet_id = fields.StringField(max_length=100, unique=True) address = fields.StringField() latitude = fields.FloatField() longitude = fields.FloatField() location = fields.PointField() state = fields.StringField(blank=True) city = fields.StringField() category = fields.StringField(blank=True) category_code = fields.StringField(blank=True) type = fields.StringField(blank=True) opening_time = fields.StringField(blank=True) closing_time = fields.StringField(blank=True) open_days = fields.StringField(default='All Seven Days') seats = fields.IntField(default=0) gender = fields.StringField(default='Gents and Ladies') child_friendly = fields.BooleanField(default=False) differntly_abled_friedly = fields.BooleanField(default=False) fee_type = fields.StringField(default='Free of Charge') cost = fields.StringField(blank=True) image = fields.StringField(blank=True) timestamp = fields.DateTimeField(default=datetime.now) comments = fields.ListField(fields.DictField(), blank=True, default=None) meta = {'collection': 'swachh_toilets'} def __str__(self): return self.qci_id def title(self): return 'Swachh Public Toilet' def get_api_url(self, request=None): return api_reverse("api-public-toilets:detail-toilet", kwargs={'pk': str(self.pk)}, request=request) def get_comments_api_url(self, request=None): return self.get_api_url(request) + '/comments' def opened_today(self): days = week_days_in_short_format() open_days_from_db = self.open_days if open_days_from_db == 'Monday to Friday': open_days = days[:5] if open_days_from_db == 'Monday to Saturday': open_days = days[:6] elif open_days_from_db == 'Tuesday,Wednesday,Thursday,\ Friday,Saturday,Sunday': open_days = days[1:7] else: open_days = days if today_name_in_short_form() in open_days: return True def opened_all_the_day(self): return (self.opening_time == '00:00' and self.closing_time == '23:59')
class DataStructureElement(Document): """Represents data structure object""" user = fields.StringField(blank=True) tag = fields.StringField() value = fields.StringField(blank=True) options = fields.DictField(default={}, blank=True) children = fields.ListField(fields.ReferenceField("self"), blank=True) data_structure = fields.GenericLazyReferenceField("DataStructure") @staticmethod def get_all_by_child_id(child_id): """Get Data structure element object which contains the given child id in its children. Args: child_id: Returns: """ try: return DataStructureElement.objects( children=ObjectId(child_id)).all() except Exception as ex: raise exceptions.ModelError(str(ex)) @staticmethod def get_all_by_child_id_and_user(child_id, user=None): """Get Data structure element object which contains the given child id in its children and an owner of the object. Args: child_id: user: Returns: """ try: return DataStructureElement.objects(children=ObjectId(child_id), user=user).all() except Exception as ex: raise exceptions.ModelError(str(ex)) @staticmethod def get_by_id(data_structure_element_id): """Returns the object with the given id. Args: data_structure_element_id: Returns: DataStructureElement (obj): DataStructureElement object with the given id """ try: return DataStructureElement.objects.get( pk=str(data_structure_element_id)) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(str(e)) except Exception as ex: raise exceptions.ModelError(str(ex)) @staticmethod def get_by_id_and_user(data_structure_element_id, user=None): """Returns the object with the given id and the given owner. Args: data_structure_element_id: user: Returns: DataStructureElement (obj): DataStructureElement object with the given id """ try: return DataStructureElement.objects.get( pk=str(data_structure_element_id), user=user) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(str(e)) except Exception as ex: raise exceptions.ModelError(str(ex)) @staticmethod def get_by_xpath(xpath): """Returns the object with the given id. Args: xpath: Returns: DataStructureElement (obj): DataStructureElement object with the given id """ try: return DataStructureElement.objects( __raw__={"options.xpath.xml": str(xpath)}) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(str(e)) except Exception as ex: raise exceptions.ModelError(str(ex)) @staticmethod def get_by_xpath_and_user(xpath, user=None): """Returns the object with the given id and owner. Args: xpath: user: Returns: DataStructureElement (obj): DataStructureElement object with the given id """ try: return DataStructureElement.objects( __raw__={"options.xpath.xml": str(xpath)}, user=user) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(str(e)) except Exception as ex: raise exceptions.ModelError(str(ex))
class Disks(EmbeddedDocument): total = fields.DictField() byType = fields.EmbeddedDocumentField(DisksByType) state = fields.StringField()
class DisksByType(EmbeddedDocument): ssd = fields.DictField(blank=True) fc = fields.DictField(blank=True) nl = fields.DictField(blank=True)
class Authentication(EmbeddedDocument): """Authentication class """ type = fields.StringField(choices=AUTH_TYPES) params = fields.DictField(blank=True)
class Navigation(Document): """ Data structure to handle the navigation tree """ name = fields.StringField(blank=True) parent = fields.StringField(blank=True) children = fields.ListField(blank=True) options = fields.DictField(blank=True) def save_object(self): """ Custom save Returns: """ try: return self.save() except NotUniqueError: raise exceptions.ModelError( "Unable to save the navigation object: not unique.") except Exception as ex: raise exceptions.ModelError(ex.message) @staticmethod def get_all(): """ Get all Navigation. Returns: Navigation(obj): Navigation object list """ return Navigation.objects.all() @staticmethod def get_by_id(navigation_id): """ Return the object with the given id. Args: navigation_id: Returns: Navigation(obj): Navigation object """ try: return Navigation.objects.get(pk=str(navigation_id)) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(e.message) except Exception as ex: raise exceptions.ModelError(ex.message) @staticmethod def get_by_name(navigation_name): """ Return the object with the given name. Args: navigation_name: Returns: Navigation(obj): Navigation object list """ return Navigation.objects(name=str(navigation_name)).all()
class AbstractData(Document): """AbstractData object""" dict_content = fields.DictField(blank=True) title = fields.StringField(blank=False, validation=not_empty_or_whitespaces) xml_file = fields.FileField(blank=False, collection_name=GRIDFS_DATA_COLLECTION) creation_date = fields.DateTimeField(blank=True, default=None) last_modification_date = fields.DateTimeField(blank=True, default=None) last_change_date = fields.DateTimeField(blank=True, default=None) _xml_content = None meta = { "abstract": True, } @property def xml_content(self): """Get xml content - read from a saved file. Returns: """ # private field xml_content not set yet, and reference to xml_file to read is set if self._xml_content is None and self.xml_file is not None: # read xml file into xml_content field xml_content = self.xml_file.read() try: self._xml_content = (xml_content.decode("utf-8") if xml_content else xml_content) except AttributeError: self._xml_content = xml_content # return xml content return self._xml_content @xml_content.setter def xml_content(self, value): """Set xml content - to be saved as a file. Args: value: Returns: """ # update modification times self.last_modification_date = datetime_now() # update content self._xml_content = value def convert_and_save(self): """Save Data object and convert the xml to dict if needed. Returns: """ self.convert_to_dict() self.convert_to_file() return self.save_object() def convert_to_dict(self): """Convert the xml contained in xml_content into a dictionary. Returns: """ # transform xml content into a dictionary dict_content = xml_utils.raw_xml_to_dict(self.xml_content, xml_utils.post_processor) # if limit on element occurrences is set if SEARCHABLE_DATA_OCCURRENCES_LIMIT is not None: # Remove lists which size exceed the limit size xml_utils.remove_lists_from_xml_dict( dict_content, SEARCHABLE_DATA_OCCURRENCES_LIMIT) # store dictionary self.dict_content = dict_content def convert_to_file(self): """Convert the xml string into a file. Returns: """ try: xml_file = BytesIO(self.xml_content.encode("utf-8")) except Exception: xml_file = BytesIO(self.xml_content) if self.xml_file.grid_id is None: # new file self.xml_file.put(xml_file, content_type="application/xml") else: # editing (self.xml_file gets a new id) self.xml_file.replace(xml_file, content_type="application/xml") def save_object(self): """Custom save. Set the datetime fields and save. Returns: """ try: # initialize times now = datetime_now() # update change date every time the data is updated self.last_change_date = now if not self.id: # initialize when first created self.creation_date = now # initialize when first saved, then only updates when content is updated self.last_modification_date = now return self.save() except mongoengine_errors.NotUniqueError as e: raise exceptions.NotUniqueError(e) except Exception as ex: raise exceptions.ModelError(ex)
class PerformanceBandwidth(EmbeddedDocument): total = fields.DictField(blank=True) read = fields.DictField(blank=True) write = fields.DictField(blank=True)