- New Features * Introduce CustomUser with role field and admin integration * Add ProjectMembership model linking users to projects * Add Ticket model with status, type, creator, and project relationships * Register CustomUser and ProjectMembership in Django admin with list views * Add URLs and views for account management and ticket CRUD operations - Enhancements * Provide pagination and filtering for ticket listings * Improve admin UI with role‑specific fieldsets - Bug Fixes * Remove obsolete serializers and placeholder files
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
from django.contrib.auth import login
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.contrib.auth.views import LoginView
|
|
from django.shortcuts import redirect
|
|
from django.urls import reverse_lazy
|
|
from django.views.generic import CreateView, DetailView, ListView, UpdateView
|
|
|
|
from apps.accounts.models import CustomUser
|
|
from apps.core.permissions import AdminRequiredMixin
|
|
|
|
|
|
class CustomLoginView(LoginView):
|
|
template_name = "pages/accounts/login.html"
|
|
redirect_authenticated_user = True
|
|
|
|
|
|
class RegisterView(CreateView):
|
|
model = CustomUser
|
|
template_name = "pages/accounts/register.html"
|
|
fields = ["username", "email", "password", "first_name", "last_name"]
|
|
success_url = reverse_lazy("home")
|
|
|
|
def form_valid(self, form):
|
|
form.instance.set_password(form.cleaned_data["password"])
|
|
form.instance.role = CustomUser.Role.CLIENT
|
|
response = super().form_valid(form)
|
|
login(self.request, self.object)
|
|
return response
|
|
|
|
|
|
class ProfileView(LoginRequiredMixin, DetailView):
|
|
model = CustomUser
|
|
template_name = "pages/accounts/profile.html"
|
|
context_object_name = "profile_user"
|
|
|
|
def get_object(self):
|
|
return self.request.user
|
|
|
|
|
|
class UserListView(AdminRequiredMixin, ListView):
|
|
model = CustomUser
|
|
template_name = "pages/accounts/user_list.html"
|
|
context_object_name = "users"
|
|
paginate_by = 20
|
|
|
|
|
|
class UserUpdateView(AdminRequiredMixin, UpdateView):
|
|
model = CustomUser
|
|
template_name = "pages/accounts/user_form.html"
|
|
fields = ["username", "email", "role", "first_name", "last_name", "is_active"]
|
|
success_url = reverse_lazy("user_list")
|