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 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