Ejemplo n.º 1
0
class Source(Model):
    '''
    Sub-model of Error.
    '''

    pointer = Field()
    '''
    '''

    parameter = Field()
    '''
Ejemplo n.º 2
0
        class Model(MemoryModel):
            username = Field()
            password = Field()

            @classmethod
            async def find_one(cls, query):
                for id in cls.db:
                    data = cls.db[id].copy()
                    del data['id']
                    if data == query:
                        return cls(cls.db[id])
                return None
Ejemplo n.º 3
0
class Course(APIModel):

    __rate__ = ( 10, 'secondly' )

    __acl__ = {
        'administrator': ['all'],
        'other': ['read', 'read_all'],
        #'unauthorized': ['read', 'read_all']
    }

    name = Field(required=True)
    sections = Field(type=[ Section ])
    description = Field(required=True)
Ejemplo n.º 4
0
class Equipment(Model):
    head = Field(type=Item)
    back = Field(type=Item)
    shoulders = Field(type=Item)
    chest = Field(type=Item)
    waist = Field(type=Item)
    legs = Field(type=Item)
    left = Field(type=Item)
    right = Field(type=Item)
    feet = Field(type=Item)
Ejemplo n.º 5
0
class Profile(MongoDBModel, JSONAPIMixin):
    username = Field(required=True)
    name = Field(type=Name)
    email = Field(required=True)
    password = Field(required=True, computed='encrypt_password')

    def encrypt_password(self):
        if self.password == 'hashed-':
            raise Exception('Invalid password.')

        if self.password.startswith('hashed-'):
            return self.password

        return f'hashed-{hashlib.sha256(self.password.encode()).hexdigest()}'
Ejemplo n.º 6
0
class User(MongoDBModel, JSONAPIMixin):

    __acl__ = {
        'self': ['read', 'update', 'subscribe'],
        'administrator': ['all'],
        'other': ['read']
    }

    __set__ = {'groups': ['administrator']}

    username = Field(required=True)
    password = Field(required=True)

    groups = Field(type=list)
Ejemplo n.º 7
0
class Post(MongoDBModel, JSONAPIMixin):

    __acl__ = {
        'administrator': ['all'],
        'other': ['read', 'read_all'],
        'unauthorized': ['read', 'read_all']
    }

    __database_options__ = {'name': 'sugar-blog'}

    title = Field(required=True)
    owner = Field(required=True)
    created = Field(required=True)
    updated = Field()
    content = Field(required=True)
Ejemplo n.º 8
0
class User(MongoDBModel, JSONAPIMixin):

    __acl__ = {
        'self': ['read', 'update'],
        'administrator': ['all'],
        'other': ['read']
    }

    __database_options__ = {
        'name': 'sugar-blog'
    }

    username = Field(required=True)
    password = Field(required=True)

    group = Field(required=True)
Ejemplo n.º 9
0
class Links(Model):
    '''
    Sub-model of Error.
    '''

    about = Field()
    '''
Ejemplo n.º 10
0
class Group(MongoDBModel, JSONAPIMixin):

    __acl__ = {'administrator': ['all']}

    __database_options__ = {'name': 'sugar-blog'}

    name = Field(required=True)
Ejemplo n.º 11
0
class Post(MongoDBModel, JSONAPIMixin, TimestampMixin):

    __rate__ = ( 10, 'secondly' )

    __acl__ = {
        'administrator': [ 'all' ],
        '$owner': [ 'read', 'update', 'delete' ],
        'user': [ 'read_all', 'read', 'create' ],
        'unauthorized': [ 'read_all', 'read' ]
    }

    __index__ = [
        {
            'keys': [('created', ASCENDING)]
        },
        {
            'keys': [('slug', ASCENDING)],
            'options': {
                'unique': True
            }
        }
    ]

    __connection__ = {
        'host': os.getenv('MONGODB_URI', 'mongodb://localhost:27017'),
        'retrywrites': False
    }

    __database__ = {
        'name': os.getenv('MONGODB_DB', 'sugar-blog')
    }


    created = Field(type='timestamp', required=True)
    owner = Field(required=True)
    slug = Field(required=True)
    title = Field(required=True)
    content = Field(required=True, computed='format_content')

    def format_content(self):
        return re.sub('\n\n\n', '\n\n', self.content)
Ejemplo n.º 12
0
class Attributes(Model):
    strength = Field(type=int)
    dexterity = Field(type=int)
    constitution = Field(type=int)
    intelligence = Field(type=int)
    wisdom = Field(type=int)
    charisma = Field(type=int)
Ejemplo n.º 13
0
class User(APIModel):

    __rate__ = (1, 'secondly')

    __acl__ = {
        'self': ['read', 'update', 'delete'],
        'administrator': ['all'],
        #'other': ['read'],
        'unauthorized': ['create']
    }

    __get__ = {'groups': ['self', 'administrator']}

    __set__ = {
        'username': ['self', 'administrator', 'unauthorized'],
        'password': ['self', 'administrator', 'unauthorized'],
        'groups': ['administrator']
    }

    __database__ = {'name': 'vue-sugar-template'}

    username = Field(required=True)
    password = Field(required=True, computed='encrypt_password')

    groups = Field(type=list, computed='default_groups', computed_empty=True)

    def on_render(self, data, token):
        del data['attributes']['password']

    def default_groups(self):
        return ['users']

    def encrypt_password(self):
        if self.password == 'hashed-':
            raise Exception('Invalid password.')

        if self.password.startswith('hashed-'):
            return self.password

        return f'hashed-{hashlib.sha256(self.password.encode()).hexdigest()}'
Ejemplo n.º 14
0
class Item(Model):
    title = Field()
    slot = Field()
    attributes = Field(type=Attributes)
    resistances = Field(type=Resistances)
    armor = Field(type=int)
    count = Field(type=int)
Ejemplo n.º 15
0
class Resistances(Model):
    fire = Field(type=int)
    frost = Field(type=int)
    poison = Field(type=int)
    shadow = Field(type=int)
    magic = Field(type=int)
    holy = Field(type=int)
Ejemplo n.º 16
0
class Error(Model, Exception):
    '''
    An JSONAPI compliant error model which can be raised or serialized.
    It can be constructed from a `dictionary`, `**kargs` or a combination
    of both.
    '''

    id = Field()
    '''
    '''

    links = Field(type=Links)
    '''
    '''

    status = Field(type=int)
    '''
    '''

    code = Field()
    '''
    '''

    title = Field()
    '''
    '''

    detail = Field()
    '''
    '''

    source = Field(type=Source)
    '''
    '''

    meta = Field(type=dict)
    '''
Ejemplo n.º 17
0
class Section(Model):
    name = Field(required=True)
    instructor = Field(required=True)
    students = Field(type=[ str ])
Ejemplo n.º 18
0
class Mixin(MongoDBModel, JSONAPIMixin):
    field = Field()
Ejemplo n.º 19
0
class Location(Model):
    type = Field()
    coordinates = Field(type=list)
Ejemplo n.º 20
0
class Name(Model):
    first = Field(required=True)
    last = Field()
    title = Field()
Ejemplo n.º 21
0
 class Alpha(MemoryModel):
     gamma = Field(type=Gamma)
Ejemplo n.º 22
0
 class Gamma(Model):
     owner = Field()
Ejemplo n.º 23
0
class User(MongoDBModel, JSONAPIMixin):

    __rate__ = (10, 'secondly')

    __acl__ = {
        'self': ['read', 'update', 'delete'],
        'administrator': ['all'],
        'other': ['read'],
        'unauthorized': ['read']
    }

    __get__ = {'groups': ['self', 'administrator']}

    __set__ = {
        'username': ['self', 'administrator', 'unauthorized'],
        'password': ['self', 'administrator', 'unauthorized'],
        'groups': ['administrator']
    }

    __index__ = [{
        'keys': [('username', ASCENDING)],
        'options': {
            'unique': True
        }
    }, {
        'keys': [('username', ASCENDING), ('password', ASCENDING)]
    }]

    __connection__ = {
        'host': os.getenv('MONGODB_URI', 'mongodb://localhost:27017'),
        'retrywrites': False
    }

    __database__ = {'name': os.getenv('MONGODB_DB', 'sugar-blog')}

    username = Field(required=True, validated='validate_username')
    password = Field(required=True,
                     computed='encrypt_password',
                     validated='validate_password',
                     validated_before_computed=True)

    groups = Field(type=list, computed='default_groups', computed_empty=True)

    def on_render(self, data, token):
        del data['attributes']['password']

    def default_groups(self):
        return ['user']

    def encrypt_password(self):
        if self.password == 'hashed-':
            raise Exception('Invalid password.')

        if self.password.startswith('hashed-'):
            return self.password

        return f'hashed-{hashlib.sha256(self.password.encode()).hexdigest()}'

    def validate_username(self, value):
        if len(value) < 8:
            raise Exception('Username cannot be less than eight characters.')

    def validate_password(self, value):
        if len(value) < 8:
            raise Exception('Password cannot be less than eight characters.')
Ejemplo n.º 24
0
class Character(MongoDBModel, JSONAPIMixin, TimestampMixin):

    __index__ = [{'keys': [('location', GEOSPHERE)]}]

    __set__ = {
        'shard': [],
        'monster_id': [],
        'profile': [],
        'name': [],
        'title': [],
        'profession': [],
        'attributes': [],
        'resistances': [],
        'equipment': [],
        'inventory': [],
        'state': [],
        'health': [],
        'level': [],
        'location': [],
        'touched': []
    }

    shard = Field()
    monster_id = Field()
    profile = Field()
    name = Field(type=Name, required=True)
    title = Field()
    race = Field(required=True)
    profession = Field(required=True)
    attributes = Field(type=Attributes, required=True)
    equipment = Field(type=Equipment)
    inventory = Field(type=[Item])
    state = Field(type=State, required=True)
    health = Field(type=int, required=True)
    level = Field(type=Level, required=True)
    location = Field(type=Location)
    touched = Field(type='timestamp')

    @property
    def socket(self):
        return Connections.socket_by_character_id(self.id)

    @property
    def connected(self):
        return self.socket

    async def set_location(self, longitude, latitude):
        redis = await Redis.connect(host='redis://localhost',
                                    minsize=1,
                                    maxsize=1)
        await redis.geoadd('location', longitude, latitude,
                           f'{self.shard}:{self.id}')
        self.longitude = longitude
        self.latitude = latitude
        await self.save()

    async def remove_location(self):
        redis = await Redis.connect(host='redis://localhost',
                                    minsize=1,
                                    maxsize=1)
        await redis.zrem('location', f'{self.shard}:{self.id}')
        self.longitude = None
        self.latitude = None
        await self.save()

    async def distance_to_character(self, character):
        redis = await Redis.connect(host='redis://localhost',
                                    minsize=1,
                                    maxsize=1)
        return await redis.geodist('location', f'{self.shard}:{self.id}',
                                   f'{character.shard}:{character.id}')
Ejemplo n.º 25
0
class State(Model):
    target = Field()
    hostile = Field(type=bool)
    retaliate = Field(type=bool)
    dead = Field(type=int)
    casting = Field(type=bool)
Ejemplo n.º 26
0
 class Gamma(Model):
     owners = Field(type=list)
Ejemplo n.º 27
0
class Level(Model):
    current = Field(type=int, required=True)
    experience = Field(type=int, required=True)
    next = Field(type=int)
Ejemplo n.º 28
0
 class Alpha(MemoryModel):
     owners = Field(type=list)
Ejemplo n.º 29
0
 class Alpha(MemoryModel):
     owners = Field()