Skip to content

Commit

Permalink
Add organizerissue model and form
Browse files Browse the repository at this point in the history
  • Loading branch information
amakarudze committed Jan 21, 2024
1 parent 6a05d70 commit 897cdbd
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 1 deletion.
25 changes: 25 additions & 0 deletions core/admin/forms/organizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django import forms
from models.event import Event
from models.organizer import OrganizerIssue
from models.user import User


class OrganizerIssueForm(forms.ModelForm):
organizer = forms.ModelChoiceField(queryset=User.objects.all())
event = forms.ModelChoiceField(queryset=Event.objects.all())
issue_handled_by = forms.ModelChoiceField(queryset=User.objects.filter(is_staff=True))

class Meta:
model = OrganizerIssue
fields = (
"organizer",
"event",
"date_reported",
"reported_by",
"issue",
"issue_handled",
"issue_handled_by",
"findings",
"comments",
"last_updated",
)
50 changes: 50 additions & 0 deletions core/admin/organizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from django.contrib import admin, messages
from django.shortcuts import get_object_or_404
from django.urls import path
from django.utils.translation import gettext_lazy as _
from models.organizer import OrganizerIssue


@admin.register(OrganizerIssue)
class OrganizerIssueAdmin(admin.ModelAdmin):
list_display = (
"organizer",
"event",
"date_reported",
"reported_by",
"issue_handled",
"issue_handled_by",
"last_updated",
)
list_filter = (
"organizer",
"event",
"reported_by",
)
search_fields = (
"organizer",
"event",
"reported_by",
)

def get_urls(self):
urls = super().get_urls()

my_urls = [
path(
"<int:organizerissue_id>/blacklist_organizer/",
self.admin_site.admin_view(self.blacklist_organizer),
name="core_organizer_blacklist_organizer",
),
]

return my_urls + urls

def blacklist_organizer(self, request, organizerissue_id):
organizer = get_object_or_404(OrganizerIssue, id=organizerissue_id)
organizer.blacklist_organizer()
messages.success(
request,
_("Organizer %(organizer)s, of %(event)s has been blackliste.")
% {"organizer": f"{organizer.organizer.get_full_name()}", "event": organizer.event},
)
2 changes: 1 addition & 1 deletion core/admin/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class UserAdmin(auth_admin.UserAdmin):
fieldsets = (
(None, {"fields": ("email", "password")}),
(_("Personal info"), {"fields": ("first_name", "last_name")}),
(_("Personal info"), {"fields": ("first_name", "last_name", "is_blacklisted")}),
(_("Permissions"), {"fields": ("is_active", "is_staff", "is_superuser", "groups", "user_permissions")}),
("Important dates", {"fields": ("last_login", "date_joined")}),
)
Expand Down
28 changes: 28 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.db import models
from models.event import Event
from models.user import User


class OrganizerIssue(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
organizer = models.ForeignKey(User, related_name="oganizer", on_delete=models.deletion.CASCADE)
event = models.ForeignKey(to=Event, null=True, blank=True, related_name="event", on_delete=models.deletion.SET_NULL)
date_reported = models.DateField()
reported_by = models.CharField(max_length=100)
reporter_email = models.EmailField(max_length=100)
issue = models.TextField()
issue_handled = models.BooleanField()
issue_handled_by = models.ForeignKey(
to=User, null=True, blank=True, related_name="staff_responsible", on_delete=models.deletion.SET_NULL
)
findings = models.TextChoices(blank=True, null=True)
comments = models.TextField(blank=True, null=True)
last_updated = models.DateTimeField(auto_now=True)

def __str__(self):
return f"{self.organizer.get_full_name()} - {self.event}"

def blacklist_organizer(self):
user = User.objects.get(id=self.organizer)
user.is_blacklisted = True
user.save()
29 changes: 29 additions & 0 deletions core/models/organizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.db import models

from .event import Event
from .user import User


class OrganizerIssue(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
organizer = models.ForeignKey(User, related_name="oganizer", on_delete=models.deletion.CASCADE)
event = models.ForeignKey(to=Event, null=True, blank=True, related_name="event", on_delete=models.deletion.SET_NULL)
date_reported = models.DateField()
reported_by = models.CharField(max_length=100)
reporter_email = models.EmailField(max_length=100)
issue = models.TextField()
issue_handled = models.BooleanField()
issue_handled_by = models.ForeignKey(
to=User, null=True, blank=True, related_name="staff_responsible", on_delete=models.deletion.SET_NULL
)
findings = models.TextChoices(blank=True, null=True)
comments = models.TextField(blank=True, null=True)
last_updated = models.DateTimeField(auto_now=True)

def __str__(self):
return f"{self.organizer.get_full_name()} - {self.event}"

def blacklist_organizer(self):
user = User.objects.get(id=self.organizer)
user.is_blacklisted = True
user.save()
1 change: 1 addition & 0 deletions core/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class User(auth_models.AbstractBaseUser, auth_models.PermissionsMixin):
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(auto_now_add=True)
is_blacklisted = models.BooleanField(default=False)

objects = UserManager()

Expand Down

0 comments on commit 897cdbd

Please sign in to comment.