def edit_service(request, template_name): id = request.GET.get("id") if request.method == "POST": services = CmsServices.objects.get(id=id) form = ServiceForm(request.POST, instance=services) if form.is_valid(): form.save() if CMS_CHECK_ON: CmsCheck(module=CmsModule.MAIN_SERVICE, table_name='CmsServices', data_id=id, op_type=CheckOpType.EDIT, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())).save() return HttpResponseRedirect(reverse('services')) else: services = CmsServices.objects.get(id=id) form = ServiceForm(instance=services) errors, fields = format_form(form) scenes = get_scenes() actions = get_actions_select() citygroups = get_city_group() cities = get_city_list() return render_to_response(template_name, { "scenes": scenes, "actions": actions, "citygroups": citygroups, "cities": cities, "id": id, "fields": fields, "errors": errors }, context_instance=RequestContext(request))
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))
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))
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))
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))
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))
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))
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))
def edit_specialtopic(request, template_name): """ 编辑专题 url :{% url 'edit_specialtopic' %}?id={{ id }} :请求方式: Get :请求参数:id :返回数据:scenes 场景列表 citygroups 城市分组列表,cities 所有城市(列表) actions 动作列表 open_type 类型 :[[id,name],[id,name],....] :请求方式:Post :请求参数:数据库字段(input name) """ id = request.GET.get("id") specialtopic = CmsSpecialTopic.objects.get(id=id) if request.method == "POST": form = SpecialTopicForm(request.POST, instance=specialtopic) if form.is_valid(): form.save() if CMS_CHECK_ON: CmsCheck(module=CmsModule.MAIN_TOPIC, table_name='CmsSpecialTopic', data_id=id, op_type=CheckOpType.EDIT).save() find_page_views = CmsViewFindTopic.objects.filter(topic_id=id) # 更新时间同步 for find_page_view in find_page_views: find_page_view.update_time = specialtopic.update_time find_page_view.save() if CMS_CHECK_ON: CmsCheck(module=CmsModule.MAIN_TOPIC, table_name='CmsViewFindTopic', data_id=find_page_view.id, op_type=CheckOpType.EDIT, is_show=0, alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())).save() return HttpResponseRedirect(reverse("specialtopics")) else: form = SpecialTopicForm(instance=specialtopic) errors, fields = format_form(form) citygroups = get_city_group() actions = get_actions_select() cities = get_city_list() scenes = get_scenes() return render_to_response(template_name, { "fields": fields, "errors": errors, "citygroups": citygroups, "actions": actions, "cities": cities, "scenes": scenes, "open_type": open_type, "id": id }, context_instance=RequestContext(request))
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))
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))
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))
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))
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))
def edit_category_first(request, template_name): id = request.GET.get("id") category = CmsNaviCategory.objects.get(id=id) if request.method == "POST": form = NaviCategoryForm(request.POST, instance=category) if form.is_valid(): form.save() cate_group_id = request.POST.get("cate_group_id") if CmsViewGroupCategory.objects.filter(category=category): ins_viewgroupcate = CmsViewGroupCategory.objects.get( category=category) ins_viewgroupcate.group_id = cate_group_id ins_viewgroupcate.save() else: CmsViewGroupCategory(category=category, group_id=cate_group_id).save() if CMS_CHECK_ON: CmsCheck(module=CmsModule.MAIN_CATEGORY, table_name='CmsNaviCategory', data_id=id, op_type=CheckOpType.EDIT, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())).save() return HttpResponseRedirect(reverse('category')) else: form = NaviCategoryForm(instance=category) errors, fields = format_form(form) if CmsViewGroupCategory.objects.filter(category=category): ins_viewgroupcate = CmsViewGroupCategory.objects.get(category=category) fields["cate_group_id"] = json.dumps(ins_viewgroupcate.group_id) scenes = get_scenes() actions = get_actions_select() citygroups = get_city_group() cities = get_city_list() cate_groups = CmsCategoryGroup.objects.all() return render_to_response(template_name, { "scenes": scenes, "actions": actions, "citygroups": citygroups, "cities": cities, "show_style_list": show_style_list, "id": id, "fields": fields, "errors": errors, "cate_groups": cate_groups, "CATE_TYPE": CATE_TYPE }, context_instance=RequestContext(request))
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))
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))
def new_specialtopic(request, template_name): """ 新建专题 url :{% url 'new_specialtopic' %} :请求方式: Get :请求参数:无 :返回数据:scenes 场景列表 citygroups 城市分组列表,cities 所有城市(列表) actions 动作列表 open_type 类型 :[[id,name],[id,name],....] :请求方式:Post :请求参数:数据库字段(input name) """ if request.method == "POST": form = SpecialTopicForm(request.POST) if form.is_valid(): ospecialtopic = form.save() if CMS_CHECK_ON: CmsCheck(module=CmsModule.MAIN_TOPIC, table_name='CmsSpecialTopic', data_id=ospecialtopic.id, op_type=CheckOpType.NEW, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())).save() return HttpResponseRedirect(reverse("specialtopics")) else: form = SpecialTopicForm() errors, fields = format_form(form) citygroups = get_city_group() actions = get_actions_select() cities = get_city_list() scenes = get_scenes() return render_to_response(template_name, { "fields": fields, "errors": errors, "citygroups": citygroups, "actions": actions, "cities": cities, "scenes": scenes, "open_type": open_type, }, context_instance=RequestContext(request))
def edit_category_second(request, template_name): id = request.GET.get("id") if request.method == "POST": goods = CmsNaviCategory.objects.get(id=id) form = NaviCategoryForm(request.POST, instance=goods) if form.is_valid(): form.save() if CMS_CHECK_ON: CmsCheck(module=CmsModule.MAIN_CATEGORY, table_name='CmsNaviCategory', data_id=id, op_type=CheckOpType.EDIT, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())).save() return HttpResponseRedirect(reverse('category')) else: navicategory = CmsNaviCategory.objects.get(id=id) form = NaviCategoryForm(instance=navicategory) errors, fields = format_form(form) scenes = get_scenes() actions = get_actions_select() citygroups = get_city_group() cities = get_city_list() cate2s = get_first_categories() return render_to_response( template_name, { "scenes": scenes, "actions": actions, "goods_form": form, "citygroups": citygroups, "show_style_list": show_style_list, "cities": cities, "id": id, "fields": fields, "errors": errors, "cate2s": cate2s, # "first_categories":first_categories }, context_instance=RequestContext(request))
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))
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))
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))
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))
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))