@@ -0,0 +1,47 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import ListView, UpdateView
|
||||
|
||||
from .forms import SearchProfileForm
|
||||
from .models import SearchProfile
|
||||
from .services import save_profile_revision
|
||||
|
||||
|
||||
class ProfileListView(LoginRequiredMixin, ListView):
|
||||
model = SearchProfile
|
||||
template_name = "profiles/list.html"
|
||||
context_object_name = "profiles"
|
||||
|
||||
def get_queryset(self):
|
||||
return SearchProfile.objects.filter(user=self.request.user)
|
||||
|
||||
|
||||
class ProfileUpdateView(LoginRequiredMixin, UpdateView):
|
||||
model = SearchProfile
|
||||
form_class = SearchProfileForm
|
||||
template_name = "profiles/edit.html"
|
||||
success_url = reverse_lazy("profiles:list")
|
||||
|
||||
def get_queryset(self):
|
||||
return SearchProfile.objects.filter(user=self.request.user)
|
||||
|
||||
def form_valid(self, form):
|
||||
response = super().form_valid(form)
|
||||
if self.object.is_active:
|
||||
self.object.activate()
|
||||
save_profile_revision(self.object, reason="user_edit")
|
||||
messages.success(self.request, "Zoekprofiel opgeslagen.")
|
||||
return response
|
||||
|
||||
|
||||
def activate_profile(request, pk: int):
|
||||
if request.method != "POST":
|
||||
return redirect("profiles:list")
|
||||
profile = get_object_or_404(SearchProfile, pk=pk, user=request.user)
|
||||
profile.activate()
|
||||
messages.success(request, f"{profile.name} is nu het actieve profiel.")
|
||||
return redirect("profiles:list")
|
||||
Reference in New Issue
Block a user