diff --git a/apps/templates/rest_framework/base.html b/apps/templates/rest_framework/base.html new file mode 100644 index 000000000..7f5170a62 --- /dev/null +++ b/apps/templates/rest_framework/base.html @@ -0,0 +1,285 @@ +{% load staticfiles %} +{% load i18n %} +{% load rest_framework %} + + + + + {% block head %} + + {% block meta %} + + + {% endblock %} + + {% block title %}{% if name %}{{ name }} – {% endif %}Django REST framework{% endblock %} + + {% block style %} + {% block bootstrap_theme %} + + + {% endblock %} + + + + {% endblock %} + + {% endblock %} + + + {% block body %} + + +
+ {% block navbar %} + + {% endblock %} + +
+ {% block breadcrumbs %} + + {% endblock %} + + +
+ + {% if 'GET' in allowed_methods %} +
+
+ {% if api_settings.URL_FORMAT_OVERRIDE %} +
+ GET + + + +
+ {% else %} + GET + {% endif %} +
+
+ {% endif %} + + {% if options_form %} +
+ +
+ {% endif %} + + {% if delete_form %} + + + + + {% endif %} + + {% if filter_form %} + + {% endif %} + +
+ +
+ {% block description %} + {{ description }} + {% endblock %} +
+ + {% if paginator %} + + {% endif %} + +
+
{{ request.method }} {{ request.get_full_path }}
+
+ +
+
HTTP {{ response.status_code }} {{ response.status_text }}{% autoescape off %}
+  {% for key, val in response_headers.items %}{{ key }}: {{ val|break_long_headers|urlize_quoted_links }}
+  {% endfor %}
+  {{ content|urlize_quoted_links }}
{% endautoescape %} +
+
+ + {% if display_edit_forms %} + {% if post_form or raw_data_post_form %} +
+ {% if post_form %} + + {% endif %} + +
+ {% if post_form %} +
+ {% with form=post_form %} +
+
+ {% csrf_token %} + {{ post_form }} +
+ +
+
+
+ {% endwith %} +
+ {% endif %} + +
+ {% with form=raw_data_post_form %} +
+
+ {% include "rest_framework/raw_data_form.html" %} +
+ +
+
+
+ {% endwith %} +
+
+
+ {% endif %} + + {% if put_form or raw_data_put_form or raw_data_patch_form %} +
+ {% if put_form %} + + {% endif %} + +
+ {% if put_form %} +
+
+
+ {{ put_form }} +
+ +
+
+
+
+ {% endif %} + +
+ {% with form=raw_data_put_or_patch_form %} +
+
+ {% include "rest_framework/raw_data_form.html" %} +
+ {% if raw_data_put_form %} + + {% endif %} + {% if raw_data_patch_form %} + + {% endif %} +
+
+
+ {% endwith %} +
+
+
+ {% endif %} + {% endif %} +
+
+
+ + {% if filter_form %} + {{ filter_form }} + {% endif %} + + {% block script %} + + + + + + + + + {% endblock %} + + + {% endblock %} + diff --git a/apps/users/api.py b/apps/users/api.py index f96e21362..ee7b5f233 100644 --- a/apps/users/api.py +++ b/apps/users/api.py @@ -5,7 +5,7 @@ import logging from rest_framework import generics -from .serializers import UserSerializer, UserGroupSerializer, UserAttributeSerializer +from .serializers import UserSerializer, UserGroupSerializer, UserAttributeSerializer, UserGroupEditSerializer from .models import User, UserGroup @@ -44,3 +44,8 @@ class UserGroupDetailDeleteUpdateApi(generics.RetrieveUpdateDestroyAPIView): class UserAttributeApi(generics.RetrieveUpdateDestroyAPIView): queryset = User.objects.all() serializer_class = UserAttributeSerializer + + +class UserGroupEditApi(generics.RetrieveUpdateAPIView): + queryset = User.objects.all() + serializer_class = UserGroupEditSerializer diff --git a/apps/users/serializers.py b/apps/users/serializers.py index 04d575c19..808bb7349 100644 --- a/apps/users/serializers.py +++ b/apps/users/serializers.py @@ -30,3 +30,11 @@ class UserAttributeSerializer(serializers.ModelSerializer): class Meta: model = User fields = ['avatar', 'wechat', 'phone', 'enable_otp', 'comment', 'is_active', 'name'] + + +class UserGroupEditSerializer(serializers.ModelSerializer): + groups = serializers.PrimaryKeyRelatedField(many=True, queryset=UserGroup.objects.all()) + + class Meta: + model = User + fields = ['id', 'groups'] diff --git a/apps/users/urls.py b/apps/users/urls.py index c3411305b..e31071c11 100644 --- a/apps/users/urls.py +++ b/apps/users/urls.py @@ -36,4 +36,6 @@ urlpatterns += [ url(r'^v1/user-groups$', api.UserGroupListAddApi.as_view(), name='user-group-list-api'), url(r'^v1/user-groups/(?P[0-9]+)$', api.UserGroupDetailDeleteUpdateApi.as_view(), name='user-group-detail-api'), + url(r'^v1/user-groups/(?P[0-9]+)/edit$', + api.UserGroupEditApi.as_view(), name='user-group-edit-api'), ]