def find(self, operator, joins, kwargs): if any("report" in item.values() for item in kwargs): dict_ = { "ticket_enddate": datetime.now().strftime("%Y-%m-%d"), "ticket_startdate": datetime.now().strftime("%Y-%m-%d"), "total": 0, } for item in kwargs: if item.get("field") in [ "ticket_enddate", "ticket_startdate", "total", ]: dict_[item.get("field")] = item.get("value") return get_cte_query("user_filtering").format(**dict_) update = [] for item in kwargs: if item.get("field") not in [ "ticket_enddate", "ticket_startdate", "total", "report", ]: update.append(item) return super().find(operator, joins, update)
def validate_seat(self, seats, showtime_id): query = get_cte_query('available_seats').format( showtime_id=showtime_id) results = self.db.execute(query, named=False) available_seats = [] if results[0][0] is None else results[0][0] seat_diff = seats.difference(set(available_seats)) if seat_diff: raise ValidationError( 'error', status_code=400, payload={ 'message': f"seat numbers '{seat_diff}' in cinema hall not available check available seats for showtime" }) return
def find(self, operator, joins, kwargs): if any('report' in item.values() for item in kwargs): dict_={ 'ticket_enddate': datetime.now().strftime("%Y-%m-%d"), 'ticket_startdate': datetime.now().strftime("%Y-%m-%d"), 'total':0 } for item in kwargs: if item.get('field') in ['ticket_enddate', 'ticket_startdate', 'total']: dict_[item.get('field')] = item.get('value') return get_cte_query('user_filtering').format(**dict_) update = [] for item in kwargs: if item.get('field') not in ['ticket_enddate', 'ticket_startdate', 'total', 'report']: update.append(item) return super().find(operator, joins, update)
def test_file_not_found(self): with pytest.raises(ValidationError) as error: get_cte_query('invsf')
def update(self, id, operator, **kwargs): query = super().update(id, operator, **kwargs) return get_cte_query("showtime_insert").format(query)
def clean(self, query): return get_cte_query("clean_showtime").format(**query)
def insert_query(self, records): query = super().insert_query(records) return get_cte_query("showtime_insert").format(query)
def get_query(self, item='', start_date=datetime.now()): """ Query to filter though the sub table from the cte """ return get_cte_query(self.query).format(item, start_date=start_date)