diff --git a/billard/forms.py b/billard/forms.py new file mode 100644 index 0000000..dd82d79 --- /dev/null +++ b/billard/forms.py @@ -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',) diff --git a/billard/urls.py b/billard/urls.py index a28b8b8..2bbb65b 100644 --- a/billard/urls.py +++ b/billard/urls.py @@ -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'), ] diff --git a/billard/views.py b/billard/views.py index 2b737d9..37fc297 100644 --- a/billard/views.py +++ b/billard/views.py @@ -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') diff --git a/templates/_base.html b/templates/_base.html index 77da87d..064f9bd 100644 --- a/templates/_base.html +++ b/templates/_base.html @@ -50,7 +50,7 @@ {{ user.username }}