def get(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("/") # If user is not admin go to home showing that he has not permissions if not (user_info.is_admin()): webapp2.add_flash("not_allowed_show_users") return self.redirect("/") # Get all users ordered by X way user_admin_set = User.query( User.level == User.Level.Admin).order(-User.added) user_staff_set = User.query(User.level != User.Level.Admin).order( User.level).order(-User.added) user_set = list(user_admin_set) + list(user_staff_set) # Prepare variables to send to view template_variables = { "users": user_set, "Level": User.Level, } # Render 'users' view sending the variables 'template_variables' return Globals.render_template(self, "users.html", template_variables)
def get(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("/") # If user is not admin go to tickets list showing that he has not permissions if not (user_info.is_admin()): webapp2.add_flash("not_allowed_delete_tickets") return self.redirect("/tickets") # Get ticket by id ticket = ndb.Key(urlsafe=ticket_id).get() # If ticket doesn't exist go to tickets list showing the error if not ticket: webapp2.add_flash("missing_ticket_to_delete") return self.redirect("/tickets") # Prepare variables to send to view template_variables = {"ticket": ticket, "ticket_model": Ticket} # Render 'delete_ticket' view sending the variables 'template_variables' return Globals.render_template(self, "delete_ticket.html", template_variables)
def get(self, user_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("/") # If user is not admin go to users list showing that he has not permissions if not (user_info.is_admin()): webapp2.add_flash("not_allowed_delete_users") return self.redirect("/users") # Get user by id user_to_delete = ndb.Key(urlsafe=user_id).get() # If user doesn't exist go to users list showing the error if not user_to_delete: webapp2.add_flash("missing_user_to_delete") return self.redirect("/users") # Prepare variables to send to view template_variables = { "user_to_delete": user_to_delete, "user_model": User } # Render 'delete_user' view sending the variables 'template_variables' return Globals.render_template(self, "delete_user.html", template_variables)
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 send_std_email_for(ticket, subject, body): body = dt.datetime.today().strftime("%Y-%m-%d %H:%M:%S")\ + "\n\nrcpts: " + AppInfo.BroadcastEmail + (", " + ticket.client_email if ticket.client_email else "") \ + body\ + u"\n\n---\n\n" + AppInfo.AppWeb + u'\n' subject = subject.strip().lower() subject = subject[0].upper() + subject[1:] subject = subject + " ticket #" + str(ticket.serial)\ + ' ' + ticket.title Globals.send_email(AppInfo.BroadcastEmail, subject, body) if ticket.client_email: Globals.send_email(ticket.client_email, subject, body)
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("/") # If user is not admin go to tickets list showing that he has not permissions if not (user_info.is_admin()): webapp2.add_flash("not_allowed_delete_tickets") return self.redirect("/tickets") # Get ticket by id ticket = ndb.Key(urlsafe=ticket_id).get() # If ticket doesn't exist go to tickets list showing the error if not ticket: webapp2.add_flash("missing_ticket_title") return self.redirect("/tickets") # Delete ticket ticket.key.delete() # Set successful message and redirect to tickets list webapp2.add_flash("ticket_deleted_successfully") return self.redirect("/tickets")
def post(self, user_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("/") # If user is not admin go to users list showing that he has not permissions if not (user_info.is_admin()): webapp2.add_flash("not_allowed_delete_users") return self.redirect("/users") # Get user by id user_to_delete = ndb.Key(urlsafe=user_id).get() # If user doesn't exist go to users list showing the error if not user_to_delete: webapp2.add_flash("missing_user_to_delete") return self.redirect("/users") # Delete user user_to_delete.key.delete() # Set successful message and redirect to users list webapp2.add_flash("user_deleted_successfully") return self.redirect("/users")
def get(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("/") # Prepare variables to send to view template_variables = { "ticket_model": Ticket } # Render 'add_ticket' view sending the variables 'template_variables' return Globals.render_template(self, "add_ticket.html", template_variables)
def get(self): # Get current user information user, user_info = Globals.get_user_info() # Check if user is logged, if he is redirect to tickets list if user and user_info: return self.redirect("/tickets") # Create empty user with a random nick usr_info = usr_mgt.create_empty_user() usr_info.nick = "Login" # Prepare variables to send to view template_variables = {} # Render 'index' view sending the variables 'template_variables' return Globals.render_template(self, "index.html", template_variables)
def get(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("ticket_not_exist") return self.redirect("/tickets") # Prepare variables to send to view template_variables = {'ticket': ticket, "ticket_model": Ticket} # Render 'modify_ticket' view sending the variables 'template_variables' return Globals.render_template(self, "modify_ticket.html", template_variables)
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 post(self, user_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("/") # If user is not admin go to users list showing that he has not permissions if not (user_info.is_admin()): webapp2.add_flash("not_allowed_edit_users") return self.redirect("/") # Get user by id user_to_modify = ndb.Key(urlsafe=user_id).get() # If user doesn't exist go to users index showing the error if not user_to_modify: webapp2.add_flash("user_not_exist") return self.redirect("/users") # Set all parameters from the request to user user_to_modify.email = self.request.get("email", "").strip() user_to_modify.nick = self.request.get("nick", "").strip() user_to_modify.level = User.Level.value_from_str( self.request.get("level", "Client").strip()) # If user email is missing return to modify view showing the error if len(user_to_modify.email) < 1: webapp2.add_flash("missing_user_email") return self.redirect("/users/modify/" + user_id) # If user nick is missing return to modify view showing the error if len(user_to_modify.nick) < 1: webapp2.add_flash("missing_user_nick") return self.redirect("/users/modify/" + user_id) # Save user User.update(user_to_modify) # Set successful message and redirect to users list webapp2.add_flash("user_modified_successfully") return self.redirect("/users")
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")