class Scan(Model): tablename = 'Scans' belongs_to({'analyzer': 'SpectrumAnalyzer'}) belongs_to({'probe': 'FieldProbe'}) has_one({'result_mat': 'ScanResultMat'}) name = Field.string() date = Field.datetime() 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') min_x = Field.float(validation={'blank': True, 'gte': 0}) min_y = Field.float(validation={'blank': True, 'gte': 0}) min_z = Field.float(validation={'blank': True, 'gte': 0}) max_x = Field.float(validation={'blank': True, 'gt': 0}) max_y = Field.float(validation={'blank': True, 'gt': 0}) max_z = Field.float(validation={'blank': True, 'gt': 0}) pcb_filename = Field.string(default='') status = Field.string() progress = Field.int(default=0) validation = { 'name': { 'presence': True }, 'kind': { 'presence': True, 'in': ('flat', 'volumetric', 'z') }, 'min_frequency': { 'presence': True, 'gt': 0 }, 'max_frequency': { 'presence': True, 'gt': 0 }, } repr_values = { 'kind': lambda kind: { 'flat': 'Flat', 'volumetric': 'Volumetric', 'z': 'Z-variable' }.get(kind), 'date': lambda date: date.strftime("%d.%m.%Y") } default_values = { 'date': lambda: datetime.now, } indexes = {'name_index': {'fields': ['name'], 'unique': True}}
class Membership(Model): belongs_to('user', 'organization') role = Field() @scope('admins') def filter_admins(self): return self.role == 'admin'
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}
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}}
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()
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
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}
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} }
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} }
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])
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
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} }
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}
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
class Thing(Model): belongs_to('person') has_many('features') name = Field() color = Field()
class Price(Model): belongs_to('feature') value = Field.int()
class ScanResultMat(Model): tablename = 'ScanResultsMat' belongs_to({'scan': 'Scan'}) mat_filename = Field.string(default='')
class XResultRow(Model): tablename = 'XResultRows' belongs_to({'result': 'ScanResult'}) x_index = Field.int() y = Field.text(auto_validation=False)
class Dog(Model): belongs_to({'owner': 'Person'}) name = Field()
class Thing(Model): belongs_to('user')
class Feature(Model): belongs_to('thing') has_one('price') name = Field()
class Appointment(Model): belongs_to('patient', 'doctor') date = Field('datetime')
class Price(Model): belongs_to('feature') value = Field('integer')