def feedback_list(self, request): check_admin(endpoints) qry = FeedbackEntity.query().order(-FeedbackEntity.date_created) fbs = qry.fetch() fms = [] for fb in fbs: created_time = fb.date_created if created_time: utc_zone = tz.gettz("UTC") cst_zone = tz.gettz("America/Chicago") created_time = created_time.replace(tzinfo=utc_zone) created_time_cst = created_time.astimezone(cst_zone) created_time_cst = created_time_cst.strftime("%Y-%m-%d") else: created_time_cst = "" fm = FeedbackWithIdMessage( id=str(fb.key.id()), restaurant=fb.restaurant, entrie=fb.entrie, quantity=fb.quantity, flavor=fb.flavor, deliverman=fb.deliverman, comment=fb.comment, overall_rating=fb.overall_rating, date=created_time_cst, useremail=fb.useremail, ) fms.append(fm) return FeedbackCollectionMessage(feedbacks=fms)
def get(self): user = users.get_current_user() logging.info(user) user_email = user.email() role = RoleEntity.get_by_id('admin') members = role.members if not members: members = [] if user_email not in members: logging.critical("Unauthorized request : " + user_email) self.response.write("Unauthorized request") return self.response.headers['Content-Type'] = 'application/csv;charset=UTF-8' self.response.headers['Content-disposition'] = 'attachment; filename=all_feedbacks.csv' csv_writer = csv.writer(self.response.out, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) u_csv_writer = UnicodeWriter(self.response.out) qry = FeedbackEntity.query().order(-FeedbackEntity.date_created) fbs = qry.fetch() fms = [] # csv_writer.writerow(['id','restaurant','entrie','quantity','flavor','deliverman','overall','timestamp']) u_csv_writer.writerow(['id','restaurant','entrie','quantity','flavor','deliverman','overall','timestamp','comment']) for fb in fbs: created_time = fb.date_created if created_time: utc_zone = tz.gettz('UTC') cst_zone = tz.gettz('America/Chicago') created_time = created_time.replace(tzinfo=utc_zone) created_time_cst = created_time.astimezone(cst_zone) created_time_cst = created_time_cst.strftime('%Y-%m-%d') else: created_time_cst = "" u_csv_writer.writerow([str(fb.key.id()),fb.restaurant or "",fb.entrie or "", fb.quantity or "", fb.flavor or "", fb.deliverman or "", fb.overall_rating or "", created_time_cst, fb.comment or ""])
def feedback_get(self, request): fm = FeedbackEntity.get_by_id(request.id) return FeedbackWithIdMessage( id=str(fm.key.id()), restaurant=fm.restaurant, entrie=fm.entrie, quantity=fm.quantity, flavor=fm.flavor, deliverman=fm.deliverman, overall_rating=fm.overall_rating, comment=fm.comment, date=fm.date_created.strftime("%Y-%m-%d"), useremail=fm.useremail, )
def feedback_insert(self, request): fm = FeedbackEntity( restaurant=request.restaurant, entrie=request.entrie, quantity=request.quantity, flavor=request.flavor, deliverman=request.deliverman, overall_rating=request.overall_rating, comment=request.comment, useremail=request.useremail, ) fm.put() return FeedbackWithIdMessage( id=str(fm.key.id()), restaurant=fm.restaurant, entrie=fm.entrie, quantity=fm.quantity, flavor=fm.flavor, deliverman=fm.deliverman, overall_rating=fm.overall_rating, comment=fm.comment, useremail=fm.useremail, )