Beispiel #1
0
def new_group(request, template_name):
    """
    新建 分类页服务组
    url :{% url 'category_pages_services_new_group' %}?channel={{ channel }}
    :请求方式: Get
    :请求参数:channel
    :返回数据: scenes 场景列表 categories 一级分类列表
    :例如:scenes 场景列表 和之前一样 streams_type = [[1,"活动"],[2,"服务"],[3,"商品"],[4,"搜索"]]

    :请求方式:Post
    :请求参数:
    """
    channel = request.GET.get("channel")
    c, v, t = getCVT(channel)
    text = get_nav_text(str(t))
    if request.method == "POST":
        form = NavicategoriesForm(request.POST)
        if form.is_valid():
            navicategories = form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel,
                         module=CmsModule.CONFIG_PAGE,
                         table_name='CmsNavicategories',
                         data_id=navicategories.id,
                         op_type=CheckOpType.NEW,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            cmschannel = CmsChannels.objects.get(id=channel)
            oviewnavi = CmsViewNavi(navicat=navicategories,
                                    channel=cmschannel,
                                    status=0)
            oviewnavi.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel,
                         module=CmsModule.CONFIG_PAGE,
                         table_name='CmsViewNavi',
                         data_id=oviewnavi.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, navicategories.id,
                          CONFIG_ITEMS.CATEGORY_PAGE_SERVICES, request)
            return HttpResponseRedirect(
                reverse("category_pages_services") + "?t=%s&c=%s&v=%s" %
                (t, c, v))
    else:
        form = NavicategoriesForm()
    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
    },
                              context_instance=RequestContext(request))
Beispiel #2
0
def new_common_category(request):
    """
    常用服务  新建常用分类
    :请求方式:ajax Post
    :请求URL:{% url 'new_common_category' %}
    :请求参数:category_id  channel_id
    :类型 :传数字
    返回: 成功:0 错误:错误信息
    """

    if request.method == 'POST':
        data = request.POST.copy()
        error = ""
        for key in data:
            if data[key] == "":
                error += key + " is null \n"
        if error:
            return HttpResponse(error)
        else:
            # navicategory.parent_id = category_id
            # navicategory.id = None
            # navicategory.save()
            try:
                category_id = request.POST.get("category_id")
                channel_id = request.POST.get("channel_id")
                navicategory = CmsNaviCategory.objects.get(id=category_id)
                if navicategory.fatherid != 0:
                    group_name = CmsViewGroupCategory.objects.get(
                        category_id=navicategory.fatherid).group.name
                else:
                    group_name = CmsViewGroupCategory.objects.get(
                        category=navicategory).group.name
                if group_name == CategoryGroupType.daojia:
                    open_type = 6
                    if navicategory.fatherid == 0:
                        open_type = 5
                else:
                    open_type = 4
                    if navicategory.fatherid == 0:
                        open_type = 3
                oCmsViewService = CmsViewService(
                    service_id=category_id,
                    channel=CmsChannels.objects.get(id=channel_id),
                    open_type=open_type)
                oCmsViewService.save()
                if CMS_CHECK_ON:
                    CmsCheck(
                        channel_id=channel_id,
                        module=CmsModule.CONFIG_COMMON_SERVICES,
                        table_name='CmsViewService',
                        data_id=oCmsViewService.id,
                        op_type=CheckOpType.NEW,
                        remark="增加了名称为%s的%d级分类" % (CheckManager.wrap_style(
                            navicategory.name), open_type - 2),
                        alter_person=request.user.username,
                        alter_date=time.strftime("%Y-%m-%d %X",
                                                 time.localtime())).save()
                new_associate(channel_id,
                              navicategory.id,
                              CONFIG_ITEMS.COMMON_SERVICES,
                              request,
                              open=open_type)
            except Exception as ex:
                if 'Duplicate entry' in ex.args[0]:
                    return HttpResponse(1)
                return HttpResponse(ex.args[0])
            return HttpResponse(0)
Beispiel #3
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))
Beispiel #4
0
def new_common_goods(request):
    """
     新建 服务导航 常用商品
    :请求方式:ajax Post
    :请求URL:{% url 'new_common_goods' %}
    :请求参数:goods_id  channel_id
    :类型 :传数字
    返回: 成功:0 错误:错误信息
    """

    if request.method == 'POST':
        data = request.POST.copy()
        error = ""
        for key in data:
            if data[key] == "":
                error += key + " is null \n"
        if error:
            return HttpResponse(error)
        else:
            goods_id = request.POST.get("goods_id")
            channel_id = request.POST.get("channel_id")
            try:
                goods = CmsGoods.objects.get(id=goods_id)
                goods.parent_id = goods_id
                goods.id = None
                goods.save()
                if CMS_CHECK_ON:
                    CmsCheck(channel_id=channel_id,
                             module=CmsModule.CONFIG_COMMON_SERVICES,
                             table_name='CmsGoods',
                             data_id=goods.id,
                             op_type=CheckOpType.NEW,
                             remark="增加了名称为%s的商品" %
                             (CheckManager.wrap_style(goods.name), ),
                             alter_person=request.user.username,
                             alter_date=time.strftime(
                                 "%Y-%m-%d %X", time.localtime())).save()
                oCmsViewService = CmsViewService(
                    service_id=goods.id,
                    channel=CmsChannels.objects.get(id=channel_id),
                    open_type=1)
                oCmsViewService.save()
                if CMS_CHECK_ON:
                    CmsCheck(channel_id=channel_id,
                             module=CmsModule.CONFIG_COMMON_SERVICES,
                             table_name='CmsViewService',
                             data_id=oCmsViewService.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,
                              goods.id,
                              CONFIG_ITEMS.COMMON_SERVICES,
                              request,
                              open=1)
            except Exception as ex:
                if 'Duplicate entry' in ex.args[0]:
                    return HttpResponse(1)
                return HttpResponse(ex.args[0])
            return HttpResponse(0)
Beispiel #5
0
def new_activity(request, template_name):
    """
    配置库 新建活动
    url :{% url 'new_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))
    if request.method == 'POST':
        form = ActivitiesForm(request.POST)
        form.data['start'] = make_timestamp(form.data['start'])
        form.data['end'] = make_timestamp(form.data['end'])
        if form.is_valid():
            activity = form.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_ACTIVITY,
                         table_name='CmsActivities',
                         data_id=activity.id,
                         op_type=CheckOpType.NEW,
                         alter_person=request.user.username,
                         alter_date=time.strftime("%Y-%m-%d %X",
                                                  time.localtime())).save()
            viewactivity = CmsViewActivity(activity=activity, channel=channel)
            viewactivity.save()
            if CMS_CHECK_ON:
                CmsCheck(channel_id=channel_id,
                         module=CmsModule.CONFIG_ACTIVITY,
                         table_name='CmsViewActivity',
                         data_id=viewactivity.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, activity.id, CONFIG_ITEMS.ACTIVITY,
                          request)
            return HttpResponseRedirect(
                reverse("activities") + "?t=%d&c=%s&v=%s" % (t, c, v))
    else:
        form = ActivitiesForm()
    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
    },
                              context_instance=RequestContext(request))