예제 #1
0
def edit_promotion(request, promotion_id):
    if not promotion_id:
        return HttpResponseRedirect("/")
    try:
        promotion_id = int(promotion_id)
    except ValueError:
        raise Http404
    promotion = Promotion.get_by_id(promotion_id)
    if not promotion:
        raise Http404
    if request.method == "POST":
        form = PromotionEditForm(request.POST)
        if form.is_valid():
            edit_promotion = form.save(commit=False)
            promotion.subject = edit_promotion.subject
            promotion.content = edit_promotion.content
            promotion.description = edit_promotion.description
            promotion.put()
            # return render_to_response('manage/edit_promotion.html', {'form':form, 'promotion_id':promotion_id, 'success_msg':u'成功修改'}, context_instance=RequestContext(request))
            return HttpResponseRedirect("/manage/promotion/")
    else:
        form = PromotionEditForm(instance=promotion)
    return render_to_response(
        "manage/edit_promotion.html",
        {"form": form, "promotion_id": promotion_id},
        context_instance=RequestContext(request),
    )
예제 #2
0
def delete_promotion(request, promotion_id):
    if not promotion_id:
        return HttpResponseRedirect("/")
    try:
        promotion_id = int(promotion_id)
    except ValueError:
        raise Http404
    promotion = Promotion.get_by_id(promotion_id)
    if not promotion:
        raise Http404
    promotion.delete()
    return HttpResponseRedirect("/manage/promotion/")
예제 #3
0
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))
예제 #4
0
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
예제 #5
0
def promotion(request):
    promotion_set = Promotion.all().order("subject")
    return render_to_response(
        "manage/promotion.html", {"promotion_set": promotion_set}, context_instance=RequestContext(request)
    )