Commit 7032fb40 authored by Davve's avatar Davve

增加获取和上下线接口

parent 9e484353
......@@ -3,4 +3,35 @@
# __author__ = "chenwei"
# Date: 2018/11/15
from utils.base import APIView
class PickListView(APIView):
def get(self, request):
page = request.GET.get('page', 1)
limit = request.GET.get('limit', 10)
try:
data = self.rpc['venus/community/pick/get'](offset=page, limit=limit).unwrap()
except Exception as e:
raise e
print(data)
return data
def post(self, request):
pass
class UpdateOrCreateView(APIView):
def get(self, request):
pass
def post(self, request):
ids = request.POST.get('ids', '').split()
type = request.POST.get('type', '')
try:
self.rpc['venus/community/pick/offline_pick'](type=type, ids=ids).unwrap()
except Exception as e:
raise e
return {
"message": "更新成功"
}
\ No newline at end of file
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "chenwei"
# Date: 2018/11/15
from django.conf.urls import url
from .pick import *
urlpatterns = [
# pick相关
url(r'pick/list$', PickListView.as_view()),
url(r'pick/update_or_create', UpdateOrCreateView.as_view()),
]
\ No newline at end of file
......@@ -4,3 +4,54 @@
# Date: 2018/11/15
from django.core.cache import cache
from django.core.exceptions import PermissionDenied
import helios.rpc
from helios.rpc.object_mapping import SimpleMapper
import gm_logging.django.middleware
from django.conf import settings
from utils.logger import auth_logger, log_error
switch_key = lambda s, d: "SESSION_SWITCH:{}::{}".format(s, d)
rpc_invoker = helios.rpc.create_default_invoker(debug=settings.DEBUG).with_config(dump_curl=settings.DEBUG)
simple_mapper = SimpleMapper()
rpc_mapper = rpc_invoker.with_config(object_mapper=simple_mapper)
class MiddlewareMixin(object):
def __init__(self, get_response=None):
self.get_response = get_response
super(MiddlewareMixin, self).__init__()
def __call__(self, request):
response = None
if hasattr(self, 'process_request'):
response = self.process_request(request)
if not response:
response = self.get_response(request)
if hasattr(self, 'process_response'):
response = self.process_response(request, response)
return response
class RPC(object):
def __init__(self, session, request):
self.rpc_invoker = rpc_invoker.with_config(
session_key=session,
client_info=gm_logging.django.middleware.get_client_info_of_request(request),
)
self.origin = self.rpc_invoker
self.mapper = self.rpc_invoker.with_config(object_mapper=simple_mapper)
class RPCSetupMiddleware(MiddlewareMixin):
def process_request(self, request):
ori_session = request.COOKIES.get(settings.USER_COOKIE_NAME, '')
request.login_session = ori_session
rpc = RPC(request=request, session=ori_session)
request.rpc = rpc
return None
......@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/1.10/ref/settings/
"""
import os
from .settings_local import *
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
......@@ -36,15 +37,17 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'middleware.rpc.RPCSetupMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
......@@ -73,12 +76,12 @@ WSGI_APPLICATION = 'sun.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
# }
# Password validation
......@@ -118,3 +121,13 @@ USE_TZ = True
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
PAGE_SIZE = 10
USER_COOKIE_NAME = 'sun_session_key'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
os.path.join(BASE_DIR, 'vu', 'dist', 'static'),
]
......@@ -3,4 +3,3 @@
# __author__ = "chenwei"
# Date: 2018/11/15
......@@ -13,9 +13,10 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.conf.urls import url, include
# from django.contrib import admin
urlpatterns = [
# url(r'^admin/', admin.site.urls),
url(r'^api/', include('api.urls')),
]
This diff is collapsed.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : RobertDing
# E-mail : robertdingx@gmail.com
# Date : 16/03/25 11:55:13
# Desc : 异常类
#
from __future__ import absolute_import, division, with_statement
from gm_types.ascle.error import ERROR
from gm_types.artemis.error import ERROR as ARTEMIS_ERROR
from gm_types.error import ERROR as GAIA_ERROR
class SunException(Exception):
"""
医生后台普通错误
"""
def __init__(self, code=0, message=None, data=None):
self.code = code
self.message = message or ERROR.getDesc(code) or GAIA_ERROR.getDesc(code) or ARTEMIS_ERROR.getDesc(code)
super().__init__(self.code, self.message)
# -*- coding: UTF-8 -*-
import logging
import traceback
from django.conf import settings
from raven.contrib.django.raven_compat.models import client
info_logger = logging.getLogger('info_logger')
error_logger = logging.getLogger('error_logger')
auth_logger = logging.getLogger('auth_logger')
profile_logger = logging.getLogger("profile_logger")
pay_logger = logging.getLogger("pay_logger")
def log_error():
msg = traceback.format_exc()
if settings.DEBUG:
info_logger.debug(msg)
error_logger.error(traceback.format_exc())
client.captureException()
#!/usr/bin/env python
# coding=utf-8
import re
import datetime
import json
from django.conf import settings
from django.http import JsonResponse
from django.http.response import HttpResponseBadRequest
from utils.logger import auth_logger
def require_login(request, origin=''):
"""
医生后台和app的返回需要登陆的方式不一样
@param: origin 需要登录发生的位置来源
!!!!! 这个方法只能结合 return 一起使用
"""
if 'api/client' in request.path_info:
# TODO Skyler 这个暂时这么处理,之后需要换种方式处理
login_require = HttpResponseBadRequest(status=403)
else:
login_require = JsonResponse({
'error': 401,
'message': '需要登录',
'data': None,
})
# 打印日志
info_msg = '!ascle {origin} {path} {session} {doctor_id} _dd:{target_uid}'
auth_logger.info(info_msg.format(
origin=origin,
path=request.path,
session=request.COOKIES.get(settings.USER_COOKIE_NAME, '-'),
doctor_id=getattr(request, 'doctor_user', {}).get('doctor', {}).get('id', '-'),
target_uid=request.GET.get('_dd', '-'),
))
return login_require
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