add an API view to get username and teams, needed for POS system
This commit is contained in:
parent
51c95ddc9d
commit
d9da1b3cd9
|
@ -1,9 +1,10 @@
|
|||
from django.urls import path
|
||||
|
||||
from .views import ProfileDetail, ProfileUpdate
|
||||
from .views import ProfileApiView, ProfileDetail, ProfileUpdate
|
||||
|
||||
app_name = "profiles"
|
||||
urlpatterns = [
|
||||
path("", ProfileDetail.as_view(), name="detail"),
|
||||
path("edit/", ProfileUpdate.as_view(), name="update"),
|
||||
path("api/", ProfileApiView.as_view(), name="api"),
|
||||
]
|
||||
|
|
|
@ -2,6 +2,8 @@ from django.contrib import messages
|
|||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import DetailView, UpdateView
|
||||
from jsonview.views import JsonView
|
||||
from oauth2_provider.views.generic import ProtectedResourceView
|
||||
|
||||
from . import models
|
||||
|
||||
|
@ -34,3 +36,18 @@ class ProfileUpdate(LoginRequiredMixin, UpdateView):
|
|||
form.instance.save()
|
||||
messages.success(self.request, "Your profile has been updated.")
|
||||
return super().form_valid(form, **kwargs)
|
||||
|
||||
|
||||
class ProfileApiView(JsonView, ProtectedResourceView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["user"] = {"username": self.request.user.username}
|
||||
context["profile"] = {
|
||||
"public_credit_name": self.request.user.profile.get_public_credit_name,
|
||||
"description": self.request.user.profile.description,
|
||||
}
|
||||
context["teams"] = [
|
||||
{"team": team.name, "camp": team.camp.title}
|
||||
for team in self.request.user.teams.all()
|
||||
]
|
||||
return context
|
||||
|
|
|
@ -14,6 +14,7 @@ django-cors-headers==3.4.0
|
|||
django-extensions==3.0.3
|
||||
django-filter==2.3.0
|
||||
django-leaflet==0.27.0
|
||||
django-jsonview==2.0.0
|
||||
django-oauth-toolkit==1.3.2
|
||||
django-reversion==3.0.7
|
||||
django-taggit==1.3.0
|
||||
|
|
Loading…
Reference in a new issue