feature (*merge): 本次提交合并master
commit
020641f3b7
|
@ -33,6 +33,8 @@ class ApiLoggingMiddleware(MiddlewareMixin):
|
|||
# 请求含有password则用*替换掉(暂时先用于所有接口的password请求参数)
|
||||
if isinstance(body, dict) and body.get('password', ''):
|
||||
body['password'] = '*' * len(body['password'])
|
||||
if not hasattr(response, 'data') or not isinstance(response.data, dict):
|
||||
response.data = {}
|
||||
info = {
|
||||
'request_ip': getattr(request, 'request_ip', 'unknown'),
|
||||
'creator': request.user,
|
||||
|
|
|
@ -228,6 +228,7 @@ class LoginInforSerializer(CustomModelSerializer):
|
|||
"""
|
||||
参数设置 简单序列化器
|
||||
"""
|
||||
creator_name = serializers.SlugRelatedField(slug_field="username", source="creator", read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = LoginInfor
|
||||
|
@ -254,6 +255,7 @@ class ExportOperationLogSerializer(CustomModelSerializer):
|
|||
导出 操作日志 简单序列化器
|
||||
"""
|
||||
creator_name = serializers.SlugRelatedField(slug_field="username", source="creator", read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = OperationLog
|
||||
fields = ('request_modular', 'request_path', 'request_body', 'request_method', 'request_msg', 'request_ip',
|
||||
|
|
|
@ -6,6 +6,7 @@ import logging
|
|||
|
||||
from django.contrib.auth.models import AbstractBaseUser
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.core.cache import cache
|
||||
from django.urls.resolvers import ResolverMatch
|
||||
from rest_framework.authentication import BaseAuthentication
|
||||
from rest_framework.settings import api_settings as drf_settings
|
||||
|
@ -165,12 +166,20 @@ def get_login_location(request, *args, **kwargs):
|
|||
"""
|
||||
import requests
|
||||
import eventlet # 导入eventlet这个模块
|
||||
request_ip = get_request_ip(request)
|
||||
# 从缓存中获取
|
||||
location = cache.get(request_ip)
|
||||
if location:
|
||||
return location
|
||||
# 通过api 获取,再缓存redis
|
||||
eventlet.monkey_patch(thread=False) # 必须加这条代码
|
||||
with eventlet.Timeout(2, False): # 设置超时时间为2秒
|
||||
apiurl = "http://whois.pconline.com.cn/ip.jsp?ip=%s" % get_request_ip(request)
|
||||
apiurl = "http://whois.pconline.com.cn/ip.jsp?ip=%s" % request_ip
|
||||
r = requests.get(apiurl)
|
||||
content = r.content.decode('GBK')
|
||||
return content.replace('\r', '').replace('\n', '')
|
||||
location = content.replace('\r', '').replace('\n', '')
|
||||
cache.set(request_ip,location, 8640)
|
||||
return location
|
||||
return ""
|
||||
|
||||
|
||||
|
@ -181,6 +190,7 @@ def get_verbose_name(queryset=None, view=None, model=None):
|
|||
:param view:
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
if queryset and hasattr(queryset, 'model'):
|
||||
model = queryset.model
|
||||
elif view and hasattr(view.get_queryset(), 'model'):
|
||||
|
@ -189,4 +199,6 @@ def get_verbose_name(queryset=None, view=None, model=None):
|
|||
model = view.get_serializer().Meta.model
|
||||
if model:
|
||||
return getattr(model, '_meta').verbose_name
|
||||
except Exception as e:
|
||||
pass
|
||||
return ""
|
||||
|
|
Loading…
Reference in New Issue