def get(self): if not isUserDelivery(self): self.session[LOGIN_NEXT_PAGE_KEY] = self.URL self.redirect("/") return userKey = self.request.get("userKey") mondayString = self.request.get("monday") monday = datetime.datetime.strptime(mondayString, "%Y-%m-%d").date() user = User.get(userKey) if user == None: print "No user!" return weeks = user.weeks.filter("monday = ", monday) referenceWeek = weeks.get() days = [] weekOrderTotal = 0 weekDeliveryTotal = 0 for i in range(0,5): day = {} actualDay = monday + datetime.timedelta(days=i) daysOrderItems = getOrderedItemsFromWeekData(weeks, actualDay) address=getOrderAddress(referenceWeek, actualDay) day['orderedItems'] = daysOrderItems day['day']=dayNames[i] day['date'] = actualDay orderedPrice = 0 for orderedItem in daysOrderItems: try: orderedPrice = orderedPrice + orderedItem['price'] * orderedItem['orderedQuantity'] except: pass weekOrderTotal = weekOrderTotal + orderedPrice day["orderedPrice"] = orderedPrice if len(daysOrderItems) > 0: day['address'] = address deliveryCost = 0 if address != None: deliveryCost = getZipBasedDeliveryCost(address.zipNumCode, orderedPrice) day["deliveryCost"] = deliveryCost weekDeliveryTotal = weekDeliveryTotal + deliveryCost days.append(day) template_values = { 'user':user, 'days':days, 'week':referenceWeek, 'deliveryTotal':weekDeliveryTotal, 'orderTotal':weekOrderTotal, 'total':weekOrderTotal + weekDeliveryTotal, } prevMonday = monday + datetime.timedelta(days= -7) template_values['prev'] = prevMonday nextMonday = monday + datetime.timedelta(days= 7) template_values['next'] = nextMonday template = jinja_environment.get_template('templates/delivery.html') self.printPage(str(day), template.render(template_values), False, False)
def get(self): if not isUserDelivery(self): self.session[LOGIN_NEXT_PAGE_KEY] = self.URL self.redirect("/") return day=getBaseDate(self) calendar=day.isocalendar() #Organize into days dayTotal = 0 dayCount = 0 dayQuantity = 0 dayObject={} dayObject["day"]=dayNames[calendar[2]-1] dayObject["date"]=day prevDay=day+datetime.timedelta(days=-1) nextDay=day+datetime.timedelta(days=1) today=datetime.date.today() monday = getMonday(day) weeks = UserWeekOrder.all().filter('monday = ', monday) deliveries = [] for week in weeks: dailyUserTotal = 0 items = getOrderedItemsFromWeekData([week], day) if len(items) > 0: for item in items: dayTotal = dayTotal + item['orderedQuantity'] * item['price'] dailyUserTotal = dailyUserTotal + item['orderedQuantity'] * item['price'] orderAddress = getOrderAddress(week, day) if orderAddress == None: orderAddress = week.user.addresses.get(0) orderAddress.comment = getOrderComment(week, day) orderAddress.orderedItems = items orderAddress.week = week orderAddress.dailyUserTotal = dailyUserTotal orderAddress.dailyUserDelivery = getZipBasedDeliveryCost(orderAddress.zipNumCode, dailyUserTotal) orderAddress.todayPaid = getPaid(week, day) orderAddress.weeklyPaid = getWeeklyPaid(week) orderAddress.weeklyTotal = getOrderTotal([week]) orderAddress.weeklyDelivery = getWeeklyDelivery(week) deliveries.append(orderAddress) sortedDeliveries = sorted(deliveries, key=lambda item:item.zipNumCode) template_values = { 'next':nextDay, 'actual':today, 'orders':sortedDeliveries, 'day':dayObject, 'dayTotal': dayTotal, } template_values['prev'] = prevDay template = jinja_environment.get_template('templates/deliveryReviewOrders.html') self.printPage(str(day), template.render(template_values), False, False)