예제 #1
0
    def create_or_update(cls, id, img_url, start, end, location, action_id,
                         city, name):
        open_type = 0
        id = int(id)
        if id > 0:
            try:
                obj = CmsAdbeans.objects.filter(id=id).get()
            except ObjectDoesNotExist:
                obj = CmsAdbeans()
            obj.img_url = img_url
            obj.start = make_timestamp(start)
            obj.end = make_timestamp(end)
            obj.location = location
            obj.city = city
            obj.action_id = action_id
            obj.name = name
            obj.open_type = open_type
            obj.save()
        else:
            obj = CmsAdbeans()
            obj.img_url = img_url
            obj.start = make_timestamp(start)
            obj.end = make_timestamp(end)
            obj.location = location
            obj.action_id = action_id
            obj.city = city
            obj.name = name
            obj.open_type = open_type
            obj.save()

        return obj
예제 #2
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))
예제 #3
0
파일: coupons.py 프로젝트: cash2one/pt
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_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))
예제 #5
0
 def create_or_update(cls, category_index_id, goods_id, sort, start_date,
                      end_date, create_uid):
     try:
         obj = CmsCategoryIndexRecommendedGoods.objects.filter(
             Q(category_index_id=category_index_id)
             & Q(goods_id=goods_id)).get()
         obj.sort = sort
         obj.start_date = make_timestamp(start_date)
         obj.end_date = make_timestamp(end_date)
         obj.save()
     except ObjectDoesNotExist:
         obj = CmsCategoryIndexRecommendedGoods()
         obj.category_index_id = category_index_id
         obj.goods_id = goods_id
         obj.sort = sort
         obj.start_date = make_timestamp(start_date)
         obj.end_date = make_timestamp(end_date)
         obj.create_date = time.time()
         obj.create_uid = create_uid
         obj.save()
     return obj
예제 #6
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))
예제 #7
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))
예제 #8
0
파일: seckills.py 프로젝트: cash2one/pt
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))
예제 #9
0
파일: seckills.py 프로젝트: cash2one/pt
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))
예제 #10
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))
예제 #11
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))