From cc526296d14b89c782d2dac3395f70df7e08d7dc Mon Sep 17 00:00:00 2001 From: Anirudh Prabhakaran Date: Sat, 24 Feb 2024 18:59:25 +0530 Subject: [PATCH 1/4] Add admin page and members page --- corpus/skyward_expedition/urls.py | 6 +++ corpus/skyward_expedition/views.py | 15 ++++++ corpus/tailwind.config.js | 3 +- .../skyward_expedition/admin/index.html | 19 ++++++++ .../admin/member_dashboard.html | 48 +++++++++++++++++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 corpus/templates/skyward_expedition/admin/index.html create mode 100644 corpus/templates/skyward_expedition/admin/member_dashboard.html diff --git a/corpus/skyward_expedition/urls.py b/corpus/skyward_expedition/urls.py index 499748d8..201d331e 100644 --- a/corpus/skyward_expedition/urls.py +++ b/corpus/skyward_expedition/urls.py @@ -19,4 +19,10 @@ views.delete_invite, name="skyward_expedition_delete_invite", ), + path("admin/", views.admin, name="skyward_expedition_admin"), + path( + "admin/members/", + views.member_dashboard, + name="skyward_expedition_member_dashboard", + ), ] diff --git a/corpus/skyward_expedition/views.py b/corpus/skyward_expedition/views.py index 44fe1764..76df156b 100644 --- a/corpus/skyward_expedition/views.py +++ b/corpus/skyward_expedition/views.py @@ -14,6 +14,7 @@ from skyward_expedition.models import Invite from skyward_expedition.models import SEUser +from corpus.decorators import ensure_group_membership from corpus.decorators import module_enabled @@ -249,3 +250,17 @@ def delete_invite(request, pk): messages.success(request, "Invite deleted!") return redirect("skyward_expedition_dashboard") + + +@login_required +@ensure_group_membership(group_names=["skyward_expedition_admin"]) +def admin(request): + return render(request, "skyward_expedition/admin/index.html") + + +@login_required +@ensure_group_membership(group_names=["skyward_expedition_admin"]) +def member_dashboard(request): + members = SEUser.objects.all() + args = {"members": members} + return render(request, "skyward_expedition/admin/member_dashboard.html", args) diff --git a/corpus/tailwind.config.js b/corpus/tailwind.config.js index 1714ddf4..498c789c 100644 --- a/corpus/tailwind.config.js +++ b/corpus/tailwind.config.js @@ -2,7 +2,8 @@ module.exports = { content: [ "./templates/*.html", - "./templates/**/*.html" + "./templates/**/*.html", + "./templates/**/**/*.html" ], theme: { extend: {}, diff --git a/corpus/templates/skyward_expedition/admin/index.html b/corpus/templates/skyward_expedition/admin/index.html new file mode 100644 index 00000000..76471182 --- /dev/null +++ b/corpus/templates/skyward_expedition/admin/index.html @@ -0,0 +1,19 @@ +{% extends 'skyward_expedition/base.html' %} + +{% block title %} + Admin Dashboard + {{ block.super }} +{% endblock %} + +{% block content %} +
+
+

Admin Dashboard

+
+ +
+{% endblock %} diff --git a/corpus/templates/skyward_expedition/admin/member_dashboard.html b/corpus/templates/skyward_expedition/admin/member_dashboard.html new file mode 100644 index 00000000..81ae3e54 --- /dev/null +++ b/corpus/templates/skyward_expedition/admin/member_dashboard.html @@ -0,0 +1,48 @@ +{% extends 'skyward_expedition/base.html' %} + +{% block title %} + Member Dashboard + {{ block.super }} +{% endblock %} + +{% block content %} +
+
+

Member Dashboard

+
+ +
+ + + + + + + + + + + + + + + + {% for member in members %} + + + + + + + + + + + {% endfor %} + +
NameCollegeDegreeYear of StudyTeamIs from NITK?NITK Roll NumberIEEE Member?IEEE Membership Number
{{ member.user }}{{ member.college_name }}{{ member.degree }}{{ member.year_of_study }}{{ member.team.team_name }}{{ member.nitk_participant | yesno }}{{ member.roll_number }}{{ member.ieee_member | yesno }}{{ member.ieee_number }}
+
+
+{% endblock %} From 046e494144818c6b824a0ed64fe676055c14af33 Mon Sep 17 00:00:00 2001 From: Anirudh Prabhakaran Date: Sat, 24 Feb 2024 21:52:00 +0530 Subject: [PATCH 2/4] Add team details page --- corpus/skyward_expedition/urls.py | 8 +++ corpus/skyward_expedition/views.py | 39 +++++++++++++- .../skyward_expedition/admin/index.html | 2 +- .../admin/member_dashboard.html | 32 +++++++---- .../admin/team_details.html | 53 +++++++++++++++++++ .../admin/teams_dashboard.html | 43 +++++++++++++++ corpus/templates/skyward_expedition/home.html | 3 +- 7 files changed, 166 insertions(+), 14 deletions(-) create mode 100644 corpus/templates/skyward_expedition/admin/team_details.html create mode 100644 corpus/templates/skyward_expedition/admin/teams_dashboard.html diff --git a/corpus/skyward_expedition/urls.py b/corpus/skyward_expedition/urls.py index 201d331e..c2c4267d 100644 --- a/corpus/skyward_expedition/urls.py +++ b/corpus/skyward_expedition/urls.py @@ -25,4 +25,12 @@ views.member_dashboard, name="skyward_expedition_member_dashboard", ), + path( + "admin/teams/", views.teams_dashboard, name="skyward_expedition_teams_dashboard" + ), + path( + "admin/teams/", + views.team_details, + name="skyward_expedition_team_details", + ), ] diff --git a/corpus/skyward_expedition/views.py b/corpus/skyward_expedition/views.py index 76df156b..036966f7 100644 --- a/corpus/skyward_expedition/views.py +++ b/corpus/skyward_expedition/views.py @@ -13,6 +13,7 @@ from skyward_expedition.models import Announcement from skyward_expedition.models import Invite from skyward_expedition.models import SEUser +from skyward_expedition.models import Team from corpus.decorators import ensure_group_membership from corpus.decorators import module_enabled @@ -27,7 +28,7 @@ def home(request): if se_user is not None: args["dashboard"] = True - if request.user.groups.filter(name__in="se_admin").exists(): + if request.user.groups.filter(name="skyward_expedition_admin").exists(): args["admin"] = True return render(request, "skyward_expedition/home.html", args) @@ -262,5 +263,39 @@ def admin(request): @ensure_group_membership(group_names=["skyward_expedition_admin"]) def member_dashboard(request): members = SEUser.objects.all() - args = {"members": members} + + members_count = members.count() + nitk_count = members.filter(nitk_participant=True).count() + ieee_count = members.filter(ieee_member=True).count() + + args = { + "members": members, + "members_count": members_count, + "nitk_count": nitk_count, + "ieee_count": ieee_count, + } + return render(request, "skyward_expedition/admin/member_dashboard.html", args) + + +@login_required +@ensure_group_membership(group_names=["skyward_expedition_admin"]) +def teams_dashboard(request): + teams = Team.objects.all() + + teams_count = teams.count() + + args = {"teams": teams, "teams_count": teams_count} + + return render(request, "skyward_expedition/admin/teams_dashboard.html", args) + + +@login_required +@ensure_group_membership(group_names=["skyward_expedition_admin"]) +def team_details(request, team_id): + team = Team.objects.get(id=team_id) + members = SEUser.objects.filter(team=team) + + args = {"team": team, "members": members} + + return render(request, "skyward_expedition/admin/team_details.html", args) diff --git a/corpus/templates/skyward_expedition/admin/index.html b/corpus/templates/skyward_expedition/admin/index.html index 76471182..518a193c 100644 --- a/corpus/templates/skyward_expedition/admin/index.html +++ b/corpus/templates/skyward_expedition/admin/index.html @@ -12,7 +12,7 @@

Admin Dashboard

diff --git a/corpus/templates/skyward_expedition/admin/member_dashboard.html b/corpus/templates/skyward_expedition/admin/member_dashboard.html index 81ae3e54..0c3d353a 100644 --- a/corpus/templates/skyward_expedition/admin/member_dashboard.html +++ b/corpus/templates/skyward_expedition/admin/member_dashboard.html @@ -13,6 +13,13 @@

Member Dashboard

+
+
+

Number of registered users: {{ members_count }}

+

Number of NITK registrants: {{ nitk_count }}

+

Number of IEEE registrants: {{ ieee_count }}

+
+
@@ -26,20 +33,25 @@

Member Dashboard

+ + {% for member in members %} - - - - - - - - - - + + + + + + + + + + + + + {% endfor %}
NITK Roll Number IEEE Member? IEEE Membership NumberEmailPhone Number
{{ member.user }}{{ member.college_name }}{{ member.degree }}{{ member.year_of_study }}{{ member.team.team_name }}{{ member.nitk_participant | yesno }}{{ member.roll_number }}{{ member.ieee_member | yesno }}{{ member.ieee_number }}
{{ member.user }}{{ member.college_name }}{{ member.degree }}{{ member.year_of_study }}{{ member.team.team_name }}{{ member.nitk_participant | yesno }}{{ member.roll_number }}{{ member.ieee_member | yesno }}{{ member.ieee_number }}{{ member.user.email }}{{ member.user.phone_no }}
diff --git a/corpus/templates/skyward_expedition/admin/team_details.html b/corpus/templates/skyward_expedition/admin/team_details.html new file mode 100644 index 00000000..00ce2da4 --- /dev/null +++ b/corpus/templates/skyward_expedition/admin/team_details.html @@ -0,0 +1,53 @@ +{% extends 'skyward_expedition/base.html' %} + +{% block title %} + Team Dashboard + {{ block.super }} +{% endblock %} + +{% block content %} +
+
+

{{ team.team_name }}

+
+ +
+ + + + + + + + + + + + + + + + + + {% for member in members %} + + + + + + + + + + + + + + {% endfor %} + +
NameCollegeDegreeYear of StudyTeamIs from NITK?NITK Roll NumberIEEE Member?IEEE Membership NumberEmailMobile
{{ member.user }}{{ member.college_name }}{{ member.degree }}{{ member.year_of_study }}{{ member.team.team_name }}{{ member.nitk_participant | yesno }}{{ member.roll_number }}{{ member.ieee_member | yesno }}{{ member.ieee_number }}{{ member.user.email }}{{ member.user.phone_no }}
+
+
+{% endblock %} diff --git a/corpus/templates/skyward_expedition/admin/teams_dashboard.html b/corpus/templates/skyward_expedition/admin/teams_dashboard.html new file mode 100644 index 00000000..1e28f8f4 --- /dev/null +++ b/corpus/templates/skyward_expedition/admin/teams_dashboard.html @@ -0,0 +1,43 @@ +{% extends 'skyward_expedition/base.html' %} + +{% block title %} + Teams Dashboard + {{ block.super }} +{% endblock %} + +{% block content %} +
+
+

Teams Dashboard

+
+ +
+
+

Number of teams: {{ teams_count }}

+
+
+
+ + + + + + + + + + {% for team in teams %} + + + + {% endfor %} + +
Team NameTeam LeaderActions
{{ team.team_name }}{{ team.team_leader.user }} + View Details +
+
+
+{% endblock %} diff --git a/corpus/templates/skyward_expedition/home.html b/corpus/templates/skyward_expedition/home.html index b5491fef..1a72c624 100644 --- a/corpus/templates/skyward_expedition/home.html +++ b/corpus/templates/skyward_expedition/home.html @@ -22,7 +22,8 @@

Skyward ExpeditionAdmin + Admin {% endif %} Rulebook From 27109358840298cc606d6f50cad5c06bacbb91d8 Mon Sep 17 00:00:00 2001 From: Anirudh Prabhakaran Date: Sat, 24 Feb 2024 22:37:50 +0530 Subject: [PATCH 3/4] Add Announcements CRUD --- corpus/skyward_expedition/forms.py | 8 ++ corpus/skyward_expedition/urls.py | 20 +++++ corpus/skyward_expedition/views.py | 59 +++++++++++++ .../admin/announcements_dashboard.html | 51 ++++++++++++ .../admin/edit_announcement.html | 82 +++++++++++++++++++ .../skyward_expedition/admin/index.html | 4 +- .../admin/new_announcement.html | 82 +++++++++++++++++++ 7 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 corpus/templates/skyward_expedition/admin/announcements_dashboard.html create mode 100644 corpus/templates/skyward_expedition/admin/edit_announcement.html create mode 100644 corpus/templates/skyward_expedition/admin/new_announcement.html diff --git a/corpus/skyward_expedition/forms.py b/corpus/skyward_expedition/forms.py index 0997e972..0ee71fd0 100644 --- a/corpus/skyward_expedition/forms.py +++ b/corpus/skyward_expedition/forms.py @@ -59,3 +59,11 @@ class AnnouncementForm(CorpusModelForm): class Meta: model = Announcement fields = ["content", "url_link", "url_link_text", "announcement_mailing"] + + def clean(self): + data = self.cleaned_data + if data.get("url_link") and not data.get("url_link_text"): + raise forms.ValidationError( + "Both URL Link and corresponding text are required." + ) + return data diff --git a/corpus/skyward_expedition/urls.py b/corpus/skyward_expedition/urls.py index c2c4267d..01bbe372 100644 --- a/corpus/skyward_expedition/urls.py +++ b/corpus/skyward_expedition/urls.py @@ -33,4 +33,24 @@ views.team_details, name="skyward_expedition_team_details", ), + path( + "admin/announcements", + views.announcements_dashboard, + name="skyward_expedition_announcements_dashboard", + ), + path( + "admin/announcements/new/", + views.new_announcement, + name="skyward_expedition_new_announcement", + ), + path( + "admin/announcements//edit/", + views.edit_announcement, + name="skyward_expedition_edit_announcement", + ), + path( + "admin/announcements//delete/", + views.delete_announcement, + name="skyward_expedition_delete_announcement", + ), ] diff --git a/corpus/skyward_expedition/views.py b/corpus/skyward_expedition/views.py index 036966f7..29d9bd72 100644 --- a/corpus/skyward_expedition/views.py +++ b/corpus/skyward_expedition/views.py @@ -7,6 +7,7 @@ from django.contrib.auth.decorators import login_required from django.shortcuts import redirect from django.shortcuts import render +from skyward_expedition.forms import AnnouncementForm from skyward_expedition.forms import InviteForm from skyward_expedition.forms import SEForm from skyward_expedition.forms import TeamCreationForm @@ -299,3 +300,61 @@ def team_details(request, team_id): args = {"team": team, "members": members} return render(request, "skyward_expedition/admin/team_details.html", args) + + +@login_required +@ensure_group_membership(group_names=["skyward_expedition_admin"]) +def announcements_dashboard(request): + announcements = Announcement.objects.all().order_by("-pk") + + args = {"announcements": announcements} + + return render( + request, "skyward_expedition/admin/announcements_dashboard.html", args + ) + + +@login_required +@ensure_group_membership(group_names=["skyward_expedition_admin"]) +def new_announcement(request): + form = AnnouncementForm() + + if request.method == "POST": + form = AnnouncementForm(request.POST) + if form.is_valid(): + form.save() + messages.success(request, "Announcement added successfully!") + return redirect("skyward_expedition_announcements_dashboard") + + args = {"form": form} + + return render(request, "skyward_expedition/admin/new_announcement.html", args) + + +@login_required +@ensure_group_membership(group_names=["skyward_expedition_admin"]) +def edit_announcement(request, announcement_id): + announcement = Announcement.objects.get(pk=announcement_id) + form = AnnouncementForm(instance=announcement) + + if request.method == "POST": + form = AnnouncementForm(request.POST, instance=announcement) + if form.is_valid(): + form.save() + + messages.success(request, "Announcement updated!") + return redirect("skyward_expedition_announcements_dashboard") + + args = {"announcement": announcement, "form": form} + + return render(request, "skyward_expedition/admin/edit_announcement.html", args) + + +@login_required +@ensure_group_membership(group_names=["skyward_expedition_admin"]) +def delete_announcement(request, announcement_id): + announcement = Announcement.objects.get(pk=announcement_id) + announcement.delete() + + messages.success(request, "Announcement deleted!") + return redirect("skyward_expedition_announcements_dashboard") diff --git a/corpus/templates/skyward_expedition/admin/announcements_dashboard.html b/corpus/templates/skyward_expedition/admin/announcements_dashboard.html new file mode 100644 index 00000000..1ef8164c --- /dev/null +++ b/corpus/templates/skyward_expedition/admin/announcements_dashboard.html @@ -0,0 +1,51 @@ +{% extends 'skyward_expedition/base.html' %} + +{% block title %} + Announcements Dashboard + {{ block.super }} +{% endblock %} + +{% block content %} +
+
+

Announcements Dashboard

+
+ +
+ + + + + + + + + + {% for announcement in announcements %} + + + + + + {% endfor %} + +
ContentURLActions
{{ announcement.content | linebreaks }} + {% if announcement.url_link %} + + {{ announcement.url_link_text }} + + {% else %} + - + {% endif %} + + + Edit + + Delete +
+
+
+{% endblock %} diff --git a/corpus/templates/skyward_expedition/admin/edit_announcement.html b/corpus/templates/skyward_expedition/admin/edit_announcement.html new file mode 100644 index 00000000..5dd92c3a --- /dev/null +++ b/corpus/templates/skyward_expedition/admin/edit_announcement.html @@ -0,0 +1,82 @@ +{% extends 'skyward_expedition/base.html' %} + +{% block title %} + Edit Announcement + {{ block.super }} +{% endblock %} + +{% block content %} +
+
+

Edit Announcement

+
+ +
+
+ {% csrf_token %} + + {% if form.errors %} +
+
+ {{ form.non_field_errors }} +
+
+ {% endif %} + +
+ + {{ form.content }} + {% if form.content.errors %} +
+ +
+ {% endif %} +
+ +
+ + {{ form.url_link }} + {% if form.url_link.errors %} +
+ +
+ {% endif %} +
+ +
+ + {{ form.url_link_text }} + {% if form.url_link_text.errors %} +
+ +
+ {% endif %} +
+ +
+ + {{ form.announcement_mailing }} + {% if form.announcement_mailing.errors %} +
+ +
+ {% endif %} +
+ + +
+
+
+{% endblock %} diff --git a/corpus/templates/skyward_expedition/admin/index.html b/corpus/templates/skyward_expedition/admin/index.html index 518a193c..b9f55e87 100644 --- a/corpus/templates/skyward_expedition/admin/index.html +++ b/corpus/templates/skyward_expedition/admin/index.html @@ -13,7 +13,9 @@

Admin Dashboard

{% endblock %} diff --git a/corpus/templates/skyward_expedition/admin/new_announcement.html b/corpus/templates/skyward_expedition/admin/new_announcement.html new file mode 100644 index 00000000..86634396 --- /dev/null +++ b/corpus/templates/skyward_expedition/admin/new_announcement.html @@ -0,0 +1,82 @@ +{% extends 'skyward_expedition/base.html' %} + +{% block title %} + Create Announcement + {{ block.super }} +{% endblock %} + +{% block content %} +
+
+

Create Announcement

+
+ +
+
+ {% csrf_token %} + + {% if form.errors %} +
+
+ {{ form.non_field_errors }} +
+
+ {% endif %} + +
+ + {{ form.content }} + {% if form.content.errors %} +
+ +
+ {% endif %} +
+ +
+ + {{ form.url_link }} + {% if form.url_link.errors %} +
+ +
+ {% endif %} +
+ +
+ + {{ form.url_link_text }} + {% if form.url_link_text.errors %} +
+ +
+ {% endif %} +
+ +
+ + {{ form.announcement_mailing }} + {% if form.announcement_mailing.errors %} +
+ +
+ {% endif %} +
+ + +
+
+
+{% endblock %} From e9185899fddaa3a76f07db795761a5dfaa572e82 Mon Sep 17 00:00:00 2001 From: Anirudh Prabhakaran Date: Sat, 24 Feb 2024 23:12:25 +0530 Subject: [PATCH 4/4] Send mails on announcement --- corpus/skyward_expedition/models.py | 20 +++++++++++++++++++ corpus/skyward_expedition/views.py | 4 +++- .../skyward_expedition/announcement.html | 15 ++++++++++++++ .../admin/edit_announcement.html | 6 +++++- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 corpus/templates/emails/skyward_expedition/announcement.html diff --git a/corpus/skyward_expedition/models.py b/corpus/skyward_expedition/models.py index 2ca3dfeb..e7ca4671 100644 --- a/corpus/skyward_expedition/models.py +++ b/corpus/skyward_expedition/models.py @@ -1,6 +1,8 @@ from accounts.models import User from django.db import models +from corpus.utils import send_email + # Create your models here. @@ -50,3 +52,21 @@ class Announcement(models.Model): content = models.TextField(blank=False, null=False) url_link = models.URLField(blank=True, null=True) url_link_text = models.CharField(max_length=200, blank=True, null=True) + + def send_email(self, mail_option): + email_ids = None + + if mail_option == 2: + email_ids = list( + Team.objects.values_list("team_leader__user__email", flat=True) + ) + elif mail_option == 3: + email_ids = list(SEUser.objects.values_list("user__email", flat=True)) + + if email_ids is not None: + send_email( + "Announcement | Skyward Expedition", + "emails/skyward_expedition/announcement.html", + {"announcement": self}, + bcc=email_ids, + ) diff --git a/corpus/skyward_expedition/views.py b/corpus/skyward_expedition/views.py index 29d9bd72..6bf48b1f 100644 --- a/corpus/skyward_expedition/views.py +++ b/corpus/skyward_expedition/views.py @@ -322,7 +322,9 @@ def new_announcement(request): if request.method == "POST": form = AnnouncementForm(request.POST) if form.is_valid(): - form.save() + announcement = form.save() + mail_option = int(form.cleaned_data.get("announcement_mail", "1")) + announcement.send_email(mail_option) messages.success(request, "Announcement added successfully!") return redirect("skyward_expedition_announcements_dashboard") diff --git a/corpus/templates/emails/skyward_expedition/announcement.html b/corpus/templates/emails/skyward_expedition/announcement.html new file mode 100644 index 00000000..6974d354 --- /dev/null +++ b/corpus/templates/emails/skyward_expedition/announcement.html @@ -0,0 +1,15 @@ +{% extends 'emails/base.html' %} + +{% block title %} + Announcement | Skyward Expedition +{% endblock %} + +{% block content %} +

Announcement - Skyward Expedition

+

{{ announcement.content | linebreaks }}

+ {% if announcement.url_link %} +

+ {{ announcement.url_link_text }} +

+ {% endif %} +{% endblock %} diff --git a/corpus/templates/skyward_expedition/admin/edit_announcement.html b/corpus/templates/skyward_expedition/admin/edit_announcement.html index 5dd92c3a..b140a9d9 100644 --- a/corpus/templates/skyward_expedition/admin/edit_announcement.html +++ b/corpus/templates/skyward_expedition/admin/edit_announcement.html @@ -15,8 +15,12 @@

Edit Announcement

Go to Announcements Dashboard +
+
Editing an announcement will not send an email.
+
-
+ {% csrf_token %} {% if form.errors %}