def new_goods(request): """ 分类导航 新建商品 :请求方式:ajax Post :请求URL:{% url 'category_pages_services_new_goods' %} :请求参数:goods_id navicategories_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") # 导航表ID navicategories_id = request.POST.get("navicategories_id") navicategories = CmsNavicategories.objects.get( id=navicategories_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_PAGE, table_name='CmsGoods', data_id=goods.id, op_type=CheckOpType.NEW, remark="在id为%s的分类组里面增加了名称为%s的商品" % (CheckManager.wrap_style(navicategories_id), CheckManager.wrap_style(goods.name)), alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())).save() ocmsnavicatesgoods = CmsNavicatesGoods(cate=navicategories, goods=goods) ocmsnavicatesgoods.save() if CMS_CHECK_ON: CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_PAGE, table_name='CmsNavicatesGoods', data_id=ocmsnavicatesgoods.id, op_type=CheckOpType.NEW, is_show=0, alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())).save() except Exception as ex: if 'Duplicate entry' in ex.args[0]: return HttpResponse(1) return HttpResponse(ex.args[0]) return HttpResponse(0)
def delete_common_category(request): id = request.POST.get("id") channel = request.POST.get("channel") related_channels = get_relate_channel_list(channel, CONFIG_ITEMS.COMMON_SERVICES) related_channels.append(channel) for channel_id in related_channels: views = CmsViewService.objects.filter(service_id=id, channel_id=channel_id, open_type__in=[3, 4, 5, 6]) for view in views: if CMS_CHECK_ON: is_show = 0 if int(view.channel_id) == int(channel): is_show = 1 check = CmsCheck(channel_id=channel, module=CmsModule.CONFIG_COMMON_SERVICES, table_name="CmsViewService", data_id=view.id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=is_show, alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())) check.save() view.delete() return HttpResponse(0)
def delete_homepage_specialtopic(request): id = request.POST.get("id") channel_id = request.POST.get("channel") relate_channels = get_relate_channel_list(channel_id, CONFIG_ITEMS.HOMEPAGE) relate_channels.append(channel_id) for c in relate_channels: hometopics = CmsViewHomepageTopic.objects.filter(topic=id, channel=c) for hometopic in hometopics: if CMS_CHECK_ON: is_show = 0 remark = "" if int(c) == int(channel_id): is_show = 1 remark = "删除标题为%s的首页专题" % CheckManager.wrap_style( hometopic.topic.title) check = CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_HOMEPAGE, table_name="CmsViewHomepageTopic", data_id=hometopic.id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=is_show, remark=remark, alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())) check.save() hometopic.delete() return HttpResponse(0)
def mark_info_foundpage(request): id = request.POST.get("id") mark_info = request.POST.get("mark_info") channel_id = request.POST.get("channel") relate_channels = get_relate_channel_list(channel_id, CONFIG_ITEMS.FOUNDPAGE) relate_channels.append(channel_id) for c in relate_channels: find_topics = CmsViewFindTopic.objects.filter(topic_id=id, channel_id=c, is_deleted=0) for find_topic in find_topics: find_topic.mark_info = mark_info find_topic.save() if CMS_CHECK_ON: check = CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_FOUNDPAGE, table_name="CmsViewFindTopic", data_id=find_topic.id, op_type=CheckOpType.EDIT, status=CheckStatu.WAIT_SUBMIT, is_show=1, alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())) check.save() return HttpResponse(0)
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 new_common_service(request): """ 新建服务导航 服务 :请求方式:ajax Post :请求参数:service_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: service_id = request.POST.get("service_id") channel_id = request.POST.get("channel_id") services = CmsServices.objects.get(id=service_id) services.type = 1 services.parent_id = service_id services.id = None services.save() try: if CMS_CHECK_ON: CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_COMMON_SERVICES, table_name='CmsServices', data_id=services.id, op_type=CheckOpType.NEW, remark="增加了名称为%s的服务" % (CheckManager.wrap_style(services.name), ), alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())).save() oCmsViewService = CmsViewService( service_id=services.id, channel=CmsChannels.objects.get(id=channel_id), open_type=0) 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, services.id, CONFIG_ITEMS.COMMON_SERVICES, request) except Exception as ex: if 'Duplicate entry' in ex.args[0]: return HttpResponse(1) return HttpResponse(ex.args[0]) return HttpResponse(0)
def new_coupons(request): """ 配置库:新建优惠券 :请求方式:ajax Post :请求URL:{% url 'new_config_coupons' %} :请求参数:coupons_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: coupons_id = request.POST.get("coupons_id") channel_id = request.POST.get("channel_id") try: coupons = CmsCoupon.objects.get(id=coupons_id) coupons.parent_id = coupons_id coupons.id = None coupons.save() if CMS_CHECK_ON: CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_COUPON, table_name='CmsCoupon', data_id=coupons.id, op_type=CheckOpType.NEW, remark="增加名称为%s的优惠券" % (CheckManager.wrap_style(coupons.name), ), alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())).save() oCmsViewCoupon = CmsViewCoupon( coupon=coupons, channel=CmsChannels.objects.get(id=channel_id)) oCmsViewCoupon.save() if CMS_CHECK_ON: CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_COUPON, table_name='CmsViewCoupon', data_id=oCmsViewCoupon.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, coupons.id, CONFIG_ITEMS.COUPONS, request) except Exception as ex: return HttpResponse(ex.args[0]) return HttpResponse(0)
def new_config_operation(request): """ 新建 运营配置 url : {% url 'new_config_operation' %} :请求方式:ajax :请求参数:channel_id key value :返回: 成功返回0 错误返回errors """ 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: channel_id = request.POST.get("channel_id") channel = CmsChannels.objects.get(id=channel_id) key = request.POST.get("key") try: if CmsOpconfig.objects.filter(cmsviewopconfig__channel=channel, key=key): return HttpResponse(-1) form = OpconfigForm(request.POST) if form.is_valid(): opconfig = form.save() if CMS_CHECK_ON: CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_OPERATION, table_name='CmsOpconfig', data_id=opconfig.id, op_type=CheckOpType.NEW, alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())).save() oCmsViewOpconfig = CmsViewOpconfig(opconfig=opconfig, channel=channel) oCmsViewOpconfig.save() if CMS_CHECK_ON: CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_OPERATION, table_name='CmsViewOpconfig', data_id=oCmsViewOpconfig.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, opconfig.id, CONFIG_ITEMS.CONFIG_OPERATION, request) return HttpResponse(0) except Exception as ex: return HttpResponse(ex.args[0])
def new_service(request): """ 猜你喜欢 添加服务 :请求方式:ajax Post :请求URL:{% url 'likes_new_service' %} :请求参数:service_id like_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: service_id = request.POST.get("service_id") like_id = request.POST.get("like_id") channel_id = request.POST.get("channel_id") try: service = CmsServices.objects.get(id=service_id) service.parent_id = service_id service.id = None service.save() if CMS_CHECK_ON: CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_LIKE, table_name='CmsServices', data_id=service.id, op_type=CheckOpType.NEW, remark="增加了名称为%s的服务" % (CheckManager.wrap_style(service.name), ), alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())).save() oCmsLikesServices = CmsLikesServices( service=service, like=CmsLikes.objects.get(id=like_id)) oCmsLikesServices.save() if CMS_CHECK_ON: CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_LIKE, table_name='CmsLikesServices', data_id=oCmsLikesServices.id, op_type=CheckOpType.NEW, is_show=0, alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())).save() except Exception as ex: return HttpResponse(ex.args[0]) return HttpResponse(0)
def delete_common_goods(request): id = request.POST.get("id") channel = request.POST.get("channel") views = CmsViewService.objects.filter(service_id=id, open_type=1) for view in views: if CMS_CHECK_ON: check = CmsCheck(channel_id=channel, module=CmsModule.CONFIG_COMMON_SERVICES, table_name="CmsViewService", data_id=view.id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=0, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() view.delete() CmsGoods.objects.get(id=id).delete() if CMS_CHECK_ON: check = CmsCheck(channel_id=channel, module=CmsModule.CONFIG_COMMON_SERVICES, table_name="CmsGoods", data_id=id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=1, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() return HttpResponse(0)
def delete_config_operation(request): id = request.POST.get("id") channel_id = request.POST.get('channel') views = CmsViewOpconfig.objects.filter(opconfig_id=id) for view in views: if CMS_CHECK_ON: check = CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_OPERATION, table_name="CmsViewOpconfig", data_id=view.id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=0, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() view.delete() CmsOpconfig.objects.filter(id=id).delete() if CMS_CHECK_ON: check = CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_OPERATION, table_name="CmsOpconfig", data_id=id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=1, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() return HttpResponse(0)
def delete_goods(request): id = request.POST.get("id") channel_id = request.POST.get('channel') cmsnavicatesgoods = CmsNavicatesGoods.objects.get(goods_id=id) if CMS_CHECK_ON: check = CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_PAGE, table_name="CmsNavicatesGoods", data_id=cmsnavicatesgoods.id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=0, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() cmsnavicatesgoods.delete() CmsGoods.objects.get(id=id).delete() if CMS_CHECK_ON: check = CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_PAGE, table_name="CmsGoods", data_id=id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=1, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() return HttpResponse(0)
def delete_choiceness_category(request): id = request.POST.get("id") channel_id = request.POST.get("channel") views = CmsViewChoicenessCategory.objects.filter(choiceness_category_id=id) for view in views: if CMS_CHECK_ON: check = CmsCheck( channel_id=channel_id, module=CmsModule.CONFIG_CHOICENESS, table_name="CmsViewChoicenessCategory", data_id=view.id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=0, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() view.delete() CmsChoicenessCategory.objects.get(id=id).delete() if CMS_CHECK_ON: check = CmsCheck( channel_id=channel_id, module=CmsModule.CONFIG_CHOICENESS, table_name="CmsChoicenessCategory", data_id=id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=1, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() return HttpResponse(0)
def delete_activity(request): id = request.POST.get("id") channel_id = request.POST.get('channel') views = CmsViewNativeActivity.objects.filter(nactivity_id=id) if CMS_CHECK_ON: for view in views: check = CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_NATIVE_ACTIVITY, table_name="CmsViewNativeActivity", data_id=view.id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=0, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() views.delete() CmsNativeActivity.objects.filter(id=id).delete() if CMS_CHECK_ON: check = CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_NATIVE_ACTIVITY, table_name="CmsNativeActivity", data_id=id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=1, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() return HttpResponse(0)
def delete_bean(request): bean = request.POST.get("bean") channel_id = request.POST.get("channel") oCmsAdsBeans = CmsAdsBeans.objects.get(bean_id=bean) if CMS_CHECK_ON: check = CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_AD, table_name="CmsAdsBeans", data_id=oCmsAdsBeans.id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=0, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() oCmsAdsBeans.delete() CmsAdbeans.objects.get(id=bean).delete() if CMS_CHECK_ON: check = CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_AD, table_name="CmsAdbeans", data_id=bean, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=1, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() return HttpResponse(0)
def delete_shop(request): id = request.POST.get("id") CmsCategoryItembean.objects.get(id=id).delete() if CMS_CHECK_ON: check = CmsCheck( module=CmsModule.MAIN_SHOP, table_name="CmsCategoryItembean", data_id=id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=1, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X",time.localtime())) check.save() return HttpResponse(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))
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 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 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_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_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_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))
def delete_category(request): id = request.POST.get("id") channel_id = request.POST.get('channel') groups = CmsNavicatesCategory.objects.filter( category_id=id, cate__cmsviewnavi__channel_id=channel_id) for group in groups: if CMS_CHECK_ON: check = CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_PAGE, table_name="CmsNavicatesCategory", data_id=group.id, op_type=CheckOpType.DELETE, status=CheckStatu.WAIT_SUBMIT, is_show=1, remark="在id为%s的分类组删除了名称为%s的分类" % (CheckManager.wrap_style(group.cate.id), CheckManager.wrap_style(group.category.name)), alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X", time.localtime())) check.save() group.delete() return HttpResponse(0)
def new_foundpage_specialtopic(request): """ 配置库: 新增发现页专题 :请求方式:ajax Post :请求URL:{% url 'new_foundpage_specialtopic' %} :请求参数:specialtopic_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: try: specialtopic_id = request.POST.get("specialtopic_id") channel_id = request.POST.get("channel_id") c, v, t = getCVT(channel_id) ospecialtopic = CmsSpecialTopic.objects.get(id=specialtopic_id) oCmsViewFindTopic = CmsViewFindTopic( channel_id=channel_id, topic_id=specialtopic_id, create_time=time.timezone.now(), update_time=time.timezone.now()) oCmsViewFindTopic.save() if CMS_CHECK_ON: CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_FOUNDPAGE, table_name='CmsViewFindTopic', data_id=oCmsViewFindTopic.id, op_type=CheckOpType.NEW, remark="增加标题为%s的发现页专题" % (CheckManager.wrap_style(ospecialtopic.title), ), alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())).save() new_associate(channel_id, specialtopic_id, CONFIG_ITEMS.FOUNDPAGE, request) # jpush_foundpage(CmsChannels.objects.get(id=channel_id).channel_no,v,oCmsViewFindTopic.id,ospecialtopic.title,ospecialtopic.city) push_foundpage(channel_id, specialtopic_id) return HttpResponse(0) except Exception as ex: if 'Duplicate entry' in ex.args[0]: return HttpResponse(1) return HttpResponse(ex.args[0])
def new_shop(request,template_name): """ 新建商户 url :{% url "new_shop" %} :请求方式: Get :请求参数:无 :返回数据: citygroups 城市分组列表,cities 所有城市(列表) :[[id,name],[id,name],....] :请求方式:Post :请求参数:cms_category_itembean字段(input name) webSite: #官方主页 weibo : #微博主页 search_key : 搜索词 search_category:搜索分类 search_show :查看附近 numbers : 电话号码 格式: [{ "number": "4008111111", #电话号码 "number_description": "顺丰速运" #电话描述 },多个..........] """ if request.method == "POST": postcopys = request.POST.copy() content = op_content_save(postcopys) postcopys["content"] = json.dumps(content,ensure_ascii=False) form = CmsCategoryItembeanForm(postcopys) if form.is_valid(): ocategoryitembean = form.save() if CMS_CHECK_ON: CmsCheck(module=CmsModule.MAIN_SHOP, table_name='CmsCategoryItembean', data_id=ocategoryitembean.id, op_type=CheckOpType.NEW, alter_person=request.user.username, alter_date=time.strftime("%Y-%m-%d %X",time.localtime())).save() return HttpResponseRedirect(reverse("static_data")) else: form = CmsCategoryItembeanForm() errors,fields = format_form(form) fields = op_content_edit(fields) citygroups = get_city_group() cities = get_city_list() return render_to_response(template_name,{ "fields": fields, "errors":errors, "citygroups":citygroups, "cities":cities, }, context_instance=RequestContext(request))
def new_category(request): """ 分类页服务 新建分类(二级分类) :请求方式:ajax Post :请求URL:{% url 'category_pages_services_new_category' %} :请求参数:navicategories_id(分类组表id) category_id(分类表id) :直接插入关系表 导航与分类关系表 cms_navicates_category :类型 :传数字 返回: 成功: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: try: category_id = request.POST.get("category_id") # 分类组ID navicategories_id = request.POST.get("navicategories_id") channel_id = request.POST.get("channel_id") c, v, t = getCVT(channel_id) navicategories = CmsNavicategories.objects.get( id=navicategories_id) category = CmsNaviCategory.objects.get(id=category_id) oCmsNavicatesCategory = CmsNavicatesCategory( cate=navicategories, category=category) oCmsNavicatesCategory.save() if CMS_CHECK_ON: CmsCheck(channel_id=channel_id, module=CmsModule.CONFIG_PAGE, table_name='CmsNavicatesCategory', data_id=oCmsNavicatesCategory.id, op_type=CheckOpType.NEW, remark="在id为%s的分类组里面增加了名称为%s的分类" % (CheckManager.wrap_style(navicategories_id), CheckManager.wrap_style(category.name)), alter_person=request.user.username, alter_date=time.strftime( "%Y-%m-%d %X", time.localtime())).save() except Exception as ex: if 'Duplicate entry' in ex.args[0]: return HttpResponse(1) return HttpResponse(ex.args[0]) return HttpResponse(0)
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))