Skip to content

Commit

Permalink
Merge branch 'main' into add_exec_member_models
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhprabhakaran3 authored Jan 8, 2024
2 parents b9d4689 + 11dcc72 commit a563ba3
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 31 deletions.
17 changes: 15 additions & 2 deletions corpus/embedathon/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from config.models import ModuleConfiguration
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.db.models import Count
from django.shortcuts import redirect
from django.shortcuts import render
from embedathon.forms import AnnouncementForm
Expand Down Expand Up @@ -263,7 +264,8 @@ def admin(request):
@ensure_group_membership(group_names=["embedathon_admin"])
def team_management(request):
teams = Team.objects.all()
args = {"teams": teams}
team_counts = teams.values("payment_status").annotate(count=Count("payment_status"))
args = {"teams": teams, "team_counts": team_counts}
return render(request, "embedathon/team_management.html", args)


Expand Down Expand Up @@ -294,7 +296,18 @@ def mark_payment_complete(request, pk):
def user_management(request):
users = EmbedathonUser.objects.all()

args = {"users": users}
nitk_count = users.values("from_nitk").annotate(count=Count("from_nitk"))
ieee_count = users.values("ieee_member").annotate(count=Count("ieee_member"))
cass_count = users.values("cass_member").annotate(count=Count("cass_member"))
years_count = users.values("year").annotate(count=Count("year"))

args = {
"users": users,
"nitk_count": nitk_count,
"ieee_count": ieee_count,
"cass_count": cass_count,
"years_count": years_count,
}

return render(request, "embedathon/user_management.html", args)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2024-01-06 18:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('impulse', '0002_remove_team_payment_proof'),
]

operations = [
migrations.AlterField(
model_name='announcement',
name='announcement_type',
field=models.CharField(choices=[('A', 'All Impulse Users'), ('P', 'Paid Teams'), ('U', 'Unpaid Teams'), ('N', 'Registered for Impulse but no team'), ('NI', 'Not Registered for Impulse')], default='A', max_length=2),
),
]
7 changes: 4 additions & 3 deletions corpus/impulse/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ def __str__(self):
class Announcement(models.Model):

AnnouncementType = (
("A", "All"),
("A", "All Impulse Users"),
("P", "Paid Teams"),
("U", "Unpaid Teams"),
("N", "Not Registered Teams"),
("N", "Registered for Impulse but no team"),
("NI", "Not Registered for Impulse"),
)

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)
announcement_type = models.CharField(max_length=1, choices=AnnouncementType, blank=False, null=False, default="A")
announcement_type = models.CharField(max_length=2, choices=AnnouncementType, blank=False, null=False, default="A")
date_created = models.DateTimeField(auto_now_add=True)
date_modified = models.DateTimeField(auto_now=True)

Expand Down
6 changes: 6 additions & 0 deletions corpus/impulse/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@
views.delete_announcement,
name="impulse_delete_announcement",
),
path(
"admin/download_csv",
views.download_csv_non_registrants,
name="impulse_download_csv",
),

]
52 changes: 51 additions & 1 deletion corpus/impulse/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,24 @@ def announcements_management(request):
"user__email", flat=True
)
)
elif announcement.announcement_type == "NI":
# all users who have not registered for impulse
users = User.objects.exclude(
email__in=ImpulseUser.objects.values_list("user__email", flat=True)
)

users = users.exclude(
email__in=[
"impulse_admin",
"embedathon_admin",
]
)
users = users.exclude(is_staff=True)
users = users.exclude(is_superuser=True)

email_ids = list(users.values_list("email", flat=True))


if email_ids is not None:
send_email(
"Announcement | Impulse",
Expand Down Expand Up @@ -463,4 +481,36 @@ def mark_payment_incomplete(request, pk):
bcc=[member.user.email],
)
messages.success(request, "Successfully marked payment as incomplete!")
return redirect("impulse_admin_team_page", pk=pk)
return redirect("impulse_admin_team_page", pk=pk)


@login_required
@ensure_group_membership(group_names=["impulse_admin"])
def download_csv_non_registrants(request):
import csv
from django.http import HttpResponse

response = HttpResponse(content_type="text/csv")
response["Content-Disposition"] = 'attachment; filename="non_registrants.csv"'

writer = csv.writer(response)
writer.writerow(["Name", "Email"])

users = User.objects.exclude(
email__in=ImpulseUser.objects.values_list("user__email", flat=True)
)

users = users.exclude(
email__in=[
"impulse_admin",
"embedathon_admin",
]
)
users = users.exclude(is_staff=True)
users = users.exclude(is_superuser=True)


for user in users:
writer.writerow([user, user.email])

return response
2 changes: 1 addition & 1 deletion corpus/templates/emails/embedathon/announcement.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{% block content %}
<h1>Announcement - Embedathon</h1>
<p>{{ announcement.content }}</p>
<p>{{ announcement.content | linebreaks }}</p>
{% if announcement.url_link %}
<p>
<a href="{{ announcement.url_link }}">{{ announcement.url_link_text }}</a>
Expand Down
4 changes: 3 additions & 1 deletion corpus/templates/emails/impulse/announcement.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

{% block content %}
<h1>Announcement - Impulse</h1>
<p>{{ announcement.content }}</p>
<div style="font-size: 1.2em;">
{{ announcement.content | linebreaks }}
</div>
{% if announcement.url_link %}
<p>
<a href="{{ announcement.url_link }}">{{ announcement.url_link_text }}</a>
Expand Down
36 changes: 36 additions & 0 deletions corpus/templates/embedathon/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@ <h2>Prizes</h2>
</p>
</section>

<section id="workshops" class="py-5 px-5">
<h2>Workshops</h2>
<div class="flex flex-col md:flex-row justify-between content-center gap-4">
<div class="card bg-base-100 shadow-xl basis-1/2 border">
<div class="card-body">
<h2 class="card-title">Image Processing using OpenCV</h2>
<strong>10th Jan, 2024 at 6:30PM</strong>
<div class="card-actions">
<a href="https://rb.gy/vjfnmb" class="btn btn-primary no-underline">
<strong>Workshop Link</strong>
</a>
</div>
</div>
</div>
<div class="card bg-base-100 shadow-xl basis-1/2 border">
<div class="card-body">
<h2 class="card-title">Introduction to Embedded Systems</h2>
<strong>15th Jan, 2024 at 6:30PM</strong>
<div class="card-actions">
<a href="https://rb.gy/xdc2xa" class="btn btn-primary no-underline">
<strong>Workshop Link</strong>
</a>
</div>
</div>
</div>
</div>
</section>

<section id="speakers" class="py-5 px-5">
<h2>Speakers</h2>
<div class="flex flex-col md:flex-row justify-between content-center gap-4">
Expand All @@ -63,6 +91,10 @@ <h2 class="card-title">Light Weight Cryptography for IoT</h2>
<a href="https://rb.gy/ciaa6q" class="btn btn-primary no-underline">
<strong>Session Link</strong>
</a>
<a href="https://drive.google.com/drive/folders/1Nnq8WbO17oH7kHY13Vj4XgYYCUXuWVhY?usp=drive_link"
class="btn btn-secondary no-underline">
<strong>Session Resources</strong>
</a>
</div>
</div>
</div>
Expand All @@ -81,6 +113,10 @@ <h2 class="card-title">Design and Validation of Hybrid Systems</h2>
<a href="https://rb.gy/a4dvll" class="btn btn-primary no-underline">
<strong>Session Link</strong>
</a>
<a href="https://drive.google.com/drive/folders/166RWAdKPtBCJBYDJMFmrhlSwX-oCSs6V?usp=drive_link"
class="btn btn-secondary no-underline">
<strong>Session Resources</strong>
</a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion corpus/templates/embedathon/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ <h2 class="text-center my-3">Announcements</h2>
<ul>
{% for announcement in announcements %}
<li>
{{ announcement.content }}
{{ announcement.content | linebreaks }}
{% if announcement.url_link %}
<a href="{{ announcement.url_link }}">{{ announcement.url_link_text }}</a>
{% endif %}
Expand Down
7 changes: 7 additions & 0 deletions corpus/templates/embedathon/team_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
<div class="prose mx-auto my-10">
<h1 class="text-center">Team Management</h1>
<p><strong>Number of teams:</strong> {{ teams.count }}</p>
<div class="my-1">
<h3>Stats</h3>
{% for item in team_counts %}
<p><strong>{{ item.payment_status }}:</strong>{{ item.count }}</p>
{% endfor %}
<p>where E = Exempt, P = Paid, U = Unpaid.</p>
</div>
<div class="overflow-x-auto my-5">
<table class="table table-zebra">
<thead>
Expand Down
21 changes: 21 additions & 0 deletions corpus/templates/embedathon/user_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@
<div class="prose max-w-none mx-10 my-10">
<h1 class="text-center">User Management</h1>
<p><strong>Number of Users:</strong>{{ users.count }}</p>

<div class="my-1">
<h3>Stats</h3>
<strong class="underline">NITK Students Stats</strong>
{% for item in nitk_count %}
<p><strong>{{ item.from_nitk | yesno:"From NITK, Not from NITK" }}</strong>: {{ item.count }}</p>
{% endfor %}
<strong class="underline">IEEE Members Stats</strong>
{% for item in ieee_count %}
<p><strong>{{ item.ieee_member | yesno:"IEEE Member, Not IEEE Member" }}</strong>: {{ item.count }}</p>
{% endfor %}
<strong class="underline">CASS Members Stats</strong>
{% for item in cass_count %}
<p><strong>{{ item.cass_member | yesno:"CASS Member, Not CASS Member" }}</strong>: {{ item.count }}</p>
{% endfor %}
<strong class="underline">Students Years Stats</strong>
{% for item in years_count %}
<p><strong>Year {{ item.year }}</strong>: {{ item.count }}</p>
{% endfor %}
</div>

<div class="overflow-x-auto my-5">
<table class="table table-zebra">
<thead>
Expand Down
32 changes: 32 additions & 0 deletions corpus/templates/impulse/admin/announcements.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,37 @@ <h2 class="text-center">Current Announcements</h2>
</table>
</div>
<a href="{% url 'impulse_admin' %}" class="btn btn-secondary text-black font-bold no-underline">Back</a>
<a href="{% url 'impulse_download_csv' %}" class="btn btn-secondary text-black font-bold no-underline">Download CSV of Non-Registrants</a>
</div>
{% endblock %}

{% block script %}
{{ block.super }}
<script>
document.addEventListener("DOMContentLoaded", function () {
let emailTypeField = document.getElementById("{{ form.announcement_mailing.id_for_label }}");
let announcementTypeField = document.getElementById("{{ form.announcement_type.id_for_label }}");

function toggleEmailType() {
if (announcementTypeField.value === "N") {
emailTypeField.value = "3";
emailTypeField.options[1].hidden = true;
emailTypeField.options[0].hidden = false;
}
else if (announcementTypeField.value === "NI") {
emailTypeField.value = "3";
emailTypeField.options[0].hidden = true;
emailTypeField.options[1].hidden = true;
}
else {
emailTypeField.options[1].hidden = false;
emailTypeField.options[0].hidden = false;
}
}

toggleEmailType();
announcementTypeField.addEventListener("change", toggleEmailType);
});
</script>
{% endblock %}
```
3 changes: 3 additions & 0 deletions corpus/templates/impulse/admin/team_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ <h3>Members</h3>
<tr>
<th></th>
<th>Name</th>
<th>Email</th>
<th>From NITK?</th>
<th>College Name</th>
<th>IEEE Member?</th>
Expand All @@ -29,10 +30,12 @@ <h3>Members</h3>
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ member.user }}</td>
<td>{{ member.user.email }} </td>
<td>{{ member.from_nitk|yesno:"Yes,No" }}</td>
<td>{{ member.college_name }}</td>
<td>{{ member.ieee_member|yesno:"Yes,No" }}</td>
<td>{{ member.ieee_membership_no }}</td>
{% comment %} Whether in team {% endcomment %}
</tr>
{% endfor %}
</tbody>
Expand Down
4 changes: 4 additions & 0 deletions corpus/templates/impulse/admin/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ <h1 class="text-center">User Management</h1>
<tr>
<th></th>
<th>Name</th>
<th>Email</th>
<th>From NITK?</th>
<th>College Name</th>
<th>IEEE Member?</th>
<th>IEEE Membership Number</th>
<th>In a Team?</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ user.user }}</td>
<td>{{ user.user.email }}</td>
<td>{{ user.from_nitk|yesno:"Yes,No" }}</td>
<td>{{ user.college_name }}</td>
<td>{{ user.ieee_member|yesno:"Yes,No" }}</td>
<td>{{ user.ieee_membership_no }}</td>
<td>{{ user.team|yesno:"Yes,No" }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
Loading

0 comments on commit a563ba3

Please sign in to comment.