Пример #1
0
def edit_activity(request, template_name):
    """
    配置库 编辑活动
    url :{% url 'edit_activity' %}?channel={{ channel }}&id={{ id }}
    :请求方式: Get
    :请求参数:channel,id
    :返回数据:fields errors scenes 场景列表 open_type(类别) citygroups cities
    :例如:scenes 场景列表 和之前一样

    :请求方式:Post
    :请求参数:
    """
    channel_id = request.GET.get('channel')
    id = request.GET.get("id")
    activity = CmsActivities.objects.get(id=id)
    c, v, t = getCVT(channel_id)
    # 根据类型得到名称
    text = get_nav_text(str(t))
    if request.method == 'POST':
        form = ActivitiesForm(request.POST, instance=activity)
        form.data['start'] = make_timestamp(form.data['start'])
        form.data['end'] = make_timestamp(form.data['end'])
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_ACTIVITY,
                         table_name='CmsActivities',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(
                reverse("activities") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        form = ActivitiesForm(instance=activity)
    scenes = get_scenes()
    cities = get_city_list()
    citygroups = get_city_group()
    errors, fields = format_form(form)
    if 'start' in fields.keys():
        fields['start'] = json.dumps(timestamp2str(fields['start']))
    if 'end' in fields.keys():
        fields['end'] = json.dumps(timestamp2str(fields['end']))
    return render_to_response(template_name, {
        "scenes": scenes,
        "fields": fields,
        "errors": errors,
        "cities": cities,
        "citygroups": citygroups,
        "open_type": open_type,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id,
        "id": id
    },
                              context_instance=RequestContext(request))
Пример #2
0
def edit_service(request, template_name):
    id = request.GET.get("id")
    if request.method == "POST":
        services = CmsServices.objects.get(id=id)
        form = ServiceForm(request.POST, instance=services)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_SERVICE,
                         table_name='CmsServices',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(reverse('services'))
    else:
        services = CmsServices.objects.get(id=id)
        form = ServiceForm(instance=services)
    errors, fields = format_form(form)
    scenes = get_scenes()
    actions = get_actions_select()
    citygroups = get_city_group()
    cities = get_city_list()
    return render_to_response(template_name, {
        "scenes": scenes,
        "actions": actions,
        "citygroups": citygroups,
        "cities": cities,
        "id": id,
        "fields": fields,
        "errors": errors
    },
                              context_instance=RequestContext(request))
Пример #3
0
def edit_coupons(request, template_name):
    """
    配置库:编辑优惠券
    url :{% url 'edit_config_coupons' %}?id={{ id }}&channel={{ channel }}
    :请求方式: Get
    :请求参数:id(优惠券id) channel渠道id
    :返回数据:scenes 场景列表 citygroups 城市分组列表,cities 所有城市(列表)
    :[[id,name],[id,name],....]

    :请求方式:Post
    :请求参数:数据库字段(input name)
    """
    id = request.GET.get("id")
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    # 根据类型得到名称
    text = get_nav_text(str(t))
    oCmsCoupon = CmsCoupon.objects.get(id=id)
    if request.method == "POST":
        form = CouponsForm(request.POST, instance=oCmsCoupon)
        form.data['start'] = make_timestamp(form.data['start'])
        form.data['end'] = make_timestamp(form.data['end'])
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_COUPON,
                         table_name='CmsCoupon',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(
                reverse("config_coupons") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        form = CouponsForm(instance=oCmsCoupon)
    errors, fields = format_form(form)
    if 'start' in fields.keys():
        fields['start'] = json.dumps(timestamp2str(fields['start']))
    if 'end' in fields.keys():
        fields['end'] = json.dumps(timestamp2str(fields['end']))
    scenes = get_scenes()
    citygroups = get_city_group()
    cities = get_city_list()
    return render_to_response(template_name, {
        "scenes": scenes,
        "citygroups": citygroups,
        "cities": cities,
        "errors": errors,
        "fields": fields,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id,
        "id": id
    },
                              context_instance=RequestContext(request))
Пример #4
0
def new(request, template_name):
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    # 根据类型得到名称
    text = get_nav_text(str(t))
    if request.method == "POST":
        form = CmsActivityV37Form(request.POST)
        if form.is_valid():
            ins_activityv37 = form.save()
            goods_lst = request.POST.get("goods_lst").split(",")
            if goods_lst == ["*"]:
                goods = CmsGoods.objects.filter(parent_id=-1)
            else:
                goods = CmsGoods.objects.filter(id__in=goods_lst)
            # add by mkh
            CmsActivityGoods.objects.filter(activity=ins_activityv37).delete()
            for good in goods:
                acitvitygoods_ins, status = CmsActivityGoods.objects.get_or_create(
                    activity=ins_activityv37, goods=good)
                acitvitygoods_ins.save()
            cp_lst = request.POST.get("cp_lst").split(",")
            if cp_lst == ['*']:
                cps = CmsCP.objects.all()
            else:
                cps = CmsCP.objects.filter(id__in=cp_lst)
            # add by mkh
            CmsActivityCP.objects.filter(activity=ins_activityv37).delete()
            for cp in cps:
                activitycp_ins, status = CmsActivityCP.objects.get_or_create(
                    activity=ins_activityv37, cp=cp)
                activitycp_ins.save()
            CmsViewActivity37(channel_id=channel_id,
                              activity=ins_activityv37).save()
            return HttpResponseRedirect(
                reverse('coupon_activities') + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        form = CmsActivityV37Form()
    errors, fields = format_form(form)
    cps = get_all_cps()
    goods = get_goods()
    actions = get_actions_select()
    citygroups = get_city_group()
    cities = get_city_list()
    return render_to_response(template_name, {
        "t": t,
        "v": v,
        "c": c,
        "id": id,
        "text": text,
        "channel": channel_id,
        "errors": errors,
        "fields": fields,
        "cps": cps,
        "goods": goods,
        "actions": actions,
        "citygroups": citygroups,
        "cities": cities
    },
                              context_instance=RequestContext(request))
Пример #5
0
def edit_homepage_specialtopic(request, template_name):
    """
     编辑 首页专题
     url:{% url edit_homepage_specialtopic %}?channel={{ channel }}&id={{ id }}
    #插入到专题表 cms_special_topic
    :请求方式:Get
    :请求参数: id , channel:渠道id
    :返回数据: form 表单 citygroups 城市分组 actions:动作列表  cities:所有城市(格式和之前一致)
    :格式:[[id,name],....]

    :请求方式:Post
    :请求参数:cms_special_topic的表字段。
    :
    """
    id = request.GET.get("id")
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    text = get_nav_text(str(t))
    specialtopic = CmsSpecialTopic.objects.get(id=id)
    if request.method == 'POST':
        form = SpecialTopicForm(request.POST, instance=specialtopic)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_HOMEPAGE,
                         table_name='CmsSpecialTopic',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(
                reverse('homepage_specialtopic') + "?t=%d&c=%s&v=%s" %
                (t, c, v))
    else:
        form = SpecialTopicForm(instance=specialtopic)
    citygroups = get_city_group()
    actions = get_actions_select()
    cities = get_city_list()
    scenes = get_scenes()
    errors, fields = format_form(form)
    return render_to_response(template_name, {
        "fields": fields,
        "errors": errors,
        "citygroups": citygroups,
        "actions": actions,
        "cities": cities,
        "open_type": open_type,
        "scenes": scenes,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id,
        "id": id
    },
                              context_instance=RequestContext(request))
Пример #6
0
def edit_common_category_second(request, template_name):
    """
    配置库 编辑二级分类
    url :{% url 'edit_common_category_second' %}?channel={{ channel }}&id={{ id }}
    :请求方式: Get
    :请求参数:channel,id
    :返回数据:和之前一样
    :例如:

    :请求方式:Post
    :请求参数:
    """
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    text = get_nav_text(str(t))
    id = request.GET.get("id")
    if request.method == "POST":
        oNaviCategory = CmsNaviCategory.objects.get(id=id)
        form = NaviCategoryForm(request.POST, instance=oNaviCategory)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_CATEGORY,
                         table_name='CmsNaviCategory',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(
                reverse("common_services") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        navicategory = CmsNaviCategory.objects.get(id=id)
        form = NaviCategoryForm(instance=navicategory)
    cate2s = get_first_categories()
    errors, fields = format_form(form)
    scenes = get_scenes()
    actions = get_actions_select()
    citygroups = get_city_group()
    cities = get_city_list()
    return render_to_response(template_name, {
        "scenes": scenes,
        "actions": actions,
        "citygroups": citygroups,
        "cities": cities,
        "show_style_list": show_style_list,
        "cate2s": cate2s,
        "id": id,
        "fields": fields,
        "errors": errors,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id
    },
                              context_instance=RequestContext(request))
Пример #7
0
def new_goods(request, template_name):
    if request.method == "POST":
        second_category = request.POST.get("second_category")
        if second_category:
            second_category = CmsNaviCategory.objects.get(id=second_category)
            if second_category.fatherid == 0:
                request.POST["category"] = request.POST["second_category"]
                request.POST['second_category'] = None
            else:
                request.POST["category"] = second_category.fatherid
        new_second_category = request.POST.get("new_second_category")
        if new_second_category:
            new_second_category = CmsNaviCategory.objects.get(
                id=new_second_category)
            if new_second_category.fatherid == 0:
                request.POST["new_category"] = request.POST[
                    "new_second_category"]
                request.POST['new_second_category'] = None
            else:
                request.POST["new_category"] = new_second_category.fatherid
        form = GoodsForm(request.POST)
        if form.is_valid():
            oGoods = form.save()
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_GOODS,
                         table_name='CmsGoods',
                         data_id=oGoods.id,
                         op_type=CheckOpType.NEW,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(reverse('goods'))
    else:
        form = GoodsForm()
    errors, fields = format_form(form)
    if 'second_category' in fields.keys(
    ) and fields['second_category'] == '""':
        fields['second_category'] = fields['category']
    if 'new_second_category' in fields.keys(
    ) and fields['new_second_category'] == '""':
        fields['new_second_category'] = fields['new_category']
    scenes = get_scenes()
    actions = get_actions_select()
    citygroups = get_city_group()
    cities = get_city_list()
    categories = get_categories()
    return render_to_response(template_name, {
        "scenes": scenes,
        "actions": actions,
        "citygroups": citygroups,
        "categories": categories,
        "cities": cities,
        "fields": fields,
        "errors": errors
    },
                              context_instance=RequestContext(request))
Пример #8
0
def edit_specialtopic(request, template_name):
    """
    编辑专题
    url :{% url 'edit_specialtopic' %}?id={{ id }}
    :请求方式: Get
    :请求参数:id
    :返回数据:scenes 场景列表 citygroups 城市分组列表,cities 所有城市(列表) actions 动作列表 open_type 类型
    :[[id,name],[id,name],....]

    :请求方式:Post
    :请求参数:数据库字段(input name)
    """
    id = request.GET.get("id")
    specialtopic = CmsSpecialTopic.objects.get(id=id)
    if request.method == "POST":
        form = SpecialTopicForm(request.POST, instance=specialtopic)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_TOPIC,
                         table_name='CmsSpecialTopic',
                         data_id=id,
                         op_type=CheckOpType.EDIT).save()
            find_page_views = CmsViewFindTopic.objects.filter(topic_id=id)
            # 更新时间同步
            for find_page_view in find_page_views:
                find_page_view.update_time = specialtopic.update_time
                find_page_view.save()
                if CMS_CHECK_ON:
                    CmsCheck(module=CmsModule.MAIN_TOPIC,
                             table_name='CmsViewFindTopic',
                             data_id=find_page_view.id,
                             op_type=CheckOpType.EDIT,
                             is_show=0,
                             alter_person=request.user.username,
                             alter_date=time.strftime(
                                 "%Y-%m-%d %X", time.localtime())).save()
            return HttpResponseRedirect(reverse("specialtopics"))
    else:
        form = SpecialTopicForm(instance=specialtopic)
    errors, fields = format_form(form)
    citygroups = get_city_group()
    actions = get_actions_select()
    cities = get_city_list()
    scenes = get_scenes()
    return render_to_response(template_name, {
        "fields": fields,
        "errors": errors,
        "citygroups": citygroups,
        "actions": actions,
        "cities": cities,
        "scenes": scenes,
        "open_type": open_type,
        "id": id
    },
                              context_instance=RequestContext(request))
Пример #9
0
def edit_shop(request, template_name):
    """
    编辑二级 商户
    url :{% url 'sc_edit_shop' %}?channel={{ channel }}&id={{ id }}
    :请求方式: Get
    :请求参数:无
    :返回数据: citygroups 城市分组列表,cities 所有城市(列表)
    :[[id,name],[id,name],....]

    :请求方式:Post
    :请求参数:cms_category_itembean字段(input name)
    """
    channel_id = request.GET.get('channel')
    id = request.GET.get("id")
    c, v, t = getCVT(channel_id)
    # 根据类型得到名称
    text = get_nav_text(str(t))
    categoryitembean = CmsCategoryItembean.objects.get(id=id)
    if request.method == "POST":
        postcopys = request.POST.copy()
        content = op_content_save(postcopys)
        postcopys["content"] = json.dumps(content, ensure_ascii=False)
        form = CmsCategoryItembeanForm(postcopys, instance=categoryitembean)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_SECOND_CATEGORY,
                         table_name='CmsCategoryItembean',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(
                reverse("second_category") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        form = CmsCategoryItembeanForm(instance=categoryitembean)
    errors, fields = format_form(form)
    fields = op_content_edit(fields)
    citygroups = get_city_group()
    cities = get_city_list()
    return render_to_response(template_name, {
        "fields": fields,
        "errors": errors,
        "citygroups": citygroups,
        "cities": cities,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id,
        "id": id,
    },
                              context_instance=RequestContext(request))
Пример #10
0
def edit_category(request, template_name):
    """
    分类页服务  编辑分类
    :请求方式:Get
    :请求URL:{% url 'category_pages_services_edit_category' %}
    :请求参数:channel(渠道号),id (CmsNaviCategory分类表id)
    :类型 :传数字
    返回: 成功:0 错误:错误信息
    """
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    text = get_nav_text(str(t))
    id = request.GET.get("id")
    if request.method == "POST":
        navicategory = CmsNaviCategory.objects.get(id=id)
        form = NaviCategoryForm(request.POST, instance=navicategory)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_CATEGORY,
                         table_name='CmsNaviCategory',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(
                reverse("category_pages_services") + "?t=%d&c=%s&v=%s" %
                (t, c, v))
    else:
        navicategory = CmsNaviCategory.objects.get(id=id)
        form = NaviCategoryForm(instance=navicategory)
    errors, fields = format_form(form)
    scenes = get_scenes()
    actions = get_actions_select()
    citygroups = get_city_group()
    cities = get_city_list()
    cate2s = get_first_categories()
    return render_to_response(template_name, {
        "scenes": scenes,
        "actions": actions,
        "citygroups": citygroups,
        "show_style_list": show_style_list,
        "cities": cities,
        "cate2s": cate2s,
        "fields": fields,
        "errors": errors,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id,
        "id": id
    },
                              context_instance=RequestContext(request))
Пример #11
0
def edit_content_stream(request, template_name):
    """
    编辑 内容流
    url :{% url 'new_content_stream' %}?channel={{ channel }}&id={{ id }}
    :请求方式:Get
    :请求参数:channel,id(内容流id)
    :返回数据:form 表单 open_type 类别(actions 动作 cities 城市列表 citygroups 城市分组)(和之前一致)
    :例如:open_type [[0,"服务"],[1,"商品"]]

    :请求方式:Post
    :请求参数:input name 和数据库表cms_streamcontentbeans字段名称一致(除了id)
    :注意: 其他没有在input展示的要搞个input-hidden value = 0
    """
    channel_id = request.GET.get('channel')
    id = request.GET.get("id")
    c, v, t = getCVT(channel_id)
    # 根据类型得到名称
    text = get_nav_text(str(t))
    if request.method == 'POST':
        beans = CmsStreamcontentbeans.objects.get(id=id)
        form = StreamcontentbeansForm(request.POST, instance=beans)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_STREAM,
                         table_name='CmsStreamcontentbeans',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X", time.localtime())).save()
            return HttpResponseRedirect(reverse("streams") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        beans = CmsStreamcontentbeans.objects.get(id=id)
        form = CmsAdsForm(instance=beans)
    actions = get_actions_select()
    cities = get_city_list()
    citygroups = get_city_group()
    errors, fields = format_form(form)
    return render_to_response(template_name, {
        "form": form,
        "open_type": open_type,
        "actions": actions,
        "cities": cities,
        "citygroups": citygroups,
        "fields": fields,
        "errors": errors,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id,
        "id": id
    }, context_instance=RequestContext(request))
Пример #12
0
def edit_service(request, template_name):
    """
     猜你喜欢 编辑服务
    :请求方式:Get
    :请求URL:{% url 'likes_edit_service' %}?channel={{ channel }}&id={{ id }}
    :请求参数:id(服务表id),channel(渠道号)
    :类型 :传数字
    """
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    text = get_nav_text(str(t))
    id = request.GET.get("id")
    if request.method == "POST":
        services = CmsServices.objects.get(id=id)
        form = ServiceForm(request.POST, instance=services)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_LIKE,
                         table_name='CmsServices',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(
                reverse("likes") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        services = CmsServices.objects.get(id=id)
        form = ServiceForm(instance=services)
    errors, fields = format_form(form)
    scenes = get_scenes()
    actions = get_actions_select()
    citygroups = get_city_group()
    cities = get_city_list()
    return render_to_response(template_name, {
        "scenes": scenes,
        "actions": actions,
        "citygroups": citygroups,
        "cities": cities,
        "id": id,
        "fields": fields,
        "errors": errors,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id
    },
                              context_instance=RequestContext(request))
Пример #13
0
def edit_choiceness_category(request, template_name):
    """
    配置库 编辑精品分类
    url :{% url 'edit_choiceness_category' %}?channel={{ channel }}&id={{ id }}
    :请求方式: Get
    :请求参数:channel,id
    :返回数据:fields errors   分类列表 categories 城市分组citygroups cities
    :例如: 和之前一样

    :请求方式:Post
    :请求参数:注意 channel_id变成channel category_id变为category
    """
    channel_id = request.GET.get('channel')
    id = request.GET.get("id")
    choicenesscategory = CmsChoicenessCategory.objects.get(id=id)
    c, v, t = getCVT(channel_id)
    # 根据类型得到名称
    text = get_nav_text(str(t))
    if request.method == 'POST':
        form = ChoicenessCategoryForm(request.POST, instance=choicenesscategory)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_CHOICENESS,
                         table_name='CmsChoicenessCategory',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X", time.localtime())).save()
            return HttpResponseRedirect(reverse("choiceness_categories") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        form = ChoicenessCategoryForm(instance=choicenesscategory)
    categories = get_categories()
    cities = get_city_list()
    citygroups = get_city_group()
    errors, fields = format_form(form)
    return render_to_response(template_name, {
        "categories": categories,
        "fields": fields,
        "errors": errors,
        "cities": cities,
        "citygroups": citygroups,
        "open_type": open_type,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id,
        "id": id
    }, context_instance=RequestContext(request))
Пример #14
0
def edit_category_first(request, template_name):
    id = request.GET.get("id")
    category = CmsNaviCategory.objects.get(id=id)
    if request.method == "POST":
        form = NaviCategoryForm(request.POST, instance=category)
        if form.is_valid():
            form.save()
            cate_group_id = request.POST.get("cate_group_id")
            if CmsViewGroupCategory.objects.filter(category=category):
                ins_viewgroupcate = CmsViewGroupCategory.objects.get(
                    category=category)
                ins_viewgroupcate.group_id = cate_group_id
                ins_viewgroupcate.save()
            else:
                CmsViewGroupCategory(category=category,
                                     group_id=cate_group_id).save()
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_CATEGORY,
                         table_name='CmsNaviCategory',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(reverse('category'))
    else:

        form = NaviCategoryForm(instance=category)
    errors, fields = format_form(form)
    if CmsViewGroupCategory.objects.filter(category=category):
        ins_viewgroupcate = CmsViewGroupCategory.objects.get(category=category)
        fields["cate_group_id"] = json.dumps(ins_viewgroupcate.group_id)
    scenes = get_scenes()
    actions = get_actions_select()
    citygroups = get_city_group()
    cities = get_city_list()
    cate_groups = CmsCategoryGroup.objects.all()
    return render_to_response(template_name, {
        "scenes": scenes,
        "actions": actions,
        "citygroups": citygroups,
        "cities": cities,
        "show_style_list": show_style_list,
        "id": id,
        "fields": fields,
        "errors": errors,
        "cate_groups": cate_groups,
        "CATE_TYPE": CATE_TYPE
    },
                              context_instance=RequestContext(request))
Пример #15
0
def new_shop(request,template_name):
    """
    新建商户
    url :{% url "new_shop" %}
    :请求方式: Get
    :请求参数:无
    :返回数据: citygroups 城市分组列表,cities 所有城市(列表)
    :[[id,name],[id,name],....]

    :请求方式:Post
    :请求参数:cms_category_itembean字段(input name)
    webSite: #官方主页
    weibo :  #微博主页
    search_key :     搜索词
    search_category:搜索分类
    search_show :查看附近
    numbers : 电话号码
    格式:
    [{
		"number": "4008111111", #电话号码
		"number_description": "顺丰速运"    #电话描述
	},多个..........]
    """
    if request.method == "POST":
        postcopys = request.POST.copy()
        content = op_content_save(postcopys)
        postcopys["content"] = json.dumps(content,ensure_ascii=False)
        form = CmsCategoryItembeanForm(postcopys)
        if form.is_valid():
            ocategoryitembean = form.save()
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_SHOP,
                         table_name='CmsCategoryItembean',
                         data_id=ocategoryitembean.id,
                         op_type=CheckOpType.NEW,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",time.localtime())).save()
            return HttpResponseRedirect(reverse("static_data"))
    else:
        form = CmsCategoryItembeanForm()
    errors,fields = format_form(form)
    fields = op_content_edit(fields)
    citygroups = get_city_group()
    cities = get_city_list()
    return render_to_response(template_name,{
        "fields": fields,
        "errors":errors,
        "citygroups":citygroups,
        "cities":cities,
    }, context_instance=RequestContext(request))
Пример #16
0
def new_cate_group(request, template_name):
    if request.method == "POST":
        form = CmsCategoryGroupForm(request.POST)
        if form.is_valid():
            return HttpResponseRedirect(reverse('category'))
    else:
        form = CmsCategoryGroupForm()
    citygroups = get_city_group()
    cities = get_city_list()
    errors, fields = format_form(form)
    return render_to_response(template_name, {
        "errors": errors,
        "fields": fields,
        "citygroups": citygroups,
        "cities": cities
    },
                              context_instance=RequestContext(request))
Пример #17
0
def new_coupons(request, template_name):
    """
    新建优惠券
    url :{% url 'new_coupons' %}
    :请求方式: Get
    :请求参数:无
    :返回数据:scenes 场景列表 citygroups 城市分组列表,cities 所有城市(列表)
    :[[id,name],[id,name],....]

    :请求方式:Post
    :请求参数:数据库字段(input name)
    """
    if request.method == "POST":
        form = CouponsForm(request.POST)
        form.data['start'] = make_timestamp(form.data['start'])
        form.data['end'] = make_timestamp(form.data['end'])
        if form.is_valid():
            oCoupons = form.save()
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_COUPON,
                         table_name='CmsCoupon',
                         data_id=oCoupons.id,
                         op_type=CheckOpType.NEW,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(reverse("coupons"))
    else:
        form = CouponsForm()
    errors, fields = format_form(form)
    if 'start' in fields.keys():
        fields['start'] = json.dumps(timestamp2str(fields['start']))
    if 'end' in fields.keys():
        fields['end'] = json.dumps(timestamp2str(fields['end']))
    scenes = get_scenes()
    citygroups = get_city_group()
    cities = get_city_list()
    return render_to_response(template_name, {
        "scenes": scenes,
        "citygroups": citygroups,
        "cities": cities,
        "errors": errors,
        "fields": fields
    },
                              context_instance=RequestContext(request))
Пример #18
0
def new_specialtopic(request, template_name):
    """
    新建专题
    url :{% url 'new_specialtopic' %}
    :请求方式: Get
    :请求参数:无
    :返回数据:scenes 场景列表 citygroups 城市分组列表,cities 所有城市(列表) actions 动作列表 open_type 类型
    :[[id,name],[id,name],....]

    :请求方式:Post
    :请求参数:数据库字段(input name)
    """
    if request.method == "POST":
        form = SpecialTopicForm(request.POST)
        if form.is_valid():
            ospecialtopic = form.save()
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_TOPIC,
                         table_name='CmsSpecialTopic',
                         data_id=ospecialtopic.id,
                         op_type=CheckOpType.NEW,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(reverse("specialtopics"))
    else:
        form = SpecialTopicForm()
    errors, fields = format_form(form)
    citygroups = get_city_group()
    actions = get_actions_select()
    cities = get_city_list()
    scenes = get_scenes()
    return render_to_response(template_name, {
        "fields": fields,
        "errors": errors,
        "citygroups": citygroups,
        "actions": actions,
        "cities": cities,
        "scenes": scenes,
        "open_type": open_type,
    },
                              context_instance=RequestContext(request))
Пример #19
0
def edit_open_services(request, template_name):
    """
    配置库新建开放服务
    url :{% url 'open_services_edit' %}?channel={{ channel }}&id={{ id }}
    :请求方式: Get
    :请求参数:channel,id
    :返回数据:fields errors actions(id,标题,备注) citygroups cities
    :例如:

    :请求方式:Post
    :请求参数:
    """
    id = request.GET.get("id")
    channel_id = request.GET.get('channel')
    open_channel = CmsOpenChannel.objects.get(id=channel_id)
    c = open_channel.name
    v = open_channel.app_version.name
    openServieIns = CmsOpenService.objects.get(id=id)
    if request.method == 'POST':
        form = CmsOpenServiceForm(request.POST, instance=openServieIns)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(
                reverse("open_services_list") + "?c=%s&v=%s" % (c, v))
    else:
        form = CmsOpenServiceForm(instance=openServieIns)
    actions = GetAllActions()
    cities = get_city_list()
    citygroups = get_city_group()
    errors, fields = format_form(form)
    return render_to_response(template_name, {
        "actions": actions,
        "fields": fields,
        "errors": errors,
        "cities": cities,
        "citygroups": citygroups,
        "c": c,
        "v": v,
        "channel": channel_id,
        "id": id
    },
                              context_instance=RequestContext(request))
Пример #20
0
def edit_shop(request, template_name):
    """
    编辑商户
    url :{% url "edit_shop" %}?id={{ id }}
    :请求方式: Get
    :请求参数:无
    :返回数据: citygroups 城市分组列表,cities 所有城市(列表)
    :[[id,name],[id,name],....]

    :请求方式:Post
    :请求参数:cms_category_itembean字段(input name)
    """
    id = request.GET.get("id")
    categoryitembean = CmsCategoryItembean.objects.get(id=id)
    if request.method == "POST":
        postcopys = request.POST.copy()
        content = op_content_save(postcopys)
        postcopys["content"] = json.dumps(content,ensure_ascii=False)
        form = CmsCategoryItembeanForm(postcopys,instance=categoryitembean)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_SHOP,
                         table_name='CmsCategoryItembean',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",time.localtime())).save()
            return HttpResponseRedirect(reverse("static_data"))
    else:
        form = CmsCategoryItembeanForm(instance=categoryitembean)
    errors,fields = format_form(form)
    fields = op_content_edit(fields)
    citygroups = get_city_group()
    cities = get_city_list()
    return render_to_response(template_name,{
        "fields": fields,
        "errors":errors,
        "citygroups":citygroups,
        "cities":cities,
        "id":id,
    }, context_instance=RequestContext(request))
Пример #21
0
def edit_cate_group(request, template_name):
    id = request.GET.get("id")
    ins_categroup = CmsCategoryGroup.objects.get(id=id)
    if request.method == "POST":
        form = CmsCategoryGroupForm(request.POST, instance=ins_categroup)
        if form.is_valid():
            return HttpResponseRedirect(reverse('category'))
    else:
        form = CmsCategoryGroupForm(instance=ins_categroup)
    errors, fields = format_form(form)
    citygroups = get_city_group()
    cities = get_city_list()
    return render_to_response(template_name, {
        "id": id,
        "errors": errors,
        "fields": fields,
        "citygroups": citygroups,
        "cities": cities
    },
                              context_instance=RequestContext(request))
Пример #22
0
def edit_category_second(request, template_name):
    id = request.GET.get("id")
    if request.method == "POST":
        goods = CmsNaviCategory.objects.get(id=id)
        form = NaviCategoryForm(request.POST, instance=goods)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_CATEGORY,
                         table_name='CmsNaviCategory',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(reverse('category'))
    else:
        navicategory = CmsNaviCategory.objects.get(id=id)
        form = NaviCategoryForm(instance=navicategory)
    errors, fields = format_form(form)
    scenes = get_scenes()
    actions = get_actions_select()
    citygroups = get_city_group()
    cities = get_city_list()
    cate2s = get_first_categories()
    return render_to_response(
        template_name,
        {
            "scenes": scenes,
            "actions": actions,
            "goods_form": form,
            "citygroups": citygroups,
            "show_style_list": show_style_list,
            "cities": cities,
            "id": id,
            "fields": fields,
            "errors": errors,
            "cate2s": cate2s,
            # "first_categories":first_categories
        },
        context_instance=RequestContext(request))
Пример #23
0
def edit_goods(request, template_name):
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    text = get_nav_text(str(t))
    id = request.GET.get("id")
    if request.method == "POST":
        second_category = request.POST.get("second_category")
        if second_category:
            second_category = CmsNaviCategory.objects.get(id=second_category)
            if second_category.fatherid == 0:
                request.POST["category"] = request.POST["second_category"]
                request.POST['second_category'] = None
            else:
                request.POST["category"] = second_category.fatherid
        new_second_category = request.POST.get("new_second_category")
        if new_second_category:
            new_second_category = CmsNaviCategory.objects.get(id=new_second_category)
            if new_second_category.fatherid == 0:
                request.POST["new_category"] = request.POST["new_second_category"]
                request.POST['new_second_category'] = None
            else:
                request.POST["new_category"] = new_second_category.fatherid
        goods = CmsGoods.objects.get(id=id)
        request.POST['sort'] = goods.sort
        request.POST['is_support_cart'] = goods.is_support_cart
        request.POST['recommend_goodsId'] = goods.recommend_goodsId
        form = GoodsForm(request.POST, instance=goods)
        if form.is_valid():
            form.save()
            data = {}
            cate_fields = ['category', 'second_category', 'new_second_category', 'new_category', 'valid_time']
            for field in cate_fields:
                if request.POST.get(field):
                    data[field] = request.POST.get(field)
            # 更新同一goods_id的商品
            if data:
                CmsGoods.objects.filter(~Q(id=id), goods_id=goods.goods_id).update(**data)
                if INSTALL_TYPE == 2 or INSTALL_TYPE == 3:
                    sync_search(goods.goods_id, data)
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_STREAM,
                         table_name='CmsGoods',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X", time.localtime())).save()
            return HttpResponseRedirect(reverse("streams") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        goods = CmsGoods.objects.get(id=id)
        form = GoodsForm(instance=goods)
    errors, fields = format_form(form)
    if 'second_category' in fields.keys() and fields['second_category'] == '""':
        fields['second_category'] = fields['category']
    if 'new_second_category' in fields.keys() and fields['new_second_category'] == '""':
        fields['new_second_category'] = fields['new_category']
    scenes = get_scenes()
    actions = get_actions_select()
    citygroups = get_city_group()
    cities = get_city_list()
    categories = get_categories()
    return render_to_response(template_name, {
        "scenes": scenes,
        "actions": actions,
        "categories": categories,
        "citygroups": citygroups,
        "cities": cities,
        "id": id,
        "fields": fields,
        "errors": errors,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id
    }, context_instance=RequestContext(request))
Пример #24
0
def new(request, template_name):
    log.error("in SECKILL")
    channel_id = request.GET.get('channel')
    list = ViewCmsSecKillView.objects.filter(channel_id=channel_id)
    c, v, t = getCVT(channel_id)
    log.error(str(c) + ":" + str(v) + ":" + str(t))
    # 根据类型得到名称
    text = get_nav_text(str(t))
    is_ok_time = True
    if request.method == "POST":
        log.error(request.POST)
        form = CmsSeckilForm(request.POST)
        if form.data['show_start_time']:
            form.data['show_start_time'] = timestamp2str_h(
                make_timestamp(form.data['show_start_time']))
        if form.data['show_end_time']:
            form.data['show_end_time'] = timestamp2str_h(
                make_timestamp(form.data['show_end_time']))
        log.error(form.data)
        if form.is_valid():
            if check_time(list, 0,
                          make_timestamp_h(form.data['show_start_time']),
                          make_timestamp_h(form.data['show_end_time'])):
                seckill = form.save()
                new_associate(channel_id, seckill.id, CONFIG_ITEMS.SECKILLS,
                              request)
                CmsSecKillView(channel_id=channel_id,
                               seckill_id=seckill.id,
                               status=0).save()
                return HttpResponseRedirect(
                    reverse('seckills') + "?t=%d&c=%s&v=%s" % (t, c, v))
            else:
                is_ok_time = False
    else:
        form = CmsSeckilForm()
    # 准备Action数据
    actionsall = CmsActions.objects.all()
    # 准备秒杀字段
    opGoodsActivitys = OpGoodsActivityView.objects.filter(is_seckill=1)
    map = {}
    if opGoodsActivitys is not None:
        for oga in opGoodsActivitys:
            map[oga.activityId] = oga
    op_goods_list = []
    for k, vl in map.items():
        op_goods_list.append(vl)
    errors, fields = format_form(form)
    if not is_ok_time:
        errors['time'] = '起始时间与结束时间不能与同渠道其他秒杀活动重合'
    citygroups = get_city_group()
    # cities = get_city_list()
    actions = get_actions_select()
    return render_to_response(template_name, {
        "t": t,
        "v": v,
        "c": c,
        "id": id,
        "text": text,
        "channel": channel_id,
        "errors": errors,
        "fields": fields,
        "citygroups": citygroups,
        "op_goods_list": op_goods_list,
        "actions": actions,
        "actionsall": actionsall
    },
                              context_instance=RequestContext(request))
Пример #25
0
def new_activity(request, template_name):
    """
    配置库 本地活动
    url :{% url 'new_native_activity' %}?channel={{ channel }}
    :请求方式: Get
    :请求参数:channel
    :返回数据:fields errors scenes 场景列表 open_type(类别) citygroups cities
    :例如:scenes 场景列表 和之前一样

    :请求方式:Post
    :请求参数:
    """
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    channel = CmsChannels.objects.get(id=channel_id)
    # 根据类型得到名称
    text = get_nav_text(str(t))
    times = ['start_time', 'end_time', 'open_time', 'close_time']
    if request.method == 'POST':
        form = CmsNativeActivityForm(request.POST)
        for time1 in times:
            if form.data[time1]:
                form.data[time1] = make_timestamp(form.data[time1])
        if form.is_valid():
            activity = form.save()
            import time
            if CMS_CHECK_ON:
                check = CmsCheck(channel_id=channel_id,
                                 module=CmsModule.CONFIG_NATIVE_ACTIVITY,
                                 table_name="CmsNativeActivity",
                                 data_id=activity.id,
                                 op_type=CheckOpType.NEW,
                                 status=CheckStatu.WAIT_SUBMIT,
                                 is_show=1,
                                 alter_person=request.user.username,
                                 alter_date=time.strftime(
                                     "%Y-%m-%d %X", time.localtime()))
                check.save()
            new_associate(channel_id, activity.id,
                          CONFIG_ITEMS.NATIVE_ACTIVITY, request)
            oCmsViewNativeActivity = CmsViewNativeActivity(nactivity=activity,
                                                           channel=channel)
            oCmsViewNativeActivity.save()
            if CMS_CHECK_ON:
                check = CmsCheck(channel_id=channel_id,
                                 module=CmsModule.CONFIG_NATIVE_ACTIVITY,
                                 table_name="CmsViewNativeActivity",
                                 data_id=oCmsViewNativeActivity.id,
                                 op_type=CheckOpType.NEW,
                                 status=CheckStatu.WAIT_SUBMIT,
                                 is_show=0,
                                 alter_person=request.user.username,
                                 alter_date=time.strftime(
                                     "%Y-%m-%d %X", time.localtime()))
                check.save()
            return HttpResponseRedirect(
                reverse("native_activities") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        form = ActivitiesForm()
    actions = get_actions_select()
    scenes = get_scenes()
    cities = get_city_list()
    citygroups = get_city_group()
    errors, fields = format_form(form)
    for time in times:
        if time in fields.keys() and json.loads(fields[time]):
            fields[time] = json.dumps(timestamp2str(fields[time]))
    return render_to_response(template_name, {
        "scenes": scenes,
        "actions": actions,
        "fields": fields,
        "errors": errors,
        "cities": cities,
        "citygroups": citygroups,
        "open_type": open_type,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id
    },
                              context_instance=RequestContext(request))
Пример #26
0
def edit_goods(request, template_name):
    id = request.GET.get("id")
    all_goods = CmsGoods.objects.filter(parent_id=-1, goods_id__gt=0)
    if request.method == "POST":
        second_category = request.POST.get("second_category")
        if second_category:
            second_category = CmsNaviCategory.objects.get(id=second_category)
            if second_category.fatherid == 0:
                request.POST["category"] = request.POST["second_category"]
                request.POST['second_category'] = None
            else:
                request.POST["category"] = second_category.fatherid
        new_second_category = request.POST.get("new_second_category")
        if new_second_category:
            new_second_category = CmsNaviCategory.objects.get(
                id=new_second_category)
            if new_second_category.fatherid == 0:
                request.POST["new_category"] = request.POST[
                    "new_second_category"]
                request.POST['new_second_category'] = None
            else:
                request.POST["new_category"] = new_second_category.fatherid
        goods = CmsGoods.objects.get(id=id)
        request.POST['is_support_cart'] = goods.is_support_cart
        request.POST['sort'] = goods.sort
        request.POST['citysJson'] = goods.citysJson
        request.POST['serviceRangeJson'] = goods.serviceRangeJson
        request.POST['card_type'] = goods.card_type
        request.POST['service_times'] = goods.service_times
        request.POST['card_minutes'] = goods.card_minutes
        request.POST['serviceRangeGraph'] = goods.serviceRangeGraph
        #V 4.5添加字段
        request.POST['sale_status'] = goods.sale_status
        request.POST['is_select_count'] = goods.is_select_count
        request.POST['min_buy_count'] = goods.min_buy_count
        request.POST['max_buy_count'] = goods.max_buy_count
        request.POST['c_time'] = goods.c_time
        request.POST['card_support_length'] = goods.card_support_length
        request.POST['service_length'] = goods.service_length
        #V 4.5添加字段完毕
        # request.POST['recommend_goodsId'] = str(goods.recommend_goodsId)
        # log.info('recommend_goodsId:'+request.POST.get('recommend_goodsId'))
        form = GoodsForm(request.POST, instance=goods)
        if form.is_valid():
            form.save()
            data = {}
            cate_fields = [
                'category', 'second_category', 'new_second_category',
                'new_category', 'valid_time', 'min_version', 'max_version',
                'recommend_icon', 'recommend_reason', 'sort', 'mark', 'tag1',
                'tag1_style', 'tag2', 'tag2_style', 'tag3', 'tag3_style',
                'recommend_goodsId', 'recommend_goods_reason', 'search_keyword'
            ]
            for field in cate_fields:
                if request.POST.get(field):
                    data[field] = request.POST.get(field)
            data['min_version'] = request.POST.get('min_version')
            data['max_version'] = request.POST.get('max_version')
            data['recommend_icon'] = request.POST.get('recommend_icon')
            data['recommend_reason'] = request.POST.get('recommend_reason')
            data['sort'] = request.POST.get('sort')
            data['mark'] = request.POST.get('mark')
            data['tag1'] = request.POST.get('tag1')
            data['tag1_style'] = request.POST.get('tag1_style')
            data['tag2'] = request.POST.get('tag2')
            data['tag2_style'] = request.POST.get('tag2_style')
            data['tag3'] = request.POST.get('tag3')
            data['tag3_style'] = request.POST.get('tag3_style')
            data['recommend_goodsId'] = request.POST.get('recommend_goodsId')
            data['recommend_goods_reason'] = request.POST.get(
                'recommend_goods_reason')
            data['citysJson'] = goods.citysJson
            data['serviceRangeJson'] = goods.serviceRangeJson
            data['card_type'] = goods.card_type
            data['service_times'] = goods.service_times
            data['card_minutes'] = goods.card_minutes
            data['serviceRangeGraph'] = goods.serviceRangeGraph
            data['card_icon'] = goods.card_icon

            # 更新同一goods_id的商品
            if data:
                CmsGoods.objects.filter(~Q(id=id),
                                        goods_id=goods.goods_id).update(**data)
                if INSTALL_TYPE == 2 or INSTALL_TYPE == 3:
                    # 同步至搜索
                    data['operation_tag'] = data['mark']
                    op_tag = []
                    if data['tag1'] and data['tag1_style']:
                        op_tag.append({
                            'tag': data['tag1'],
                            'tag_style': data['tag1_style']
                        })

                    if data['tag2'] and data['tag2_style']:
                        op_tag.append({
                            'tag': data['tag2'],
                            'tag_style': data['tag2_style']
                        })

                    if data['tag3'] and data['tag3_style']:
                        op_tag.append({
                            'tag': data['tag3'],
                            'tag_style': data['tag3_style']
                        })
                    data['op_tag'] = op_tag
                    sync_search(goods.goods_id, data)
            if CMS_CHECK_ON:
                CmsCheck(module=CmsModule.MAIN_GOODS,
                         table_name='CmsGoods',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(reverse('goods'))
    else:
        goods = CmsGoods.objects.get(id=id)
        form = GoodsForm(instance=goods)
    errors, fields = format_form(form)
    if 'second_category' in fields.keys(
    ) and fields['second_category'] == '""':
        fields['second_category'] = fields['category']
    if 'new_second_category' in fields.keys(
    ) and fields['new_second_category'] == '""':
        fields['new_second_category'] = fields['new_category']
    scenes = get_scenes()
    actions = get_actions_select()
    citygroups = get_city_group()
    cities = get_city_list()
    categories = get_categories()
    return render_to_response(template_name, {
        "scenes": scenes,
        "actions": actions,
        "categories": categories,
        "citygroups": citygroups,
        "cities": cities,
        "id": id,
        "fields": fields,
        "errors": errors,
        "all_goods": all_goods
    },
                              context_instance=RequestContext(request))
Пример #27
0
def new_ads(request, template_name):
    """
    新建 广告
    #插入到广告表,插入广告和广告组关联表
    :请求方式:Get
    :请求参数:id:广告组id,channel:渠道id
    :返回数据:ad_id:广告组id form 表单 citygroups 城市分组 actions:动作列表 (services 服务列表 goods 商品列表) open_type:类别 cities:所有城市(格式和之前一致)
    :格式:[[id,name],....]

    :请求方式:Post
    :请求参数:ad_id,img_url,start,end,location,action_id,strategy(删除了)
    valid_time,city,open_cp_id,open_service_id,open_goods_id,open_type,action_json
    :
    """
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    text = get_nav_text(str(t))
    location_flag = True
    if request.method == 'POST':
        form = CmsAdbeansForm(request.POST)
        form.data['start'] = make_timestamp(form.data['start'])
        form.data['end'] = make_timestamp(form.data['end'])
        ad_id = request.POST.get('ad_id')

        if form.is_valid():
            if not CmsAdbeans.objects.filter(
                    cmsadsbeans__ad_id=ad_id,
                    location=request.POST.get('location')):
                oCmsAdbeans = form.save()
                if CMS_CHECK_ON:
                    CmsCheck(channel_id=channel_id,
                             module=CmsModule.CONFIG_AD,
                             table_name='CmsAdbeans',
                             data_id=oCmsAdbeans.id,
                             op_type=CheckOpType.NEW,
                             alter_person=request.user.username,
                             alter_date=time.strftime(
                                 "%Y-%m-%d %X", time.localtime())).save()
                oCmsAdsBeans = CmsAdsBeans(ad=CmsAds.objects.get(id=ad_id),
                                           bean=oCmsAdbeans)
                oCmsAdsBeans.save()
                if CMS_CHECK_ON:
                    CmsCheck(channel_id=channel_id,
                             module=CmsModule.CONFIG_AD,
                             table_name='CmsAdsBeans',
                             data_id=oCmsAdsBeans.id,
                             op_type=CheckOpType.NEW,
                             is_show=0,
                             alter_person=request.user.username,
                             alter_date=time.strftime(
                                 "%Y-%m-%d %X", time.localtime())).save()
                return HttpResponseRedirect(
                    reverse('ads') + "?t=%d&c=%s&v=%s" % (t, c, v))
            else:
                location_flag = False

    else:
        form = CmsAdbeansForm()
    ad_id = request.GET.get('id')
    citygroups = get_city_group()
    actions = get_actions_select()
    cities = get_city_list()
    errors, fields = format_form(form)
    if not location_flag:
        errors['location'] = '广告排序:%s 已存在请填入其他的值' % request.POST.get(
            'location')
    if 'start' in fields.keys():
        fields['start'] = json.dumps(timestamp2str(fields['start']))
    if 'end' in fields.keys():
        fields['end'] = json.dumps(timestamp2str(fields['end']))
    return render_to_response(template_name, {
        "fields": fields,
        "errors": errors,
        "citygroups": citygroups,
        "actions": actions,
        "cities": cities,
        "open_type": open_type,
        "ad_id": ad_id,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id
    },
                              context_instance=RequestContext(request))
Пример #28
0
def edit(request, template_name):
    id = request.GET.get("id")
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    list = ViewCmsSecKillView.objects.filter(channel_id=channel_id)
    # 根据类型得到名称
    text = get_nav_text(str(t))
    seckill = CmsSecKill.objects.get(id=id)
    log.error(str(seckill.id) + "----" + seckill.title)
    is_ok_time = True
    if request.method == "POST":
        form = CmsSeckilForm(request.POST, instance=seckill)
        if form.data['show_start_time']:
            form.data['show_start_time'] = timestamp2str_h(
                make_timestamp(form.data['show_start_time']))
        if form.data['show_end_time']:
            form.data['show_end_time'] = timestamp2str_h(
                make_timestamp(form.data['show_end_time']))
        if form.is_valid():
            if check_time(list, id,
                          make_timestamp_h(form.data['show_start_time']),
                          make_timestamp_h(form.data['show_end_time'])):
                form.save()
                return HttpResponseRedirect(
                    reverse('seckills') + "?t=%d&c=%s&v=%s" % (t, c, v))
            else:
                is_ok_time = False
    else:
        form = CmsSeckilForm(instance=seckill)
        if form.initial['show_start_time']:
            form.initial['show_start_time'] = str(
                form.initial['show_start_time'])
        if form.initial['show_end_time']:
            form.initial['show_end_time'] = str(form.initial['show_end_time'])
    log.error(form.initial)
    errors, fields = format_form(form)
    if not is_ok_time:
        errors['time'] = '起始时间与结束时间不能与同渠道其他秒杀活动重合'
    if 'show_start_time' in fields.keys(
    ) and fields['show_start_time'] != '""':
        fields['show_start_time'] = json.dumps(
            timestamp2str(
                make_timestamp_h(
                    str(fields['show_start_time']).replace("\"", ""))))
    if 'show_end_time' in fields.keys() and fields['show_end_time'] != '""':
        fields['show_end_time'] = json.dumps(
            timestamp2str(
                make_timestamp_h(
                    str(fields['show_end_time']).replace("\"", ""))))
    citygroups = get_city_group()
    cities = get_city_list()
    actions = get_actions_select()
    actionsall = CmsActions.objects.all()
    # 准备秒杀字段
    opGoodsActivitys = OpGoodsActivityView.objects.filter(is_seckill=1)
    op = OpGoodsActivityView.objects.filter(
        Q(activityId=seckill.activity_id) & Q(is_seckill=1)).first()
    map = {}
    if opGoodsActivitys is not None:
        for oga in opGoodsActivitys:
            map[oga.activityId] = oga
    op_goods_list = []
    for k, vl in map.items():
        op_goods_list.append(vl)
    current_city = seckill.city
    if current_city == '*':
        current_city = '不限(全国)'
    return render_to_response(template_name, {
        "t": t,
        "v": v,
        "c": c,
        "id": id,
        "text": text,
        "channel": channel_id,
        "errors": errors,
        "fields": fields,
        "citygroups": citygroups,
        "cities": cities,
        "product_types": product_types,
        "actions": actions,
        "op_goods_list": op_goods_list,
        "actionsall": actionsall,
        "activity_id": seckill.activity_id,
        "origin_city": op.activityCity,
        "current_city": current_city,
    },
                              context_instance=RequestContext(request))
Пример #29
0
def edit_ads(request, template_name):
    """
    编辑 广告
    #
    :请求方式:Get
    :请求参数:id 广告id
    :返回数据:form 表单 citygroups 城市分组 actions:动作列表 (services 服务列表 goods 商品列表) open_type:类别 cities:所有城市(格式和之前一致)
    :格式:[[id,name],....]
    :备注:scenes 场景列表 和之前一样,ad_size = [["半栏",2],["通栏",1]]  ad_type = [["轮播",1],["单播",2]]

    :请求方式:Post
    :请求参数:id,img_url,start,end,location,action_id,strategy(删除了)
    valid_time,city,open_cp_id,open_service_id,open_goods_id,open_type,action_json
    :
    """
    id = request.GET.get("id")
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    text = get_nav_text(str(t))
    if request.method == 'POST':
        cmsadbeans = CmsAdbeans.objects.get(id=id)
        form = CmsAdbeansForm(request.POST, instance=cmsadbeans)
        form.data['start'] = make_timestamp(form.data['start'])
        form.data['end'] = make_timestamp(form.data['end'])
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_AD,
                         table_name='CmsAdbeans',
                         data_id=id,
                         op_type=CheckOpType.EDIT,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            return HttpResponseRedirect(
                reverse('ads') + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        cmsadbeans = CmsAdbeans.objects.get(id=id)
        form = CmsAdbeansForm(instance=cmsadbeans)
    citygroups = get_city_group()
    actions = get_actions_select()
    cities = get_city_list()
    errors, fields = format_form(form)
    if 'start' in fields.keys():
        fields['start'] = json.dumps(timestamp2str(fields['start']))
    if 'end' in fields.keys():
        fields['end'] = json.dumps(timestamp2str(fields['end']))
    return render_to_response(template_name, {
        "fields": fields,
        "errors": errors,
        "citygroups": citygroups,
        "actions": actions,
        "cities": cities,
        "open_type": open_type,
        "id": id,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id
    },
                              context_instance=RequestContext(request))
Пример #30
0
def new_ad(request, template_name):
    """
    新建开屏广告
    #插入到开屏广告表,插入开屏广告和渠道关联表
    url :{% url 'new_screen_ad' %}?channel={{ channel }}
    :请求方式:Get
    :请求参数:channel:渠道id
    :返回数据: form 表单 citygroups 城市分组 actions:动作列表 (services 服务列表 goods 商品列表) open_type:类别 cities:所有城市(格式和之前一致)
               screen_ad_times = [[1, "仅展示一次"], [100, "每次进入展示"]]
    :格式:[[id,name],....]

    :请求方式:Post
    :请求参数:cms_screenads 表各字段
    :
    """
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    text = get_nav_text(str(t))
    if request.method == 'POST':
        form = CmsScreenadsForm(request.POST)
        form.data['start'] = make_timestamp(form.data['start'])
        form.data['end'] = make_timestamp(form.data['end'])
        if form.is_valid():
            oCmsScreenads = form.save()
            if CMS_CHECK_ON:
                check = CmsCheck(channel_id=channel_id,
                                 module=CmsModule.CONFIG_SCREEN_AD,
                                 table_name="CmsScreenads",
                                 data_id=oCmsScreenads.id,
                                 op_type=CheckOpType.NEW,
                                 status=CheckStatu.WAIT_SUBMIT,
                                 alter_person=request.user.username,
                                 alter_date=time.strftime(
                                     "%Y-%m-%d %X", time.localtime()))
                check.save()
            new_associate(channel_id, oCmsScreenads.id, CONFIG_ITEMS.SCREEN_AD,
                          request)
            oCmsViewScreenads = CmsViewScreenads(
                screenad=oCmsScreenads,
                channel=CmsChannels.objects.get(id=channel_id),
                status=0)
            oCmsViewScreenads.save()
            if CMS_CHECK_ON:
                check = CmsCheck(channel_id=channel_id,
                                 module=CmsModule.CONFIG_SCREEN_AD,
                                 table_name="CmsViewScreenads",
                                 data_id=oCmsViewScreenads.id,
                                 op_type=CheckOpType.NEW,
                                 status=CheckStatu.WAIT_SUBMIT,
                                 is_show=0,
                                 alter_person=request.user.username,
                                 alter_date=time.strftime(
                                     "%Y-%m-%d %X", time.localtime()))
                check.save()
            return HttpResponseRedirect(
                reverse('screen_ads') + "?t=%d&c=%s&v=%s" % (t, c, v))

    else:
        form = CmsAdbeansForm()
    citygroups = get_city_group()
    actions = get_actions_select()
    cities = get_city_list()
    errors, fields = format_form(form)
    if 'start' in fields.keys():
        fields['start'] = json.dumps(timestamp2str(fields['start']))
    if 'end' in fields.keys():
        fields['end'] = json.dumps(timestamp2str(fields['end']))
    return render_to_response(template_name, {
        "fields": fields,
        "errors": errors,
        "citygroups": citygroups,
        "actions": actions,
        "cities": cities,
        "open_type": open_type,
        "screen_ad_times": screen_ad_times,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id
    },
                              context_instance=RequestContext(request))