Exemplo n.º 1
0
class B(Model):
    tablename = "b"

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

    validation = {'a': {'len': {'gte': 5}}}
Exemplo n.º 2
0
class Person(Model):
    has_many('things', {'features': {
        'via': 'things'
    }}, {'pets': 'Dog.owner'}, 'subscriptions')

    name = Field()
    age = Field('integer')
Exemplo n.º 3
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'
    }})
Exemplo n.º 4
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)
            }
        }
    }
Exemplo n.º 5
0
class Inside(Model):
    a = Field()
    b = Field.int()

    validation = {
        'a': {'in': ['a', 'b']},
        'b': {'in': {'range': (1, 5)}}
    }
Exemplo n.º 6
0
class Match(Model):
    a = Field()
    b = Field()

    validation = {
        'a': {'match': 'ab'},
        'b': {'match': {'expression': 'ab', 'strict': True}}
    }
Exemplo n.º 7
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}
Exemplo n.º 8
0
class Eq(Model):
    a = Field()
    b = Field.int()
    c = Field.float()

    validation = {
        'a': {'equals': 'asd'},
        'b': {'equals': 2},
        'c': {'not': {'equals': 2.4}}
    }
Exemplo n.º 9
0
class Num(Model):
    a = Field.int()
    b = Field.int()
    c = Field.int()

    validation = {
        'a': {'gt': 0},
        'b': {'lt': 5},
        'c': {'gt': 0, 'lte': 4}
    }
Exemplo n.º 10
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}}
Exemplo n.º 11
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}
Exemplo n.º 12
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}
    }
Exemplo n.º 13
0
class Donation(Model):
    belongs_to('user', 'campaign')

    date = Field.datetime(default=now)
    amount = Field.int()

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

    validation = {
        'amount': {'gt': 1}
    }
Exemplo n.º 14
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()
Exemplo n.º 15
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')
Exemplo n.º 16
0
class Fortune(Model):
    tablename = "fortune"
    message = Field.string()

    @rowmethod("serialize")
    def _serialize(self, row):
        return {"id": row.id, "message": row.message}
Exemplo n.º 17
0
class Fortune(Model):
    tablename = "fortune"
    message = Field.string()

    @rowmethod('serialize')
    def _serialize(self, row):
        return {'id': row.id, 'message': row.message}
Exemplo n.º 18
0
class Membership(Model):
    belongs_to('user', 'organization')
    role = Field()

    @scope('admins')
    def filter_admins(self):
        return self.role == 'admin'
Exemplo n.º 19
0
class World(Model):
    tablename = "world"
    randomnumber = Field.int()

    @rowmethod('serialize')
    def _serialize(self, row):
        return {'id': row.id, 'randomNumber': row.randomnumber}
Exemplo n.º 20
0
class World(Model):
    tablename = "world"
    randomnumber = Field.int()

    @rowmethod("serialize")
    def _serialize(self, row):
        return {"id": row.id, "randomNumber": row.randomnumber}
Exemplo n.º 21
0
class Reading(Model):
    """ Weather Reading """
    station_id = Field.text()
    date = Field.datetime()
    temperature = Field.float()

    validation = {
        'station_id': {
            'presence': True
        },
        'date': {
            'presence': True
        },
        'temperature': {
            'presence': True
        }
    }
Exemplo n.º 22
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])
Exemplo n.º 23
0
class User(Model):
    name = Field()
    has_many('memberships', {'organizations': {
        'via': 'memberships'
    }}, {
        'cover_orgs': {
            'via': 'memberships.organization',
            'where': lambda m: m.is_cover == True
        }
    })
Exemplo n.º 24
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}
Exemplo n.º 25
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
Exemplo n.º 26
0
class User(AuthUser):
    has_many('campaigns', 'donations')

    money = Field.int(default=0)
    avatar = Field.upload(uploadfolder='uploads')

    form_profile_rw = {"avatar": True}

    @rowmethod('backed_campaigns')
    def get_backed_campaigns(self, row):
        count = self.db.Donation.campaign.count()
        return (row.donations(count,
                              groupby=self.db.Donation.campaign).first()
                or {}).get(count) or 0

    @rowmethod('backed_amount')
    def get_backed_amount(self, row):
        total = self.db.Donation.amount.sum()
        return (self.db(self.db.Donation.user == row.id).select(
            total, groupby=self.db.Donation.user).first()
                or {}).get(total) or 0
Exemplo n.º 27
0
class FieldProbe(Model):
    tablename = 'FieldProbes'
    name = Field.string()
    kind = Field.string()
    min_frequency = Field.float()
    max_frequency = Field.float()
    min_frequency_unit = Field.string(default='GHz')
    max_frequency_unit = Field.string(default='GHz')
    correction_factor = Field.string()  # filename
    default = Field.bool()

    validation = {
        "name": {
            'presence': True
        },
        "kind": {
            'presence': True,
            'in': ('e', 'h')
        },
        "min_frequency": {
            'presence': True
        },
        "max_frequency": {
            'presence': True
        },
        "correction_factor": {
            'allow': 'empty'
        },
    }

    repr_values = {'kind': lambda kind: {'e': 'E', 'h': 'H'}.get(kind)}

    default_values = {'default': False, 'correction_factor': 1}

    indexes = {'name_index': {'fields': ['name'], 'unique': True}}

    @before_update
    def set_as_default(self, dbset, fields):
        self._set_as_default(fields)

    @before_insert
    def set_new_as_default(self, fields):
        self._set_as_default(fields)

    @staticmethod
    def _set_as_default(fields):
        if fields['default']:
            probes = FieldProbe.where(lambda s: (s.default == True)).select()
            for probe in probes:
                probe.update_record(default=False)
Exemplo n.º 28
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'
        }
    }
Exemplo n.º 29
0
class Consist(Model):
    email = Field()
    url = Field()
    ip = Field()
    image = Field('upload')
    emails = Field('list:string')
    emailsplit = Field('list:string')

    validation = {
        'email': {
            'is': 'email'
        },
        'url': {
            'is': 'url'
        },
        'ip': {
            'is': 'ip'
        },
        'image': {
            'is': 'image'
        },
        'emails': {
            'is': 'list:email'
        },
        'emailsplit': {
            'is': {
                'list:email': {
                    'splitter': ',;'
                }
            }
        }
    }
Exemplo n.º 30
0
class ScanResult(Model):
    tablename = 'ScanResults'
    belongs_to({'scan': 'Scan'})
    has_many({'x_results': 'XResultRow'})
    x = Field.text()
    y = Field.text()
    z = Field.text()
    f = Field.text()
    e = Field.text(auto_validation=False)
    s = Field.blob()