Example #1
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']
    }
class Thought(db.Document):
    dys_thought = db.StringField(required=True)
    user = db.StringField(required=True)
    rational = db.StringField(required=False)
    distress = db.IntField(required=True)
    distortion = db.StringField(required=True)
    timestamp = db.StringField(required=True, default=datetime.now())
Example #3
0
class Category(db.DynamicDocument):
    """
    Why dynamic document ?
    So we can add other languages fields dynamically (e.g. Tamazight language)
    and add the new translation to all existing categories, see:

    docs.mongoengine.org/guide/defining-documents.html#dynamic-document-schemas

    """

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

    category_id = db.SequenceField(primary_key=True)

    # you can add your name_[lang] at runtime with no worries,
    # it's a Dynamic Document!
    name_ar = db.StringField(max_length=50)
    name_fr = db.StringField(max_length=50)
    name_en = db.StringField(max_length=50)

    description = db.StringField()

    def get_name(self, lang):
        # make this better, latter
        return eval('self.name_%s' % lang) or 'Unknown'
Example #4
0
class Equipment(db.Model):
    mac_address = db.Column(db.String(), primary_key=True)
    name = db.Column(db.StringField())
    description = db.Column(db.StringField())
    samppling_frequency = db.Column(db.IntField())
    sensors = db.relationship('Sensor', backref='equipment', lazy=True)
    available = db.Column(db.Boolean(True))
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()
Example #6
0
class Post(db.Document):
    title = db.StringField()
    body = db.StringField()
    created_at = db.DateTimeField()

    def __unicode__(self):
        return '%s' % self.title
Example #7
0
class License(db.DynamicDocument):

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

    license_id = db.SequenceField(primary_key=True)

    name = db.StringField()
    link = db.URLField()

    description = db.StringField()
Example #8
0
class WindTurbine(db.Document):
    _id = db.ObjectIdField()
    case_id = db.IntField(unique=True)  # Unique stable identification number.
    faa_ors = db.StringField(
    )  # Unique identifier for cross-reference to the Federal Aviation Administration (FAA) digital obstacle files.
    faa_asn = db.StringField(
    )  # Unique identifier for cross-reference to the FAA obstruction evaluation airport airspace analysis dataset.
    usgs_pr_id = db.IntField(
    )  # Unique identifier for cross-reference to the 2014 USGS turbine dataset.
    t_state = db.StringField()  # State where turbine is located.
    t_county = db.StringField()  # County where turbine is located.
    t_fips = db.StringField(
    )  # State and county fips where turbine is located, based on spatial join of turbine points with US state and county.
    p_name = db.StringField(
    )  # Name of the wind power project that the turbine is a part of
    p_year = db.IntField(
    )  # Year that the turbine became operational and began providing power. Note this may differ from the year that construction began.
    p_tnum = db.IntField()  # Number of turbines in the wind power project.
    p_cap = db.FloatField(
    )  # Cumulative capacity of all turbines in the wind power project in megawatts (MW).
    t_manu = db.StringField(
    )  # Turbine manufacturer - name of the original equipment manufacturer of the turbine.
    t_model = db.StringField(
    )  # Turbine model - manufacturer's model name of each turbine.
    t_cap = db.IntField(
    )  # Turbine rated capacity - stated output power at rated wind speed from manufacturer, AWEA, and/or internet resources in kilowatts (kW).
    t_hh = db.FloatField()  # Turbine hub height in meters (m).
    t_rd = db.FloatField()  # Turbine rotor diameter in meters (m).
    t_rsa = db.FloatField()  # Turbine rotor swept area in square meters (m2).
    t_ttlh = db.FloatField(
    )  # Turbine total height from ground to tip of a blade at its apex in meters (m).
    t_conf_atr = db.IntField(
    )  # Level of confidence in the turbine attributes (1 - no confidence, 3 - full confidence)
    t_conf_loc = db.IntField(
    )  # Level of confidence in turbine location (1 - no turbine in image, 3 - turbine in image)
    t_img_date = db.DateTimeField(
    )  # Date of image used to visually verify turbine location.
    t_img_srce = db.StringField(
    )  # Source of image used to visually verify turbine location.
    longitude = db.FloatField(
    )  # Longitude of the turbine point, in decimal degrees.
    latitude = db.FloatField(
    )  # Latitude of the turbine point, in decimal degrees.
    eia_id = db.IntField(
    )  # Plant ID from Energy Information Administration (EIA).
    #updated = db.DateTimeField()
    created = db.DateTimeField(default=datetime.datetime.utcnow)

    meta = {'collection': 'wind_turbines'}

    # https://stackoverflow.com/questions/10252010/serializing-class-instance-to-json
    # https://stackoverflow.com/questions/7907596/json-dumps-vs-flask-jsonify
    # https://stackoverflow.com/questions/16586180/typeerror-objectid-is-not-json-serializable
    def to_json(self):
        return {
            'id': str(self._id),
            'name': self.p_name,
            'latitude': self.latitude,
            'longitude': self.longitude
        }
Example #9
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']
    }
Example #10
0
class User(db.Document):
    _id = db.ObjectIdField()
    # lots of duplicate mail fields
    # dupe query: https://stackoverflow.com/questions/14770170/how-to-find-mongo-documents-with-a-same-field
    name = db.StringField(max_length=100, required=True)
    email = db.EmailField(required=True)
    password = db.StringField(required=True)

    meta = {'collection': 'users'}

    def to_json(self):
        return {'id': str(self._id), 'name': self.name, 'email': self.email}

    #@staticmethod
    def encrypt_password(self, pass_raw):
        self.password = bcrypt.generate_password_hash(pass_raw).decode('utf-8')
Example #11
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)
Example #12
0
class Patient(db.Document):
    cpf = db.StringField(primary_key=True)
    birth_date = db.DateTimeField()
    first_name = db.StringField(required=True)
    last_name = db.StringField(required=True)
    email = db.EmailField()
    phone = db.StringField()
    address = db.StringField()
    lat = db.StringField()
    long = db.StringField()
Example #13
0
class Patient(db.Model):
    cpf = db.Column(db.String(), primary_key=True)
    name = db.Column(db.StringField())
    last_name = db.Column(db.StringField())
    email = db.Column(db.StringField())
    telefone = db.Column(db.StringField())
    lat = db.Column(db.StringField())
    long = db.Column(db.StringField())
Example #14
0
class Title(db.EmbeddedDocument):

    title = db.StringField()
    lang = db.StringField(max_length=3)
Example #15
0
class Sensor(db.Document):
    model = db.StringField()
    measuring_dimentions = db.ListField()
    description = db.StringField()
Example #16
0
class UserGif(db.EmbeddedDocument):
    id = db.StringField(required=True)
    category = db.StringField(required=True)
    url = db.URLField(require=True)
Example #17
0
class Comic(db.Document):
    image = db.ImageField()
    title = db.StringField()

    def __unicode__(self):
        return '%s' % self.title
Example #18
0
class User(db.Document):

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

    user_id = db.SequenceField(unique=True)

    is_admin = db.BooleanField(default=False)

    email = db.StringField()

    name = db.StringField(max_length=50)

    lang = db.StringField(max_length=3)
    bio = db.StringField()
    location = db.StringField()
    # Available for hire or not
    hireable = db.BooleanField(default=False)

    github_username = db.StringField(max_length=50)
    github_id = db.IntField()

    twitter_username = db.StringField(max_length=50)
    facebook_username = db.StringField(max_length=100)
    website = db.StringField(max_length=50)

    oauth_token = db.StringField()
    oauth_secret = db.StringField()

    _password = db.StringField()

    @property
    def password(self):
        return self._password

    @password.setter
    def password(self, password):
        self._password = bcrypt.generate_password_hash(password)

    def check_password(self, password):
        return bcrypt.check_password_hash(self._password, password)

    # Flask-Login integration
    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

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

    # helpers
    def getGithub(self):
        if self.github_username:
            return "https://github.com/%s" % (self.github_username)
        return ''

    def getTwitter(self):
        if self.twitter_username:
            return "https://twitter.com/%s" % (self.twitter_username)
        return ''

    def getFacebook(self):
        if self.facebook_username:
            return "https://facebook.com/%s" % (self.facebook_username)
        return ''

    def getName(self):
        return '%s' % self.name or self.github_username

    # Required for administrative interface
    def __unicode__(self):
        return self.name

    meta = {'ordering': ['-created_at']}
Example #19
0
class Apartment(db.Document):
    title = db.StringField()
    url = db.StringField()
    price = db.IntField()
Example #20
0
class Role(db.Document, RoleMixin):
    name = db.StringField(max_length=80, unique=True)
    description = db.StringField(max_length=255)

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