Exemplo n.º 1
0
 def category(self):
     # /category/{category_id}/{page}
     page = self.request.matchdict.get("page", "category")
     category_id = util.to_uuid(self.request.matchdict.get("category_id"))
     category = ProductCategory.load(category_id)
     self.redir_if(not category)
     self.session["back_link"] = "/category/%s" % category_id
     params = self.params()
     params["products"] = util.page_list(
         SmartCatalog.category_product_list(self.request.ctx.campaign, category_id),
         self.request.GET.get("offset"),
         self.request.GET.get("limit"),
     )
     params["category"] = category
     (params["seo_title"], params["seo_keywords"], params["seo_description"]) = SmartSeo.category_seo(
         category, self.request.ctx.site
     )
     return self.render(page, params)
Exemplo n.º 2
0
 def test_util(self):
     d8e = util.today_date()
     dtime = util.today()
     assert util.format_rss_date(d8e) == d8e.strftime("%a, %d %b %Y %H:%M:%S EST")
     assert util.words_date(dtime) == dtime.strftime("%B %d, %Y")
     assert util.is_empty(" ") == True
     assert util.float_("8") == None
     assert util.page_list([1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 2) == [3, 4]
     assert util.page_list([1, 2, 3, 4, 5, 6, 7, 8, 9], None, None) == [1, 2, 3, 4, 5, 6, 7, 8, 9]
     assert util.parse_date("2012-05-06") == datetime.datetime.strptime("2012-05-06", "%Y-%m-%d")
     today_ = datetime.date.today()
     assert [today_.year + 10, today_.year + 10] in util.year_list()
     assert util.month_list()[0] == ["1", "January"]
     assert util.this_year() == datetime.date.today().year
     assert util.get_first_day(today_) == util.get_first_day(
         today_
     )  # this is pretty dumb.  it works, just get it covered.
     assert util.get_last_day(today_) == util.get_last_day(today_)
     assert util.to_uuid("ken") == None
     assert int(util.average([1, 2, 3])) == 2
     assert util.format_date(util.truncate_datetime(dtime)) == util.str_today()
     assert util.is_today(d8e) == True