Example #1
0
class Admin(orm.Document):
    _db = "lablog"
    _collection = "client_admins"
    _indexes = [
        orm.Index('email', key=('email', 1), unique=True),
    ]

    name = field.Char()
    email = field.Char()
    password = field.Char()
    last_login = field.Date()
    clients = orm.List(type=ClientRef)
    social_accounts = orm.List(type=SocialAccount)
    facebook_pages = orm.List(type=FacebookPage)
    in_office = field.Boolean(default=False)

    @staticmethod
    def passwords_match(pwd, cpwd):
        return pwd == cpwd

    def save(self):
        if self.password:
            if not password.identify(self.password):
                self.password = password.encrypt_password(self.password)
        return super(Admin, self).save()

    def verify_pwd(self, pwd):
        return password.check_password(pwd, self.password)

    def social_account(self, account_type=None):
        for sa in self.social_accounts:
            if sa.type == account_type: return sa
        sa = SocialAccount()
        sa.type = account_type
        return sa

    def get_punchcard(self, influx):
        try:
            res = influx.query(
                "SELECT value from \"lablog\".\"realtime\".\"presence\" where user_id='{}' AND time > now() - 2d"
                .format(self._id))
            r = [p for p in res.get_points()]
            r.reverse()
            return r
        except:
            return []

    def is_authenticated(self):
        if self._id: return True
        return False

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        self.logger.info(unicode(self._id))
        return unicode(self._id)
Example #2
0
class Car(orm.Document):
    _db = "test"
    _collection = "cars"
    owner = field.DocumentId(type=Human)
    make = field.Char()
    model = field.Char()
    year = field.Date()
    features = orm.List(type=unicode)
    properties = orm.List(type=Property)
Example #3
0
class Feature(orm.Document):
    """
    Feature class
    """
    _db = "os_mongo"
    _collection = "features"
    feature_id = field.AutoIncrement(collection="experiment")
    experiment_id = field.Integer(required=True)
    mass = field.Float(required=True)
    rt = field.Float(required=True)
    abundances = orm.List(type=Abundance)
    main_attribution = field.Char()
    annotations = orm.List(type=Annotation)
class Admin(orm.Document):
    _db = "flaskaws"
    _collection = "client_admins"
    _indexes = [
        orm.Index('email', key=('email', 1), unique=True),
    ]

    name = field.Char()
    email = field.Char()
    password = field.Char()
    last_login = field.Date()
    client = field.DocumentId(type=Client)
    social_accounts = orm.List(type=SocialAccount)
    facebook_pages = orm.List(type=FacebookPage)

    def social_account(self, account_type=None):
        for sa in self.social_accounts:
            if sa.type == account_type: return sa
        sa = SocialAccount()
        sa.type = account_type
        return sa

    @staticmethod
    def passwords_match(pwd, cpwd):
        if pwd == cpwd: return True
        return False

    def save(self):
        if not password.identify(self.password):
            self.password = password.encrypt_password(self.password)
        return super(Admin, self).save()

    def verify_pwd(self, pwd):
        self.logger.info(password.encrypt_password(pwd))
        self.logger.info(self.password)
        return password.check_password(pwd, self.password)

    def is_authenticated(self):
        if self._id: return True
        return False

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        self.logger.info(unicode(self._id))
        return unicode(self._id)
Example #5
0
class Human(orm.Document):
    _db = "test"
    _collection = "humans"
    human_id = field.AutoIncrement(collection="human")
    name = field.Char(required=True, min=2, max=25)
    age = field.Integer(required=True, min=0, max=3000)
    height = field.Float(min=1, max=100000)
    weight = field.Float(min=1, max=30000)
    jobs = orm.List(type=Job)
    genitalia = field.Char()
    location = Location()
    car = field.ModelChoice(type=Car)
    color = field.Choice(choices=[{
        'value': 'red',
        'display': 'Red'
    }, {
        'value': 'blue',
        'display': 'Blue'
    }, {
        'value': 'green',
        'display': 'Green'
    }])
    state = field.CollectionChoice(db='test',
                                   collection='states',
                                   sort=[('fullname', 1)])
    email = field.Email()
Example #6
0
class Token(orm.Document):
    _db = 'lablog'
    _collection = 'tokens'

    _indexes = [
        orm.Index('access_token', key=('access_token', 1), unique=True),
        orm.Index('refresh_token', key=('refresh_token', 1), unique=True),
        orm.Index('client', key=('client', 1)),
        orm.Index('user', key=('user', 1)),
        orm.Index('user_agent', key=('user_agent', 1)),
    ]

    access_token = field.Char()
    refresh_token = field.Char()
    client = field.DocumentId(type=Client)
    scopes = orm.List(type=unicode)
    expires = field.Date()
    user = field.DocumentId(type=Admin)
    user_agent = field.Char()
    _type = field.Char()

    @property
    def token_type(self):
        return self._type

    def delete(self):
        self.remove()
Example #7
0
class MetabolomicsExperiment(Experiment):
    """
    Metabolomics experiments
    """
    software = field.Char(required=True)
    version = field.Char(required=True)
    parameters = field.Char()
    filenames = orm.List(type=str)
Example #8
0
class Human(orm.Document):
    _db = "test"
    _collection = "humans"
    name = field.Char(required=True, min=2, max=25)
    age = field.Integer(min=0, max=3000)
    height = field.Float(min=1, max=100000)
    weight = field.Float(min=1, max=30000)
    jobs = orm.List(type=Job)
    genitalia = field.Char()
Example #9
0
class Grant(orm.Document):
    _db = 'lablog'
    _collection = 'grants'
    client = field.DocumentId(type=Client)
    code = field.Char()
    user = field.DocumentId(type=Admin)
    scopes = orm.List(type=unicode)
    expires = field.Date()
    redirect_url = field.Char()

    def delete(self):
        self.remove()
Example #10
0
class SocialAccount(orm.EmbeddedDocument):
    TWITTER = 'twitter'
    FACEBOOK = 'facebook'
    GOOGLE = 'google'
    LINKEDIN = 'linkedin'

    type = field.Char()
    id = field.Char()
    name = field.Char()
    app_id = field.Char()
    token = orm.Field()
    secret = field.Char()
    avatar = field.Char()
    permissions = orm.List(type=unicode)
    categories = orm.List(type=PageCategory)
    last_sync = field.Date()

    def __call__(self, *args, **kwargs):
        data = kwargs.pop('data', {})
        self._map(data)
        return self
Example #11
0
class SocialAccount(orm.EmbeddedDocument):
    TWITTER = 'twitter'
    FACEBOOK = 'fb'
    GOOGLE = 'google'
    LINKEDIN = 'linkedin'

    type = field.Char()
    username = field.Char()
    id = field.Char()
    token = field.Char()
    secret = field.Char()
    avatar = field.Char()
    app_id = field.Char()
    permissions = orm.List(type=unicode)
Example #12
0
class Client(orm.Document):
    _db = "lablog"
    _collection = "clients"

    _indexes = [
        orm.Index('name', key=('name', 1), unique=True),
    ]

    name = field.Char()
    description = field.Char()
    facebook_page = FacebookPage()
    secret = field.Char()
    redirect_uris = orm.List(type=unicode)
    default_scopes = orm.List(type=unicode)
    _type = field.Char()

    @property
    def client_type(self):
        return self._type

    @property
    def default_redirect_uri(self):
        self.logger.info(self.redirect_uris)
        return self.redirect_uris[0]
Example #13
0
class Human(orm.Document):
    _db = "test"
    _collection = "humans"
    _indexes = [
        orm.Index("name", key=[("name", orm.Index.DESCENDING)]), 
        orm.Index("human_id", key=[("human_id", orm.Index.ASCENDING)]),
        orm.Index("geo_location", key=[("jobs.locations.geo", orm.Index.GEO2D)])
    ]
    human_id = field.AutoIncrement(collection="human")
    name = field.Char(required=True, min=2, max=25)
    age = field.Integer(min=0, max=3000)
    height = field.Float(min=1, max=100000)
    weight = field.Float(min=1)
    jobs = orm.List(type=Job, length=3)
    genitalia = field.Char()
Example #14
0
class Rodeo(Car):
    tires = orm.List(type=int)
Example #15
0
class Job(orm.EmbeddedDocument):
    employer = field.Char()
    title = field.Char(required=True)
    locations = orm.List(type=Location)
Example #16
0
class User(orm.Document):
    _collection = "users"
    username = field.Char(required=True, min=2, max=24)
    password = field.Char()
    bets = orm.List(type=Bet)
Example #17
0
class Location(orm.Document):
    _db = 'lablog'
    _collection = 'locations'

    name = field.Char()
    description = field.Char()
    geo = field.Geo()
    property_id = field.Char()
    interfaces = orm.List(type=LocationInterface)
    zipcode = field.Char()
    meta = LocationMeta()
    floorplan = Floorplan()

    def get_interface_data(self, db, _from="7d"):
        vals = {}
        for i in self.interfaces:
            inter = i.interface
            vals[inter.__class__.__name__] = inter.get_values(db, _from)

        return vals

    def get_interface(self, interface):
        inte = None
        for i in self.interfaces:
            inter = i._get('interface')._value.get('cls').split(".")[-1]
            self.logger.info(inter)
            if inter == interface:
                inte = i.interface
                break
        return inte

    @property
    def mls(self):
        if not self.meta.mls or self.property_id != self.meta.mls.get(
                'ListingId'):
            try:
                od = OData(config.MLS_ODATA_URL, config.MLS_ODATA_UN,
                           config.MLS_ODATA_PASSWORD)
                res = od.entity("Property").id(
                    self.property_id
                )  #filter("PostalCode eq '60626'").orderby("ListingContractDate desc").top("1").get()
                self.meta.mls = res
                self.save()
            except:
                self.meta.mls = {}

        return self.meta.mls

    @property
    def tlc(self):
        if not self.meta.tlc or self.zipcode != self.meta.tlc.get(
                'msa', {}).get('zip'):
            ret = {'msa': {'zip': self.zipcode}, 'vibes': {}}
            try:
                tlc = TLCEngine(un=config.TLC_UN, pw=config.TLC_PASSWORD)
                vibes = tlc.vibes(self.zipcode)

                for k, v in vibes.get('VibesData').items():
                    d = ret['msa'] if k.lower().startswith(
                        'msa') else ret['vibes']
                    try:
                        d[k] = float(v)
                    except Exception as e:
                        d[k] = v

                self.meta.tlc = ret
                self.save()
            except Exception as e:
                logging.error(e)
                self.meta.tlc = ret

        return self.meta.tlc['vibes']
Example #18
0
 class Hybrid(objects.Car):
     fuels = orm.List(type=objects.Property)
Example #19
0
class FacebookPage(orm.EmbeddedDocument):
    name = field.Char()
    token = field.Char()
    id = field.Char()
    permissions = orm.List(type=unicode)
    categories = orm.List(type=PageCategory)