示例#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 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)
示例#3
0
class SpectrumAnalyzer(Model):
    tablename = 'SpectrumAnalyzers'
    has_many({'probes': 'FieldProbe'}, {'scans': 'Scan'})
    name = Field.string()
    model = Field.string()
    min_frequency = Field.float()
    max_frequency = Field.float()
    min_frequency_unit = Field.string(default='GHz')
    max_frequency_unit = Field.string(default='GHz')
    default = Field.bool()

    validation = {
        "name": {
            'presence': True
        },
        "model": {
            'presence': True
        },
        "min_frequency": {
            'presence': True
        },
        "max_frequency": {
            'presence': True
        },
    }

    default_values = {'default': False}

    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']:
            analyzers = SpectrumAnalyzer.where(lambda s:
                                               (s.default == True)).select()
            for analyzer in analyzers:
                analyzer.update_record(default=False)
示例#4
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
示例#5
0
class StepFourThingEdit(Model):
    tablename = "step_four_things"
    name = Field()
    value = Field.float()
    available = Field.bool(default=True)
    asd = Field.int()
示例#6
0
class StepFourThing(Model):
    name = Field(notnull=True)
    value = Field.float(default=8.8)
    available = Field.bool(default=True)
    asd = Field()