From 9a6d20b6ecaaff9aeeb549e4899f1070a185d5a5 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 23 Aug 2016 23:00:55 +0800 Subject: [PATCH 1/3] Modify requirement: add some module --- requirements.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index f4137fba9..a0d9dcf1f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ -django==1.10 -pillow -django-bootstrap-form \ No newline at end of file +Django==1.10 +django-bootstrap-form==3.2.1 +djangorestframework==3.4.5 +ForgeryPy==0.1 +Pillow==3.3.0 \ No newline at end of file From 6458231946d3b350dcc2a5c28b651a32af78db52 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 24 Aug 2016 00:11:13 +0800 Subject: [PATCH 2/3] Add api file --- apps/jumpserver/settings.py | 11 ++++++++++- apps/jumpserver/urls.py | 4 ++++ apps/users/api.py | 11 ++++++++++- apps/users/api_urls.py | 17 +++++++++++++++++ apps/users/serializers.py | 12 ++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 apps/users/api_urls.py create mode 100644 apps/users/serializers.py diff --git a/apps/jumpserver/settings.py b/apps/jumpserver/settings.py index 8b69953ee..90b9aa94e 100644 --- a/apps/jumpserver/settings.py +++ b/apps/jumpserver/settings.py @@ -48,6 +48,7 @@ INSTALLED_APPS = [ 'ops.apps.OpsConfig', 'audits.apps.AuditsConfig', 'common.apps.CommonConfig', + 'rest_framework', 'bootstrapform', # 'django.contrib.admin', 'django.contrib.auth', @@ -166,4 +167,12 @@ AUTH_USER_MODEL = 'users.User' BOOTSTRAP_COLUMN_COUNT = 11 # Init data or generate fake data source for development -FIXTURE_DIRS = [os.path.join(BASE_DIR, 'fixtures'), ] \ No newline at end of file +FIXTURE_DIRS = [os.path.join(BASE_DIR, 'fixtures'), ] + +REST_FRAMEWORK = { + # Use Django's standard `django.contrib.auth` permissions, + # or allow read-only access for unauthenticated users. + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' + ], +} \ No newline at end of file diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index a362f54d6..491c2ad70 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -25,6 +25,10 @@ urlpatterns = [ # url(r'^admin/', admin.site.urls), ] +urlpatterns += [ + url(r'^api/users/', include('users.api_urls')), +] + if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/apps/users/api.py b/apps/users/api.py index ecbf4289f..1970a6d0f 100644 --- a/apps/users/api.py +++ b/apps/users/api.py @@ -1,3 +1,12 @@ # ~*~ coding: utf-8 ~*~ -# +# +from rest_framework import viewsets + +from .serializers import UserSerializer +from .models import User, UserGroup, Role + + +class UserViewSet(viewsets.ModelViewSet): + queryset = User.objects.all() + serializer_class = UserSerializer diff --git a/apps/users/api_urls.py b/apps/users/api_urls.py new file mode 100644 index 000000000..e31d59ebb --- /dev/null +++ b/apps/users/api_urls.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# + +from django.conf.urls import url, include +from rest_framework import routers + +from .api import UserViewSet + + +router = routers.DefaultRouter() +router.register(r'users', UserViewSet) + +urlpatterns = [ + url(r'v1/', include(router.urls)), + url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) +] + diff --git a/apps/users/serializers.py b/apps/users/serializers.py new file mode 100644 index 000000000..aefe0569b --- /dev/null +++ b/apps/users/serializers.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# + +from rest_framework import serializers + +from .models import Role, User, UserGroup + + +class UserSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = User + fields = '__all__' From a43ac90b21a1715f9dbc70127cdcda10a4dc2b23 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 24 Aug 2016 00:13:58 +0800 Subject: [PATCH 3/3] Modify CRLF to LF --- apps/__init__.py | 14 +++++++------- apps/users/api_urls.py | 32 +++++++++++++++----------------- apps/users/serializers.py | 24 ++++++++++++------------ 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/apps/__init__.py b/apps/__init__.py index f93d0bec7..597573362 100644 --- a/apps/__init__.py +++ b/apps/__init__.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# - - -if __name__ == '__main__': - pass +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# + + +if __name__ == '__main__': + pass diff --git a/apps/users/api_urls.py b/apps/users/api_urls.py index e31d59ebb..40a1ff414 100644 --- a/apps/users/api_urls.py +++ b/apps/users/api_urls.py @@ -1,17 +1,15 @@ -# -*- coding: utf-8 -*- -# - -from django.conf.urls import url, include -from rest_framework import routers - -from .api import UserViewSet - - -router = routers.DefaultRouter() -router.register(r'users', UserViewSet) - -urlpatterns = [ - url(r'v1/', include(router.urls)), - url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) -] - +# -*- coding: utf-8 -*- +# + +from django.conf.urls import url, include +from rest_framework import routers + +from .api import UserViewSet + + +router = routers.DefaultRouter() +router.register(r'users', UserViewSet) + +urlpatterns = [ + url(r'v1/', include(router.urls)), + url(r'^api-auth/', include('rest_framework.urls', namespace='rest_fr \ No newline at end of file diff --git a/apps/users/serializers.py b/apps/users/serializers.py index aefe0569b..e08b52b47 100644 --- a/apps/users/serializers.py +++ b/apps/users/serializers.py @@ -1,12 +1,12 @@ -# -*- coding: utf-8 -*- -# - -from rest_framework import serializers - -from .models import Role, User, UserGroup - - -class UserSerializer(serializers.HyperlinkedModelSerializer): - class Meta: - model = User - fields = '__all__' +# -*- coding: utf-8 -*- +# + +from rest_framework import serializers + +from .models import Role, User, UserGroup + + +class UserSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = User + fields = \ No newline at end of file