class Workspace(MappedClass): class __mongometa__: session = DBSession name = 'workspaces' custom_indexes = [ dict(fields=('name', '_owner'), unique=True, sparse=True) ] _id = FieldProperty(s.ObjectId) name = FieldProperty(s.String, required=True) visible = FieldProperty(s.Bool, if_missing=True, index=True) _owner = ForeignIdProperty('User') owner = RelationProperty('User') @classmethod def per_user(cls, user_id): return cls.query.find({ '_owner': { '$in': [user_id, None] }, 'visible': True }).sort('_id').all() @classmethod def by_id(cls, _id): return cls.query.get(_id=ObjectId(_id))
class Thing(MappedClass): class __mongometa__: session = DBSession name = 'thing' _id = FieldProperty(s.ObjectId) name = FieldProperty(s.String)
class ProfileActivation(MappedClass): class __mongometa__: session = DBSession name = 'userprofile_activation' _id = FieldProperty(s.ObjectId) activated = FieldProperty(s.DateTime) old_email_address = FieldProperty(s.String, required=True) email_address = FieldProperty(s.String, required=True) activation_code = FieldProperty(s.String, required=True, unique=True) @cached_property def activation_link(self): return url(mount_point('userprofile') + '/activate', params=dict(activation_code=self.activation_code), qualified=True) @classmethod def generate_activation_code(cls, email): from hashlib import sha1 import hmac return hmac.new(email.encode(), str(datetime.now()).encode(), sha1).hexdigest() @classmethod def by_code(cls, code): return cls.query.find({'activated': None, 'activation_code': code}).first() def get_user(self): return app_model.User.query.find({'email_address': self.old_email_address}).one()
class Basic(MappedClass): class __mongometa__: name = 'hook' session = self.session _id = FieldProperty(S.ObjectId) a = FieldProperty(int)
class Message(MappedClass): class __mongometa__: session = session name = 'Message' _id = FieldProperty(schema.ObjectId) name = FieldProperty(str)
class Event(MappedClass): class __mongometa__: session = session name = 'Event' _id = FieldProperty(schema.ObjectId) name = FieldProperty(str)
class Qualifier(TermInTree, MeshTerm): class __mongometa__: polymorphic_identity = "q" annotation = FieldProperty(schema.String) tree_nodes_allowed = FieldProperty(schema.Array(schema.String)) tree_numbers = FieldProperty(schema.Array(schema.String)) # used for querying tree ex. db.descriptor.find({parents:"A02"}) parents = FieldProperty(schema.Array(schema.String), index=True) _type = FieldProperty(schema.String(if_missing="q")) def __init__(self, *args, **kwargs): record = kwargs.get("record", None) super(Qualifier, self).__init__(*args, **kwargs) if record is not None: if "TreeNodeAllowedList" in record: if isinstance(record["TreeNodeAllowedList"]["TreeNodeAllowed"], list): self.tree_nodes_allowed = record["TreeNodeAllowedList"][ "TreeNodeAllowed"] else: self.tree_nodes_allowed = [ record["TreeNodeAllowedList"]["TreeNodeAllowed"] ] if "Annotation" in record: self.annotation = record["Annotation"]
class GeoIP(MappedClass): """ GeoIP definition. """ class __mongometa__: session = DBSession name = 'geoip' unique_indexes = [ ('range1', ), ] def __json__(self): return dict(range1=self.range1, range2=self.range2, country=self.country, country_code=self.country_code) _id = FieldProperty(s.ObjectId) range1 = FieldProperty(s.Int) range2 = FieldProperty(s.Int) country = FieldProperty(s.String) country_code = FieldProperty(s.String) @classmethod def getRange(cls, decimal_ip): return cls.query.find({ "range1": { "$lt": decimal_ip }, "range2": { "$gt": decimal_ip } }).first()
class User(MappedClass, Mixin1, Mixin2): class __mongometa__: name = "userswithmixin" session = self.session _id = FieldProperty(S.ObjectId) username = FieldProperty(str)
class Counter(MappedClass): """ Counter definition """ class __mongometa__: session = DBSession name = 'counter' _id = FieldProperty(s.ObjectId) name = FieldProperty(s.String) uid = FieldProperty(s.Int) @staticmethod def get_next_id(name): """ Get next id to specified name Args: name (string): name of id collection Returns: Next autoincremented id """ return Counter.query.find_and_modify(query={ 'name': name }, update={ '$inc': { 'uid': 1 } }, new=True).uid
class MyModel(MappedClass): class __mongometa__: session = session name = 'mymodel' version_of = collection( 'mymodel', session, Field('_id', schema.ObjectId), Field('name', schema.String), Field('_version', schema.Value(1, required=True)), version_of=collection( 'mymodel', session, Field('_id', schema.ObjectId), Field('name', schema.String), ), migrate=lambda data: dict( _id=data['_id'], name=data['name'].upper(), _version=1)) @staticmethod def migrate(data): return dict(_id=data['_id'], name=data['name'][::-1], _version=2) _id = FieldProperty(schema.ObjectId) name = FieldProperty(schema.String(required=True)) _version = FieldProperty(2, required=True)
class Billing(MappedClass): class __mongometa__: session = session name = 'Billing' _id = FieldProperty(schema.ObjectId) name = FieldProperty(str)
class Channel(MappedClass): class __mongometa__: session = session name = 'Channel' _id = FieldProperty(schema.ObjectId) name = FieldProperty(str)
class UserWithSchema(MappedClass): class __mongometa__: session = session name = 'user_with_schema' _id = FieldProperty(schema.ObjectId) name = FieldProperty(schema.String(required=True)) password = FieldProperty(PasswordSchema)
class Contact(MappedClass): class __mongometa__: session = session name = 'contact' _id = FieldProperty(schema.ObjectId) name = FieldProperty(schema.String(required=True)) email = FieldProperty(EmailSchema)
class TWorker(MappedClass, EnhancingClass): class __mongometa__: session = session name = 'testworkers' _id = FieldProperty(schema.ObjectId) name = FieldProperty(schema.String(required=True)) surname = FieldProperty(schema.String(required=True))
class HelloWorld(MappedClass): class __mongometa__: session = session name = 'testcollection' _id = FieldProperty(schema.ObjectId) title = FieldProperty(schema.String(required=True)) text = FieldProperty(schema.String(if_missing='empty...'))
class WikiPage(MappedClass): class __mongometa__: session = session name = 'wiki_page' _id = FieldProperty(schema.ObjectId) title = FieldProperty(schema.String(required=True)) text = FieldProperty(schema.String(if_missing=''))
class User(MappedClass): class __mongometa__: session = session name = 'user' _id = FieldProperty(schema.ObjectId) name = FieldProperty(schema.String(required=True)) password = PasswordProperty()
class WikiComment(MappedClass): class __mongometa__: session = session name = 'wiki_comment' _id = FieldProperty(schema.ObjectId) page_id = ForeignIdProperty('WikiPage') text = FieldProperty(schema.String(if_missing=''))
class Result(MappedClass): class __mongometa__: session = DBSession name = 'results' _id = FieldProperty(s.ObjectId) url = FieldProperty(s.String) result = FieldProperty(s.String)
class ThingWithDate(MappedClass): class __mongometa__: session = DBSession name = 'thing' _id = FieldProperty(s.ObjectId) name = FieldProperty(s.String) updated_at = FieldProperty(s.DateTime, if_missing=datetime.now)
class HomerQ(MappedClass): class __mongometa__: session = DBSession name = 'homer_q' _id = FieldProperty(s.ObjectId) q = FieldProperty(s.Anything, index=True) datasets = RelationProperty('Dataset')
class Config(MappedClass): class __mongometa__: session = session name = 'configs' _id = FieldProperty(schema.ObjectId) name = FieldProperty(schema.String) value = FieldProperty(schema.String)
class Author(MappedClass): class __mongometa__: session = cls.s name = 'wiki_author' _id = FieldProperty(schema.ObjectId) name = FieldProperty(str) pages = RelationProperty('WikiPage')
class Child(MappedClass): class __mongometa__: name = 'child' session = session _id = FieldProperty(schema.ObjectId) name = FieldProperty(schema.String(required=True)) parents = RelationProperty('Parent')
class AirBus(Bus): class __mongometa__: polymorphic_identity = 'airbus' _type = FieldProperty(str, if_missing='airbus') wings_count = FieldProperty(schema.Int(if_missing=2)) def move(self): return 'flying from {} to {}'.format(self.origin, self.destination)
class WikiPage(MappedClass): class __mongometa__: session = session name = 'testcollection' extensions = [ MyExtension ] _id = FieldProperty(schema.ObjectId) title = FieldProperty(schema.String(required=True)) text = FieldProperty(schema.String(if_missing=''))
class Base(MappedClass): class __mongometa__: name='test_doc' session = self.odm_session polymorphic_on='type' polymorphic_identity='base' _id = FieldProperty(S.ObjectId) type=FieldProperty(str, if_missing='base') a=FieldProperty(int)
class Bus(Transport): class __mongometa__: polymorphic_identity = 'bus' _type = FieldProperty(str, if_missing='bus') passengers_count = FieldProperty(schema.Int(if_missing=0)) def move(self): return 'driving from {} to {}'.format(self.origin, self.destination)
def __set__(self, instance, value): value = self._hash_password(value) return FieldProperty.__set__(self, instance, value)