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 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 }
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'
class Post(db.Document): title = db.StringField() body = db.StringField() created_at = db.DateTimeField() def __unicode__(self): return '%s' % self.title
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()
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()
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'] }
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']}
class LoanHistory(db.Document): equipment = db.ReferenceField('Equipment') patient = db.ReferenceField('Patient') loan_date = db.DateTimeField(default=datetime.utcnow) devolution_date = db.DateTimeField()
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')