class Product_data(Mini_func): def __init__(self): self.__session = Session() def purchase_product(self, **kwargs): prod = T_Products() for key in kwargs: try: setattr(prod, key, kwargs[key]) except TypeError: continue self.__session.add(prod) self.__session.commit()
class Add_Ons_data(Mini_func): def __init__(self, **kwargs): self.__session = Session() self.__args = kwargs self._retval = list() self.__search_filter = list() self.__search_param = ['add_ons_name'] self.__data = None def get_add_ons_data(self): for key in self.__search_param: if key in self.__args and self.__args[key] not in (None, ""): self.__search_filter.append( getattr(T_Add_Ons, key) == self.__args[key]) if len(self.__search_filter) != 0: self.__data = self.__session.query(T_Add_Ons).filter( *self.__search_filter).order_by(T_Add_Ons.add_ons_id).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) else: self.__data = self.__session.query(T_Add_Ons).order_by( T_Add_Ons.add_ons_id).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) def edit_add_ons_data(self, **kwargs): update_kwargs = kwargs search_param = ['add_ons_id'] search_filter = list() for key in search_param: if key in update_kwargs and update_kwargs[key] not in (None, ""): search_filter.append( getattr(T_Add_Ons, key) == update_kwargs[key]) if search_filter: result = self.__session.query(T_Add_Ons).filter( *search_filter).all() else: return False update_param = ['member_price', 'non_member_price', 'duration'] for obj in result: for key in update_param: if key in update_kwargs and update_kwargs[key] not in (None, ""): try: setattr(obj, key, update_kwargs[key]) except TypeError: continue self.__session.commit() def del_Add_Ons(self, **kwargs): addonid = kwargs.get('id', 0) resdata = self.__session.query(T_Add_Ons).filter( T_Add_Ons.add_ons_id == addonid).first() if resdata: self.__session.delete(resdata) try: self.__session.commit() except: self.__session.rollback() def insert_add_ons(self, **kwargs): addons = T_Add_Ons() for key, value in kwargs.items(): try: setattr(addons, key, value) except TypeError: continue self.__session.add(addons) self.__session.commit() def __del__(self): if self.__session is not None: self.__session.close()
class Regular_Services_data(Mini_func): def __init__(self,**kwargs): self.__session = Session() self.__args = kwargs self._retval = list() self.__search_filter = list() self.__search_param = ['service_name'] self.__data = None def get_regular_services_data(self): for key in self.__search_param: if key in self.__args and self.__args[key] not in (None,""): self.__search_filter.append(getattr(T_Regular_Services,key)==self.__args[key]) if len(self.__search_filter) != 0: self.__data = self.__session.query(T_Regular_Services).filter(*self.__search_filter).order_by( T_Regular_Services.peak_price).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) else: self.__data = self.__session.query(T_Regular_Services).order_by(T_Regular_Services.peak_price).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) def edit_regular_services_data(self, **kwargs): update_kwargs = kwargs search_param = ['regular_services_id'] search_filter = list() for key in search_param: if key in update_kwargs and update_kwargs[key] not in (None,""): search_filter.append(getattr(T_Regular_Services, key) == update_kwargs[key]) if search_filter: result = self.__session.query(T_Regular_Services).filter(*search_filter).all() else: return False update_param = ['off_peak_price', 'peak_price', 'non_member_price', 'duration'] for obj in result: for key in update_param: if key in update_kwargs and update_kwargs[key] not in (None, ""): try: setattr(obj,key,update_kwargs[key]) except TypeError: continue self.__session.commit() def insert_regular_services_data(self, **kwargs): """.""" regularservices = T_Regular_Services() for key in kwargs: try: setattr(regularservices,key,kwargs[key]) except TypeError: continue self.__session.add(regularservices) self.__session.commit() def del_regular_services_data(self, **kwargs): """.""" retval = True regid = kwargs.get('id', 0) resdata = self.__session.query(T_Regular_Services).filter(T_Regular_Services.regular_services_id == regid).first() if resdata: self.__session.delete(resdata) try: self.__session.commit() except: self.__session.rollback() retval = False return retval def __del__(self): if self.__session is not None: self.__session.close()
class Member01_data(Mini_func): def __init__(self, **kwargs): self.__session = Session() self.__args = kwargs self._retval = list() self.__search_filter = list() self.__search_param = ['member00id'] self.__data = None def getmemberdata(self): for key in self.__search_param: if key in self.__args and self.__args[key] not in (None, ""): self.__search_filter.append( getattr(T_Member01, key) == self.__args[key]) if not self.__search_filter: self.__data = self.__session.query(T_Member01).order_by( T_Member01.member00id).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) else: if len(self.__search_filter) != 0: self.__data = self.__session.query(T_Member01).filter( *self.__search_filter).order_by( T_Member01.member01id).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) def postmemberdata(self, **kwargs): member = T_Member01() for key in kwargs: try: setattr(member, key, kwargs[key]) except TypeError: continue self.__session.add(member) self.__session.commit() def get_customize_members(self, char): sel_statement = """SELECT name, membertype, member00id from member00 where name like '%{0}%' union all SELECT name, relationship, member00id from member01 where name like '%{0}%' """.format( char) result = self.__session.execute(sel_statement) for d in result: r = { 'name': d.name, 'membertype': d.membertype, 'member00id': d.member00id } self._retval.append(r) def __del__(self): if self.__session is not None: self.__session.close()
class Login_data(Mini_func, object): def __init__(self, **kwargs): self.__session = Session() self.__args = kwargs self._retval = list() self.__search_filter = list() self.__search_param = ['username', 'password', 'role'] self.__data = None for key in self.__search_param: if key in self.__args and self.__args[key] not in (None, ''): self.__search_filter.append( getattr(Users_table, key) == self.__args[key]) if len(self.__search_filter) != 0: self.__data = self.__session.query(Users_table).filter( *self.__search_filter).order_by(Users_table.userid).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) else: self.__data = self.__session.query(Users_table).order_by( Users_table.userid).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) def insert_user(self, **kwargs): user = Users_table() for key in kwargs: if key in ('password'): try: setattr(user, key, self.encrypt_password(kwargs[key])) except TypeError: continue else: try: setattr(user, key, kwargs[key]) except TypeError: continue self.__session.add(user) self.__session.commit() data = self.__session.query(Users_table).filter( Users_table.userid == user.userid) self._retval = list() for d in data: r = d.toJSONExcept() self._retval.append(r) def encrypt_password(self, password): converted_pass = str.encode(password) salt = bcrypt.gensalt() hashed = bcrypt.hashpw(converted_pass, salt) retval = hashed.decode('utf-8') return retval def __del__(self): if self.__session is not None: self.__session.close()
class Reservations_data(Mini_func): def __init__(self, **kwargs): self.__session = Session() self.__args = kwargs self._retval = list() self.__search_filter = list() self.__search_param = ['reservationid'] self.__data = None def get_reservations(self): for key in self.__search_param: if key in self.__args and self.__args[key] not in (None, ""): self.__search_filter.append( getattr(T_Reservation, key) == self.__args[key]) ds = self.__args.get('from', None) de = self.__args.get('to', None) if ds and de: self.__search_filter.append( getattr(T_Reservation, 'res_date').between(ds, de)) if self.__search_filter: self.__data = self.__session.query(T_Reservation).filter( and_(*self.__search_filter)).order_by( T_Reservation.reservationid).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) else: self.__data = self.__session.query(T_Reservation).order_by( T_Reservation.reservationid).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) def post_reservations(self): reservation = T_Reservation() for key in self.__args: try: setattr(reservation, key, self.__args[key]) except TypeError: continue self.__session.add(reservation) self.__session.commit() def put_reservations(self): pass def del_reservations(self): retval = False if self.__data: retval = True for data in self.__data: self.__session.delete(data) try: self.__session.commit() except: self.__session.rollback() return retval
class Facialmodel(Mini_func): def __init__(self, **kwargs): self.__session = Session() self.__args = kwargs def get_services(self): retval = None result = self.__session.query(T_Facial_Services).all() temp_list = list() for d in result: r = d.toJSONExcept() temp_list.append(r) if temp_list: retval = temp_list return retval def insert_facial_service(self, **kwargs): fservices = T_Facial_Services() for key, value in kwargs.items(): try: setattr(fservices, key, value) except TypeError: continue self.__session.add(fservices) self.__session.commit() def del_facial_service(self, **kwargs): fsid = kwargs.get('id', 0) resdata = self.__session.query(T_Facial_Services).filter( T_Facial_Services.facial_services_id == fsid).first() if resdata: self.__session.delete(resdata) try: self.__session.commit() except: self.__session.rollback() def edit_facial_services(self, **kwargs): facialid = kwargs.get('facial_services_id', 0) result = self.__session.query(T_Facial_Services).filter( T_Facial_Services.facial_services_id == facialid).first() update_param = ['member_price', 'non_member_price', 'duration'] for param in update_param: data = kwargs.get(param, None) if data: try: setattr(result, param, data) except TypeError: continue self.__session.commit()
class Member00_data(Mini_func): def __init__(self, **kwargs): self.__session = Session() self.__args = kwargs self._retval = list() self.__search_filter = list() self.__search_param = [ 'member00id', 'membertype', 'attendantid', 'upgraded_by' ] self.__data = None def getmemberdata(self): for key in self.__search_param: if key in self.__args and self.__args[key] not in (None, ""): self.__search_filter.append( getattr(T_Member00, key) == self.__args[key]) ds = self.__args.get('from', None) de = self.__args.get('to', None) upg = self.__args.get('upgraded_by', None) if ds and de and not upg: self.__search_filter.append( getattr(T_Member00, 'datecreated').between(ds, de)) if ds and de and upg: self.__search_filter.append( getattr(T_Member00, 'upgraded').between(ds, de)) if not self.__search_filter: self.__data = self.__session.query(T_Member00).order_by( T_Member00.member00id).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) else: self.__data = self.__session.query(T_Member00).filter( *self.__search_filter).order_by(T_Member00.member00id).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) def postmemberdata(self, **kwargs): member = T_Member00() for key in kwargs: try: setattr(member, key, kwargs[key]) except TypeError: continue self.__session.add(member) self.__session.commit() query = "select max(member00id) from member00;" result = self.__session.execute(query).first() for memid in result: r = {'member00id': memid} self._retval.append(r) def editmemberdata(self, **kwargs): update_kwargs = kwargs search_param = ['member00id'] search_filter = list() retval = False for key in search_param: if key in update_kwargs and update_kwargs[key] not in (None, ""): search_filter.append( getattr(T_Member00, key) == update_kwargs[key]) if search_filter: retval = True data = self.__session.query(T_Member00).filter( *search_filter).order_by(T_Member00.member00id).all() update_param = [ 'membershipcost', 'membertype', 'upgraded_by', 'upgraded', 'address', 'mobile_number', 'landline_number', 'email_address', 'birthdate', 'name' ] print(update_kwargs) for obj in data: for key in update_param: if key in update_kwargs and update_kwargs[key] not in (None, ""): if key == 'upgraded': print('upgraded') update_kwargs[key] = datetime.datetime.strptime( update_kwargs[key], '%m/%d/%Y') print(update_kwargs[key]) try: setattr(obj, key, update_kwargs[key]) except TypeError: continue self.__session.commit() return retval def get_customize_members(self, char): memtype = self.__args.get('membertype', None) result = self.__session.query(T_Member00).filter( T_Member00.name.like("%{}%".format(char))).filter( T_Member00.membertype == "{}".format(memtype)).all() for d in result: r = d.toJSONExcept() print(r) self._retval.append(r) def __del__(self): if self.__session is not None: self.__session.close()
class Attendants_data(Mini_func): def __init__(self, **kwargs): self.__session = Session() self.__args = kwargs self._retval = list() self.__search_filter = list() self.__search_param = ['attendant_name', 'attendantid'] self.__data = None def get_attendants(self): for key in self.__search_param: if key in self.__args and self.__args[key] not in (None, ""): self.__search_filter.append( getattr(T_Attendants, key) == self.__args[key]) if not self.__search_filter: self.__data = self.__session.query(T_Attendants).order_by( T_Attendants.attendantid).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) else: self.__data = self.__session.query(T_Attendants).filter( *self.__search_filter).order_by( T_Attendants.attendantid).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) def del_attendants(self): retval = False if self.__data: retval = True for data in self.__data: self.__session.delete(data) try: self.__session.commit() except: self.__session.rollback() return retval def insert_Attendant(self, **kwargs): attendant = T_Attendants() for key in kwargs: try: setattr(attendant, key, kwargs[key]) except TypeError: continue self.__session.add(attendant) self.__session.commit() def edit_attendant(self, **kwargs): update_kwargs = kwargs search_param = ['attendantid'] search_filter = list() for key in search_param: if key in update_kwargs and update_kwargs[key] not in (None, ''): search_filter.append( getattr(T_Attendants, key) == update_kwargs[key]) if search_filter: retval = True self.__data = self.__session.query(T_Attendants).filter( and_(*search_filter)).order_by(T_Attendants.attendantid).all() else: retval = False update_list = ['position', 'allowance'] for obj in self.__data: for key in update_list: if key in update_kwargs and update_kwargs[key] not in ('', None): try: setattr(obj, key, update_kwargs[key]) except TypeError: continue self.__session.commit() def __del__(self): if self.__session is not None: self.__session.close()
class Promomodel(object): def __init__(self, **kwargs): self.__session = Session() self.__kwargs = kwargs def make_promo(self): promo = T_promos() for key, value in self.__kwargs.items(): if value: if key in ('datestart', 'dateend'): value = value.strftime('%Y-%m-%d') setattr(promo, key, value) self.__session.add(promo) self.__session.commit() def get_promo(self): retval = list() search_filter = list() for key, value in self.__kwargs.items(): if key in ('curdate') and value: datetoday = datetime.datetime.now().date().strftime('%Y-%m-%d') search_filter.append( getattr(T_promos, 'datestart') <= datetoday) search_filter.append(getattr(T_promos, 'dateend') >= datetoday) else: if value: search_filter.append(getattr(T_promos, key) == value) if search_filter: result = self.__session.query(T_promos).filter( and_(*search_filter)).all() for data in result: dict_data = data.toJSONExcept() retval.append(dict_data) else: result = self.__session.query(T_promos).all() for data in result: dict_data = data.toJSONExcept() retval.append(dict_data) return retval def edit_promo(self): retval = None promoid = self.__kwargs.get('promoid', 0) if not promoid: return retval promoobj = self.__session.query(T_promos).filter( getattr(T_promos, 'promoid') == promoid).first() for key, value in self.__kwargs.items(): if value in ('', None): continue if key in ('datestart', 'dateend'): dateval = datetime.datetime.strptime(value, '%m/%d/%Y') value = dateval.strftime('%Y-%m-%d') setattr(promoobj, key, value) try: self.__session.commit() except: retval = None else: retval = self.__kwargs return retval
class Transactions_data(Mini_func): def __init__(self, querytype='all', **kwargs): self.__session = Session() self.__args = kwargs self._retval = list() self.__search_filter = list() self.__search_param = [ 'active', 'transaction_type', 'transactionid', 'attendantid', 'member00id' ] self.__data = None for key in self.__search_param: if key in self.__args and self.__args[key] not in (None, ""): self.__search_filter.append( getattr(T_Transaction, key) == self.__args[key]) ds = self.__args.get('from', None) de = self.__args.get('to', None) if ds and de: self.__search_filter.append( getattr(T_Transaction, 'datecreated').between(ds, de)) if self.__search_filter: self.__data = self.__session.query(T_Transaction).filter( and_(*self.__search_filter)).order_by( T_Transaction.datestart).all() for d in self.__data: r = d.toJSONExcept() time = datetime.datetime.strptime(r['datestart'], '%m/%d/%Y %H:%M') r['started'] = time.time().strftime("%I:%M %p") etime = time + datetime.timedelta( minutes=int(d.estimated_time)) r['endtime'] = etime.strftime("%I:%M %p") self._retval.append(r) elif querytype is not None: self.__data = self.__session.query(T_Transaction).order_by( T_Transaction.datestart).all() for d in self.__data: r = d.toJSONExcept() time = datetime.datetime.strptime(r['datestart'], '%m/%d/%Y %H:%M') r['started'] = time.time().strftime("%I:%M %p") etime = time + datetime.timedelta( minutes=int(d.estimated_time)) r['endtime'] = etime.strftime("%I:%M %p") self._retval.append(r) def insert_transaction(self, **kwargs): transaction = T_Transaction() for key in kwargs: try: setattr(transaction, key, kwargs[key]) except TypeError: continue self.__session.add(transaction) self.__session.commit() def edit_transaction(self, **kwargs): update_kwargs = kwargs search_param = ['transactionid'] search_filter = list() for key in search_param: if key in update_kwargs and update_kwargs[key] not in (None, ''): search_filter.append( getattr(T_Transaction, key) == update_kwargs[key]) if search_filter: retval = True self.__data = self.__session.query(T_Transaction).filter( and_(*search_filter)).order_by(T_Transaction.datestart).all() else: retval = False update_list = [ 'payment_type', 'dateend', 'time_spent', 'active', 'service_type', 'service', 'add_ons', 'attendant_name', 'attendantid', 'estimated_time', 'total_amount', 'service_price', 'add_ons_price' ] for obj in self.__data: for key in update_list: if key in update_kwargs and update_kwargs[key] is not None: if key == 'dateend': update_kwargs[key] = datetime.datetime.strptime( update_kwargs[key], '%m/%d/%Y, %I:%M:%S %p') try: setattr(obj, key, update_kwargs[key]) except TypeError: continue self.__session.commit() return retval def del_transaction(self): retval = False if self.__data: retval = True for data in self.__data: self.__session.delete(data) try: self.__session.commit() except: self.__session.rollback() return retval def __del__(self): self.__session.close()
class Attendants01_data(Mini_func): def __init__(self, **kwargs): self.__session = Session() self.__args = kwargs self._retval = list() self.__search_filter = list() self.__search_param = ['attendantid'] self.__data = None def get_rawtime(self): for key in self.__search_param: if key in self.__args and self.__args[key] not in (None, ''): self.__search_filter.append( getattr(T_Attendants01, key) == self.__args[key]) ds = self.__args.get('from', None) de = self.__args.get('to', None) if ds and de: self.__search_filter.append( getattr(T_Attendants01, 'trandate').between(ds, de)) if self.__search_filter: self.__data = self.__session.query(T_Attendants01).filter( *self.__search_filter).order_by( T_Attendants01.attendantid).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) else: self.__data = self.__session.query(T_Attendants01).order_by( T_Attendants01.attendantid).all() for d in self.__data: r = d.toJSONExcept() self._retval.append(r) def insert_rawtime(self, **kwargs): attendant = T_Attendants01() attendantid = kwargs.get('attendantid', 0) trandate = kwargs.get('trandate', 0) print(attendantid, trandate) att_filter = [ getattr(T_Attendants01, 'attendantid') == attendantid, getattr(T_Attendants01, 'trandate') == trandate ] if not attendantid or not trandate: return None exist = self.__session.query(T_Attendants01).filter( *att_filter).first() if not exist: for key in kwargs: if kwargs[key]: try: setattr(attendant, key, kwargs[key]) except TypeError: continue self.__session.add(attendant) self.__session.commit() else: update_list = ['timein', 'timeout'] for key in update_list: if key in kwargs and kwargs[key]: try: setattr(exist, key, kwargs[key]) except TypeError: continue self.__session.commit()