Skip to content

Commit

Permalink
Merge pull request #1554 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
generating qr in backend function
  • Loading branch information
Aashish Vinu authored Nov 16, 2023
2 parents 95b824b + 4dd9282 commit ed26805
Show file tree
Hide file tree
Showing 22 changed files with 414 additions and 160 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ EMAIL_USE_TLS=True
FROM_MAIL =
PROTECTED_API_KEY=
FR_DOMAIN_NAME=http://127.0.0.1:8000
BE_DOMAIN_NAME = http://127.0.0.1:8000
AUTH_DOMAIN=http://127.0.0.1:8000

26 changes: 15 additions & 11 deletions api/dashboard/college/college_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@

class CollegeApi(APIView):
def get(self, request, college_code=None):
colleges = (
College.objects.select_related("created_by", "updated_by", "org")
.prefetch_related(
Prefetch(
"org__org_discord_link_org_id",
queryset=OrgDiscordLink.objects.all(),
)
)
.all()
)
if college_code:
colleges = colleges.filter(org__code=college_code)
colleges = College.objects.filter(id=college_code)
else:
colleges = College.objects.all()

# College.objects.select_related("created_by", "updated_by", "org")
# .prefetch_related(
# Prefetch(
# "org__org_discord_link_org_id",
# queryset=OrgDiscordLink.objects.all(),
# )
# )
# .all()

# if college_code:
# colleges = colleges.filter(org__code=college_code)
serializer = CollegeListSerializer(colleges, many=True)
return CustomResponse(response=serializer.data).get_success_response()

Expand Down
30 changes: 24 additions & 6 deletions api/dashboard/college/serializer.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
import uuid
from utils.utils import DateTimeUtils
from rest_framework import serializers
from db.organization import College, Organization, OrgDiscordLink
from db.organization import College, Organization, OrgDiscordLink, UserOrganizationLink
from db.user import User
from utils.types import RoleType
from django.db.models import Count


class CollegeListSerializer(serializers.ModelSerializer):
created_by = serializers.CharField(source="created_by.fullname")
updated_by = serializers.CharField(source="updated_by.fullname")
org = serializers.CharField(source="org.title")
discord_link = serializers.SerializerMethodField()
number_of_students = serializers.SerializerMethodField()
leadname = serializers.CharField(source="lead.fullname",default=None)
# discord_link = serializers.SerializerMethodField()

class Meta:
model = College
fields = "__all__"

def get_discord_link(self, obj):
return obj.org.org_discord_link_org_id.exists()
fields = [
"id",
"level",
"org",
"updated_by",
"created_by",
"updated_at",
"created_at",
"number_of_students",
"leadname",
]

def get_number_of_students(self, obj):
return obj.org.user_organization_link_org.filter(user__user_role_link_user__role__title=RoleType.STUDENT.value).count()

# def get_discord_link(self, obj):
# return obj.org.org_discord_link_org_id.exists()


class CollegeCreateDeleteSerializer(serializers.ModelSerializer):
Expand Down
6 changes: 3 additions & 3 deletions api/dashboard/lc/dash_lc_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def get_rank(self, obj):
)

def get_previous_meetings(self, obj):
previous_meetings = obj.circle_meeting_log_learning_circle.all().values(
return obj.circle_meeting_log_learning_circle.all().values(
"id",
"meet_time",
"day",
Expand Down Expand Up @@ -486,7 +486,7 @@ def update(self, instance, validated_data):
return instance


class LearningCircleCreateEditDeleteSerializer(serializers.ModelSerializer):
class ScheduleMeetingSerializer(serializers.ModelSerializer):
class Meta:
model = LearningCircle
fields = [
Expand All @@ -504,7 +504,7 @@ def update(self, instance, validated_data):
return instance


class MeetCreateEditDeleteSerializer(serializers.ModelSerializer):
class MeetRecordsCreateEditDeleteSerializer(serializers.ModelSerializer):

class Meta:
model = CircleMeetingLog
Expand Down
85 changes: 40 additions & 45 deletions api/dashboard/lc/dash_lc_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.shortcuts import redirect
from rest_framework.views import APIView


from api.notification.notifications_utils import NotificationUtils
from db.learning_circle import LearningCircle, UserCircleLink, CircleMeetingLog
from db.user import User
Expand All @@ -16,7 +15,7 @@
from .dash_lc_serializer import LearningCircleSerializer, LearningCircleCreateSerializer, LearningCircleHomeSerializer, \
LearningCircleUpdateSerializer, LearningCircleJoinSerializer, LearningCircleCreateEditDeleteSerializer, \
LearningCircleMainSerializer, LearningCircleNoteSerializer, LearningCircleDataSerializer, \
LearningCircleMemberListSerializer, MeetCreateEditDeleteSerializer
LearningCircleMemberListSerializer, MeetRecordsCreateEditDeleteSerializer

domain = config("FR_DOMAIN_NAME")
from_mail = config("FROM_MAIL")
Expand All @@ -32,6 +31,7 @@ class LearningCircleListApi(APIView):
CustomResponse: A custom response containing a list of learning circles
associated with the user.
"""

def get(self, request): # Lists user's learning circle
user_id = JWTUtils.fetch_user_id(request)

Expand Down Expand Up @@ -177,7 +177,6 @@ def post(self, request, circle_code=None):
Q(circle_code=circle_code) |
Q(name__icontains=circle_code)
).exists():

return CustomResponse(
general_message='invalid circle code or Circle Name'
).get_failure_response()
Expand Down Expand Up @@ -205,14 +204,7 @@ class LearningCircleJoinApi(APIView):
def post(self, request, circle_id):
user_id = JWTUtils.fetch_user_id(request)
user = User.objects.filter(id=user_id).first()

full_name = f'{user.fullname}'

user_learning_circle = UserCircleLink.objects.filter(
circle_id=circle_id,
lead=True
).first()

serializer = LearningCircleJoinSerializer(
data=request.data,
context={
Expand All @@ -222,12 +214,10 @@ def post(self, request, circle_id):
)
if serializer.is_valid():
serializer.save()
user = User.objects.filter(
id=user_learning_circle.user.id
).first()
lead = UserCircleLink.objects.filter(circle_id=circle_id, lead=True).first().user_id

NotificationUtils.insert_notification(
user=user,
user=lead,
title="Member Request",
description=f"{full_name} has requested to join your learning circle",
button="LC",
Expand All @@ -251,7 +241,6 @@ def get(self, request, circle_id, member_id=None):
if not LearningCircle.objects.filter(
id=circle_id
).exists():

return CustomResponse(
general_message='Learning Circle not found'
).get_failure_response()
Expand Down Expand Up @@ -300,7 +289,6 @@ def patch(self, request, member_id, circle_id):
).exists() or not LearningCircle.objects.filter(
id=circle_id
).exists():

return CustomResponse(
general_message='Learning Circle Not Available'
).get_failure_response()
Expand Down Expand Up @@ -368,7 +356,7 @@ def delete(self, request, circle_id):
usr_circle_link = UserCircleLink.objects.filter(
circle__id=circle_id,
user__id=user_id
).first()
).first()

if not usr_circle_link:
return CustomResponse(general_message='User not part of circle').get_failure_response()
Expand All @@ -377,7 +365,7 @@ def delete(self, request, circle_id):
if (
next_lead := UserCircleLink.objects.filter(
circle__id=circle_id, accepted=1
)
)
.exclude(user__id=user_id)
.order_by('accepted_at')
.first()
Expand All @@ -392,31 +380,41 @@ def delete(self, request, circle_id):
if not UserCircleLink.objects.filter(circle__id=circle_id).exists():
if learning_circle := LearningCircle.objects.filter(
id=circle_id
).first():
).first():
learning_circle.delete()
return CustomResponse(general_message='Learning Circle Deleted').get_success_response()

return CustomResponse(general_message='Left').get_success_response()


class MeetGetPostPatchDeleteAPI(APIView):

def get(self, request, meet_id):
class MeetRecordsGetPostPatchDeleteAPI(APIView):

def get(self, request, circle_id=None, meet_id=None):

if meet_id:
circle_meeting_log = CircleMeetingLog.objects.filter(
id=meet_id
).values(
"id",
"meet_time",
"meet_place",
"day",
"attendees",
"agenda",
meet_created_by=F("created_by__first_name"),
meet_created_at=F("created_at"),
meet_updated_by=F("updated_by__first_name"),
meet_updated_at=F("updated_at"),
)

circle_meeting_log = CircleMeetingLog.objects.filter(
id=meet_id
).values(
"id",
"meet_time",
"meet_place",
"day",
"attendees",
"agenda",
meet_created_by=F("created_by__first_name"),
meet_created_at=F("created_at"),
meet_updated_by=F("updated_by__first_name"),
meet_updated_at=F("updated_at"),
)
if circle_id:
circle_meeting_log = CircleMeetingLog.objects.filter(
circle_id=circle_id
).values(
"id",
"meet_time",
"day"
)

return CustomResponse(
response=circle_meeting_log
Expand All @@ -425,7 +423,7 @@ def get(self, request, meet_id):
def post(self, request, circle_id):
user_id = JWTUtils.fetch_user_id(request)

serializer = MeetCreateEditDeleteSerializer(
serializer = MeetRecordsCreateEditDeleteSerializer(
data=request.data,
context={
'user_id': user_id,
Expand All @@ -450,7 +448,7 @@ def patch(self, request, circle_id):
id=circle_id
).first()

serializer = MeetCreateEditDeleteSerializer(
serializer = MeetRecordsCreateEditDeleteSerializer(
learning_circle,
data=request.data,
context={
Expand Down Expand Up @@ -486,7 +484,6 @@ def patch(self, request, circle_id, lead_id):
if not LearningCircle.objects.filter(
id=circle_id
).exists():

return CustomResponse(
general_message='Learning Circle not found'
).get_failure_response()
Expand Down Expand Up @@ -535,7 +532,7 @@ def post(self, request):
from_mail,
[user.email],
fail_silently=False,
)
)
return CustomResponse(general_message='User Invited').get_success_response()


Expand Down Expand Up @@ -586,12 +583,12 @@ def post(self, request, circle_id, muid):
"circle_id": circle_id,
"muid": muid,
"email": receiver_email,
}
}
status = send_template_mail(
context=context,
subject="MuLearn - Invitation to learning circle",
address=html_address,
)
)

if status == 1:
UserCircleLink.objects.create(
Expand All @@ -601,7 +598,7 @@ def post(self, request, circle_id, muid):
is_invited=True,
accepted=False,
created_at=DateTimeUtils.get_current_utc_time(),
)
)

return CustomResponse(
general_message='User Invited'
Expand Down Expand Up @@ -654,5 +651,3 @@ def post(self, request, circle_id, muid, status):
return CustomResponse(
general_message='User rejected invitation'
).get_failure_response()


10 changes: 7 additions & 3 deletions api/dashboard/lc/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
path('list-all/', dash_lc_view.TotalLearningCircleListApi.as_view()),
path('create/', dash_lc_view.LearningCircleCreateApi.as_view()),
path('list-members/<str:circle_id>/', dash_lc_view.LearningCircleListMembersApi.as_view()),
path('schedule-meet/<str:circle_id>/', dash_lc_view.ScheduleMeetAPI.as_view()),
# path('invite/', dash_lc_view.LearningCircleInviteLeadAPI.as_view()),
path('list-all/<str:circle_code>/', dash_lc_view.TotalLearningCircleListApi.as_view()),
path('join/<str:circle_id>/', dash_lc_view.LearningCircleJoinApi.as_view()),
path('<str:circle_id>/<str:member_id>/', dash_lc_view.LearningCircleHomeApi.as_view()),
path('<str:circle_id>/', dash_lc_view.LearningCircleHomeApi.as_view()),
path('meeting-log/<str:meet_id>/', dash_lc_view.MeetGetPostPatchDeleteAPI.as_view()),
path('meet/edit/<str:circle_id>/', dash_lc_view.MeetGetPostPatchDeleteAPI.as_view()), # optim
path('meet/create/<str:circle_id>/', dash_lc_view.MeetGetPostPatchDeleteAPI.as_view()), # optim
# meet record
path('meet-record/list-all/<str:circle_id>/', dash_lc_view.MeetRecordsGetPostPatchDeleteAPI.as_view()), # optim
path('meet-record/show/<str:meet_id>/', dash_lc_view.MeetRecordsGetPostPatchDeleteAPI.as_view()),
path('meet-record/edit/<str:circle_id>/', dash_lc_view.MeetRecordsGetPostPatchDeleteAPI.as_view()), # optim
path('meet-record/create/<str:circle_id>/', dash_lc_view.MeetRecordsGetPostPatchDeleteAPI.as_view()), # optim

path('member/invite/<str:circle_id>/<str:muid>/', dash_lc_view.LearningCircleInviteMemberAPI.as_view()),
path('member/invite/status/<str:circle_id>/<str:muid>/<str:status>/', dash_lc_view.LearningCircleInvitationStatus.as_view()),
path('lead/<str:circle_id>/<str:lead_id>/', dash_lc_view.LearningCircleLeadTransfer.as_view()),
Expand Down
6 changes: 3 additions & 3 deletions api/dashboard/location/location_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class StateCreateEditSerializer(serializers.ModelSerializer):
# value = serializers.CharField(source="id")
class Meta:
model = State
fields = ["label", "created_by", "updated_by"]
fields = ["label", "country", "created_by", "updated_by"]


class ZoneRetrievalSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -92,7 +92,7 @@ class ZoneCreateEditSerializer(serializers.ModelSerializer):

class Meta:
model = Zone
fields = ["label", "created_by", "updated_by"]
fields = ["label", "state", "created_by", "updated_by"]


class DistrictRetrievalSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -129,4 +129,4 @@ class DistrictCreateEditSerializer(serializers.ModelSerializer):

class Meta:
model = District
fields = ["label", "created_by", "updated_by"]
fields = ["label", "zone","created_by", "updated_by"]
Loading

0 comments on commit ed26805

Please sign in to comment.