def get_sqlalchemy_mapping(self, registry, namespace, fieldname, properties): """Return the instance of the real field :param registry: current registry :param namespace: name of the model :param fieldname: name of the field :param properties: known properties of the model :rtype: sqlalchemy column instance """ self.format_label(fieldname) args = self.args kwargs = self.kwargs.copy() if 'info' not in kwargs: kwargs['info'] = {} args = self.format_foreign_key(registry, args, kwargs) kwargs['info']['label'] = self.label if self.sequence: args = (self.sequence, ) + args if self.db_column_name: db_column_name = self.db_column_name else: db_column_name = fieldname if self.default_val is not NoDefaultValue: if isinstance(self.default_val, str): kwargs['default'] = wrap_default(registry, namespace, self.default_val) elif isinstance(self.default_val, ColumnDefaultValue): kwargs['default'] = self.default_val.get_default_callable( registry, namespace, fieldname, properties) else: kwargs['default'] = self.default_val sqlalchemy_type = self.native_type(registry) if self.encrypt_key: encrypt_key = self.format_encrypt_key(registry, namespace) if sgdb_in(registry.engine, ['MsSQL']): sqlalchemy_type = MsSQLEncryptedType(sqlalchemy_type, encrypt_key) else: sqlalchemy_type = EncryptedType(sqlalchemy_type, encrypt_key) return SA_Column(db_column_name, sqlalchemy_type, *args, **kwargs)
class TNSRobot(Base): """A TNS robot entry.""" create = read = update = delete = accessible_by_group_members group_id = sa.Column( sa.ForeignKey('groups.id', ondelete='CASCADE'), index=True, doc='The ID of the Group the allocation is associated with.', nullable=False, ) group = relationship( 'Group', back_populates='tnsrobots', doc='The Group the TNS robot is associated with.', ) bot_name = sa.Column(sa.String, doc="Name of the TNS bot.", nullable=False) bot_id = sa.Column(sa.Integer, doc="ID of the TNS bot.", nullable=False) source_group_id = sa.Column( sa.Integer, doc="Source group ID of the TNS bot.", nullable=False ) _altdata = sa.Column( EncryptedType(JSONType, cfg['app.secret_key'], AesEngine, 'pkcs5') ) @property def altdata(self): if self._altdata is None: return {} else: return json.loads(self._altdata) @altdata.setter def altdata(self, value): self._altdata = value
def phone(cls): return sa.Column(EncryptedType(sa.String(120), key=secret_key, engine=AesEngine, padding='pkcs5'), unique=True)
class Allocation(Base): """An allocation of observing time on a robotic instrument.""" create = (read) = ( update ) = delete = accessible_by_group_members & AccessibleIfRelatedRowsAreAccessible( instrument='read') pi = sa.Column(sa.String, doc="The PI of the allocation's proposal.") proposal_id = sa.Column( sa.String, doc="The ID of the proposal associated with this allocation.") start_date = sa.Column(sa.DateTime, doc='The UTC start date of the allocation.') end_date = sa.Column(sa.DateTime, doc='The UTC end date of the allocation.') hours_allocated = sa.Column(sa.Float, nullable=False, doc='The number of hours allocated.') requests = relationship( 'FollowupRequest', back_populates='allocation', doc='The requests made against this allocation.', passive_deletes=True, ) observation_plans = relationship( 'ObservationPlanRequest', back_populates='allocation', doc='The observing plan requests for this allocation.', passive_deletes=True, ) group_id = sa.Column( sa.ForeignKey('groups.id', ondelete='CASCADE'), index=True, doc='The ID of the Group the allocation is associated with.', nullable=False, ) group = relationship( 'Group', back_populates='allocations', doc='The Group the allocation is associated with.', ) instrument_id = sa.Column( sa.ForeignKey('instruments.id', ondelete='CASCADE'), index=True, doc="The ID of the Instrument the allocation is associated with.", nullable=False, ) instrument = relationship( 'Instrument', back_populates='allocations', doc="The Instrument the allocation is associated with.", ) _altdata = sa.Column( EncryptedType(JSONType, cfg['app.secret_key'], AesEngine, 'pkcs5')) @property def altdata(self): if self._altdata is None: return {} else: return json.loads(self._altdata) @altdata.setter def altdata(self, value): self._altdata = value