示例#1
0
文件: plans.py 项目: wangjun/appetsy
 def update(self):
     plan = storage.Counters.get_or_insert("%s:week_%s_plans" % (self.shop.id, appetsy.monday(self.shop).strftime("%U")),
                                           shop = self.shop,
                                           name = "weeks_plan",
                                           count = 10,
                                           timestamp = dt.datetime.combine(appetsy.monday(self.shop), dt.time()))
     plan.count = int(self.request.get("weeks_plan"))
     plan.put()
     
     memcache.set("week_%s_plans" % appetsy.monday(self.shop).strftime("%U"), plan,
                  namespace = str(self.shop.id))
     appetsy.invalidate_memcache("goods", namespace = str(self.shop.id))
示例#2
0
文件: index.py 项目: wangjun/appetsy
    def progress_box(self):
        income_progress = memcache.get("income_progress",
                                       namespace = str(self.shop.id))
        plan = memcache.get("week_%s_plans" % appetsy.monday(self.shop).strftime("%U"),
                            namespace = str(self.shop.id))

        if not income_progress or not plan:
            # total income for the progress box
            data = {}

            totals = storage.Totals.all().filter("shop =", self.shop) \
                                 .filter("name =", "shop_income").fetch(1000)
            data["total_money"] = sum([total.total for total in totals])

            monday = appetsy.monday(self.shop)

            goods_week = storage.Goods.all().filter("shop =", self.shop) \
                                    .filter("created >=", monday).fetch(100)

            goods_week = [good for good in goods_week if good.status in ("in_stock", "sold")]

            days = {}
            plan = storage.Counters.get_or_insert("%s:week_%s_plans" % (self.shop.id, appetsy.monday(self.shop).strftime("%U")),
                                                  shop = self.shop,
                                                  name = "weeks_plan",
                                                  count = 10,
                                                  timestamp = dt.datetime.combine(appetsy.monday(self.shop), dt.time()))
            planned = plan.count

            for good in goods_week:
                days.setdefault(good.created.weekday(), []).append(good)

            day_max = max(2, max([len(goods) for goods in days.values()] or [0]))
            weekday_count = max(4, max(days.keys() or [0]))

            data["planned"] = planned
            data["days"], data["day_max"], data["weekday_count"] = days, day_max, weekday_count

            data["goods_week"] = goods_week
            if planned > 0:
                weekday = appetsy.today(self.shop).weekday()
                data["percentage_complete"] = "%d" % (len(goods_week) / ((planned / float(max(5.0, weekday + 1))) * (weekday + 1)) * 100)
            else:
                data["percentage_complete"] = None



            income_progress = appetsy.get_template("index/progress_box.html").render(**data)
            memcache.set("income_progress", income_progress, namespace = str(self.shop.id))

        return income_progress