Commit 0a9e4a5e authored by ibuler's avatar ibuler

Modify urls.conf: Merge to single

parent 8aa92bb6
......@@ -182,6 +182,7 @@ WSGI_APPLICATION = 'ws4redis.django_runserver.application'
# URL that distinguishes websocket connections from normal requests
WEBSOCKET_URL = '/ws/'
# WebSocket Redis
WS4REDIS_CONNECTION = {
'host': '127.0.0.1',
......
......@@ -20,24 +20,22 @@ from django.views.generic.base import TemplateView
from django.http import HttpResponseRedirect
def view(request, **kwargs):
if kwargs:
print kwargs
return HttpResponseRedirect('/' + kwargs["module"] + '/' + kwargs["version"] + '/' + kwargs["api"])
# def view(request, **kwargs):
# if kwargs:
# print kwargs
# return HttpResponseRedirect('/' + kwargs["module"] + '/' + kwargs["version"] + '/' + kwargs["api"])
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='base.html')),
url(r'^users/', include('users.urls')),
url(r'^(api/)?users/', include('users.urls')),
url(r'^assets/', include('assets.urls')),
url(r'^terminal/', include('webterminal.urls')),
# url(r'^api/(?P<version>.*)/(?P<module>.*)/(?P<api>.*)', view),
# url(r'^admin/', admin.site.urls),
]
urlpatterns += [
url(r'^api/users/', include('users.api_urls')),
]
#urlpatterns += [
# url(r'^api/users/', include('users.api_urls')),
#]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
......
......@@ -4,10 +4,11 @@
from django.conf.urls import url, include
import api
app_name = 'users'
urlpatterns = [
url(r'^v1/users/$', api.UserListAddApi.as_view(), name='user-list-api'),
url(r'^v1/users/(?P<pk>[0-9]+)/$', api.UserDetailDeleteUpdateApi.as_view(), name='user-detail-api'),
url(r'^v1/usergroups/$', api.UserGroupListAddApi.as_view(), name='usergroup-list-api'),
url(r'^v1/usergroups/(?P<pk>[0-9]+)/$', api.UserGroupDetailDeleteUpdateApi.as_view(),
name='usergroup-detail-api'),
url(r'^v1/usergroups/(?P<pk>[0-9]+)/$', api.UserGroupDetailDeleteUpdateApi.as_view(), name='usergroup-detail-api'),
]
......@@ -25,7 +25,7 @@ from django.db import OperationalError
# return self.name
#
# def delete(self, using=None, keep_parents=False):
# if self.user_set.all().count() > 0:
# if self.users.all().count() > 0:
# raise OperationalError('Role %s has some member, should not be delete.' % self.name)
# else:
# return super(Role, self).delete(using=using, keep_parents=keep_parents)
......@@ -99,7 +99,7 @@ class User(AbstractUser):
username = models.CharField(max_length=20, unique=True, verbose_name='用户名')
name = models.CharField(max_length=20, blank=True, verbose_name='姓名')
email = models.EmailField(max_length=30, unique=True, verbose_name='邮件')
groups = models.ManyToManyField(UserGroup, blank=True, verbose_name='用户组')
groups = models.ManyToManyField(UserGroup, related_name='users', blank=True, verbose_name='用户组')
role = models.CharField(choices=ROLE_CHOICES, default='User', max_length=10, blank=True, verbose_name='角色')
avatar = models.ImageField(upload_to="avatar", verbose_name='头像')
wechat = models.CharField(max_length=30, blank=True, verbose_name='微信')
......
......@@ -7,6 +7,8 @@ from .models import User, UserGroup
class UserSerializer(serializers.ModelSerializer):
groups = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='users:usergroup-detail-api')
class Meta:
model = User
exclude = [
......@@ -16,6 +18,8 @@ class UserSerializer(serializers.ModelSerializer):
class UserGroupSerializer(serializers.ModelSerializer):
users = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='users:user-detail-api')
class Meta:
model = UserGroup
fields = '__all__'
......
......@@ -26,7 +26,7 @@
{{ usergroup.name }}
</a>
</td>
<td class="text-center">{{ usergroup.user_set.all|length }}</td>
<td class="text-center">{{ usergroup.users.all|length }}</td>
<td class="text-center">数量</td>
<th class="text-center">{{ usergroup.comment|truncatewords:8 }}</th>
<td class="text-center">
......
......@@ -2,6 +2,7 @@ from django.conf.urls import url
from .views import UserListView, UserAddView, UserUpdateView, UserDeleteView, UserDetailView
from .views import UserGroupListView, UserGroupAddView, UserGroupUpdateView, UserGroupDeleteView, UserGroupDetailView
import api
app_name = 'users'
......@@ -17,3 +18,11 @@ urlpatterns = [
url(r'^usergroup/(?P<pk>[0-9]+)/edit/$', UserGroupUpdateView.as_view(), name='usergroup-edit'),
url(r'^usergroup/(?P<pk>[0-9]+)/delete/$', UserGroupDeleteView.as_view(), name='usergroup-delete'),
]
urlpatterns += [
url(r'^v1/users/$', api.UserListAddApi.as_view(), name='user-list-api'),
url(r'^v1/users/(?P<pk>[0-9]+)/$', api.UserDetailDeleteUpdateApi.as_view(), name='user-detail-api'),
url(r'^v1/usergroups/$', api.UserGroupListAddApi.as_view(), name='usergroup-list-api'),
url(r'^v1/usergroups/(?P<pk>[0-9]+)/$', api.UserGroupDetailDeleteUpdateApi.as_view(), name='usergroup-detail-api'),
]
......@@ -147,7 +147,7 @@ class UserGroupAddView(CreateView):
users_id_list = self.request.POST.getlist('users', [])
users = [get_object_or_404(User, id=user_id) for user_id in users_id_list]
usergroup.created_by = self.request.user.username or 'Admin'
usergroup.user_set.add(*tuple(users))
usergroup.users.add(*tuple(users))
usergroup.save()
return super(UserGroupAddView, self).form_valid(form)
......
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