Commit 6e843533 authored by ibuler's avatar ibuler

Base finish user

parent d8a229c0
......@@ -6,14 +6,14 @@ from rest_framework.views import APIView
from rest_framework_bulk import BulkListSerializer, BulkSerializerMixin, ListBulkCreateUpdateDestroyAPIView
from django.shortcuts import get_object_or_404
from common.mixins import BulkDeleteApiMixin
from common.mixins import IDInFilterMixin
from common.utils import get_object_or_none, signer
from .hands import IsSuperUserOrTerminalUser, IsSuperUser
from .models import AssetGroup, Asset, IDC, SystemUser, AdminUser
from . import serializers
class AssetViewSet(viewsets.ModelViewSet):
class AssetViewSet(IDInFilterMixin, viewsets.ModelViewSet):
"""API endpoint that allows Asset to be viewed or edited."""
queryset = Asset.objects.all()
serializer_class = serializers.AssetSerializer
......@@ -71,7 +71,7 @@ class SystemUserViewSet(viewsets.ModelViewSet):
# return self.object.assets.all()
class AssetListUpdateApi(BulkDeleteApiMixin, ListBulkCreateUpdateDestroyAPIView):
class AssetListUpdateApi(IDInFilterMixin, ListBulkCreateUpdateDestroyAPIView):
queryset = Asset.objects.all()
serializer_class = serializers.AssetSerializer
permission_classes = (IsSuperUser,)
......
......@@ -2,7 +2,7 @@
from django.utils.translation import ugettext_lazy as _
from rest_framework import viewsets, serializers,generics
from .models import AssetGroup, Asset, IDC, AssetExtend, AdminUser, SystemUser
from common.mixins import BulkDeleteApiMixin
from common.mixins import IDInFilterMixin
from rest_framework_bulk import BulkListSerializer, BulkSerializerMixin
......
......@@ -46,7 +46,7 @@ class JSONResponseMixin(object):
return JsonResponse(context)
class BulkDeleteApiMixin(object):
class IDInFilterMixin(object):
def filter_queryset(self, queryset):
id_list = self.request.query_params.get('id__in')
......
......@@ -15,7 +15,7 @@ from rest_framework import authentication
import django_filters
from django_filters.rest_framework import DjangoFilterBackend
from common.mixins import BulkDeleteApiMixin
from common.mixins import IDInFilterMixin
from common.utils import get_logger
from .utils import check_user_valid, token_gen
from .models import User, UserGroup
......@@ -27,29 +27,12 @@ from . import serializers
logger = get_logger(__name__)
class IDInFilter(django_filters.rest_framework.FilterSet):
id__in = django_filters.CharFilter(method='in_filter')
class Meta:
model = User
fields = ['id__in']
def in_filter(self, queryset, name, value):
try:
value = json.loads(value)
except ValueError:
value = []
return queryset.filter(**{name+'__in': value})
class UserViewSet(BulkModelViewSet):
class UserViewSet(IDInFilterMixin, BulkModelViewSet):
queryset = User.objects.all()
serializer_class = serializers.UserSerializer
permission_classes = (IsSuperUser,)
filter_backends = (DjangoFilterBackend,)
filter_fields = ('username', 'email', 'name', 'id')
filter_class = IDInFilter
ordering_fields = ('username', 'email')
class UserUpdateGroupApi(generics.RetrieveUpdateAPIView):
......
......@@ -9,12 +9,6 @@ from common.utils import signer, validate_ssh_public_key
from .models import User, UserGroup
# class UserDetailSerializer(BulkSerializerMixin, serializers.ModelSerializer):
# class Meta:
# model = User
# fields = ['avatar', 'wechat', 'phone', 'enable_otp', 'comment', 'is_active', 'name']
class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
groups_display = serializers.SerializerMethodField()
groups = serializers.PrimaryKeyRelatedField(many=True, queryset=UserGroup.objects.all())
......@@ -33,10 +27,6 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
def get_groups_display(obj):
return " ".join([group.name for group in obj.groups.all()])
# @staticmethod
# def get_active_display(obj):
# return not (obj.is_expired and obj.is_active)
class UserPKUpdateSerializer(serializers.ModelSerializer):
class Meta:
......
......@@ -86,7 +86,7 @@ $(document).ready(function(){
}
}}],
ajax_url: '{% url "api-users:user-list" %}',
columns: [{data: "id"}, {data: "username" }, {data: "name" }, {data: "get_role_display" },
columns: [{data: "id"}, {data: "name" }, {data: "username" }, {data: "get_role_display" },
{data: "groups_display" }, {data: "is_valid" }, {data: "id" }],
op_html: $('#actions').html()
};
......
......@@ -3,12 +3,10 @@
from __future__ import unicode_literals
import json
import uuid
import codecs
from openpyxl import Workbook
from openpyxl.writer.excel import save_virtual_workbook
from openpyxl import load_workbook
import unicodecsv as csv
from django import forms
from django.utils import timezone
from django.core.cache import cache
......
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