Modernise, refactor profile code; remove unused files
This commit is contained in:
parent
1e6359489e
commit
0d65c3c7b9
@ -1,2 +0,0 @@
|
|||||||
# from django.contrib import admin
|
|
||||||
# Register your models here.
|
|
@ -1,7 +0,0 @@
|
|||||||
from django.contrib.auth import get_user_model
|
|
||||||
from django.forms import ModelForm
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateProfile(ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = get_user_model()
|
|
@ -1,2 +0,0 @@
|
|||||||
# from django.db import models
|
|
||||||
# Create your models here.
|
|
@ -1,6 +0,0 @@
|
|||||||
{% extends "base_page.html" %}
|
|
||||||
Profile page
|
|
||||||
<form action="" method="post">{% csrf_token %}
|
|
||||||
{{ form.as_p }}
|
|
||||||
<input type="submit" value="Update" />
|
|
||||||
</form>
|
|
@ -1,2 +0,0 @@
|
|||||||
# from django.test import TestCase
|
|
||||||
# Create your tests here.
|
|
@ -1,11 +1,11 @@
|
|||||||
from django.conf.urls import url
|
from django.urls import path
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
app_name = "profiles"
|
app_name = "profiles"
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(regex=r"^~redirect/$", view=views.UserRedirectView.as_view(), name="redirect"),
|
path("", view=views.UserDetailView.as_view(), name="detail"),
|
||||||
url(regex=r"^$", view=views.UserDetailView.as_view(), name="detail"),
|
path("~redirect", view=views.UserRedirectView.as_view(), name="redirect"),
|
||||||
url(regex=r"^~update/$", view=views.UserUpdateView.as_view(), name="update"),
|
path("~update", view=views.UserUpdateView.as_view(), name="update"),
|
||||||
]
|
]
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
try:
|
|
||||||
from django.urls import reverse
|
|
||||||
except ImportError:
|
|
||||||
from django.core.urlresolvers import reverse
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from django.views.generic import DetailView, ListView, RedirectView, UpdateView
|
|
||||||
|
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
from django.views.generic import DetailView
|
||||||
|
from django.views.generic import ListView
|
||||||
|
from django.views.generic import RedirectView
|
||||||
|
from django.views.generic import UpdateView
|
||||||
|
|
||||||
from apps.map.models import CaseStudy
|
from apps.map.models import CaseStudy
|
||||||
|
|
||||||
@ -21,13 +17,13 @@ class UserDetailView(LoginRequiredMixin, DetailView):
|
|||||||
slug_url_kwarg = "username"
|
slug_url_kwarg = "username"
|
||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
return get_user_model().objects.get(username=self.request.user.username)
|
return self.model.objects.get(username=self.request.user.username)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
# Get case studies for this user
|
# Get case studies for this user
|
||||||
case_studies = CaseStudy.objects.filter(author=self.request.user.id)
|
case_studies = CaseStudy.objects.filter(author=self.request.user)
|
||||||
context["case_studies"] = case_studies
|
context["case_studies"] = case_studies
|
||||||
|
|
||||||
context["enable_edit"] = settings.FF_CAN_EDIT
|
context["enable_edit"] = settings.FF_CAN_EDIT
|
||||||
@ -37,25 +33,17 @@ class UserDetailView(LoginRequiredMixin, DetailView):
|
|||||||
|
|
||||||
class UserRedirectView(LoginRequiredMixin, RedirectView):
|
class UserRedirectView(LoginRequiredMixin, RedirectView):
|
||||||
permanent = False
|
permanent = False
|
||||||
|
url = reverse_lazy("profile:detail")
|
||||||
def get_redirect_url(self):
|
|
||||||
return reverse("profile:detail")
|
|
||||||
|
|
||||||
|
|
||||||
class UserUpdateView(LoginRequiredMixin, UpdateView):
|
class UserUpdateView(LoginRequiredMixin, UpdateView):
|
||||||
|
|
||||||
fields = ["first_name", "last_name"]
|
|
||||||
|
|
||||||
# we already imported User in the view code above, remember?
|
|
||||||
model = get_user_model()
|
model = get_user_model()
|
||||||
|
fields = ["first_name", "last_name"]
|
||||||
# send the user back to their own page after a successful update
|
success_url = reverse_lazy("profile:detail")
|
||||||
def get_success_url(self):
|
|
||||||
return reverse("profile:detail")
|
|
||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
# Only get the User record for the user making the request
|
# Only get the User record for the user making the request
|
||||||
return get_user_model().objects.get(username=self.request.user.username)
|
return self.model.objects.get(username=self.request.user.username)
|
||||||
|
|
||||||
|
|
||||||
class UserListView(LoginRequiredMixin, ListView):
|
class UserListView(LoginRequiredMixin, ListView):
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
from django.urls import include
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
from django.urls import path
|
|
||||||
from django.conf.urls.i18n import i18n_patterns
|
from django.conf.urls.i18n import i18n_patterns
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.urls import include
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from .views import LanguageDropdownView
|
from .views import LanguageDropdownView
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user