class Boar(base.BaseObject): VERSION = '1.0' dbapi = dbapi.get_instance() fields = { 'id': fields.IntegerField(nullable=False), 'ear_tag': fields.IntegerField(nullable=True), 'ear_lack': fields.IntegerField(nullable=True), #'birthday': fields.DateTimeField(nullable=True), #'entryday': fields.DateTimeField(nullable=True), 'birthday': fields.StringField(nullable=True), 'entryday': fields.StringField(nullable=True), 'dormitory_id': fields.IntegerField(nullable=True), 'category_id': fields.IntegerField(nullable=True), 'breed_num': fields.IntegerField(nullable=True), 'breed_acceptability': fields.FloatField(nullable=True), #'state_id': fields.IntegerField(nullable=True), #'state_day': fields.IntegerField(nullable=True), 'source_id': fields.IntegerField(nullable=True), 'category': fields.StringField(nullable=True), 'dormitory': fields.StringField(nullable=True), 'source': fields.StringField(nullable=True), } @staticmethod def _from_db_object(boar, db_boar): """Converts a database entity to a formal object.""" foreign_key = ['category', 'dormitory', 'source'] for field in boar.fields: if field in ['birthday', 'entryday']: boar[field] = db_boar[field].strftime("%Y-%m-%d") elif field not in foreign_key: boar[field] = db_boar[field] elif field == 'category' and db_boar.category: boar[field] = db_boar.category.name elif field == 'dormitory' and db_boar.dormitory: boar[field] = db_boar.dormitory.name elif field == 'source' and db_boar.source: boar[field] = db_boar.source.name boar.obj_reset_changes() return boar @staticmethod def _from_db_object_list(db_objects, cls, context): """Converts a list of database entities to a list of formal objects.""" return [Boar._from_db_object(cls(context), obj) for obj in db_objects] @base.remotable_classmethod def list(cls, context, filters=None, limit=3000, marker=1, sort_key='id', sort_dir='asc'): """Return a list of Boar objects. :param context: Security context. :param limit: maximum number of resources to return in a single result. :param marker: pagination marker for large data sets. :param sort_key: column to sort results by. :param sort_dir: direction to sort. "asc" or "desc". :returns: a list of :class:`Boar` object. """ db_boars = cls.dbapi.get_boar_list(context, limit=limit, marker=marker, sort_key=sort_key, sort_dir=sort_dir, filters=filters) #import pdb; pdb.set_trace() return [Boar._from_db_object(cls(context), obj) for obj in db_boars] @base.remotable_classmethod def get_by_id(cls, context, id): db_boar = cls.dbapi.get_boar_by_id(context, id) return Boar._from_db_object(cls(context), db_boar) @base.remotable def create(self, context=None): values = self.obj_get_changes() db_boar = self.dbapi.create_boar(context, values) return self._from_db_object(self, db_boar) @base.remotable def save(self, context=None): """Save updates to this boar. Updates will be made column by column based on the result of self.what_changed(). :param context: Security context. NOTE: This should only be used internally by the indirection_api. Unfortunately, RPC requires context as the first argument, even though we don't use it. A context should be set when instantiating the object, e.g.: Boar(context) """ updates = self.obj_get_changes() self.dbapi.update_boar(context, self.id, updates) self.obj_reset_changes() @base.remotable def delete(self, context=None): self.dbapi.delete_boar(context, self.id)
class User(base.BaseObject): VERSION = '1.0' dbapi = dbapi.get_instance() fields = { 'id': fields.IntegerField(nullable=False), 'uuid': fields.UUIDField(nullable=False), 'project_id': fields.UUIDField(nullable=True), 'name': fields.StringField(nullable=False), 'password': fields.StringField(nullable=False), 'phone': fields.StringField(nullable=True), 'role': fields.StringField(nullable=True), 'email': fields.StringField(nullable=True), 'address': fields.StringField(nullable=True), 'extra': fields.StringField(nullable=True), 'project': fields.StringField(nullable=True), } @staticmethod def _from_db_object(user, db_user): """Converts a database entity to a formal object.""" foreign_key = ['project'] for field in user.fields: if field not in foreign_key: user[field] = db_user[field] elif field == 'project' and db_user.project: user['project'] = db_user.project.name user.obj_reset_changes() return user @staticmethod def _from_db_object_list(db_objects, cls, context): """Converts a list of database entities to a list of formal objects.""" return [User._from_db_object(cls(context), obj) for obj in db_objects] @base.remotable_classmethod def list(cls, context, filters=None, limit=3000, marker=1, sort_key='id', sort_dir='asc'): """Return a list of User objects. :param context: Security context. :param limit: maximum number of resources to return in a single result. :param marker: pagination marker for large data sets. :param sort_key: column to sort results by. :param sort_dir: direction to sort. "asc" or "desc". :returns: a list of :class:`User` object. """ #import pdb; pdb.set_trace() db_users = cls.dbapi.get_user_list(context, limit=limit, marker=marker, sort_key=sort_key, sort_dir=sort_dir, filters=filters) total = db_users.total return [User._from_db_object(cls(context), obj) for obj in db_users], total @base.remotable_classmethod def get_by_id(cls, context, id): db_user = cls.dbapi.get_user_by_id(context, id) return User._from_db_object(cls(context), db_user) @base.remotable def create(self, context=None): values = self.obj_get_changes() db_user = self.dbapi.create_user(context, values) return self._from_db_object(self, db_user) @base.remotable def save(self, context=None): """Save updates to this user. Updates will be made column by column based on the result of self.what_changed(). :param context: Security context. NOTE: This should only be used internally by the indirection_api. Unfortunately, RPC requires context as the first argument, even though we don't use it. A context should be set when instantiating the object, e.g.: User(context) """ updates = self.obj_get_changes() self.dbapi.update_user(context, self.id, updates) self.obj_reset_changes() @base.remotable def delete(self, context=None): self.dbapi.delete_user(context, self.id)
class Dormitory(base.BaseObject): VERSION = '1.0' dbapi = dbapi.get_instance() fields = { 'id': fields.IntegerField(nullable=False), 'name': fields.StringField(nullable=True), } @staticmethod def _from_db_object(dormitory, db_dormitory): """Converts a database entity to a formal object.""" for field in dormitory.fields: dormitory[field] = db_dormitory[field] dormitory.obj_reset_changes() return dormitory @staticmethod def _from_db_object_list(db_objects, cls, context): """Converts a list of database entities to a list of formal objects.""" return [ Dormitory._from_db_object(cls(context), obj) for obj in db_objects ] @base.remotable_classmethod def list(cls, context, filters=None, limit=3000, marker=1, sort_key='id', sort_dir='asc'): """Return a list of Dormitory objects. :param context: Security context. :param limit: maximum number of resources to return in a single result. :param marker: pagination marker for large data sets. :param sort_key: column to sort results by. :param sort_dir: direction to sort. "asc" or "desc". :returns: a list of :class:`Dormitory` object. """ #import pdb; pdb.set_trace() db_dormitorys = cls.dbapi.get_dormitory_list(context, limit=limit, marker=marker, sort_key=sort_key, sort_dir=sort_dir, filters=filters) total = db_dormitorys.total return [ Dormitory._from_db_object(cls(context), obj) for obj in db_dormitorys ], total @base.remotable_classmethod def get_by_id(cls, context, id): db_dormitory = cls.dbapi.get_dormitory_by_id(context, id) return Dormitory._from_db_object(cls(context), db_dormitory) @base.remotable def create(self, context=None): values = self.obj_get_changes() db_dormitory = self.dbapi.create_dormitory(context, values) return self._from_db_object(self, db_dormitory) @base.remotable def save(self, context=None): """Save updates to this dormitory. Updates will be made column by column based on the result of self.what_changed(). :param context: Security context. NOTE: This should only be used internally by the indirection_api. Unfortunately, RPC requires context as the first argument, even though we don't use it. A context should be set when instantiating the object, e.g.: Dormitory(context) """ updates = self.obj_get_changes() self.dbapi.update_dormitory(context, self.id, updates) self.obj_reset_changes() @base.remotable def delete(self, context=None): self.dbapi.delete_dormitory(context, self.id)
def __init__(self): super(GestationalAgeReportsController, self).__init__() self.dbapi = dbapi.get_instance()
def __init__(self): super(ParturitionReportsController, self).__init__() self.dbapi = dbapi.get_instance()