Ejemplo n.º 1
0
class Posts(Document):
    post_id = SequenceField()

    title = StringField()
    description = StringField()

    created_at = DateTimeField(default=datetime.utcnow)
Ejemplo n.º 2
0
class NurseModel(RidDocument):
    rid = SequenceField(
        unique=True
    )  # Overriding to use own counter rather than the one common to all RidDocument childs.
    user = ReferenceField(UserModel,
                          required=True,
                          unique=True,
                          reverse_delete_rule=2)
    name = StringField(min_lenght=1, max_length=255, required=True)
    treatment_types = ListField(ReferenceField(TreatmentTypeModel,
                                               required=False),
                                default=list)
    agenda = SortedListField(DateTimeField(), required=False, default=list())

    def clean(self):
        errs = dict()
        self.agenda.sort()
        for i in range(len(self.agenda) - 1):
            if self.agenda[i].date() == self.agenda[i + 1].date():
                errs["agenda"] = "Can only have one agenda per day!"

        duplicates = find_duplicates(self.treatment_types)
        if duplicates:
            errs[
                "treatment_types"] = f"Treatment types list cannot contains duplicate elements."

        if errs:
            raise ValidationError(errors=errs)
Ejemplo n.º 3
0
class MongoJob(Document):
    """
    Document of job in metadata backend storage.
    """

    uuid = SequenceField(db_alias=MONGO_DB_ALIAS_META_SERVICE)
    name = StringField(max_length=255, required=True, unique=True)
    workflow_execution_id = IntField()
    job_id = StringField(max_length=1000)
    properties = StringField(max_length=1000)
    start_time = LongField()
    end_time = LongField()
    job_state = StringField(max_length=256)
    log_uri = StringField(max_length=256)
    signature = StringField(max_length=1000)
    is_deleted = BooleanField(default=False)

    meta = {'db_alias': MONGO_DB_ALIAS_META_SERVICE}

    def __repr__(self):
        return '<Document Job ({}, {}, {}, {}, {}, {}, {}, {}, {}, {})>'.format(
            self.uuid,
            self.job_str_id,
            self.name,
            self.properties,
            self.start_time,
            self.end_time,
            self.job_state,
            self.log_uri,
            self.signature,
            self.workflow_execution_id)
Ejemplo n.º 4
0
class MongoProject(Document):
    """
    Document of project in metadata backend storage.
    """
    
    uuid = SequenceField(db_alias=MONGO_DB_ALIAS_META_SERVICE)
    name = StringField(max_length=255, required=True, unique=True)
    properties = StringField(max_length=1000)
    project_type = StringField(max_length=1000)
    user = StringField(max_length=1000)
    password = StringField(max_length=1000)
    uri = StringField(max_length=1000)
    is_deleted = BooleanField(default=False)

    model_relation = ListField(ReferenceField(MongoModelRelation))
    workflow_execution = ListField(ReferenceField(MongoWorkflowExecution))

    meta = {'db_alias': MONGO_DB_ALIAS_META_SERVICE}

    def __repr__(self):
        return '<Document Project ({}, {}, {}, {}, {}, {}, {})>'.format(
            self.uuid,
            self.name,
            self.properties,
            self.project_type,
            self.user,
            self.password,
            self.uri)
Ejemplo n.º 5
0
class Thing(Document, Base):
    meta = {'indexes': [{'fields': ('company', 'name'), 'unique': True}]}
    id = SequenceField(primary_key=True)
    name = StringField(nullable=False)
    description = StringField(nullable=True)
    company = ReferenceField('Company', nullable=False)
    deleted = BooleanField(default=False)
Ejemplo n.º 6
0
class Company(Document, Base):
    id = SequenceField(primary_key=True)
    name = StringField(unique=True)
    status = StringField(default='trialling')
    created = DateTimeField(default=datetime.now)
    owner = ReferenceField('Person', reverse_delete_rule=DENY)

    def save(self, *args, **kwargs):

        # Create default Roles
        admin = Role(name='Administrator',
                     theme='success',
                     company=self,
                     permissions=[
                         'edit_events', 'edit_people', 'edit_places',
                         'edit_system_settings'
                     ]).save()
        Role(name='Regular User',
             theme='primary',
             company=self,
             permissions=['edit_events', 'edit_people', 'edit_places']).save()
        Role(name='Read-Only User',
             theme='warning',
             company=self,
             permissions=['view_events', 'view_people', 'view_places']).save()

        # Set owner as Admin
        self.owner.update(role=admin,
                          role_name=admin.name,
                          role_theme=admin.theme,
                          active=True)

        return super(Company, self).save(*args, **kwargs)
Ejemplo n.º 7
0
class MongoArtifact(Document):
    """
    Document of artifact in metadata backend storage.
    """

    uuid = SequenceField(db_alias=MONGO_DB_ALIAS_META_SERVICE)
    name = StringField(max_length=255, required=True, unique=True)
    data_format = StringField(max_length=256)
    description = StringField(max_length=1000)
    batch_uri = StringField(max_length=1000)
    stream_uri = StringField(max_length=1000)
    create_time = LongField()
    update_time = LongField()
    properties = StringField(max_length=1000)
    is_deleted = BooleanField(default=False)

    meta = {'db_alias': MONGO_DB_ALIAS_META_SERVICE}

    def __repr__(self):
        return '<Document Artifact ({}, {}, {}, {}, {}, {}, {}, {}, {}, {})>'.format(
            self.pk,
            self.name,
            self.data_format,
            self.description,
            self.batch_uri,
            self.stream_uri,
            self.create_time,
            self.update_time,
            self.properties,
            self.is_deleted)
Ejemplo n.º 8
0
class User(DynamicDocument):
    """
    用户信息表
    """

    uid = SequenceField(primary_key=True,
                        value_decorator=uid_value_decorator)  # 用户id
    username = StringField(max_length=100, required=True)
    password_hash = StringField(max_length=200, required=True)
    phone = StringField(max_length=200, unique=True, required=True)
    create_time = DateTimeField(default=datetime.datetime.now)  # 记录的创建时间
    update_time = DateTimeField(default=datetime.datetime.now,
                                onupdate=datetime.datetime.now)  # 记录的最后更新时间

    def hash_password(self, password):
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        return check_password_hash(self.password_hash, password)

    meta = {
        "collection": "user",
        "db_alias": "default",
        "shard_key": ("uid", )
    }

    def __init__(self, *args, **kwargs):
        super(User, self).__init__(*args, **kwargs)

    @property
    def id(self):
        return self.uid
Ejemplo n.º 9
0
class UserModel(RidDocument):
    """User mongoengine model. Defines methods to work with password hash.

    Notes
    -----
        Only set `password` with an hash.
    """
    rid = SequenceField(
        unique=True
    )  # Overriding to use own counter rather than the one commun to all RidDocument childs.
    username = StringField(min_lenght=1,
                           max_length=64,
                           required=True,
                           unique=True)
    usertype = IntField(choices={0, 1}, required=True)

    password = StringField(min_lenght=1, required=True)

    @staticmethod
    def hash_password(password):
        """Hash and returns password."""
        return sha256.hash(password)

    def set_password(self, password):
        """Hash and set password."""
        self.password = self.hash_password(password)

    def verify_password(self, password):
        """Hash password and compares it to stored value."""
        return sha256.verify(password, self.password)
Ejemplo n.º 10
0
class TaskDocument(Document):
    counter = SequenceField()
    title = StringField()
    project = ReferenceField(ProjectDocument)
    status = StringField(
        choices=['new', 'pending', 'pausing', 'waiting', 'done'])
    tags = ListField(ReferenceField(TagDocument))
    created_at = DateTimeField(default=datetime.datetime.utcnow())
    updated_at = DateTimeField(default=datetime.datetime.utcnow())
    user = StringField()

    def to_dict(self):
        rec = {
            'id':
            str(self.id).decode('unicode-escape'),
            'counter':
            str(self.counter).decode('unicode-escape'),
            'title':
            self.title,
            'project_id':
            str(self.project.id).decode('unicode-escape')
            if self.project is not None else '',
            'status':
            self.status,
            'tags_ref':
            [str(tag.id).decode('unicode-escape') for tag in self.tags],
            'created_at':
            self.created_at.isoformat().decode('unicode-escape'),
            'updated_at':
            self.updated_at.isoformat().decode('unicode-escape'),
            'user':
            self.user
        }
        return rec
Ejemplo n.º 11
0
class TreatmentTypeModel(RidDocument):
    rid = SequenceField(
        unique=True
    )  # Overriding to use own counter rather than the one commun to all RidDocument childs.
    code = IntField(required=True, unique=True)
    name = StringField(min_length=1, max_length=255)
    duration = IntField(required=True)
Ejemplo n.º 12
0
class MongoExample(Document):
    """
    Document of example in metadata backend storage.
    """

    uuid = SequenceField(db_alias=MONGO_DB_ALIAS_META_SERVICE)
    name = StringField(max_length=255, required=True, unique=True)
    support_type = StringField(max_length=256, required=True)
    data_type = StringField(max_length=256)
    format = StringField(max_length=256)
    description = StringField(max_length=1000)
    batch_uri = StringField(max_length=1000)
    stream_uri = StringField(max_length=1000)
    create_time = LongField()
    update_time = LongField()
    properties = StringField(max_length=1000)
    name_list = StringField(max_length=1000)
    type_list = StringField(max_length=1000)
    catalog_name = StringField(max_length=1000)
    catalog_type = StringField(max_length=1000)
    catalog_database = StringField(max_length=1000)
    catalog_connection_uri = StringField(max_length=1000)
    catalog_version = StringField(max_length=1000)
    catalog_table = StringField(max_length=1000)
    is_deleted = BooleanField(default=False)

    meta = {'db_alias': MONGO_DB_ALIAS_META_SERVICE}

    def __repr__(self):
        return '<Document Example ({}, {}, {}, {}, {}, {}, {}, {}, {})>'.format(
            self.uuid, self.name, self.properties, self.support_type,
            self.name_list, self.type_list, self.format, self.batch_uri,
            self.stream_uri)
Ejemplo n.º 13
0
class MongoWorkflowExecution(Document):
    """
    Document of workflow execution in metadata backend storage.
    """

    uuid = SequenceField(db_alias=MONGO_DB_ALIAS_META_SERVICE)
    name = StringField(max_length=255, required=True, unique=True)
    project_id = IntField()
    properties = StringField(max_length=1000)
    start_time = LongField()
    end_time = LongField()
    execution_state = StringField(max_length=256)
    log_uri = StringField(max_length=1000)
    workflow_json = StringField()
    signature = StringField(max_length=1000)
    is_deleted = BooleanField(default=False)

    job_info = ListField(ReferenceField(MongoJob))
    model_version_relation = ListField(
        ReferenceField(MongoModelVersionRelation))

    meta = {'db_alias': MONGO_DB_ALIAS_META_SERVICE}

    def __repr__(self):
        return '<Document WorkflowExecution ({}, {}, {}, {}, {}, {}, {}, {}, {}, {})>'.format(
            self.uuid, self.name, self.properties, self.start_time,
            self.end_time, self.execution_state, self.log_uri,
            self.workflow_json, self.signature, self.project_id)
Ejemplo n.º 14
0
class TreatmentModel(RidDocument):
    rid = SequenceField(unique=True)  # Overriding to use own counter rather than the one common to all RidDocument childs.
    patient = ReferenceField(PatientModel, required=True, reverse_delete_rule=2)
    ttype = ReferenceField(TreatmentTypeModel, required=True, reverse_delete_rule=2)
    date = DateField(required=True)
    time = DateTimeField(default=None)
    nurse = ReferenceField(NurseModel, default=None, reverse_delete_rule=2)
Ejemplo n.º 15
0
class MongoMetricMeta(Document):
    """
    Document of metric meta
    """

    uuid = SequenceField(db_alias=MONGO_DB_ALIAS_META_SERVICE)
    name = StringField(max_length=255, required=True, unique=True)
    dataset_id = IntField()
    model_name = StringField(max_length=256)
    model_version = StringField(max_length=500)
    job_id = IntField()
    start_time = LongField()
    end_time = LongField()
    metric_type = StringField(max_length=256, default=MetricType.DATASET.value)
    uri = StringField(max_length=1000)
    tags = StringField(max_length=256)
    metric_description = StringField(max_length=4096)
    properties = StringField(max_length=1000)
    is_deleted = BooleanField(default=False)

    meta = {'db_alias': MONGO_DB_ALIAS_META_SERVICE}

    def __repr__(self):
        return '<Document MetricMeta ({}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})>' \
            .format(self.name,
                    self.dataset_id,
                    self.model_id,
                    self.job_id,
                    self.start_time,
                    self.end_time,
                    self.metric_type,
                    self.metric_description,
                    self.uri,
                    self.tags,
                    self.properties)
Ejemplo n.º 16
0
class Option(EmbeddedDocument):
    Id = SequenceField()
    title = StringField(required=True)
    value = IntField(default=0)

    def inc(self, value):
        self.value += value
        self.save()
Ejemplo n.º 17
0
class ImageDoc(Document):

    id_no = SequenceField()
    description = StringField()
    #asfdffimage = ImageField(thumbnail_size=(120, 100, True))
    image = FileField()  # sdf
    url = StringField()
    create = DateTimeField(default=datetime.datetime.now)
Ejemplo n.º 18
0
class Role(Document, Base):
    meta = {'indexes': [{'fields': ('company', 'name'), 'unique': True}]}
    id = SequenceField(primary_key=True)
    name = StringField(nullable=False)
    theme = StringField(nullable=False)
    company = ReferenceField('Company', nullable=False)
    permissions = ListField(StringField(nullable=False), nullable=False)
    deleted = BooleanField(default=False)
Ejemplo n.º 19
0
class Quote(Document):
    id_no = SequenceField()
    body = StringField(required=True, unique=True)
    author = StringField()
    create = DateTimeField(default=datetime.datetime.now)

    meta = {
        'ordering': ['-create'],
    }
Ejemplo n.º 20
0
class Account(Document):
    id = SequenceField(required=True, primary_key=True)
    name = StringField(required=True)
    user = StringField(required=True)
    timestamp = DateTimeField(default=datetime.utcnow)
    status = BooleanField(default=True)

    def validate(self, clean=True):
        if Utility.check_empty_string(self.name):
            raise ValidationError("Account Name cannot be empty or blank space")
Ejemplo n.º 21
0
class Course(Document):
    '''Course class
    '''
    courseId = SequenceField()
    courseName = StringField(max_length=100)
    description = StringField(max_length=8000)
    suitableFor = StringField(max_length=200)
    courseLevel = StringField()
    language = StringField(max_length=100)
    active = IntField(default=1)  # 0 = inactive, 1 = active
Ejemplo n.º 22
0
class Place(Document, Base):
    meta = {'indexes': [{'fields': ('company', 'name'), 'unique': True}]}
    id = SequenceField(primary_key=True)
    name = StringField(nullable=False)
    address = StringField(nullable=False)
    directions = StringField()
    mail = StringField()
    phone = StringField()
    company = ReferenceField('Company', nullable=False)
    deleted = BooleanField(default=False)
Ejemplo n.º 23
0
class DBTaskHandler(Document):
    task_id = SequenceField(primary_key=True)
    stock_name = StringField(required=True, max_length=200)
    stock_code = StringField(required=True, max_length=200)

    obj_amount = StringField(required=True, max_length=200)

    strategy_name = StringField(required=True, max_length=200)
    riskctrl_name = StringField(required=True, max_length=200)
    gateway_name = StringField(required=True, max_length=200)
Ejemplo n.º 24
0
class Dog(Document):

    identifier = SequenceField(primary_key=True)
    name = StringField(min_length=4, max_length=20)
    age = IntField(min_value=0)
    race = StringField(min_length=4)
    gender = StringField(choice=GENDERS_DOG)
    owner = ReferenceField(User)

    meta = {'queryset_class': DogQuerySet}
Ejemplo n.º 25
0
class VoteRecord(BaseDocument):
    Id = SequenceField()
    vote = ReferenceField(BlindVote)
    options = EmbeddedDocumentListField(Option, default=list)
    track_id = StringField(required=True)

    @classmethod
    def get_records_by_vote_id(cls, vote_id):
        vote = BlindVote.get_by_id(vote_id)
        records = cls.objects(vote=vote)
        return records
Ejemplo n.º 26
0
class Notification(Document, Base):
    id = SequenceField(primary_key=True)
    stamp = DateTimeField(default=datetime.now)
    body = StringField()
    message = StringField(nullable=True)
    company = ReferenceField('Company')
    owner = ReferenceField('Person')

    def to_dict(self):
        output = self.to_mongo()
        output['stamp'] = str(output['stamp'])
        return output
class Product(Document):
    product_id = SequenceField(primary_key=True)
    product_name = StringField()
    product_description = StringField()
    product_category = StringField(default="Minerals")
    product_image_gallery = EmbeddedDocumentListField(ProductImage)
    product_size_metrics = DictField(default={
        'min_size': 10,
        'max_size': 100,
        'metrics': 'mm'
    })
    product_created_timestamp = DateTimeField(
        default=datetime.datetime.utcnow())
Ejemplo n.º 28
0
class Content(DynamicDocument):
    """
    日记内容表
    """
    cid = SequenceField(primary_key=True,
                        value_decorator=con_value_decorator)  # 文章id
    phone = StringField(max_length=200, required=True)
    uid = SequenceField(max_length=100, required=True)  # 用户id
    username = StringField(max_length=100, required=True)
    title = StringField(max_length=100, required=True)
    data = StringField(max_length=100, required=True)  # 发布时间
    text = StringField(max_length=100000, required=True)
    status = IntField(required=True)  # 是否公开
    create_time = DateTimeField(default=datetime.datetime.now)  # 记录的创建时间
    update_time = DateTimeField(default=datetime.datetime.now,
                                onupdate=datetime.datetime.now)  # 记录的最后更新时间

    meta = {
        "collection": "content",
        "db_alias": "default",
        "shard_key": ("phone", "cid")
    }
Ejemplo n.º 29
0
class BaseArticle(Document):

    id_no = SequenceField()
    title = StringField(required=True)
    create_time = DateTimeField(default=datetime.datetime.now)
    md_content = StringField()
    html_content = StringField()
    img_list = ListField(StringField(), default=[])
    is_del = IntField(default=0, choices=(0, 1))

    meta = {
        'allow_inheritance': True,
        'abstract': True,
    }
Ejemplo n.º 30
0
class MongoMetricSummary(Document):
    """
    Document of metric summary
    """

    uuid = SequenceField(db_alias=MONGO_DB_ALIAS_META_SERVICE)
    metric_id = IntField()
    metric_key = StringField(max_length=128, required=True)
    metric_value = StringField(max_length=2048, required=True)
    is_deleted = BooleanField(default=False)

    meta = {'db_alias': MONGO_DB_ALIAS_META_SERVICE}

    def __repr__(self):
        return '<Document MetricSummary ({}, {}, {})>'.format(self.metric_id, self.metric_key, self.metric_value)