|
@@ -1,15 +1,15 @@
|
|
# coding=utf-8
|
|
# coding=utf-8
|
|
-
|
|
|
|
|
|
+import json
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
from rest_framework.views import APIView
|
|
from rest_framework.views import APIView
|
|
from rest_framework.decorators import action
|
|
from rest_framework.decorators import action
|
|
from utils import response_ok
|
|
from utils import response_ok
|
|
from utils.custom_modelviewset import CustomModelViewSet
|
|
from utils.custom_modelviewset import CustomModelViewSet
|
|
from utils.exceptions import CustomError
|
|
from utils.exceptions import CustomError
|
|
-from apps.foundation.models import BizLog, Option
|
|
|
|
|
|
+from apps.foundation.models import BizLog, Option, Config
|
|
from apps.account import tenant_log
|
|
from apps.account import tenant_log
|
|
-from .filters import OptionFilter
|
|
|
|
-from .serializers import OptionSerializer
|
|
|
|
|
|
+from .filters import OptionFilter, ConfigFilter
|
|
|
|
+from .serializers import OptionSerializer, ConfigSerializer
|
|
|
|
|
|
class OptionDictView(APIView):
|
|
class OptionDictView(APIView):
|
|
|
|
|
|
@@ -20,7 +20,7 @@ class OptionDictView(APIView):
|
|
return response_ok(ret)
|
|
return response_ok(ret)
|
|
|
|
|
|
class OptionViewSet(CustomModelViewSet):
|
|
class OptionViewSet(CustomModelViewSet):
|
|
- queryset = Option.objects.filter()
|
|
|
|
|
|
+ queryset = Option.objects.filter(delete=False)
|
|
serializer_class = OptionSerializer
|
|
serializer_class = OptionSerializer
|
|
|
|
|
|
def filter_queryset(self, queryset):
|
|
def filter_queryset(self, queryset):
|
|
@@ -43,25 +43,11 @@ class OptionViewSet(CustomModelViewSet):
|
|
def destroy(self, request, *args, **kwargs):
|
|
def destroy(self, request, *args, **kwargs):
|
|
with transaction.atomic():
|
|
with transaction.atomic():
|
|
instance = self.get_object()
|
|
instance = self.get_object()
|
|
|
|
+ instance.delete = True
|
|
|
|
+ instance.save()
|
|
tenant_log(self.request.user, BizLog.DELETE, u'删除系统选项[%s],id=%d' % (instance.name, instance.id))
|
|
tenant_log(self.request.user, BizLog.DELETE, u'删除系统选项[%s],id=%d' % (instance.name, instance.id))
|
|
- instance.delete()
|
|
|
|
- return response_ok()
|
|
|
|
-
|
|
|
|
- def create_default(self, request):
|
|
|
|
- if not self.request.user.has_perm('option.add_option'):
|
|
|
|
- raise CustomError(u"您没有[系统选项-添加]权限,无法执行该操作,请联系管理员分配权限!")
|
|
|
|
- tenant = request.user.employee.tenant
|
|
|
|
- with transaction.atomic():
|
|
|
|
- for default in Option.DEFAULT_OPTION:
|
|
|
|
- default['tenant'] = tenant
|
|
|
|
- is_exist = Option.is_exist(tenant, default['type'], default['name'])
|
|
|
|
- if is_exist:
|
|
|
|
- continue
|
|
|
|
- Option.objects.create(**default)
|
|
|
|
- tenant_log(self.request.user, BizLog.INSERT, u'添加默认系统选项')
|
|
|
|
return response_ok()
|
|
return response_ok()
|
|
|
|
|
|
-
|
|
|
|
class OptionSearchSearch(APIView):
|
|
class OptionSearchSearch(APIView):
|
|
def get(self, request):
|
|
def get(self, request):
|
|
type = request.GET.get('type')
|
|
type = request.GET.get('type')
|
|
@@ -84,3 +70,29 @@ class OptionSearchSearch(APIView):
|
|
data.append(item)
|
|
data.append(item)
|
|
|
|
|
|
return response_ok(data)
|
|
return response_ok(data)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class ConfigViewSet(CustomModelViewSet):
|
|
|
|
+ queryset = Config.objects.filter()
|
|
|
|
+ serializer_class = ConfigSerializer
|
|
|
|
+
|
|
|
|
+ def filter_queryset(self, queryset):
|
|
|
|
+ queryset = queryset.filter()
|
|
|
|
+ f = ConfigFilter(self.request.GET, queryset=queryset)
|
|
|
|
+ return f.qs
|
|
|
|
+
|
|
|
|
+ #@action(methods=['post'], detail=True)
|
|
|
|
+ def create(self, request):
|
|
|
|
+
|
|
|
|
+ data = json.loads(request.POST.get('data'))
|
|
|
|
+ with transaction.atomic():
|
|
|
|
+ for item in data:
|
|
|
|
+ config = Config.objects.filter(property=item['key']).first()
|
|
|
|
+ if item['value']:
|
|
|
|
+ if config:
|
|
|
|
+ config.value = item['value']
|
|
|
|
+ config.save()
|
|
|
|
+ else:
|
|
|
|
+ config = Config.objects.create(property=item['key'], value=item['value'])
|
|
|
|
+ tenant_log(self.request.user, BizLog.INSERT, u'修改系统设置', data)
|
|
|
|
+ return response_ok()
|