Skip to content

Create variousteams dashboard #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ env
.coverage
.state
staticroot
__pycache__/
Empty file added dashboard/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions dashboard/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin
from .models import SponsorshipApplication, VolunteerTask, StaffTask

# Register your models here.
admin.site.register(SponsorshipApplication)
admin.site.register(VolunteerTask)
admin.site.register(StaffTask)

6 changes: 6 additions & 0 deletions dashboard/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class DashboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dashboard'
38 changes: 38 additions & 0 deletions dashboard/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 5.1.7 on 2025-04-03 15:14

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='SponsorshipApplication',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('company_name', models.CharField(max_length=255)),
('status', models.CharField(choices=[('Pending', 'Pending'), ('Approved', 'Approved'), ('Rejected', 'Rejected')], default='Pending', max_length=10)),
],
),
migrations.CreateModel(
name='StaffTask',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('status', models.CharField(choices=[('Pending', 'Pending'), ('Completed', 'Completed')], default='Pending', max_length=10)),
],
),
migrations.CreateModel(
name='VolunteerTask',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('status', models.CharField(choices=[('Pending', 'Pending'), ('Completed', 'Completed')], default='Pending', max_length=10)),
],
),
]
Empty file.
18 changes: 18 additions & 0 deletions dashboard/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.db import models
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a new model here but no migrations file for SponsorshipApplication , VolunteerTask , StaffTask . Please Add it.

Steps to add it

make migrations

after that

make migrate

and commit the migrations file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright sir , i was actually planning to do all that already as well, i just gave some samples code for you to see.
I'll correct that right away sir and get back to you

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello @Mr-Sunglasses made the migrations and migrated for the 3 models and also done the commit as well pls review thank you very much

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mr-Sunglasses i saw that you requested a change , please what do you mean, i dont really understand, do you want an access to the files uploaded here


#code models for various dashboard implementations

class SponsorshipApplication(models.Model):
STATUS_CHOICES = [("Pending", "Pending"), ("Approved", "Approved"), ("Rejected", "Rejected")]
company_name = models.CharField(max_length=255)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default="Pending")

class VolunteerTask(models.Model):
STATUS_CHOICES = [("Pending", "Pending"), ("Completed", "Completed")]
title = models.CharField(max_length=255)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default="Pending")

class StaffTask(models.Model):
STATUS_CHOICES = [("Pending", "Pending"), ("Completed", "Completed")]
title = models.CharField(max_length=255)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default="Pending")
3 changes: 3 additions & 0 deletions dashboard/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
11 changes: 11 additions & 0 deletions dashboard/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import path
from .views import staffteam_dashboard, sponsorship_dashboard, volunteer_dashboard


app_name = "dashboard"

urlpatterns = [
path("dashboard/", staffteam_dashboard, name="team_dashboard"),
path("dashboard/sponsorship/", sponsorship_dashboard, name="sponsorship_dashboard"),
path("dashboard/volunteer/", volunteer_dashboard, name="volunteer_dashboard"),
]
54 changes: 54 additions & 0 deletions dashboard/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import Group
from .models import SponsorshipApplication, VolunteerTask

#views functionality
#sample code for functionalities of various dashboards for various teams
@login_required
def staffteam_dashboard(request):
""" Redirect users to their respective team dashboards based on group membership. """
if request.user.groups.filter(name="Sponsorship Team").exists():
return redirect("sponsorship_dashboard")
elif request.user.groups.filter(name="Volunteer Team").exists():
return redirect("volunteer_dashboard")
elif request.user.groups.filter(name="Staff Team").exists():
return redirect("staff_dashboard")
else:
return render(request, "dashboard/no_access.html")

@login_required
def sponsorship_dashboard(request):
""" Dashboard for Sponsorship Team. """
if not request.user.groups.filter(name="Sponsorship Team").exists():
return render(request, "dashboard/no_access.html")

total_applications = SponsorshipApplication.objects.count()
approved = SponsorshipApplication.objects.filter(status="Approved").count()
pending = SponsorshipApplication.objects.filter(status="Pending").count()
rejected = SponsorshipApplication.objects.filter(status="Rejected").count()

context = {
"total_applications": total_applications,
"approved": approved,
"pending": pending,
"rejected": rejected,
}
return render(request, "dashboard/sponsorship_dashboard.html", context)

@login_required
def volunteer_dashboard(request):
""" Dashboard for Volunteer Management Team. """
if not request.user.groups.filter(name="Volunteer Team").exists():
return render(request, "dashboard/no_access.html")

total_tasks = VolunteerTask.objects.count()
completed_tasks = VolunteerTask.objects.filter(status="Completed").count()
pending_tasks = VolunteerTask.objects.filter(status="Pending").count()

context = {
"total_tasks": total_tasks,
"completed_tasks": completed_tasks,
"pending_tasks": pending_tasks,
}
return render(request, "dashboard/volunteer_dashboard.html", context)
35 changes: 7 additions & 28 deletions portal/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.1.7 on 2025-03-18 22:57
# Generated by Django 5.1.7 on 2025-04-03 15:14

import django.utils.timezone
from django.db import migrations, models
Expand All @@ -8,37 +8,16 @@ class Migration(migrations.Migration):

initial = True

dependencies = []
dependencies = [
]

operations = [
migrations.CreateModel(
name="BaseModel",
name='BaseModel',
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"creation_date",
models.DateTimeField(
default=django.utils.timezone.now,
editable=False,
verbose_name="creation_date",
),
),
(
"modified_date",
models.DateTimeField(
default=django.utils.timezone.now,
editable=False,
verbose_name="modified_date",
),
),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('creation_date', models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='creation_date')),
('modified_date', models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='modified_date')),
],
),
]
6 changes: 6 additions & 0 deletions portal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@


class ChoiceArrayField(ArrayField):
def __init__(self, *args, **kwargs):
# Set default to empty list if it's not provided
if 'default' not in kwargs:
kwargs['default'] = []
super().__init__(*args, **kwargs)

def formfield(self, **kwargs):
defaults = {
"form_class": forms.TypedMultipleChoiceField,
Expand Down
23 changes: 17 additions & 6 deletions portal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@
"""

import os
import environ
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might have missed adding the dependency for django-environ, and it should be added to requirements.txt


env = environ.Env()
environ.Env.read_env()

ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", default=["localhost"])
from pathlib import Path

import dj_database_url

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))




# Quick-start development settings - unsuitable for production
Expand All @@ -28,9 +36,8 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(os.environ.get("DEBUG", default=0))

ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS")
if ALLOWED_HOSTS:
ALLOWED_HOSTS = ALLOWED_HOSTS.split(",")
# Ensure ALLOWED_HOSTS is a list
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", "").split(",")

# Application definition

Expand All @@ -48,6 +55,8 @@
"portal",
"volunteer",
"portal_account",
"sponsorship",
"dashboard",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -140,8 +149,10 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "staticroot"
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticroot")
if not os.path.exists(STATIC_ROOT):
os.makedirs(STATIC_ROOT)
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

# Default primary key field type
Expand Down
2 changes: 2 additions & 0 deletions portal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
path("admin/", admin.site.urls),
path("accounts/", include("allauth.urls")),
path("portal_account/", include("portal_account.urls", namespace="portal_account")),
path("dashboard/", include("dashboard.urls", namespace="dashboard")),
path("sponsorship/", include("sponsorship.urls", namespace="sponsorship")),
]
32 changes: 8 additions & 24 deletions portal_account/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.1.7 on 2025-03-23 21:45
# Generated by Django 5.1.7 on 2025-04-03 15:14

import django.db.models.deletion
from django.conf import settings
Expand All @@ -10,35 +10,19 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
("portal", "0001_initial"),
('portal', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="PortalProfile",
name='PortalProfile',
fields=[
(
"basemodel_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="portal.basemodel",
),
),
("pronouns", models.CharField(blank=True, max_length=100, null=True)),
("coc_agreement", models.BooleanField(default=False)),
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
('basemodel_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='portal.basemodel')),
('pronouns', models.CharField(blank=True, max_length=100, null=True)),
('coc_agreement', models.BooleanField(default=False)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
bases=("portal.basemodel",),
bases=('portal.basemodel',),
),
]
Empty file added sponsorship/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions sponsorship/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions sponsorship/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class SponsorshipConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'sponsorship'
Empty file.
26 changes: 26 additions & 0 deletions sponsorship/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#model schema creation for more functionality addition to sponsorship portal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a new model here but no migrations for SponsorshipApplication model. Please Add it.

Steps to add it

make migrations

after that

make migrate

and commit the migrations file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright sir, i'll rectify this as well and get back to you

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello @Mr-Sunglasses i have removed the pycache/ folder , and made the migrations and migrated for the sponsorship application models and also done the commit as well pls review thank you

from django.db import models

class SponsorshipApplication(models.Model):
STATUS_CHOICES = [
("Pending", "Pending"),
("Approved", "Approved"),
("Rejected", "Rejected"),
]
company_name = models.CharField(max_length=255)
email = models.EmailField()
tier = models.CharField(max_length=100)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default="Pending")
contract_sent = models.BooleanField(default=False)
payment_received = models.BooleanField(default=False)

def __str__(self):
return f"{self.company_name} - {self.status}"

class SponsorshipAsset(models.Model):
sponsorship_application = models.ForeignKey(SponsorshipApplication, on_delete=models.CASCADE)
asset_file = models.FileField(upload_to="sponsorship_assets/")
uploaded_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"Asset for {self.sponsorship_application.company_name}"
3 changes: 3 additions & 0 deletions sponsorship/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Empty file added sponsorship/urls.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content seems to be missing.

Empty file.
Loading