def get(self): today = dt.datetime.today() if (today.weekday() < 5 and today.month != 8): message_body = "Daily report\n\nPending open tickets\n\n===\n\n" tickets = Ticket.query( Ticket.status == Ticket.Status.Open).order(-Ticket.added) for ticket in tickets: message_body += str(ticket) + "\n\n---\n\n" message_body += "\n\n---\n\n" + AppInfo.AppWeb + "\n" EmailMessage(sender=AppInfo.AppEmail, subject=AppInfo.Name + " report: " + today.strftime("%Y-%m-%d %H:%M:%S"), to=AppInfo.BroadcastEmail, body=message_body.decode("ascii", "replace")).send() self.redirect("/info?url=/manage_tickets&msg=Report sent to: " + AppInfo.BroadcastEmail.decode("ascii", "replace")) else: self.redirect( "/info?url=/manage_tickets&msg=Report only to be sent 9h mon-fri, except on august" )
def get(self, page): # Get current user information user, user_info = Globals.get_user_info() # Check if user is logged, if not redirect to home if not user or not user_info: webapp2.add_flash("not_logged_user") return self.redirect("/") # Describe query to get all tickets ordered by added date tickets = Ticket.query().order(-Ticket.added) # Obtain url parameter show_all show_all = self.request.get('show_all') # If show_all is not a GET parameter initialize to 'opened' if not show_all: show_all = 'opened' # If parameter show_all is not 'all' filter tickets by opened status if show_all != "all": tickets = tickets.filter(Ticket.status == Ticket.Status.Open) # If user role is client filter tickets matching his email with owner_email or user_info.email if user_info.is_client(): tickets = tickets.filter(Ticket.owner_email == user_info.email or Ticket.client_email == user_info.email) # Fetch all tickets tickets = tickets.fetch(keys_only=True) # Get search parameter and filter tickets by search field search_arg = self.request.get('search') if search_arg: list_search_terms = [x.lower() for x in search_arg.split()] tickets = TicketsManager.filter_by_search_terms( tickets, list_search_terms) # If page is not in the url set page to 0 if not page: page = 0 # Paginate tickets and generate pages information pages_info = {} tickets = TicketsManager.paginate(tickets, pages_info, page) # Prepare variables to send to view template_variables = { "ticket_model": Ticket, "show_all": show_all, "search_terms": search_arg, "pages_info": pages_info, "tickets": tickets, } # Render 'tickets' view sending the variables 'template_variables' return Globals.render_template(self, "tickets.html", template_variables)
def ocuparPlaza(self, vehiculo, ticketRepository): estado = False for i in self.listaPlazas: if i.estaLibre and estado != True: i.ocupar(vehiculo) ticketRepository.listaTicket.append(Ticket(vehiculo, i)) self.plazasLibres -= 1 estado = True return estado
def post(self): # Get current user information user, user_info = Globals.get_user_info() # Check if user is logged, if not redirect to home if not user or not user_info: webapp2.add_flash("not_logged_user") return self.redirect("/") # Create empty ticket ticket = Ticket() # Set all parameters from the request to ticket ticket.title = self.request.get("title", "").strip() ticket.desc = self.request.get("desc", "").strip() ticket.client_email = self.request.get("client_email", "").strip() ticket.classroom = self.request.get("classroom", "").strip() ticket.progress = Ticket.Progress.value_from_str(self.request.get("progress")) ticket.status = Ticket.Status.value_from_str(self.request.get("status")) ticket.priority = Ticket.Priority.value_from_str(self.request.get("priority")) ticket.type = Ticket.Type.value_from_str(self.request.get("type")) # If ticket title is missing return to modify view showing the error if len(ticket.title) < 1: webapp2.add_flash("missing_ticket_title") return self.redirect("/tickets/add/") # If ticket description is missing return to modify view showing the error if len(ticket.desc) < 1: webapp2.add_flash("missing_ticket_description") return self.redirect("/tickets/add/") # Save ticket tickets.update(ticket) # Set successful message and redirect to tickets list webapp2.add_flash("ticket_modified_successfully") return self.redirect("/tickets")
def get(self): user = users.get_current_user() usr_info = usr_mgt.retrieve(user) if user and usr_info and usr_info.is_admin(): self.csv_content = "" tickets = Ticket.query( Ticket.type == Ticket.Type.Supplies).order(-Ticket.added) tickets.map(self.add_csv_row) self.response.headers['Content-Type'] = "text/csv" self.response.headers[ 'Content-Disposition'] = "attachment; filename=supplies.csv" self.response.write(self.csv_content) else: self.redirect("/") return
def ticket(): id = request.form['id'] flight = Flight.query.filter_by(id=id).one() if flight.numberseats == 0: flash('Cannot buy') else: flight.numberseats = flight.numberseats - 1 Flight.query.filter_by(id=id).update( {"numberseats": flight.numberseats}) client = Client.query.filter_by(username=session['name']).one() airline = Airline.query.filter_by(id=flight.airline).one() ticket = Ticket(client_id=client.id, flight_id=flight.id, cost=flight.cost) db.session.add(ticket) db.session.commit() return redirect('/flight')
def lambda_handler(event, context): message_id = event['webhook_event']['message_id'] reply_account = event['webhook_event']['account_id'] keyword = event['webhook_event']['body'] if reply_account == MY_ACCOUNT: return print('No New Messages') es_client = EsClient() response = es_client.get_document_and(keyword) tickets = [] for ticket_record in response['hits']['hits']: ticket = Ticket(ticket_record) tickets.append(ticket) message = Message.get_message_body(message_id, reply_account, tickets, ROOM_ID) response = ChatWorkClient.post_messages(message, ROOM_ID) print(response)
def purchase(self): choose_train = self.tv.selection() choose_seat = self.combobox.get() if self.validate_purchase(choose_train, choose_seat): choose_train = self.tv.item(self.tv.selection()[0], 'values') split_from_time, split_to_time = self.split_time(choose_train) from_time = datetime.time(split_from_time[0], split_from_time[1], split_from_time[2]) to_time = datetime.time(split_to_time[0], split_to_time[1], split_to_time[2]) # 第一步,检查之前是否购买过当天的该车次 is_purchase = self.session.query(Ticket).filter( Ticket.user_id == self.user_id, Ticket.train_id == choose_train[0], Ticket.date == self.go_date).count() if is_purchase != 0: messagebox.showerror('错误', '您已经购买过当天的该车次,不能重复购买') else: # 第二步,检查当前该车次是否还有余票,因为别的用户也在操作,列表中的信息已经滞后了 from_order = self.session.query(TrainPass.order)\ .join(Station, Station.station_id == TrainPass.station_id)\ .filter(TrainPass.train_id == choose_train[0], Station.station_name == choose_train[1]).first() to_order = self.session.query(TrainPass.order) \ .join(Station, Station.station_id == TrainPass.station_id) \ .filter(TrainPass.train_id == choose_train[0], Station.station_name == choose_train[2]).first() if choose_seat == '硬座': seat_count = self.session.query(func.min(TrainRemain.seat_count))\ .filter(TrainRemain.train_id == choose_train[0], TrainRemain.order >= from_order[0], TrainRemain.order < to_order[0])\ .all() if seat_count[0][0] == 0: messagebox.showerror('错误', '票已售完') else: # 更新区间余票信息(都减1) self.session.query(TrainRemain)\ .filter(TrainRemain.train_id == choose_train[0], TrainRemain.order >= from_order[0], TrainRemain.order < to_order[0])\ .update({TrainRemain.seat_count: TrainRemain.seat_count-1}, synchronize_session="evaluate") # 生成订单 new_ticket = Ticket(user_id=self.user_id, train_id=choose_train[0], from_station_name=choose_train[1], to_station_name=choose_train[2], from_time=from_time, to_time=to_time, seat_type=choose_seat, price=int(choose_train[7]), date=self.go_date, is_get=0) self.session.add(new_ticket) self.session.commit() messagebox.showinfo('提示', '购买成功') else: bed_count = self.session.query(func.min(TrainRemain.bed_top_count), func.min(TrainRemain.bed_mid_count), func.min(TrainRemain.bed_bot_count)) \ .filter(TrainRemain.train_id == choose_train[0], TrainRemain.order >= from_order[0], TrainRemain.order < to_order[0]) \ .all() if bed_count[0][0] + bed_count[0][1] + bed_count[0][2] == 0: messagebox.showerror('错误', '票已售完') else: bed_type = self.random_selection(bed_count[0]) if bed_type == '上铺': # 更新区间余票信息(都减1) self.session.query(TrainRemain) \ .filter(TrainRemain.train_id == choose_train[0], TrainRemain.order >= from_order[0], TrainRemain.order < to_order[0]) \ .update({TrainRemain.bed_top_count: TrainRemain.bed_top_count - 1}, synchronize_session="evaluate") # 生成订单 new_ticket = Ticket( user_id=self.user_id, train_id=choose_train[0], from_station_name=choose_train[1], to_station_name=choose_train[2], from_time=from_time, to_time=to_time, seat_type='上铺', price=int(choose_train[8]), date=self.go_date, is_get=0) self.session.add(new_ticket) self.session.commit() messagebox.showinfo('提示', '购买成功(上铺)') elif bed_type == '中铺': # 更新区间余票信息(都减1) self.session.query(TrainRemain) \ .filter(TrainRemain.train_id == choose_train[0], TrainRemain.order >= from_order[0], TrainRemain.order < to_order[0]) \ .update({TrainRemain.bed_mid_count: TrainRemain.bed_mid_count - 1}, synchronize_session="evaluate") # 生成订单 new_ticket = Ticket( user_id=self.user_id, train_id=choose_train[0], from_station_name=choose_train[1], to_station_name=choose_train[2], from_time=from_time, to_time=to_time, seat_type='中铺', price=int(int(choose_train[8]) * 1.03), date=self.go_date, is_get=0) self.session.add(new_ticket) self.session.commit() messagebox.showinfo('提示', '购买成功(中铺)') else: # 更新区间余票信息(都减1) self.session.query(TrainRemain) \ .filter(TrainRemain.train_id == choose_train[0], TrainRemain.order >= from_order[0], TrainRemain.order < to_order[0]) \ .update({TrainRemain.bed_bot_count: TrainRemain.bed_bot_count - 1}, synchronize_session="evaluate") # 生成订单 new_ticket = Ticket( user_id=self.user_id, train_id=choose_train[0], from_station_name=choose_train[1], to_station_name=choose_train[2], from_time=from_time, to_time=to_time, seat_type='下铺', price=int(int(choose_train[8]) * 1.07), date=self.go_date, is_get=0) self.session.add(new_ticket) self.session.commit() messagebox.showinfo('提示', '购买成功(下铺)')