示例#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()