def post(self): if not isUserDelivery(self): self.session[LOGIN_NEXT_PAGE_KEY] = self.URL self.redirect("/") return day=getBaseDate(self) weekKey = self.request.get("weekKey") try: amount = int(self.request.get("todayPaid")) week = UserWeekOrder.get(weekKey) if day.weekday() == 0: week.mondayPaid = amount elif day.weekday() == 1: week.tuesdayPaid = amount elif day.weekday() == 2: week.wednesdayPaid = amount elif day.weekday() == 3: week.thursdayPaid = amount elif day.weekday() == 4: week.fridayPaid = amount elif day.weekday() == 5: week.saturdayPaid = amount elif day.weekday() == 6: week.sundayPaid = amount week.put() except: pass self.redirect(DeliveryReviewOrdersPage.URL + "?day=" + str(day));
def post(self): self.session[LOGIN_NEXT_PAGE_KEY] = self.URL if not isUserAdmin(self): self.session[LOGIN_NEXT_PAGE_KEY] = self.URL self.redirect("/") return toReplace = self.request.get('toReplace') replaceWith = self.request.get('replaceWith') monday = self.request.get('monday') mondaysWeeks = UserWeekOrder.all().filter("monday = ", parseDate(monday)) weeks = [] for week in mondaysWeeks: newComposits = [] modified = False for item in week.orderedComposits: if item.find(toReplace) != -1: modified = True newItem = item.replace(toReplace, replaceWith) newComposits.append(newItem) else: newComposits.append(item) if modified: week.orderedComposits = newComposits week.put() weeks.append(week) template_values = { 'toReplace':toReplace, 'replaceWith':replaceWith, 'monday':monday, 'weeks':weeks } template = jinja_environment.get_template('templates/admin/replaceComposit.html') self.printPage("Kompositok cseréje", template.render(template_values), False, False)
def getUserWeek(key): client = memcache.Client() week = client.get(str(key)) # If not in memcache, does nothing if week != None: return week else: weekDb = UserWeekOrder.get(key) if (weekDb == None): return None week = createWeekDb(weekDb) client.add(str(key), week) return week
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)
def get(self): if not isUserAdmin(self): self.session[LOGIN_NEXT_PAGE_KEY] = self.URL self.redirect("/") return weeks = UserWeekOrder.all() newWeeks = [] for week in weeks: try: week.user.key() except: week.user = None newWeeks.append(week) template_values = { 'weeks' : newWeeks } template = jinja_environment.get_template('templates/csv/userOrders.download') self.response.out.write(template.render(template_values))
def post(self): if(not isUserLoggedIn(self)): self.redirect("/registration") return userKey = self.session.get(USER_KEY,None) user=None if (userKey != None): user = User.get(userKey) addresses = user.addresses.filter("active = ", True) if addresses.count()==0: template = jinja_environment.get_template('templates/no_address.html') self.printPage('Rendelesek', template.render(), True) return actualOrder = self.session.get(ACTUAL_ORDER,{}) firstOrderableDay = getFirstOrderableDate(self) orderTotal = 0 orderedItems = [] if (len(actualOrder) > 0): # Organize actual order into weeks ordersInWeeks = {} # A map holding ordered items with ordered quantiy for orderKey in actualOrder.keys(): orderItemCount = int(actualOrder[orderKey]) if (orderItemCount != 0): item = db.get(orderKey) day = item.day if day < firstOrderableDay: continue monday = getMonday(day) if ordersInWeeks.has_key(monday): weekHolder = ordersInWeeks.get(monday) else: weekHolder = [] orderItem = { 'key' : orderKey, 'quantity' : orderItemCount } weekHolder.append(orderItem) ordersInWeeks[monday] = weekHolder # Go through order week by week if len(ordersInWeeks) > 0: orderedItemsForMail = {} for monday in ordersInWeeks.keys(): weekHolder = ordersInWeeks.get(monday) alreadyOrdered = getUserOrdersForWeek(user, monday) # Merge orders for the week for item in weekHolder: orderedQuantity = item['quantity'] orderItemKey = item['key'] # Order should not remove more items than already ordered if alreadyOrdered.has_key(orderItemKey): alreadyOrderedQuantity = alreadyOrdered.get(orderItemKey) if alreadyOrderedQuantity + orderedQuantity < 0: orderedQuantity = 0 - alreadyOrderedQuantity if isMenuItem(orderItemKey): menuItem = getMenuItem(orderItemKey) day = menuItem['day'] menuItem['quantity'] = orderedQuantity menuItem['totalPrice'] = orderedQuantity * menuItem['price'] menuItem['isMenuItem'] = True orderTotal = orderTotal + orderedQuantity * menuItem['price'] orderedItems.append(str(day) + " " + str(orderItemKey) + " " + str(orderedQuantity) + " " + str(menuItem['price'])) if orderedItemsForMail.has_key(day): daysItems = orderedItemsForMail.get(day) daysItems.append(menuItem) else: daysItems = [] daysItems.append(menuItem) orderedItemsForMail[day] = daysItems else: composit = getComposit(orderItemKey) day = composit['day'] composit['quantity'] = orderedQuantity composit['totalPrice'] = orderedQuantity * composit['price'] composit['isMenuItem'] = False orderTotal = orderTotal + orderedQuantity * composit['price'] orderedItems.append(str(day) + " " + str(orderItemKey) + " " + str(orderedQuantity) + " " + str(composit['price'])) if orderedItemsForMail.has_key(day): daysItems = orderedItemsForMail.get(day) daysItems.append(composit) else: daysItems = [] daysItems.append(composit) orderedItemsForMail[day] = daysItems if alreadyOrdered.has_key(orderItemKey): orderedQuantity = orderedQuantity + alreadyOrdered.get(orderItemKey) if (orderedQuantity > 0): alreadyOrdered[orderItemKey] = orderedQuantity else: alreadyOrdered.pop(orderItemKey, 0) # Add stuff to the first week the user created daysForMail = orderedItemsForMail.keys() sortedDays = sorted(daysForMail) sortedItemsForMail = [] for day in sortedDays: sortedItemsForMail.append( {'day':day, 'orders':orderedItemsForMail.get(day)} ) weeks = user.weeks.filter("monday = ", monday) if (weeks.count() > 0): week = weeks.get() else: week = UserWeekOrder() week = UserWeekOrder() week.user = user week.monday = monday # Add address for every day defaultAddress = user.addresses.filter("active = ", True).get() week.mondayAddress = defaultAddress week.tuesdayAddress = defaultAddress week.wednesdayAddress = defaultAddress week.thursdayAddress = defaultAddress week.fridayAddress = defaultAddress week.saturdayAddress = defaultAddress week.sundayAddress = defaultAddress orderedMenuItems = [] orderedComposits = [] for itemKey in alreadyOrdered.keys(): newItem = str(alreadyOrdered.get(itemKey)) + " " + itemKey if isMenuItem(itemKey): orderedMenuItems.append(newItem) else: orderedComposits.append(newItem) week.orderedMenuItems = orderedMenuItems week.orderedComposits = orderedComposits week.put() user.lastOrder = datetime.datetime.now(timeZone).date() user.lastOrderFlag = True user.put() updateUser(user) template_values = { "user":user, 'userOrder':sortedItemsForMail, } logInfo(self, self.URL, "ORDER_POSTED") event = UserOrderEvent() event.orderDate = datetime.datetime.now(timeZone) event.user = user event.price = orderTotal event.orderedItems = orderedItems event.put() # Send email notification to the user messageTxtTemplate = jinja_environment.get_template('templates/orderNotificationMail.txt') messageHtmlTemplate = jinja_environment.get_template('templates/orderNotificationMail.html') message = mail.EmailMessage(sender="Diet Futar <*****@*****.**>") message.subject="Diet-futar, rendeles visszaigazolasa" message.to = user.email message.bcc = "*****@*****.**" message.body = messageTxtTemplate.render(template_values) message.html = messageHtmlTemplate.render(template_values) message.send() self.session[ACTUAL_ORDER]={} #self.response.out.write(messageTemplate.render(template_values)); self.redirect("/personalMenu") else: print "Error #100: Can't process orders." else: print "Error #100: Can't process orders."
def getOrdersForWeek(monday): weeks = UserWeekOrder.all().filter("monday = ", monday) return getOrdersFromWeeks(weeks)