Пример #1
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))
Пример #2
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))
Пример #3
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))
Пример #4
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))
Пример #5
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))