Ejemplo n.º 1
0
def new_version(request):
    type_id = request.POST["type_id"]
    src_ver_id = request.POST.get('src_ver_id')
    form = NewVerForm(request.POST)
    if form.is_valid():
        channelsappversion = form.save()
        remark = ""
        if src_ver_id:
            src_ver = CmsChannelsAppVersion.objects.get(id=src_ver_id)
            src_ver_text = src_ver.app_version
            src_type_text = get_nav_text(src_ver.type_id)
            type_text = get_nav_text(type_id)
            remark = "在%s下新建了版本%s,它是由%s%s版本复制而来" % (
                type_text, channelsappversion.app_version, src_type_text,
                src_ver_text)
        if CMS_CHECK_ON:
            CmsCheck(module=CmsModule.MAIN_CHANNEL,
                     table_name='CmsChannelsAppVersion',
                     data_id=channelsappversion.id,
                     op_type=CheckOpType.NEW,
                     remark=remark,
                     alter_person=request.user.username,
                     alter_date=time.strftime("%Y-%m-%d %X",
                                              time.localtime())).save()
        if src_ver_id:
            copy_version(src_ver_id, channelsappversion.id, request)
    return HttpResponseRedirect(reverse('main_index') + "?t=%s" % type_id)
Ejemplo n.º 2
0
def show_cvt(channel_id, module):
    if channel_id:
        try:
            # 不是删除渠道
            m = get_2array_value(item_modules, module)
            relate_channels = get_relate_channel_list(channel_id, m)
            relate_channels.append(channel_id)
            relate_channels.sort()
            types = []
            channel_nos = []
            app_versions = []
            for channel in relate_channels:
                obj = CmsChannels.objects.get(id=channel)
                c, v, t = getCVT(channel)
                types.append(get_nav_text(str(t)))
                app_versions.append(v)
                channel_nos.append(obj.channel_no)
            return "<br />".join(types), "<br />".join(
                app_versions), "<br />".join(channel_nos)
        except:
            # 删除的是渠道,情况比较特殊
            c, v, t = getCVT(channel_id, 'online')
            return get_nav_text(str(t)), v, c

    else:
        return "内容库", "内容库", "内容库"
Ejemplo n.º 3
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))
Ejemplo n.º 4
0
def common_services(request, template_name):
    t = request.GET.get("t")
    if not t:
        t = "1"
    v = request.GET.get("v")
    c = request.GET.get("c")
    channel = CmsChannels.objects.get(channel_no=c,
                                      app_version__app_version=v,
                                      app_version__type_id=t).id
    services = get_services()
    goods = get_goods()
    if v[0].isdigit() and v >= '3.7.0':
        categories = get_v37_categories()
    else:
        categories = get_categories()
    return render_to_response(template_name, {
        "text": get_nav_text(t),
        "t": t,
        "v": v,
        "c": c,
        "channel": channel,
        "services": services,
        "goods": goods,
        "categories": categories,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 5
0
Archivo: likes.py Proyecto: cash2one/pt
def new_group(request, template_name):
    """
    猜你喜欢 新建组
    url :{% url 'new_likes_group' %}?channel={{ channel }}
    :请求方式: Get
    :请求参数:channel
    :返回数据:form 表单 scenes 场景列表
    :例如: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))
    if request.method == 'POST':
        form = LikesForm(request.POST)
        if form.is_valid():
            likes = form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_LIKE,
                         table_name='CmsLikes',
                         data_id=likes.id,
                         op_type=CheckOpType.NEW,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            oCmsViewLike = CmsViewLike(like=likes, channel=channel, status=0)
            oCmsViewLike.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_LIKE,
                         table_name='CmsViewLike',
                         data_id=oCmsViewLike.id,
                         op_type=CheckOpType.NEW,
                         is_show=0,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            new_associate(channel_id, likes.id, CONFIG_ITEMS.LIKES, request)
            return HttpResponseRedirect(
                reverse("likes") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        form = LikesForm()
    scenes = get_scenes()
    errors, fields = format_form(form)
    return render_to_response(template_name, {
        "scenes": scenes,
        "fields": fields,
        "errors": errors,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 6
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))
Ejemplo n.º 7
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))
Ejemplo n.º 8
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))
Ejemplo n.º 9
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))
Ejemplo n.º 10
0
def new_streamsgroup(request, template_name):
    """
    新建 内容流组
    url :{% url 'new_streamsgroup' %}?channel={{ channel }}
    :请求方式: Get
    :请求参数:channel
    :返回数据:form 表单 scenes 场景列表 streams_type:类型
    :例如:scenes 场景列表 和之前一样 streams_type = [[1,"活动"],[2,"服务"],[3,"商品"],[4,"搜索"]]

    :请求方式:Post
    :请求参数:`type` `location`  `scene_id`
    """
    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))
    if request.method == 'POST':
        form = StreamcontentForm(request.POST)
        if form.is_valid():
            streamcontent = form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_STREAM,
                         table_name='CmsStreamcontent',
                         data_id=streamcontent.id,
                         op_type=CheckOpType.NEW,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X", time.localtime())).save()
            oCmsViewStream = CmsViewStream(streamcontent=streamcontent, channel=channel, status=0)
            oCmsViewStream.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_STREAM,
                         table_name='CmsViewStream',
                         data_id=oCmsViewStream.id,
                         op_type=CheckOpType.NEW,
                         is_show=0,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X", time.localtime())).save()
            new_associate(channel_id, streamcontent.id, CONFIG_ITEMS.STREAMS, request)
            return HttpResponseRedirect(reverse("streams") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        form = CmsAdsForm()
    scenes = get_scenes()
    errors, fields = format_form(form)
    return render_to_response(template_name, {
        "scenes": scenes,
        "streams_type": streams_type,
        "fields": fields,
        "errors": errors,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id
    }, context_instance=RequestContext(request))
Ejemplo n.º 11
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))
Ejemplo n.º 12
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))
Ejemplo n.º 13
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))
Ejemplo n.º 14
0
def edit_group(request, template_name):
    """
    编辑 分类页服务组
    url :{% url 'category_pages_services_new_group' %}?channel={{ channel }}
    :请求方式: Get
    :请求参数:channel ,id
    :返回数据:scenes 场景列表 categories 一级分类列表
    :例如:scenes 场景列表 和之前一样 streams_type = [[1,"活动"],[2,"服务"],[3,"商品"],[4,"搜索"]]

    :请求方式:Post
    :请求参数:
    """
    id = request.GET.get("id")
    navicategories = CmsNavicategories.objects.get(id=id)
    channel = request.GET.get("channel")
    c, v, t = getCVT(channel)
    text = get_nav_text(str(t))
    if request.method == "POST":
        form = NavicategoriesForm(request.POST, instance=navicategories)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel,
                         module=CmsModule.CONFIG_PAGE,
                         table_name='CmsNavicategories',
                         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=%s&c=%s&v=%s" %
                (t, c, v))
    else:
        form = NavicategoriesForm(instance=navicategories)
    errors, fields = format_form(form)
    # 一级分类
    categories = get_first_categories()
    scenes = get_scenes()
    return render_to_response(template_name, {
        "categories": categories,
        "scenes": scenes,
        "fields": fields,
        "errors": errors,
        "channel": channel,
        "text": text,
        "t": t,
        "c": c,
        "v": v,
        "id": id
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 15
0
Archivo: likes.py Proyecto: cash2one/pt
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))
Ejemplo n.º 16
0
def edit_second_category(request, template_name):
    """
    编辑二级分类
    url :{% url 'sc_edit_second_category' %}?channel={{ channel }}&id={{ id }}
    :请求方式: Get
    :请求参数:channel,id
    :返回数据:form 表单 scenes 场景列表 services 服务列表
    :例如:scenes 场景列表 和之前一样 streams_type = [[1,"活动"],[2,"服务"],[3,"商品"],[4,"搜索"]]

    :请求方式:Post
    :请求参数:
    """
    channel_id = request.GET.get('channel')
    id = request.GET.get("id")
    category_item = CmsCategoryItem.objects.get(id=id)
    c, v, t = getCVT(channel_id)
    # 根据类型得到名称
    text = get_nav_text(str(t))
    if request.method == 'POST':
        form = CmsCategoryItemForm(request.POST, instance=category_item)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_SECOND_CATEGORY,
                         table_name='CmsCategoryItem',
                         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 = CmsCategoryItemForm(instance=category_item)
    scenes = get_scenes()
    services = get_services()
    errors, fields = format_form(form)
    return render_to_response(template_name, {
        "scenes": scenes,
        "services": services,
        "fields": fields,
        "errors": errors,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id,
        "id": id
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 17
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))
Ejemplo n.º 18
0
def edit_adgroup(request, template_name):
    """
     编辑 广告分组
    :请求方式:Get
    :请求参数:id 广告组表id号 channel:渠道id
    :返回数据:form 表单 scenes 场景列表 ad_size:篇幅列表 ad_type: 类型 (list)
    :例如:scenes 场景列表 和之前一样, ad_size = [[2,"半栏"],[1,"通栏"]] ad_type = [[2,"单播"],[1,"轮播"]]

    :请求方式:Post
    :请求参数:排序:location 篇幅  size 类型:type 场景:scene_id
    :备注 :传数字
    """
    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":
        ads = CmsAds.objects.get(id=id)
        form = CmsAdsForm(request.POST, instance=ads)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_AD,
                         table_name='CmsAds',
                         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:
        ads = CmsAds.objects.get(id=id)
        form = CmsAdsForm(instance=ads)
    scenes = get_scenes()
    errors, fields = format_form(form)
    return render_to_response(template_name, {
        "id": id,
        "scenes": scenes,
        "ad_size": ad_size,
        "ad_type": ad_type,
        "fields": fields,
        "errors": errors,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 19
0
def choiceness_categories(request, template_name):
    t = request.GET.get("t")
    if not t:
        t = "1"
    v = request.GET.get("v")
    c = request.GET.get("c")
    channel = CmsChannels.objects.get(channel_no=c, app_version__app_version=v, app_version__type_id=t).id
    return render_to_response(template_name, {
        "text": get_nav_text(t),
        "t": t,
        "v": v,
        "c": c,
        "channel": channel
    }, context_instance=RequestContext(request))
Ejemplo n.º 20
0
Archivo: likes.py Proyecto: cash2one/pt
def edit_group(request, template_name):
    """
    猜你喜欢 编辑组
    url :{% url 'edit_likes_group' %}?channel={{ channel }}&id={{ id }}
    :请求方式: Get
    :请求参数:channel,id
    :返回数据:form 表单 scenes 场景列表
    :例如:scenes 场景列表 和之前一样

    :请求方式:Post
    :请求参数:
    """
    channel_id = request.GET.get('channel')
    id = request.GET.get("id")
    c, v, t = getCVT(channel_id)
    likes = CmsLikes.objects.get(id=id)
    #根据类型得到名称
    text = get_nav_text(str(t))
    if request.method == 'POST':
        form = LikesForm(request.POST, instance=likes)
        if form.is_valid():
            form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_LIKE,
                         table_name='CmsLikes',
                         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:
        form = LikesForm(instance=likes)
    scenes = get_scenes()
    errors, fields = format_form(form)
    return render_to_response(template_name, {
        "scenes": scenes,
        "fields": fields,
        "errors": errors,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id,
        "id": id
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 21
0
def streams(request, template_name):
    t = request.GET.get("t")
    if not t:
        t = "1"
    v = request.GET.get("v")
    c = request.GET.get("c")
    channel = CmsChannels.objects.get(channel_no=c, app_version__app_version=v, app_version__type_id=t).id
    goods = get_goods()
    return render_to_response(template_name, {
        "text": get_nav_text(t),
        "t": t,
        "v": v,
        "c": c,
        "channel": channel,
        "goods": goods
    }, context_instance=RequestContext(request))
Ejemplo n.º 22
0
def edit(request, template_name):
    id = request.GET.get("id")
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    text = get_nav_text(str(t))
    cpdis_ins = CmsCpdisplay.objects.get(id=id)
    cp_id = cpdis_ins.meta_id
    ins_cp = CmsCP.objects.get(id=cpdis_ins.meta_id)
    if request.method == "POST":
        form = CmsCPForm(request.POST, instance=ins_cp)
        cpdis_form = CmsCpdisplayForm(request.POST, instance=cpdis_ins)
        if form.is_valid() and cpdis_form.is_valid():
            form.save()
            cpdis_form.save()
            cp_category = request.POST.get("cp_category")
            if CmsViewCP.objects.filter(cp_id=cp_id):
                ins_viewcp = CmsViewCP.objects.get(cp_id=cp_id)
                ins_viewcp.cp_category_id = cp_category
                ins_viewcp.save()
            else:
                CmsViewCP(cp_id=cp_id, cp_category_id=cp_category).save()
            setCpAction(cp_id, request.POST.get('action_id'))
            return HttpResponseRedirect(reverse('config_cp_list') + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        form = CmsCPForm(instance=ins_cp)
        cpdis_form = CmsCpdisplayForm(instance=cpdis_ins)
    errors, fields = format_form(form)
    cpdiserrors, cpdisfields = format_form(cpdis_form)
    if CmsViewCP.objects.filter(cp_id=cp_id):
        fields['cp_category'] = json.dumps(CmsViewCP.objects.get(cp_id=cp_id).cp_category_id)
    actions = get_actions_select()
    cp_cates = CmsCPCategory.objects.all()
    return render_to_response(template_name, {
        "t": t,
        "v": v,
        "c": c,
        "text": text,
        "id": id,
        "cp_id": cp_id,
        "channel": channel_id,
        "errors": errors,
        "fields": fields,
        "cp_cates": cp_cates,
        "actions": actions,
        "cpdiserrors": cpdiserrors,
        "cpdisfields": cpdisfields
    }, context_instance=RequestContext(request))
Ejemplo n.º 23
0
def seckills(request, template_name):
    t = request.GET.get("t")
    if not t:
        t = "1"
    v = request.GET.get("v")
    c = request.GET.get("c")
    channel = CmsChannels.objects.get(channel_no=c,
                                      app_version__app_version=v,
                                      app_version__type_id=t).id
    print("channel_id is:[" + str(channel) + "]")
    return render_to_response(template_name, {
        "text": get_nav_text(t),
        "t": t,
        "v": v,
        "c": c,
        "channel": channel
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 24
0
def config_operation(request, template_name):
    t = request.GET.get("t")
    if not t:
        t = "1"
    v = request.GET.get("v")
    c = request.GET.get("c")
    channel = CmsChannels.objects.get(channel_no=c,
                                      app_version__app_version=v,
                                      app_version__type_id=t).id
    return render_to_response(template_name, {
        "text": get_nav_text(t),
        "t": t,
        "v": v,
        "c": c,
        "channel": channel,
        "OP_CONFIG": OP_CONFIG
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 25
0
def foundpage_specialtopic(request, template_name):
    t = request.GET.get("t")
    if not t:
        t = "1"
    v = request.GET.get("v")
    c = request.GET.get("c")
    channel = CmsChannels.objects.get(channel_no=c,
                                      app_version__app_version=v,
                                      app_version__type_id=t).id
    topics = get_topics()
    return render_to_response(template_name, {
        "text": get_nav_text(t),
        "t": t,
        "v": v,
        "c": c,
        "channel": channel,
        "topics": topics
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 26
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))
Ejemplo n.º 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))
Ejemplo n.º 28
0
def new_adgroup(request, template_name):
    """
    新建 广告分组
    插入广告组表和广告组和渠道关联表
    :请求方式:Get
    :请求参数:无
    :返回数据:form 表单 scenes 场景列表 ad_size:篇幅列表 ad_type: 类型 (list)
    :例如:scenes 场景列表 和之前一样, ad_size = [[2,"半栏"],[1,"通栏"]] ad_type = [[2,"单播"],[1,"轮播"]]

    :请求方式:Post
    :请求参数:排序:location 篇幅  size 类型:type 场景:scene_id
    :备注 :传数字
    """
    channel_id = request.GET.get('channel')
    c, v, t = getCVT(channel_id)
    # 根据类型得到名称
    text = get_nav_text(str(t))
    if request.method == 'POST':
        form = CmsAdsForm(request.POST)
        if form.is_valid():
            oCmsAds = form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_AD,
                         table_name='CmsAds',
                         data_id=oCmsAds.id,
                         op_type=CheckOpType.NEW,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            oViewAd = CmsViewAd(ad=oCmsAds,
                                channel=CmsChannels.objects.get(id=channel_id))
            oViewAd.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_AD,
                         table_name='CmsViewAd',
                         data_id=oViewAd.id,
                         op_type=CheckOpType.NEW,
                         is_show=0,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            new_associate(channel_id, oCmsAds.id, CONFIG_ITEMS.AD, request)
            return HttpResponseRedirect(
                reverse('ads') + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        form = CmsAdsForm()
    scenes = get_scenes()
    errors, fields = format_form(form)
    return render_to_response(template_name, {
        "scenes": scenes,
        "ad_size": ad_size,
        "ad_type": ad_type,
        "fields": fields,
        "errors": errors,
        "t": t,
        "c": c,
        "v": v,
        "text": text,
        "channel": channel_id
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 29
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))
Ejemplo n.º 30
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))