Ejemplo n.º 1
0
class Item(db.Document):

    item_id = db.SequenceField(primary_key=True)

    submitted_at = db.DateTimeField(default=datetime.datetime.now,
                                    required=True)

    titles = db.ListField(db.EmbeddedDocumentField(Title), required=True)

    submitter = db.ReferenceField(User)

    category = db.ReferenceField(Category)

    files = db.ListField(db.FileField())

    github = db.URLField()

    blog_post = db.URLField()

    tags = db.ListField(db.StringField(max_length=30))

    description = db.StringField()

    thumbnail = db.ImageField(thumbnail_size=(230, 330, True))

    license = db.ReferenceField(License)

    has_api = db.BooleanField()
    api_url = db.URLField()

    def get_thumbnail(self):
        from flask import url_for
        if self.thumbnail:
            return url_for('items.serve_thumbnail',
                           item_id=self.item_id,
                           filename=self.thumbnail.filename)

        return url_for('static', filename='images/no-thumbnail.png')

    def get_title(self, lang):
        for title in self.titles:
            if title.lang == lang:
                return title.title

        return ''

    meta = {
        'indexes': ['-submitted_at', 'tags'],
        'ordering': ['-submitted_at']
    }
Ejemplo n.º 2
0
class Equipment(db.Document):
    mac_address = db.StringField(primary_key=True)
    name = db.StringField()
    description = db.StringField()
    samppling_frequency = db.IntField()
    sensors = db.ListField(db.ReferenceField('Sensor'), default=list)
    available = db.BooleanField()
Ejemplo n.º 3
0
class User(UserMixin, db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    email = db.StringField(max_length=255, required=True)
    username = db.StringField(max_length=255, required=False)
    password = db.StringField(required=True)
    active = db.BooleanField(default=False)
    roles = db.ListField(db.ReferenceField(Role), default=[])
    #email confirmation
    confirmed_at = db.DateTimeField()
    #tracking
    last_login_at = db.DateTimeField()
    current_login_at = db.DateTimeField()
    last_login_ip = db.StringField()
    current_login_ip = db.StringField()
    login_count = db.IntField()

    def __unicode__(self):
        return '%s' % self.id

    def __repr__(self):
        return "%s %s %s" % (self.username, self.id, self.email)

    def get_id(self):
        return unicode(self.id)

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at', 'email', 'username'],
        'ordering': ['-created_at']
    }
Ejemplo n.º 4
0
class User(db.Document):
    email = db.EmailField(required=True, unique=True)
    password = db.StringField(required=True, min_length=6, max_len=100)
    gifs = db.ListField(db.EmbeddedDocumentField(UserGif), default=list)

    def hash_password(self):
        self.password = bcrypt.generate_password_hash(
            self.password).decode('utf8')

    def verify_password(self, password):
        return bcrypt.check_password_hash(self.password, password)
Ejemplo n.º 5
0
class Sensor(db.Document):
    model = db.StringField()
    measuring_dimentions = db.ListField()
    description = db.StringField()
Ejemplo n.º 6
0
class Sample(db.Document):
    timestamp_start = db.DateTimeField(default=datetime.utcnow)
    timestamp_end = db.DateTimeField()
    header = db.ListField(default=list)
    data_captured = db.DynamicField()
    collect = db.ReferenceField('Collect')