def post(self, request, *args, **kwargs): w = request.REQUEST.get("w", "") if not w: kwargs["result"] = None return self.get(request, *args, **kwargs) else: if ALI_OPEN_SEARCH_ON: url = "%s/ns/search?search_flag=help&query=%s" % ( ALI_OPEN_SEARCH, w.strip()) try: jsonstr = urllib2.urlopen(url).read() result = json.loads(jsonstr) contents = result['result']['result'].get("items", []) except Exception as e: print e contents = [] else: contents = HelpContent.search(w) result = [] for i in contents: # help_menu_id = i.help_menu_id # menu_title = HelpMenu.objects.get(pk=help_menu_id).title if ALI_OPEN_SEARCH_ON: content_id = i["id"] content_title = i["title"] else: content_id = i.id content_title = i.title result.append({ # "menu_title": menu_title, "content_id": content_id, "content_title": content_title }) kwargs["result"] = result return self.get(request, *args, **kwargs)
def get(self, request, *args, **kwargs): """ get请求 by:王健 at:2015-05-12 :param request: :param args: :param kwargs: :return: """ id = request.REQUEST.get('id') if not id: id = kwargs.get('id', '') if id: obj = HelpMenu.objects.get(pk=id) else: obj = HelpContent() kwargs['obj'] = obj return super(HelpMenuManager, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): """ post保存帮助信息 by:王健 at:2015-04-19 增加了一层目录结构 by:尚宗凯 at:2015-05-12 优化排序 by:王健 at:2015-05-12 """ id = request.REQUEST.get('id') if id: obj = HelpContent.objects.get(pk=id) else: obj = HelpContent() obj.sorted = int(request.REQUEST.get('sorted', 0)) obj.title = request.REQUEST.get('title') obj.text = request.REQUEST.get('content') obj.help_menu_id = request.REQUEST.get('menu_id') obj.save() kwargs['id'] = obj.pk return self.get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): """ post保存帮助信息 by:王健 at:2015-04-19 增加了一层目录结构 by:尚宗凯 at:2015-05-12 优化排序 by:王健 at:2015-05-12 """ id = request.REQUEST.get("id") if id: obj = HelpContent.objects.get(pk=id) else: obj = HelpContent() obj.sorted = int(request.REQUEST.get("sorted", 0)) obj.title = request.REQUEST.get("title") obj.text = request.REQUEST.get("content") obj.help_menu_id = request.REQUEST.get("menu_id") obj.save() kwargs["id"] = obj.pk return self.get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): w = request.REQUEST.get("w", "") if not w: kwargs["result"] = None return self.get(request, *args, **kwargs) else: if ALI_OPEN_SEARCH_ON: url = "%s/ns/search?search_flag=help&query=%s" % (ALI_OPEN_SEARCH, w.strip()) try: jsonstr = urllib2.urlopen(url).read() result = json.loads(jsonstr) contents = result["result"]["result"].get("items", []) except Exception as e: print e contents = [] else: contents = HelpContent.search(w) result = [] for i in contents: # help_menu_id = i.help_menu_id # menu_title = HelpMenu.objects.get(pk=help_menu_id).title if ALI_OPEN_SEARCH_ON: content_id = i["id"] content_title = i["title"] else: content_id = i.id content_title = i.title result.append( { # "menu_title": menu_title, "content_id": content_id, "content_title": content_title, } ) kwargs["result"] = result return self.get(request, *args, **kwargs)