Add myAccount view

This commit is contained in:
2018-02-13 08:38:17 +01:00
parent 679a831b7d
commit f952204606
5 changed files with 48 additions and 1 deletions

10
billard/forms.py Normal file
View File

@@ -0,0 +1,10 @@
from django import forms
from django.contrib.auth.models import User
class UserInformationUpdateForm(forms.ModelForm):
email = forms.EmailField()
class Meta:
model = User
fields = ('first_name', 'last_name', 'email',)

View File

@@ -27,4 +27,6 @@ urlpatterns = [
path('api/v1/', include(router.urls)),
# ex. /billard/process_location_data/
path('process_location_data/', views.process_location_data, name='process_location_data'),
# ex. /billard/myaccount/
path('my_account', views.UserUpdateView.as_view(), name='my_account'),
]

View File

@@ -8,11 +8,15 @@ from django.shortcuts import render, redirect
from django.utils import timezone
from django.utils.decorators import method_decorator
from django.views import generic
from django.views.generic import UpdateView
from django.urls import reverse_lazy
from rest_framework import viewsets
from billard.models import LocationData, Location, Client, Accounting
from billard.serializers import LocationDataSerializer, ClientUpdateLastSeenSerializer
from billard.tasks import process_location_data
from .forms import UserInformationUpdateForm
log = logging.getLogger(__name__)
@@ -113,6 +117,16 @@ class ClientUpdateLastSeenViewSet(viewsets.ModelViewSet):
serializer_class = ClientUpdateLastSeenSerializer
@method_decorator(login_required, name='dispatch')
class UserUpdateView(UpdateView):
form_class = UserInformationUpdateForm
template_name = 'registration/my_account.html'
success_url = reverse_lazy('billard:my_account')
def get_object(self):
return self.request.user
def process_location_data(request):
process_location_data()
return HttpResponse('DONE')