Add myAccount view
This commit is contained in:
parent
679a831b7d
commit
f952204606
10
billard/forms.py
Normal file
10
billard/forms.py
Normal 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',)
|
@ -27,4 +27,6 @@ urlpatterns = [
|
|||||||
path('api/v1/', include(router.urls)),
|
path('api/v1/', include(router.urls)),
|
||||||
# ex. /billard/process_location_data/
|
# ex. /billard/process_location_data/
|
||||||
path('process_location_data/', views.process_location_data, name='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'),
|
||||||
]
|
]
|
||||||
|
@ -8,11 +8,15 @@ from django.shortcuts import render, redirect
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
from django.views.generic import UpdateView
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
|
||||||
from billard.models import LocationData, Location, Client, Accounting
|
from billard.models import LocationData, Location, Client, Accounting
|
||||||
from billard.serializers import LocationDataSerializer, ClientUpdateLastSeenSerializer
|
from billard.serializers import LocationDataSerializer, ClientUpdateLastSeenSerializer
|
||||||
from billard.tasks import process_location_data
|
from billard.tasks import process_location_data
|
||||||
|
from .forms import UserInformationUpdateForm
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -113,6 +117,16 @@ class ClientUpdateLastSeenViewSet(viewsets.ModelViewSet):
|
|||||||
serializer_class = ClientUpdateLastSeenSerializer
|
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):
|
def process_location_data(request):
|
||||||
process_location_data()
|
process_location_data()
|
||||||
return HttpResponse('DONE')
|
return HttpResponse('DONE')
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
{{ user.username }}
|
{{ user.username }}
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="userMenu">
|
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="userMenu">
|
||||||
<!-- <a class="dropdown-item" href="#">My account</a> -->
|
<a class="dropdown-item" href="{% url 'billard:my_account' %}">My account</a>
|
||||||
<a class="disabled dropdown-item" href="#">{% settings_value "PRODUCT_VERSION" %}</a>
|
<a class="disabled dropdown-item" href="#">{% settings_value "PRODUCT_VERSION" %}</a>
|
||||||
<div class="dropdown-divider"></div>
|
<div class="dropdown-divider"></div>
|
||||||
<a class="dropdown-item" href="{% url 'logout' %}">Log out</a>
|
<a class="dropdown-item" href="{% url 'logout' %}">Log out</a>
|
||||||
|
21
templates/registration/my_account.html
Normal file
21
templates/registration/my_account.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{% extends '_base.html' %}
|
||||||
|
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
|
||||||
|
{% block title %}My account{% endblock %}
|
||||||
|
|
||||||
|
{% block breadcrumb %}
|
||||||
|
<li class="breadcrumb-item active">My account</li>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-6 col-md-8 col-sm-10">
|
||||||
|
<form method="post" novalidate>
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form|crispy }}
|
||||||
|
<button type="submit" class="btn btn-success">Save changes</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user