def add_promotion(request): if request.method == "POST": form = PromotionForm(request.POST) if form.is_valid(): promotion = form.save(commit=False) check_data = Promotion.all().filter("subject =", promotion.subject).get() if check_data: return render_to_response( "manage/add_promotion.html", {"form": form, "error_msg": u"重复添加:%s" % promotion.subject}, context_instance=RequestContext(request), ) promotion.put() return render_to_response( "manage/add_promotion.html", {"form": form, "success_msg": u"成功添加:%s" % promotion.subject}, context_instance=RequestContext(request), ) else: form = PromotionForm() return render_to_response("manage/add_promotion.html", {"form": form}, context_instance=RequestContext(request))
def get_cached_promotion_data(promotion_subject, time=6000): """ 使用规则的名称获得缓存的数据list。 TODO 应该做类型检查! """ cached_data = memcache.get(promotion_subject) if not cached_data: promotion = Promotion.all().filter('subject', promotion_subject) cached_data_ids = [] for item in promotion: cached_data_string_ids_str = item.content.split(',') for id_str in cached_data_string_ids_str: try: id = int(id_str) except Exception: continue if id > 0: cached_data_ids.append(id) temp_cached_data = Content.get_by_id(cached_data_ids) cached_data = [data for data in temp_cached_data if data is not None] memcache.set(promotion_subject, cached_data, time) return cached_data
def promotion(request): promotion_set = Promotion.all().order("subject") return render_to_response( "manage/promotion.html", {"promotion_set": promotion_set}, context_instance=RequestContext(request) )