예제 #1
0
class Organization(Model):
    name = Field()
    is_cover = Field('bool', default=False)

    @has_many()
    def admin_memberships3(self):
        return Membership.admins()

    has_many('memberships', {'users': {
        'via': 'memberships'
    }}, {'admin_memberships': {
        'target': 'Membership',
        'scope': 'admins'
    }}, {'admins': {
        'via': 'admin_memberships.user'
    }}, {
        'admin_memberships2': {
            'target': 'Membership',
            'where': lambda m: m.role == 'admin'
        }
    }, {'admins2': {
        'via': 'admin_memberships2.user'
    }}, {'admins3': {
        'via': 'admin_memberships3.user'
    }})
예제 #2
0
class Person(Model):
    has_many('things', {'features': {
        'via': 'things'
    }}, {'pets': 'Dog.owner'}, 'subscriptions')

    name = Field()
    age = Field('integer')
예제 #3
0
class Len(Model):
    a = Field()
    b = Field()
    c = Field()
    d = Field()

    validation = {
        'a': {
            'len': 5
        },
        'b': {
            'len': {
                'gt': 4,
                'lt': 13
            }
        },
        'c': {
            'len': {
                'gte': 5,
                'lte': 12
            }
        },
        'd': {
            'len': {
                'range': (5, 13)
            }
        }
    }
예제 #4
0
class B(Model):
    tablename = "b"

    a = Field()
    b = Field(validation={'len': {'gte': 5}})

    validation = {'a': {'len': {'gte': 5}}}
예제 #5
0
class Match(Model):
    a = Field()
    b = Field()

    validation = {
        'a': {'match': 'ab'},
        'b': {'match': {'expression': 'ab', 'strict': True}}
    }
예제 #6
0
class Comment(Model):
    belongs_to('user', 'post')

    text = Field('text')
    date = Field('datetime')

    default_values = {'user': lambda: session.auth.user.id, 'date': now}
    validation = {'text': {'presence': True}}
    fields_rw = {'user': False, 'post': False, 'date': False}
예제 #7
0
class Post(Model):
    belongs_to('user')
    has_many('comments')

    title = Field()
    text = Field('text')
    date = Field('datetime')

    default_values = {'user': lambda: session.auth.user.id, 'date': now}
    validation = {'title': {'presence': True}, 'text': {'presence': True}}
    fields_rw = {'user': False, 'date': False}
예제 #8
0
class Thing(Model):
    belongs_to('person')

    name = Field()
    color = Field()
    uid = Field(unique=True)

    validation = {
        'name': {'presence': True},
        'color': {'in': ['blue', 'red']},
        'uid': {'empty': False}
    }
예제 #9
0
class A(Model):
    tablename = "a"

    name = Field()
    val = Field('int')
    fval = Field('float')
    text = Field('text')
    password = Field('password')
    d = Field('date')
    t = Field('time')
    dt = Field('datetime')
    json = Field('json')
예제 #10
0
class Fortune(Model):
    tablename = "fortune"
    message = Field()

    @rowmethod('serialize')
    def _serialize(self, row):
        return {'id': row.id, 'message': row.message}
예제 #11
0
class World(Model):
    tablename = "world"
    randomnumber = Field('int')

    @rowmethod('serialize')
    def _serialize(self, row):
        return {'id': row.id, 'randomNumber': row.randomnumber}
예제 #12
0
class Consist(Model):
    email = Field()
    url = Field()
    ip = Field()
    image = Field.upload()
    emails = Field.string_list()
    emailsplit = Field.string_list()

    validation = {
        'email': {'is': 'email'},
        'url': {'is': 'url'},
        'ip': {'is': 'ip'},
        'image': {'is': 'image'},
        'emails': {'is': 'list:email'},
        'emailsplit': {'is': {'list:email': {'splitter': ',;'}}}
    }
예제 #13
0
class Membership(Model):
    belongs_to('user', 'organization')
    role = Field()

    @scope('admins')
    def filter_admins(self):
        return self.role == 'admin'
예제 #14
0
class Proc(Model):
    a = Field()
    b = Field()
    c = Field()
    d = Field()
    e = Field.password()
    f = Field.password()

    validation = {
        'a': {'lower': True},
        'b': {'upper': True},
        'c': {'clean': True},
        'd': {'urlify': True},
        'e': {'len': {'range': (6, 25)}, 'crypt': True},
        'f': {'len': {'gt': 5, 'lt': 25}, 'crypt': 'md5'}
    }
예제 #15
0
class Inside(Model):
    a = Field()
    b = Field.int()

    validation = {
        'a': {'in': ['a', 'b']},
        'b': {'in': {'range': (1, 5)}}
    }
예제 #16
0
class Eq(Model):
    a = Field()
    b = Field('int')
    c = Field('float')

    validation = {
        'a': {
            'equals': 'asd'
        },
        'b': {
            'equals': 2
        },
        'c': {
            'not': {
                'equals': 2.4
            }
        }
    }
예제 #17
0
class Subscription(Model):
    belongs_to('person')

    name = Field()
    status = Field('int')
    expires_at = Field('datetime')

    STATUS = {'active': 1, 'suspended': 2, 'other': 3}

    @scope('expired')
    def get_expired(self):
        return self.expires_at < datetime.now()

    @scope('of_status')
    def filter_status(self, *statuses):
        if len(statuses) == 1:
            return self.status == self.STATUS[statuses[0]]
        return self.status.belongs(*[self.STATUS[v] for v in statuses])
예제 #18
0
class Cost(Model):
    belongs_to('campaign')

    name = Field(notnull=True)
    date = Field.datetime(default=now)
    amount = Field.int()

    fields_rw = {"campaign": False, "date": False}

    validation = {'amount': {'gt': 1}}
예제 #19
0
class User(Model):
    name = Field()
    has_many('memberships', {'organizations': {
        'via': 'memberships'
    }}, {
        'cover_orgs': {
            'via': 'memberships.organization',
            'where': lambda m: m.is_cover == True
        }
    })
예제 #20
0
class Image(Model):
    belongs_to('user')
    has_many('comments')

    id = Field('text')
    title = Field('text')
    path = Field('text')
    comment = Field('text')
    date = Field('datetime')

    default_values = {
        'user': lambda: session.auth.user.id,
        'date': lambda: now
    }
    validation = {
        'id': {
            'presence': True
        },
    }
    fields_rw = {'user': False, 'date': False}
예제 #21
0
class Elephant(Animal):
    belongs_to('mouse')
    color = Field()

    @rowattr('pretty')
    def get_pretty(self, row):
        return row.name + " " + row.color

    @before_insert
    def bi2(self, *args, **kwargs):
        pass
예제 #22
0
class Mixed(Model):
    belongs_to('person')

    date = Field.date()
    type = Field()
    inside = Field()
    number = Field.int()
    dont = Field()
    yep = Field()
    psw = Field.password()

    validation = {
        'date': {'format': '%d/%m/%Y', 'gt': lambda: datetime.utcnow().date()},
        'type': {'in': ['a', 'b'], 'allow': None},
        'inside': {'in': ['asd', 'lol']},
        'number': {'allow': 'blank'},
        'dont': {'empty': True},
        'yep': {'presence': True},
        'psw': {'len': {'range': (6, 25)}, 'crypt': True}
    }
예제 #23
0
class A(Model):
    tablename = "a"

    name = Field()
    val = Field.int()
    fval = Field.float()
    text = Field.text()
    password = Field.password()
    d = Field.date()
    t = Field.time()
    dt = Field.datetime()
    json = Field.json()
예제 #24
0
class Campaign(Model):
    belongs_to('user')
    has_many('donations', 'costs')

    title = Field(notnull=True)
    description = Field(notnull=True)
    start = Field.datetime()
    end = Field.datetime()
    goal = Field.int()
    closed = Field.bool(default=True)

    fields_rw = {"user": False, "closed": False}

    validation = {
        "goal": {
            'gt': 1
        },
        "start": {
            'gt': now,
            'format': "%d/%m/%Y %H:%M:%S"
        },
        "end": {
            'gt': now,
            'format': "%d/%m/%Y %H:%M:%S"
        }
    }

    form_labels = {"title": T("Title: ")}

    @rowmethod('pledged')
    def get_pledge(self, row):
        summed = self.db.Donation.amount.sum()
        return row.donations(summed).first()[summed] or 0

    @rowmethod('spended')
    def get_spended(self, row):
        summed = self.db.Cost.amount.sum()
        return row.costs(summed).first()[summed] or 0
예제 #25
0
class Animal(Model):
    belongs_to('zoo')
    name = Field()

    @rowattr('doublename')
    def get_double_name(self, row):
        return row.name * 2

    @rowattr('pretty')
    def get_pretty(self, row):
        return row.name

    @before_insert
    def bi(self, *args, **kwargs):
        pass

    @before_insert
    def bi2(self, *args, **kwargs):
        pass
예제 #26
0
class StepOneThing(Model):
    name = Field()
    value = Field.float()
예제 #27
0
class StepFiveThing(Model):
    name = Field()
    value = Field.int()
    created_at = Field.datetime()

    indexes = {'name': True, ('name', 'value'): True}
예제 #28
0
class StepFourThingEdit(Model):
    tablename = "step_four_things"
    name = Field()
    value = Field.float()
    available = Field.bool(default=True)
    asd = Field.int()
예제 #29
0
class StepFourThing(Model):
    name = Field(notnull=True)
    value = Field.float(default=8.8)
    available = Field.bool(default=True)
    asd = Field()
예제 #30
0
class StepThreeThingThree(Model):
    tablename = "step_three_thing_ones"
    b = Field()