def autotag_post(request): """ Take a post content as input, find matching tags and return. {domain}/api/post/autotag/ """ resp = { 'alert': None, 'tags': [], } # Validate post content f = PostForm(request.POST) if not f.is_valid(): resp['alert'] = "post title or body is not valid" return _response(resp) post = f.save(commit=False) # get matching tags g = TagGraph(_miner) g.add_text(post.title) g.add_text(post.body) # resp['tags'] = list(g.direct_tags) resp['tags'] = g.get_recommend_tags() return _response(resp)
def autotag_post(request): """ Take a post content as input, find matching tags and return. {domain}/api/post/autotag/ """ try: resp = {"alert": None, "tags": []} # Validate post content f = PostForm(request.POST) if not f.is_valid(): return response_errors(f.errors.as_text()) post = f.save(commit=False) # get matching tags g = TagGraph(_miner) g.add_text(post.title) g.add_text(post.body) # resp['tags'] = list(g.direct_tags) resp["tags"] = g.get_recommend_tags() return response(resp) except Exception as e: print e traceback.print_exc() return response_errors(str(e))