Skip to content

Commit

Permalink
Merge pull request #525 from DevCom-IITB/Events
Browse files Browse the repository at this point in the history
Events
  • Loading branch information
HariRags authored Nov 19, 2024
2 parents bfdb31e + d0a7a10 commit ad37249
Show file tree
Hide file tree
Showing 39 changed files with 2,138 additions and 107 deletions.
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
exclude = .git,__pycache__,backend/settings*,*/migrations/*,venv,.venv
ignore = E302,E731,W503
max-complexity = 15
max-line-length = 120
max-complexity = 25
max-line-length = 150
10 changes: 8 additions & 2 deletions backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
# SSO Config
SSO_TOKEN_URL = "https://gymkhana.iitb.ac.in/sso/oauth/token/"
SSO_PROFILE_URL = "https://gymkhana.iitb.ac.in/sso/user/api/user/?fields=first_name,last_name,type,profile_picture,sex,username,email,program,contacts,insti_address,secondary_emails,mobile,roll_number"
SSO_CLIENT_ID = "HeKlfCluQLxa5cG5c4yHYiAEFZynroiKwylpiwNV"
SSO_CLIENT_ID_SECRET_BASE64 = "SGVLbGZDbHVRTHhhNWNHNWM0eUhZaUFFRlp5bnJvaUt3eWxwaXdOVjpYbDg4OHNaOWFhbVVmV1FMR0Y3SjI1MU5taUFYeHRtdzRtM3pHejJLUVQ1d3M0b3hTRGNCTnhSNWw4SXpYbHNDTVVWVHh3MUE0VXRnRU5YZ1FpWlFDZ1RUcERoVHFXeUZmckhLdDhadU5SQk9SY2Q3Z2ZmWjNXUzQ5bGxCMXNBUg=="
SSO_CLIENT_ID = "0vptOdXpmB8MIGhV6ZeADQxNQ7xuaa3ntITZwqPX"
SSO_CLIENT_ID_SECRET_BASE64 = "MHZwdE9kWHBtQjhNSUdoVjZaZUFEUXhOUTd4dWFhM250SVRad3FQWDpsanRQbVN2WGZVTnlXZEVRTWQ1aElaYUNXRXZyVFRXTllTU0p3cExwbUhTZ1pTRXI5WUdZWm40SHFOczZlWHBhQjBlSXhzV3p2UlJSSTRoM3FreDJlbmFrSzczUXhPRldiVFh6RkRuUFk4aVdNeERuZndXdU8yOEg0eVloSlpWZw=="

# Password Login
SSO_DEFAULT_REDIR = "https://insti.app/login"
Expand Down Expand Up @@ -72,4 +72,10 @@
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = "587"
EMAIL_HOST_USER = ""
EMAIL_HOST_PASSWORD = ""
EMAIL_EVENT_HOST_USER = ""
EMAIL_USE_TLS = True
RECIPIENT_LIST = ['[email protected]', '[email protected]']
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
AUTH_USER = ""
2 changes: 1 addition & 1 deletion bans/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from uuid import uuid4
from django.db import models
from users.models import UserProfile

# Create your models here.
Expand Down
19 changes: 7 additions & 12 deletions bans/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ def list(self, request):
queryset = self.get_queryset()
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
else:
return forbidden_no_privileges()
return forbidden_no_privileges()

@login_required_ajax
def retrieve(self, request, pk):
if user_has_insti_privilege(request.user.profile, "RoleB"):
instance = get_object_or_404(self.queryset, pk=pk)
serializer = self.get_serializer(instance)
return Response(serializer.data)
else:
return forbidden_no_privileges()
return forbidden_no_privileges()

@login_required_ajax
def create(self, request):
Expand Down Expand Up @@ -69,11 +67,10 @@ def create(self, request):
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
else:
return forbidden_no_privileges()
return forbidden_no_privileges()

@login_required_ajax
def update(self, request, pk=None, *args, **kwargs):
def update(self, request, *args, pk=None, **kwargs):
if user_has_insti_privilege(request.user.profile, "RoleB"):
instance = get_object_or_404(self.queryset, pk=pk)
serializer = self.get_serializer(instance, data=request.data, partial=True)
Expand All @@ -84,14 +81,12 @@ def update(self, request, pk=None, *args, **kwargs):
return Response(serializer.data)

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
else:
return forbidden_no_privileges()
return forbidden_no_privileges()

@login_required_ajax
def destroy(self, request, pk=None, *args, **kwargs):
def destroy(self, request, *args, pk=None, **kwargs):
if user_has_insti_privilege(request.user.profile, "RoleB"):
instance = get_object_or_404(self.queryset, pk=pk)
instance.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
else:
return forbidden_no_privileges()
return forbidden_no_privileges()
2 changes: 1 addition & 1 deletion buyandsell/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from uuid import uuid4
from django.db.models.deletion import SET
from django.db.models.fields.related import ForeignKey
from django.db import models
from uuid import uuid4
from helpers.misc import get_url_friendly

PDT_NAME_MAX_LENGTH = 60
Expand Down
8 changes: 4 additions & 4 deletions buyandsell/views.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""Views for BuyAndSell."""
import json
from django.conf import settings
from django.core.mail import send_mail
from rest_framework.response import Response
from rest_framework import viewsets
from django.shortcuts import get_object_or_404
from django.db.models import Q
from django.utils import timezone
from roles.helpers import login_required_ajax
from buyandsell.models import Ban, Category, ImageURL, Limit, Product, Report
from buyandsell.serializers import ProductSerializer
from helpers.misc import query_search
from users.models import UserProfile
from django.db.models import Q
import json
from django.utils import timezone

REPORTS_THRES = 3

Expand Down Expand Up @@ -93,7 +93,7 @@ def list(self, request):
data = ProductSerializer(queryset, many=True).data
return Response(data)

def get_contact_details(userpro: UserProfile):
def get_contact_details(self, userpro: UserProfile):
return f"""
Phone: {userpro.contact_no}
Email: {userpro.email}"""
Expand Down
3 changes: 1 addition & 2 deletions community/serializer_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def get_posted_by(self, obj):
pb.name = "Anonymous"
pb.id = "null"
pb.ldap_id = "null"
pb.profile_pic = \
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSM9q9XJKxlskry5gXTz1OXUyem5Ap59lcEGg&usqp=CAU'
pb.profile_pic = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSM9q9XJKxlskry5gXTz1OXUyem5Ap59lcEGg&usqp=CAU"
elif (
obj.anonymous
and "return_for_mod" in self.context
Expand Down
3 changes: 1 addition & 2 deletions community/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ def get_posted_by(self, obj):
pb.name = "Anonymous"
pb.id = "null"
pb.ldap_id = "null"
pb.profile_pic = \
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSM9q9XJKxlskry5gXTz1OXUyem5Ap59lcEGg&usqp=CAU'
pb.profile_pic = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSM9q9XJKxlskry5gXTz1OXUyem5Ap59lcEGg&usqp=CAU"
elif (
obj.anonymous
and "return_for_mod" in self.context
Expand Down
4 changes: 3 additions & 1 deletion community/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def test_communitypost_yourlist(self):
self.assertEqual(
response.data["count"],
CommunityPost.objects.filter(
thread_rank=1, posted_by=self.user1.profile, community=self.test_community_1
thread_rank=1,
posted_by=self.user1.profile,
community=self.test_community_1,
).count(),
)
self.assertListEqual(
Expand Down
1 change: 1 addition & 0 deletions events/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class EventAdmin(admin.ModelAdmin):
list_filter = (
"start_time",
"bodies",
"venues",
)
list_display = (
"name",
Expand Down
22 changes: 22 additions & 0 deletions events/migrations/0032_auto_20231211_2316.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.16 on 2023-12-11 17:46

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("events", "0031_alter_event_event_interest"),
]

operations = [
migrations.AddField(
model_name="event",
name="email_body",
field=models.TextField(default=""),
),
migrations.AddField(
model_name="event",
name="email_verified",
field=models.BooleanField(default=False),
),
]
17 changes: 17 additions & 0 deletions events/migrations/0033_rename_email_body_event_longdescription.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.16 on 2023-12-12 10:01

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("events", "0032_auto_20231211_2316"),
]

operations = [
migrations.RenameField(
model_name="event",
old_name="email_body",
new_name="longdescription",
),
]
37 changes: 37 additions & 0 deletions events/migrations/0034_event_verification_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 3.2.16 on 2023-12-13 13:01

from django.db import migrations
import multiselectfield.db.fields


class Migration(migrations.Migration):
dependencies = [
("events", "0033_rename_email_body_event_longdescription"),
]

operations = [
migrations.AddField(
model_name="event",
name="verification_body",
field=multiselectfield.db.fields.MultiSelectField(
choices=[
(
"91199c20-7488-41c5-9f6b-6f6c7c5b897d",
"Institute Cultural Council",
),
(
"81e05a1a-7fd1-45b5-84f6-074e52c0f085",
"Institute Technical Council",
),
(
"a9f81e69-fcc9-4fe3-b261-9e5e7a13f898",
"Institute Sports Council",
),
("f3ae5230-4441-4586-81a8-bf75a2e47318", "Hostel Affairs"),
],
default="91199c20-7488-41c5-9f6b-6f6c7c5b897d",
max_length=147,
),
preserve_default=False,
),
]
35 changes: 35 additions & 0 deletions events/migrations/0035_alter_event_verification_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.2.16 on 2023-12-14 04:48

from django.db import migrations
import multiselectfield.db.fields


class Migration(migrations.Migration):
dependencies = [
("events", "0034_event_verification_body"),
]

operations = [
migrations.AlterField(
model_name="event",
name="verification_body",
field=multiselectfield.db.fields.MultiSelectField(
choices=[
(
"d920d898-0998-4ed9-8fb8-f270310b2bec",
"Institute Cultural Council",
),
(
"ae084ebb-6009-4095-a774-44ad0f107bc0",
"Institute Technical Council",
),
(
"0aa10bcc-f08f-44c6-bf50-1ce9b5c2f0f0",
"Institute Sports Council",
),
("6c43632e-de1f-4088-8e77-60af60139e91", "Hostel Affairs"),
],
max_length=147,
),
),
]
35 changes: 35 additions & 0 deletions events/migrations/0036_alter_event_verification_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.2.16 on 2023-12-14 07:32

from django.db import migrations
import multiselectfield.db.fields


class Migration(migrations.Migration):
dependencies = [
("events", "0035_alter_event_verification_body"),
]

operations = [
migrations.AlterField(
model_name="event",
name="verification_body",
field=multiselectfield.db.fields.MultiSelectField(
choices=[
(
"Institute Cultural Council",
"d920d898-0998-4ed9-8fb8-f270310b2bec",
),
(
"ae084ebb-6009-4095-a774-44ad0f107bc0",
"Institute Technical Council",
),
(
"0aa10bcc-f08f-44c6-bf50-1ce9b5c2f0f0",
"Institute Sports Council",
),
("6c43632e-de1f-4088-8e77-60af60139e91", "Hostel Affairs"),
],
max_length=137,
),
),
]
35 changes: 35 additions & 0 deletions events/migrations/0037_alter_event_verification_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.2.16 on 2023-12-14 07:34

from django.db import migrations
import multiselectfield.db.fields


class Migration(migrations.Migration):
dependencies = [
("events", "0036_alter_event_verification_body"),
]

operations = [
migrations.AlterField(
model_name="event",
name="verification_body",
field=multiselectfield.db.fields.MultiSelectField(
choices=[
(
"d920d898-0998-4ed9-8fb8-f270310b2bec",
"Institute Cultural Council",
),
(
"ae084ebb-6009-4095-a774-44ad0f107bc0",
"Institute Technical Council",
),
(
"0aa10bcc-f08f-44c6-bf50-1ce9b5c2f0f0",
"Institute Sports Council",
),
("6c43632e-de1f-4088-8e77-60af60139e91", "Hostel Affairs"),
],
max_length=147,
),
),
]
35 changes: 35 additions & 0 deletions events/migrations/0038_alter_event_verification_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.2.16 on 2023-12-14 10:06

from django.db import migrations
import multiselectfield.db.fields


class Migration(migrations.Migration):
dependencies = [
("events", "0037_alter_event_verification_body"),
]

operations = [
migrations.AlterField(
model_name="event",
name="verification_body",
field=multiselectfield.db.fields.MultiSelectField(
choices=[
(
"91199c20-7488-41c5-9f6b-6f6c7c5b897d",
"Institute Cultural Council",
),
(
"81e05a1a-7fd1-45b5-84f6-074e52c0f085",
"Institute Technical Council",
),
(
"a9f81e69-fcc9-4fe3-b261-9e5e7a13f898",
"Institute Sports Council",
),
("f3ae5230-4441-4586-81a8-bf75a2e47318", "Hostel Affairs"),
],
max_length=147,
),
),
]
Loading

0 comments on commit ad37249

Please sign in to comment.