def post(self): user = users.get_current_user(); rootPath = os.path.split(os.path.dirname(__file__))[0] if user and users.is_current_user_admin(): #delete the specified feedbacks from db prev = False next = True FeedbackIds = self.request.get_all('feedback_id'); deletedFeedbacks = 0 for id in FeedbackIds: feedback = Feedback.get_by_id(int(id)) if feedback: feedback.delete() deletedFeedbacks += 1 feedbacks_query = Feedback.all().order('-timestamp') feedbacks = feedbacks_query.fetch(DeleteFeedbacks.PAGESIZE+1) if len(feedbacks) == DeleteFeedbacks.PAGESIZE+1: feedbacks = feedbacks[:DeleteFeedbacks.PAGESIZE] next = True template_values = { "feedbackslen" : len(feedbacks), "feedbacks" : feedbacks, 'username' : user.nickname(), 'success_msg' : str(deletedFeedbacks)+" feedbacks successfully deleted", 'next' : next, 'previous' : prev, 'lastResultIndex' : len(feedbacks), } path = os.path.join(rootPath, "html/view_feedback.html") else: #insufficient privileges template_values = { 'error_msg' : "insufficient privileges" } path = os.path.join(rootPath, "html/error.html") self.response.out.write(template.render(path, template_values))
def get(self): user = users.get_current_user(); rootPath = os.path.split(os.path.dirname(__file__))[0] if user and users.is_current_user_admin(): #TODO: value error if Xscripting goToNext = self.request.get('goToNext'); goToPrevious = self.request.get('goToPrevious'); try: prevLastResultIndex = int(self.request.get('lastResultIndex')) except ValueError: prevLastResultIndex = 0 next = False prev = False calcOffset = 0 feedback_query = Feedback.all().order('-timestamp') if goToNext and len(goToNext) > 0: #show next PAGESIZE results calcOffset = prevLastResultIndex elif goToPrevious and len(goToPrevious) > 0: #show previous PAGESIZE results if (prevLastResultIndex % ViewFeedback.PAGESIZE) != 0: prevLastResultIndex = (prevLastResultIndex / ViewFeedback.PAGESIZE) * ViewFeedback.PAGESIZE calcOffset = prevLastResultIndex - ViewFeedback.PAGESIZE; else: calcOffset = prevLastResultIndex - 2*ViewFeedback.PAGESIZE; calcOffset = 0 if (calcOffset < 0) else calcOffset else: calcOffset = 0 feedbacks = feedback_query.fetch(limit=ViewFeedback.PAGESIZE+1, offset=calcOffset) if len(feedbacks) == ViewFeedback.PAGESIZE + 1: feedbacks = feedbacks[:ViewFeedback.PAGESIZE] next = True else: next = False if calcOffset == 0: prev = False else: prev = True lastResultIndex = calcOffset + len(feedbacks) template_values = { "feedbackslen" : len(feedbacks), "feedbacks" : feedbacks, 'username' : user.nickname(), 'lastResultIndex' : lastResultIndex, 'next' : next, 'previous' : prev } path = os.path.join(rootPath, "html/view_feedback.html") else: template_values = { 'errorMsg' : 'Not sufficient privileges' } path = os.path.join(rootPath, "html/error.html") self.response.out.write(template.render(path, template_values))