feat(apps): add role‑based CustomUser admin and ticketing system
- 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
This commit is contained in:
37 files changed
+954
-126
No files matched your search
+19
-3
@@ -1,5 +1,21 @@
|
||||
"""generated with djinit"""
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
from apps.issues.models import Issue, IssueComment
|
||||
|
||||
|
||||
class IssueCommentInline(admin.TabularInline):
|
||||
model = IssueComment
|
||||
extra = 1
|
||||
|
||||
|
||||
@admin.register(Issue)
|
||||
class IssueAdmin(admin.ModelAdmin):
|
||||
list_display = ["title", "project", "status", "priority", "assignee", "created_at"]
|
||||
list_filter = ["status", "priority"]
|
||||
search_fields = ["title"]
|
||||
inlines = [IssueCommentInline]
|
||||
|
||||
|
||||
@admin.register(IssueComment)
|
||||
class IssueCommentAdmin(admin.ModelAdmin):
|
||||
list_display = ["issue", "author", "created_at"]
|
||||
+49
-3
@@ -1,5 +1,51 @@
|
||||
"""generated with djinit"""
|
||||
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class Issue(models.Model):
|
||||
class Status(models.TextChoices):
|
||||
OPEN = "open"
|
||||
IN_PROGRESS = "in_progress"
|
||||
RESOLVED = "resolved"
|
||||
CLOSED = "closed"
|
||||
|
||||
class Priority(models.TextChoices):
|
||||
LOW = "low"
|
||||
MEDIUM = "medium"
|
||||
HIGH = "high"
|
||||
|
||||
project = models.ForeignKey(
|
||||
"projects.Project",
|
||||
on_delete=models.CASCADE,
|
||||
related_name="issues",
|
||||
)
|
||||
reporter = models.ForeignKey(
|
||||
"accounts.CustomUser",
|
||||
on_delete=models.CASCADE,
|
||||
related_name="reported_issues",
|
||||
)
|
||||
assignee = models.ForeignKey(
|
||||
"accounts.CustomUser",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="assigned_issues",
|
||||
)
|
||||
title = models.CharField(max_length=255)
|
||||
description = models.TextField(blank=True)
|
||||
status = models.CharField(max_length=20, choices=Status.choices, default=Status.OPEN)
|
||||
priority = models.CharField(max_length=20, choices=Priority.choices, default=Priority.MEDIUM)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
class IssueComment(models.Model):
|
||||
issue = models.ForeignKey(Issue, on_delete=models.CASCADE, related_name="comments")
|
||||
author = models.ForeignKey("accounts.CustomUser", on_delete=models.CASCADE)
|
||||
body = models.TextField()
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"Comment by {self.author} on {self.issue}"
|
||||
@@ -1,5 +0,0 @@
|
||||
"""generated with djinit"""
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
# Create your serializers here.
|
||||
+14
-4
@@ -1,7 +1,17 @@
|
||||
"""generated with djinit"""
|
||||
|
||||
from django.urls import path
|
||||
|
||||
from apps.issues.views import (
|
||||
IssueCommentCreateView,
|
||||
IssueCreateView,
|
||||
IssueDetailView,
|
||||
IssueListView,
|
||||
IssueUpdateView,
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
# Add your URL patterns here
|
||||
]
|
||||
path("issues/", IssueListView.as_view(), name="issue_list"),
|
||||
path("issues/create/", IssueCreateView.as_view(), name="issue_create"),
|
||||
path("issues/<int:pk>/", IssueDetailView.as_view(), name="issue_detail"),
|
||||
path("issues/<int:pk>/edit/", IssueUpdateView.as_view(), name="issue_edit"),
|
||||
path("issues/<int:issue_pk>/comments/", IssueCommentCreateView.as_view(), name="issue_comment"),
|
||||
]
|
||||
+64
-3
@@ -1,5 +1,66 @@
|
||||
"""generated with djinit"""
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import CreateView, DetailView, ListView, UpdateView, View
|
||||
|
||||
from rest_framework import viewsets
|
||||
from apps.issues.models import Issue, IssueComment
|
||||
|
||||
# Create your views here.
|
||||
|
||||
class IssueListView(LoginRequiredMixin, ListView):
|
||||
model = Issue
|
||||
template_name = "pages/issues/issue_list.html"
|
||||
context_object_name = "issues"
|
||||
paginate_by = 20
|
||||
|
||||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
qs = Issue.objects.select_related("project", "assignee", "reporter")
|
||||
if user.is_admin():
|
||||
return qs.all()
|
||||
if user.is_client():
|
||||
return qs.filter(project__client=user)
|
||||
return qs.filter(assignee=user)
|
||||
|
||||
|
||||
class IssueDetailView(LoginRequiredMixin, DetailView):
|
||||
model = Issue
|
||||
template_name = "pages/issues/issue_detail.html"
|
||||
context_object_name = "issue"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["comments"] = self.object.comments.select_related("author").all()
|
||||
return context
|
||||
|
||||
|
||||
class IssueCreateView(LoginRequiredMixin, CreateView):
|
||||
model = Issue
|
||||
template_name = "pages/issues/issue_form.html"
|
||||
fields = ["project", "title", "description", "priority", "assignee"]
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.reporter = self.request.user
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("issue_detail", kwargs={"pk": self.object.pk})
|
||||
|
||||
|
||||
class IssueUpdateView(LoginRequiredMixin, UpdateView):
|
||||
model = Issue
|
||||
template_name = "pages/issues/issue_form.html"
|
||||
fields = ["title", "description", "status", "priority", "assignee"]
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("issue_detail", kwargs={"pk": self.object.pk})
|
||||
|
||||
|
||||
class IssueCommentCreateView(LoginRequiredMixin, View):
|
||||
def post(self, request, issue_pk):
|
||||
issue = get_object_or_404(Issue, pk=issue_pk)
|
||||
body = request.POST.get("body", "")
|
||||
if body:
|
||||
IssueComment.objects.create(issue=issue, author=request.user, body=body)
|
||||
if request.htmx:
|
||||
return render(request, "partials/issues/comment_list.html", {"comments": issue.comments.all()})
|
||||
return render(request, "pages/issues/issue_detail.html", {"issue": issue, "comments": issue.comments.all()})
|
||||
Reference in new issue
Block a user