diff --git a/civicfix/core/__pycache__/models.cpython-313.pyc b/civicfix/core/__pycache__/models.cpython-313.pyc index a6af577..ca9962d 100644 Binary files a/civicfix/core/__pycache__/models.cpython-313.pyc and b/civicfix/core/__pycache__/models.cpython-313.pyc differ diff --git a/civicfix/core/__pycache__/urls.cpython-313.pyc b/civicfix/core/__pycache__/urls.cpython-313.pyc index 864507a..b6bde5b 100644 Binary files a/civicfix/core/__pycache__/urls.cpython-313.pyc and b/civicfix/core/__pycache__/urls.cpython-313.pyc differ diff --git a/civicfix/core/__pycache__/views.cpython-313.pyc b/civicfix/core/__pycache__/views.cpython-313.pyc index 0f287f7..a59bdfc 100644 Binary files a/civicfix/core/__pycache__/views.cpython-313.pyc and b/civicfix/core/__pycache__/views.cpython-313.pyc differ diff --git a/civicfix/core/migrations/0002_user_banned_until_user_is_banned.py b/civicfix/core/migrations/0002_user_banned_until_user_is_banned.py new file mode 100644 index 0000000..3696ffd --- /dev/null +++ b/civicfix/core/migrations/0002_user_banned_until_user_is_banned.py @@ -0,0 +1,23 @@ +# Generated by Django 5.2.5 on 2025-08-26 08:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='banned_until', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AddField( + model_name='user', + name='is_banned', + field=models.BooleanField(default=False), + ), + ] diff --git a/civicfix/core/migrations/__pycache__/0002_user_banned_until_user_is_banned.cpython-313.pyc b/civicfix/core/migrations/__pycache__/0002_user_banned_until_user_is_banned.cpython-313.pyc new file mode 100644 index 0000000..3d811db Binary files /dev/null and b/civicfix/core/migrations/__pycache__/0002_user_banned_until_user_is_banned.cpython-313.pyc differ diff --git a/civicfix/core/models.py b/civicfix/core/models.py index 318a41c..fe643a5 100644 --- a/civicfix/core/models.py +++ b/civicfix/core/models.py @@ -1,7 +1,9 @@ +from datetime import timedelta from django.contrib.auth.models import AbstractUser from django.core.validators import FileExtensionValidator from django.conf import settings from django.db import models +from django.utils import timezone class User(AbstractUser): is_citizen = models.BooleanField(default=False) @@ -25,6 +27,24 @@ class User(AbstractUser): related_name='core_user_permissions', related_query_name='core_user', ) + is_banned = models.BooleanField(default=False) + banned_until = models.DateTimeField(null=True, blank=True) + + def ban(self, days=1): + """Ban user for given days (default 7 days).""" + self.is_banned = True + self.banned_until = timezone.now() + timedelta(days=days) + self.save() + + def unban(self): + self.is_banned = False + self.banned_until = None + self.save() + + def is_currently_banned(self): + if self.is_banned and self.banned_until: + return timezone.now() < self.banned_until + return False class Department(models.Model): name = models.CharField(max_length=100, unique=True) diff --git a/civicfix/core/templates/core/manage_users.html b/civicfix/core/templates/core/manage_users.html new file mode 100644 index 0000000..80ad9e9 --- /dev/null +++ b/civicfix/core/templates/core/manage_users.html @@ -0,0 +1,60 @@ +{% extends "core/base.html" %} + +{% block content %} +
| No. | +Username | +Phone No. | +Date Joined | +Status | +Action | +|
|---|---|---|---|---|---|---|
| {{ forloop.counter }} | +{{ citizen.username }} | +{{ citizen.email }} | +{{ citizen.phone }} | +{{ citizen.date_joined|date:"M d, Y" }} | ++ {% if citizen.is_currently_banned %} + Banned until {{ citizen.banned_until|date:"M d, Y" }} + {% else %} + Active + {% endif %} + | ++ {% if citizen.is_currently_banned %} + + Unban + + {% else %} + + Ban + + {% endif %} + | +
No citizen users found.
+ {% endif %} +