diff --git a/core/admin/forms/organizer.py b/core/admin/forms/organizer.py new file mode 100644 index 000000000..2d5fe2d9d --- /dev/null +++ b/core/admin/forms/organizer.py @@ -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", + ) diff --git a/core/admin/organizer.py b/core/admin/organizer.py new file mode 100644 index 000000000..8d733e164 --- /dev/null +++ b/core/admin/organizer.py @@ -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( + "/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}, + ) diff --git a/core/admin/user.py b/core/admin/user.py index 5b6c2e301..d58370f95 100644 --- a/core/admin/user.py +++ b/core/admin/user.py @@ -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")}), ) diff --git a/core/models.py b/core/models.py index e69de29bb..45ae5c762 100644 --- a/core/models.py +++ b/core/models.py @@ -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() diff --git a/core/models/organizer.py b/core/models/organizer.py new file mode 100644 index 000000000..d942d954e --- /dev/null +++ b/core/models/organizer.py @@ -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() diff --git a/core/models/user.py b/core/models/user.py index e2371936a..d0d8dbdbd 100644 --- a/core/models/user.py +++ b/core/models/user.py @@ -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()