def post(self): try: id = self.request.GET['ticket_id'] except KeyError: id = None if not id: self.redirect("/error?msg=missing id for modification") return user = users.get_current_user() usr_info = usr_mgt.retrieve(user) if user and usr_info: # Get ticket by key try: ticket = ndb.Key(urlsafe=id).get() except KeyError: self.redirect("/error?msg=key " + id + " does not exist") return 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 (not ticket.client_email and usr_info.is_client()): ticket.client_email = usr_info.email # Chk if len(ticket.title) < 1: self.redirect("/error?msg=Aborted modification: missing title") return if len(ticket.desc) < 1: self.redirect("/error?msg=Aborted modification: missing desc") return # Report tickets.send_email_for(ticket, "modified", " modified by: " + unicode(usr_info)) # Save ticket.born = True tickets.update(ticket) self.redirect("/info?url=/manage_tickets&msg=Ticket modified: " + ticket.title.encode("ascii", "replace")) else: self.redirect("/")
def post(self, ticket_id): # 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("/") # Get ticket by id ticket = ndb.Key(urlsafe=ticket_id).get() # If ticket doesn't exist go to tickets index showing the error if not ticket: webapp2.add_flash("missing_ticket_title") return self.redirect("/tickets") # 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/modify/" + ticket_id) # 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/modify/" + ticket_id) # Send email report to broadcast email # tickets.send_email_for(ticket, "modified", " modified by: " + str(user_info)) # 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: key = tickets.update(tickets.create(usr_info)) self.redirect("/tickets/modify?ticket_id=" + key.urlsafe()) else: self.redirect("/") return
def post(self): try: id = self.request.GET['ticket_id'] except: id = None if not id: self.redirect("/error?msg=missing id for modification") return user = users.get_current_user() usr_info = usr_mgt.retrieve(user) if user and usr_info: # Get ticket by key try: ticket = ndb.Key(urlsafe=id).get() except: self.redirect("/error?msg=key #" + id + " does not exist") return if (usr_info.email != ticket.owner_email and usr_info.is_client()): self.redirect("/error?msg=User " + user.email + " not allowed to check tickets") return new_comment = self.request.get("comment", "").strip() if len(new_comment) >= ChkTicket.MinCommentLength: 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.comments.append( tickets.Comment(author=usr_info.email, text=new_comment)) # Assure the ticket's progress is Fixed when appropriate if (ticket.status == Ticket.Status.Closed and (ticket.progress == Ticket.Progress.New or ticket.progress == Ticket.Progress.Tracked or ticket.progress == Ticket.Progress.Stalled)): ticket.progress = Ticket.Progress.Fixed # Save tickets.update(ticket) self.redirect( "/info?url=/manage_tickets&msg=Ticket checked: " + ticket.Status.values[ticket.status] + " " + ticket.Progress.values[ticket.progress] + " " + ticket.title.encode("ascii", "replace")) # Report tickets.send_email_chk_for( ticket, "checked", usr_info.email + " says:\n" + new_comment) else: self.redirect("/error?msg=Comment should be at least of " + unicode(ChkTicket.MinCommentLength) + " chars.") else: self.redirect("/")
def post(self): user = users.get_current_user() usr_info = usr_mgt.retrieve(user) if user and usr_info: # Retrieve values cartridge_model = self.request.get("cartridge_model", "").strip() printer_maker = self.request.get("printer_maker", "").strip() printer_model = self.request.get("printer_model", "").strip() str_num_units = self.request.get("number_of_units", "").strip() num_units = 1 # Chk if len(cartridge_model) < 3: self.redirect( "/error?msg=Aborted modification: missing cartridge model") return if len(printer_maker) < 2: self.redirect( "/error?msg=Aborted modification: missing printer maker") return if len(printer_model) < 5: self.redirect( "/error?msg=Aborted modification: missing printer model") return try: num_units = int(str_num_units) except ValueError: logs.error("Invalid number of units: " + str_num_units) if (num_units < 1 or num_units > 10): logs.error("Invalid number of units (1 < units < 10): " + str_num_units) # Create ticket ticket = tickets.create(usr_info) ticket.progress = Ticket.Progress.Tracked ticket.status = Ticket.Status.Open ticket.priority = Ticket.Priority.Low ticket.type = Ticket.Type.Supplies ticket.title = "Supplies: toner" ticket.desc = "Ink cartridge requested for: "\ + printer_maker + " " + printer_model + '\n'\ + "Cartridge #" + cartridge_model + "\n"\ + str(num_units) + " units" ticket.client_email = "" ticket.classroom = "" # Report tickets.send_email_for(ticket, "Ink cartridge request", " by " + str(usr_info)) # Save tickets.update(ticket) self.redirect( "/info?url=/manage_tickets&msg=Ink cartridge requested: " + ticket.title.replace('#', '').encode("ascii", "replace")) else: self.redirect("/")