예제 #1
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)
예제 #2
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)
예제 #3
0
파일: scanning.py 프로젝트: guy881/nfs-web
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}}
예제 #4
0
class Eq(Model):
    a = Field()
    b = Field.int()
    c = Field.float()

    validation = {
        'a': {'equals': 'asd'},
        'b': {'equals': 2},
        'c': {'not': {'equals': 2.4}}
    }
예제 #5
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()
예제 #6
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
        }
    }
예제 #7
0
class StepOneThing(Model):
    name = Field()
    value = Field.float()
예제 #8
0
class StepFourThingEdit(Model):
    tablename = "step_four_things"
    name = Field()
    value = Field.float()
    available = Field.bool(default=True)
    asd = Field.int()
예제 #9
0
class StepFourThing(Model):
    name = Field(notnull=True)
    value = Field.float(default=8.8)
    available = Field.bool(default=True)
    asd = Field()
예제 #10
0
class Stuff(Model):
    a = Field.string()
    b = Field()
    price = Field.float()
    quantity = Field.int()
    total = Field.float()
    invisible = Field()

    validation = {"a": {'presence': True}}

    fields_rw = {"invisible": False}

    form_labels = {"a": "A label"}

    form_info = {"a": "A comment"}

    update_values = {"a": "a_update"}

    repr_values = {"a": _represent_f}

    form_widgets = {"a": _widget_f}

    def setup(self):
        self.table.b.requires = notInDb(self.db, self.table.b)

    @compute('total')
    def eval_total(self, row):
        return row.price * row.quantity

    @before_insert
    def bi(self, fields):
        return _call_bi(fields)

    @after_insert
    def ai(self, fields, id):
        return _call_ai(fields, id)

    @before_update
    def bu(self, set, fields):
        return _call_u(set, fields)

    @after_update
    def au(self, set, fields):
        return _call_u(set, fields)

    @before_delete
    def bd(self, set):
        return _call_d(set)

    @after_delete
    def ad(self, set):
        return _call_d(set)

    @rowattr('totalv')
    def eval_total_v(self, row):
        return row.price * row.quantity

    @rowmethod('totalm')
    def eval_total_m(self, row):
        return row.price * row.quantity

    @classmethod
    def method_test(cls, t):
        return cls.db, cls.table, t