class DataDir(Document): name = fields.StringField(max_length=2048) path = fields.StringField(max_length=2048) realm = fields.StringField(max_length=2048) def __unicode__(self): return self.name + "/" + self.realm + "/" + self.path
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 AccountRequest(Document): """ Represents a request sent by an user to get an account """ username = fields.StringField( blank=False) #: Username associated with the request first_name = fields.StringField(blank=False) last_name = fields.StringField(blank=False) email = fields.StringField(blank=False) date = fields.DateTimeField(default=datetime.datetime.now, blank=False) @staticmethod def get_by_id(request_id): """ Get a request given its primary key Parameters: request_id (str): Primary key of the request Returns: Request object corresponding to the given id """ try: return AccountRequest.objects().get(pk=str(request_id)) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(e.message) except Exception as ex: raise exceptions.ModelError(ex.message)
class User(Document): name = fields.StringField() username = fields.StringField(unique=True) email = fields.EmailField(unique=True) # these 2 fields are NOT TO BE FILLED ratings = fields.IntField(default=0) date_joined = fields.DateTimeField(default=timezone.now, editable=False) gears = fields.ListField(fields.ReferenceField('Gear'), default=[], blank=True) password = fields.StringField(min_length=8, max_length=128) USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['name', 'email', 'password'] def __str__(self): return self.username def get_username(self): return self.username def get_name(self): return self.name def get_ratings(self): return self.ratings def is_active(self): return True def check_password(self, raw_password): """ Checks the password if it matches the stored password """ return check_password(raw_password, self.password)
class ContentType(document.Document): name = fields.StringField(max_length=100) app_label = fields.StringField(max_length=100) model = fields.StringField(max_length=100, verbose_name=_('python model class name'), unique_with='app_label') objects = ContentTypeManager() class Meta: verbose_name = _('content type') verbose_name_plural = _('content types') # db_table = 'django_content_type' # ordering = ('name',) # unique_together = (('app_label', 'model'),) def __unicode__(self): return self.name def model_class(self): "Returns the Python model class for this type of content." from django.db import models return models.get_model(self.app_label, self.model) def get_object_for_this_type(self, **kwargs): """ Returns an object of this type for the keyword arguments given. Basically, this is a proxy around this object_type's get_object() model method. The ObjectNotExist exception, if thrown, will not be caught, so code that calls this method should catch it. """ return self.model_class()._default_manager.using( self._state.db).get(**kwargs) def natural_key(self): return (self.app_label, self.model)
class GlobalElement(Document): """ Storage model for a globally defined element within a schema document. Such an element can be used as the root element of a document. :property name str: the local name for the element :property namespace str: the namespace URI of the schema within which the element is defined :property version int: the version of the schema document that this :property schemaname str: the unique name given to the schema document where the element is defined element is defined in :property schema ref: a reference to the SchemaVersion record where this version of the element is defined :property annots ref: a reference to the GlobalElementAnnots that contains user annotations. """ name = fields.StringField( unique_with=["namespace", "schemaname", "version"]) namespace = fields.StringField() schemaname = fields.StringField() version = fields.IntField() schema = fields.ReferenceField(SchemaVersion) annots = fields.ReferenceField(GlobalElementAnnots) @property def qname(self): """ the type's qualified name of the form "{NS}LOCAL-NAME" """ return "{{{0}}}{1}".format(self.namespace, self.name) @classmethod def get_all_elements(cls): """ return all of the global elements from all the representative namespaces that aren't marked as hidden. :return dict: a dictionary that has namespaces as keys and GlobalElement records as values. """ currents = {} scs = SchemaCommon.objects.filter(current__gt=0) for sc in scs: sv = SchemaVersion.get_by_version(sc.name, sc.current) if sv: currents[sc.name] = sc.current elsbyns = {} for name in currents: glels = GlobalElement.objects.filter(schemaname=name) \ .filter(version=currents[name]) for el in glels: if el.annots.hide: continue if el.namespace not in elsbyns: elsbyns[el.namespace] = [] elsbyns[el.namespace].append(el) return elsbyns
class HistoryQuery(Document): """ History object to retrieve a query to a specific step """ user_id = fields.IntField() # User link to the history query_id = fields.StringField() # Query link to the history message = fields.StringField() # History message status = fields.IntField( ) # History status (0: Query step, 1: Waiting for treatment, 2: Output files created) @staticmethod def get_by_id(history_query_id): """ Return a HistoryQuery given its id. Args: history_query_id: Returns: """ try: return HistoryQuery.objects.get(pk=str(history_query_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 a list of all HistoryQuery. Returns: """ return HistoryQuery.objects().all() @staticmethod def get_all_by_user_id(user_id): """ Return a list of HistoryQuery given their user_id. Args: user_id: Returns: """ return HistoryQuery.objects.filter(user_id=str(user_id)) def delete_database(self, from_query_admin=False): """ Delete function. If the deletion come from the admin panel, Delete all the user query linked to this history. Args: from_query_admin: Variable to avoid circle deletion. """ if not from_query_admin: temp_user_queries = TempUserQuery.objects.filter(id=self.query_id) for temp_user_query in temp_user_queries: temp_user_query.delete_database(from_history=True) self.delete()
class ExportedCompressedFile(Document): """ Represents exported files """ file_name = fields.StringField() file = fields.FileField( blank=True, collection_name=GRIDFS_EXPORTED_COMPRESSED_FILE_COLLECTION) is_ready = fields.BooleanField(default=False) mime_type = fields.StringField() @staticmethod def get_by_id(object_id): """ Get Exported compressed file with the given id Args: object_id: Returns: """ try: return ExportedCompressedFile.objects.get(pk=str(object_id)) except mongoengine_errors.DoesNotExist as e: raise exceptions.DoesNotExist(e.message) except Exception as ex: raise exceptions.ModelError(ex.message)
class Post(Document): created_at = fields.DateTimeField( default=datetime.datetime.now, required=True, editable=False, ) title = fields.StringField(max_length=255, required=True) slug = fields.StringField(max_length=255, required=True, primary_key=True) comments = fields.ListField(fields.EmbeddedDocumentField('Comment')) def get_absolute_url(self): return reverse('post', kwargs={"slug": self.slug}) def __unicode__(self): return self.title @property def post_type(self): return self.__class__.__name__ meta = { 'indexes': ['-created_at', 'slug'], 'ordering': ['-created_at'], 'allow_inheritance': True }
class Comment(fields.EmbeddedDocument): created_at = fields.DateTimeField(default=datetime.datetime.now, required=True) author = fields.StringField(verbose_name="Name", max_length=255, required=True) body = fields.StringField(verbose_name="Comment", required=True)
class LocalId(Document): """Handle object""" record_name = fields.StringField(blank=False, unique=True, regex=NOT_EMPTY_OR_WHITESPACES) record_object_class = fields.StringField(blank=True) record_object_id = fields.StringField(blank=True) @staticmethod def get_by_name(record_name): try: return LocalId.objects.get(record_name=record_name) except mongoengine_errors.DoesNotExist as dne: raise exceptions.DoesNotExist(str(dne)) except Exception as exc: raise exceptions.ModelError(str(exc)) @staticmethod def get_by_class_and_id(record_object_class, record_object_id): try: return LocalId.objects.get( record_object_class=record_object_class, record_object_id=record_object_id, ) except mongoengine_errors.DoesNotExist as dne: raise exceptions.DoesNotExist(str(dne)) except Exception as exc: raise exceptions.ModelError(str(exc))
class ContactMessage(Document): """Represents a message sent via the Contact form""" name = fields.StringField(max_length=100) email = fields.EmailField() content = fields.StringField() @staticmethod def get_by_id(message_id): """Get a message using its primary key Args: message_id: Returns: """ try: return ContactMessage.objects().get(pk=str(message_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(): """Get all messages Returns: """ return ContactMessage.objects.all()
class Comment(EmbeddedDocument): created_at = fields.DateTimeField( default=datetime.datetime.now, editable=False, ) author = fields.StringField(verbose_name="Name", max_length=255) email = fields.EmailField(verbose_name="Email", blank=True) body = fields.StringField(verbose_name="Comment")
class TemplateVersion(Document): """ Storage model for storing different versions of a template. :property name str: the template name being versioned :property version seq: the version for this template :property common ref: a reference to the common information record in the Template collection :property label str: the label to give to the root element :property spec ref: the TypeRenderSpec object to use to render the root element; if not set, this will be generated dynamically. :property tranforms ref: a reference to a record in Transforms that identifies the XSL stylesheets :property deleted bool: True if this version is currently deleted :property comment str: A brief (displayable) comment noting what is different about this version. """ name = fields.StringField(blank=False) version = fields.SequenceField(blank=False) common = fields.ReferenceField(TemplateCommon, blank=False) schema = fields.ReferenceField(SchemaVersion, blank=False) extschemas = fields.ListField(SchemaVersion, blank=True, default=[]) label = fields.StringField() spec = fields.ReferenceField(TypeRenderSpec, blank=True) # transforms = fields.ReferenceField(Transforms, blank=True) deleted = fields.BooleanField(blank=False, default=False) comment = fields.StringField(default="") @classmethod def get_all_by_name(cls, name, include_deleted=False): """ return a list of TemplateVersion records that have given name :param name str: the name of the template to match :param include_deleted bool: if False, return only records that have not been marked as deleted. """ vers = TemplateVersion.objects.filter(name=name) if not include_deleted: vers = vers.filter(deleted=False) return vers @classmethod def get_by_version(cls, name, version, include_deleted=False): """ return the TemplateVersion record with a given name and version. :param name str: the name of the schema to match :param version int: the version of the schema to select :param include_deleted bool: if False, return only records that have not been marked as deleted. """ vers = cls.get_all_by_name(name, include_deleted).filter(version=version) if len(vers) > 0: return vers[0] return None
class DataStructure(Document): """Stores data being entered and not yet curated""" user = fields.StringField() template = fields.ReferenceField(Template) name = fields.StringField(unique_with=['user', 'template']) data_structure_element_root = fields.ReferenceField(DataStructureElement, blank=True) meta = {'abstract': True} @staticmethod def get_by_id(data_structure_id): """ Returns the object with the given id Args: data_structure_id: Returns: Data Structure (obj): DataStructure object with the given id """ # FIXME: temporary solution to query concrete children of abstract class # (https://github.com/MongoEngine/mongoengine/issues/741) data_structure = None # iterate concrete data structure classes for subclass in DataStructure.__subclasses__(): try: # get data structure from concrete subclass data_structure = subclass.get_by_id(data_structure_id) # break if found break except: # data structure not found, continue search pass # data structure found if data_structure is not None: # return data structure return data_structure else: # raise exception raise exceptions.DoesNotExist("No data structure found for the given id.") @classmethod def pre_delete(cls, sender, document, **kwargs): """ Pre delete operations Returns: """ # Delete data structure elements document.delete_data_structure_elements_from_root() def delete_data_structure_elements_from_root(self): """ Delete all data structure elements from the root Returns: """ if self.data_structure_element_root is not None: delete_branch_task.apply_async((str(self.data_structure_element_root.id),))
class Historico(Document): stock = fields.StringField(max_length=255) open = fields.DecimalField(max_digits=10, decimal_places=2) high = fields.DecimalField(max_digits=10, decimal_places=2) low = fields.DecimalField(max_digits=10, decimal_places=2) close = fields.DecimalField(max_digits=10, decimal_places=2) volume = fields.DecimalField(max_digits=10, decimal_places=2) date = fields.StringField(max_length=60)
class Setup(Document): user = fields.StringField(max_length=50) service = fields.StringField(max_length=50) cloud = fields.StringField(max_length=50) options = fields.EmbeddedDocumentField(Options, blank=True) playbook = fields.ReferenceField(AnsiblePlaybook, blank=True) key_id = fields.ReferenceField(Key, blank=True) status = fields.StringField()
class Result(Document): """Result class """ title = fields.StringField(blank=False) xml_content = fields.StringField(blank=False) template_info = fields.EmbeddedDocumentField(TemplateInfo) detail_url = fields.StringField(blank=True) access_data_url = fields.StringField(blank=True)
class FormData(dme_Document): """Stores data being entered and not yet curated""" user = dme_fields.StringField() template = dme_fields.StringField() name = dme_fields.StringField(unique_with=['user', 'template']) schema_element_root = dme_fields.ReferenceField(SchemaElement, blank=True) xml_data = dme_fields.StringField(default='') xml_data_id = dme_fields.StringField(blank=True)
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 Notifications(EmbeddedDocument): user_id = fields.StringField(unique=False) notification_id = fields.StringField(unique=False) notification_received_at = fields.DateTimeField(default=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), unique=False) notification_type = fields.IntField() notification_details = fields.EmbeddedDocumentField(NotificationDetails, required=False, default= None, blank=True,unique=False)
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 Author(Document): id = fields.StringField(primary_key=True, default=ObjectId) name = fields.StringField(max_length=100) slug = fields.StringField() _meta = {"ordering": ["name"], "exclude": "id"} def __unicode__(self): return self.name or ""
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 CommentDetails(EmbeddedDocument): comment_id = fields.StringField(unique=False) notification_id = fields.StringField(unique=False) user_id = fields.StringField(unique=False) comment = fields.StringField(unique=False) created_at = fields.DateTimeField( default=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") , required=True, unique=False )
class ReportPosts(Document): post_id = fields.StringField(max_length=36,required=True) user_id = fields.StringField(required=True, max_length=36) report_id = fields.StringField(max_length=36,required=True) report_type = fields.IntField(default=0) created_at = fields.DateTimeField( default=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") , required=True, unique=False )
class WebTxLocal(Document): sender = fields.StringField(max_length=250) page_hash = fields.StringField(max_length=250) page_name = fields.StringField(max_length=250) last_page_hash = fields.StringField(max_length=250) timestamp = fields.IntField(default=0) page_content = fields.StringField(default='', max_length=2000000) def __unicode__(self): return self.page_hash
class Result(Document): """Result class""" title = fields.StringField(blank=False) xml_content = fields.StringField(blank=False) template_info = fields.EmbeddedDocumentField(TemplateInfo) permission_url = fields.StringField(blank=True, null=True) detail_url = fields.StringField(blank=True) access_data_url = fields.StringField(blank=True) last_modification_date = fields.DateTimeField(blank=True, default=None)
class Bucket(Document): """Bucket class to store types by domain.""" label = fields.StringField(unique=True) color = fields.StringField(unique=True) types = fields.ListField(fields.ReferenceField(TypeVersionManager), blank=True) @staticmethod def get_by_id(bucket_id): """Return a bucket given its id. Args: bucket_id: Returns: """ try: return Bucket.objects.get(pk=str(bucket_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 buckets. Returns: """ return Bucket.objects().all() @staticmethod def get_colors(): """Return all colors. Returns: """ return Bucket.objects.values_list("color") def save_object(self): """Custom save Returns: """ try: return self.save() except mongoengine_errors.NotUniqueError as e: raise exceptions.NotUniqueError(str(e)) except Exception as ex: raise exceptions.ModelError(str(ex))
class Key(Document): key = fields.StringField(max_length=2048) name = fields.StringField(max_length=2048) email = fields.StringField(max_length=2048) def save(self, *args, **kwargs): self.key = binascii.hexlify(os.urandom(24)).decode('utf-8') super(Key, self).save(*args, **kwargs) def __unicode__(self): return self.name + "/" + self.email + "/" + self.key