Commit 17f7c3c7 authored by 段英荣's avatar 段英荣

add

parent c3a3f1ff
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
from django.conf import settings from django.conf import settings
from pytz import timezone from pytz import timezone
from datetime import datetime from datetime import datetime
from django.http import HttpResponse
def tzlc(dt, truncate_to_sec=True): def tzlc(dt, truncate_to_sec=True):
...@@ -16,3 +18,18 @@ def tzlc(dt, truncate_to_sec=True): ...@@ -16,3 +18,18 @@ def tzlc(dt, truncate_to_sec=True):
return timezone(settings.TIME_ZONE).localize(dt) return timezone(settings.TIME_ZONE).localize(dt)
else: else:
return timezone(settings.TIME_ZONE).normalize(dt) return timezone(settings.TIME_ZONE).normalize(dt)
def json_http_response(result, status=200, extra_headers=None):
if extra_headers is None:
extra_headers = dict()
if 'extra' not in result:
result['extra'] = {}
response = HttpResponse(
json.dumps(result),
content_type="application/json; charset=UTF-8",
status=status,
)
for header_key, header_value in extra_headers.items():
response[header_key] = header_value
return response
from django.contrib import admin
# Register your models here.
from __future__ import unicode_literals
from django.apps import AppConfig
class SearchConfig(AppConfig):
name = 'search'
from __future__ import unicode_literals
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import, print_function
from gm_rpcd.all import bind
import logging
import traceback
import json
from libs.es import ESPerform
from libs.cache import redis_client
from libs.tools import json_http_response
def auto_complete(request):
"""auto complate words/tags/doctors etc.
URL:
~/api/auto_complete?scope=[kw]&q=双
Return:
{'error': 0|1, 'data': [word, word, word],}
"""
q = request.GET.get('q', '').strip()
if not q:
return json_http_response({'error': 0, 'data': []})
data = list()
result = {
'error': 0,
'data': data,
}
return json_http_response(result)
No preview for this file type
...@@ -18,4 +18,5 @@ from django.contrib import admin ...@@ -18,4 +18,5 @@ from django.contrib import admin
urlpatterns = [ urlpatterns = [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^auto_complete$', 'search.views.auto_complete'),
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment