django-orchestra/orchestra/apps/systemusers/api.py

24 lines
791 B
Python
Raw Normal View History

2014-10-23 15:38:46 +00:00
from django.utils.translation import ugettext_lazy as _
from rest_framework import viewsets, exceptions
from orchestra.api import router, SetPasswordApiMixin
from orchestra.apps.accounts.api import AccountApiMixin
2014-09-30 16:39:47 +00:00
from .models import SystemUser
from .serializers import SystemUserSerializer
2014-09-30 16:39:47 +00:00
class SystemUserViewSet(AccountApiMixin, SetPasswordApiMixin, viewsets.ModelViewSet):
model = SystemUser
serializer_class = SystemUserSerializer
filter_fields = ('username',)
2014-10-23 15:38:46 +00:00
def destroy(self, request, pk=None):
user = self.get_object()
if user.is_main:
raise exceptions.PermissionDenied(_("Main system user can not be deleted."))
super(SystemUserViewSet, self).destroy(request, pk=pk)
2014-09-30 16:39:47 +00:00
router.register(r'systemusers', SystemUserViewSet)