Example #1
0
    def sold_and_featured_today(self):
        # TODO - should maybe add memcache but then have to check age
        # of the oldest item
        whole_day = appetsy.time(self.shop) - dt.timedelta(days=1)

        data = {}
        data["sold_today"] = storage.EtsyListings.all() \
                               .filter("shop =", self.shop) \
                               .filter("sold_on >", whole_day).fetch(100)

        data["frontpaged_today"] = storage.Frontpaged.all() \
                                     .filter("shop =", self.shop) \
                                     .filter("exposure_time >", whole_day).fetch(100)
        return appetsy.get_template("index/sold_and_featured_today.html").render(**data)
Example #2
0
    def index(self):
        """
        fan_list = memcache.get("500fans")
        # TODO we are relying on index.py resetting memcache on day change here
        if fan_list:
            return fan_list
        """
        
        fans = db.Query(storage.ShopFans).filter("shop =", self.shop) \
                                 .order("-favored_on").fetch(limit=500)
        
        fan_counter = storage.Counters.get_by_key_name("%d:fans" % self.shop.id)
        if not fan_counter or not fans or fans[0].favored_on > fan_counter.timestamp:
            fan_counter = self._count_fans(fan_counter)        
        
        fan_count = fan_counter.count
    
        dates = []
        for group in itertools.groupby(fans, lambda entry: appetsy.to_local_time(self.shop, entry.favored_on).date()):
            fans = list(group[1])
            fans.reverse()
            dates.append ({"cur_date": group[0],
                           "fans": fans 
                           })

        #filter out expired and sold listings
    
        data = {
            "dates": dates,
            "now": appetsy.time(self.shop),
            "fan_count": fan_count,
            "today": appetsy.today(self.shop),
            "yesterday": appetsy.today(self.shop) - dt.timedelta(days=1),            
        }
        
        fan_list = appetsy.get_template("etsy.html").render(**data)
        memcache.set("500fans", fan_list)
        return fan_list