Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added create staff #25

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions maintt/api/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import pre_delete, post_save
from django.dispatch import receiver

from rest_framework.authtoken.models import Token


class UserProfile(models.Model):
'''
UserProfile model, and extension of the Django User models
Expand Down Expand Up @@ -40,6 +44,11 @@ def create_user_profile(sender, instance=None, created=False, **kwargs):
if created:
UserProfile.objects.create(user=instance)

@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
Token.objects.create(user=instance)


class Notification(models.Model):
'''
Expand Down
7 changes: 6 additions & 1 deletion maintt/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@

urlpatterns = [
url(r'^', include(router.urls)),
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework'))
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),

url(r'^admin/staff/', views.AdminUserAPI.as_view({
'post': 'create_staff',
}), name='create_staff'),

]
27 changes: 26 additions & 1 deletion maintt/api/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
from api.models import UserProfile
from rest_framework import viewsets
from rest_framework import viewsets, status
from rest_framework.response import Response

from api.serializers import UserSerializer


class UserViewSet(viewsets.ModelViewSet):
'''
API endpoint that allows users to be viewed or edited
'''
queryset = UserProfile.objects.all().order_by('-created_at')
serializer_class = UserSerializer


#############
# ADMIN API #
#############
class AdminUserAPI(viewsets.ViewSet):
""" API endpoint that allows admin user
to manage administrators
"""
def list(self, *args, **kwargs):
return Response({'yo': 'asdjasjdas'}, status=200)

def create_staff(self, *args, **kwargs):
serializer = UserSerializer(data=self.request.data)
if serializer.is_valid():
serializer.save(is_staff=True)

return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

def login_staff(self, *args, **kwargs):
test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this like a stray one?

10 changes: 9 additions & 1 deletion maintt/maintt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'api',
)

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
'PAGE_SIZE': 10
'PAGE_SIZE': 10,
}

MIDDLEWARE_CLASSES = (
Expand Down Expand Up @@ -119,3 +120,10 @@
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'


try:
from .local_settings import *
except ImportError as e:
if "local_settings" not in str(e):
raise e