Skip to content
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

Dev server #2161

Merged
merged 20 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
aae1925
Add LaunchPadListAdmin endpoint
SharonAliyas5573 Jul 9, 2024
dfdd982
Add user profile APIs in Launchpad
SharonAliyas5573 Jul 9, 2024
9c23fd0
Merge pull request #2151 from SharonAliyas5573/dev
jelanmathewjames Jul 10, 2024
9590c29
Merge pull request #2152 from gtech-mulearn/dev
jelanmathewjames Jul 10, 2024
7ef6514
Fix launchpad profile view
SharonAliyas5573 Jul 10, 2024
b48a210
Merge branch 'gtech-mulearn:dev' into dev
SharonAliyas5573 Jul 10, 2024
ce1b24d
Merge pull request #2153 from SharonAliyas5573/dev
jelanmathewjames Jul 10, 2024
cb8c55d
Merge pull request #2154 from gtech-mulearn/dev
jelanmathewjames Jul 10, 2024
8e1c5bc
Refactor LaunchPadListAdmin get method to use query_params instead of…
SharonAliyas5573 Jul 11, 2024
8f559fd
Merge branch 'dev' of https://github.com/SharonAliyas5573/mulearnback…
SharonAliyas5573 Jul 11, 2024
6c06d97
Merge pull request #2155 from SharonAliyas5573/dev
jelanmathewjames Jul 11, 2024
c97eae4
Merge pull request #2156 from gtech-mulearn/dev
jelanmathewjames Jul 11, 2024
1a76327
Update foreign key column names in LaunchPad model
SharonAliyas5573 Jul 12, 2024
7a1a77a
Merge branch 'gtech-mulearn:dev' into dev
SharonAliyas5573 Jul 12, 2024
8e665e9
Merge pull request #2157 from SharonAliyas5573/dev
jelanmathewjames Jul 12, 2024
5d3f946
feat: BadgesAPI to retrieve completed tasks for a given user
jelanmathewjames Jul 12, 2024
1d48405
Merge pull request #2158 from gtech-mulearn/dev
jelanmathewjames Jul 12, 2024
a7c4675
Merge branch 'gtech-mulearn:dev' into dev
jelanmathewjames Jul 12, 2024
be9ee6c
Merge pull request #2159 from jelanmathewjames/dev
jelanmathewjames Jul 12, 2024
3693889
Merge pull request #2160 from gtech-mulearn/dev
jelanmathewjames Jul 12, 2024
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
16 changes: 16 additions & 0 deletions api/dashboard/profile/profile_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,19 @@ def get(self, request, uuid):
return CustomResponse(
response="The given UUID seems to be invalid"
).get_failure_response()


class BadgesAPI(APIView):
def get(self, request, muid):
try:
user = User.objects.get(muid=muid)
hastags = ["#tfp2.0-scratch"]
response_data = {"full_name": user.full_name, "completed_tasks":[]}
for tag in hastags:
if KarmaActivityLog.objects.filter(user=user, task__hashtag=tag).exists():
response_data["completed_tasks"] = tag
return CustomResponse(response=response_data).get_success_response()
except User.DoesNotExist:
return CustomResponse(
response="The given muid seems to be invalid"
).get_failure_response()
2 changes: 1 addition & 1 deletion api/dashboard/profile/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

urlpatterns = [
path('', profile_view.UserProfileEditView.as_view()),

path('badges/<str:muid>', profile_view.BadgesAPI.as_view()),
path('user-profile/', profile_view.UserProfileAPI.as_view()),
path('ig-edit/', profile_view.UserIgEditView.as_view()),
path('user-profile/<str:muid>/', profile_view.UserProfileAPI.as_view()),
Expand Down
124 changes: 121 additions & 3 deletions api/launchpad/launchpad_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

from .serializers import LaunchpadLeaderBoardSerializer, LaunchpadParticipantsSerializer, LaunchpadUserListSerializer,\
CollegeDataSerializer, LaunchpadUserSerializer, UserProfileUpdateSerializer, LaunchpadUpdateUserSerializer
from api.dashboard.profile.profile_serializer import UserProfileSerializer , LinkSocials ,UserLevelSerializer ,UserLogSerializer

from utils.response import CustomResponse
from utils.utils import CommonUtils, ImportCSV
from utils.types import LaunchPadLevels, LaunchPadRoles
from db.user import User, UserRoleLink
from utils.permission import JWTUtils
from db.user import User, UserRoleLink , Role , Socials
from db.organization import UserOrganizationLink, Organization
from db.task import KarmaActivityLog
from db.launchpad import LaunchPadUsers, LaunchPadUserCollegeLink
from db.task import KarmaActivityLog , Level
from db.launchpad import LaunchPadUsers, LaunchPadUserCollegeLink , LaunchPad



Expand Down Expand Up @@ -470,3 +473,118 @@ def post(self, request):
if error:
return CustomResponse(message=errors).get_failure_response()
return CustomResponse(general_message="Successfully added users").get_success_response()


class LaunchPadListAdmin(APIView):

def get(self, request):
auth_mail = request.query_params.get('current_user', None)
auth_mail = auth_mail[0] if isinstance(auth_mail, list) else auth_mail
if not (auth_user := LaunchPadUsers.objects.filter(email=auth_mail, role=LaunchPadRoles.ADMIN.value).first()):
return CustomResponse(general_message="Unauthorized").get_failure_response()
total_karma_subquery = KarmaActivityLog.objects.filter(
user=OuterRef('id'),
task__event='launchpad',
appraiser_approved=True,
).values('user').annotate(
total_karma=Sum('karma')
).values('total_karma')
allowed_org_types = ["College", "School", "Company"]

intro_task_completed_users = KarmaActivityLog.objects.filter(
task__event='launchpad',
appraiser_approved=True,
task__hashtag='#lp24-introduction',
).values('user')

latest_org_link = UserOrganizationLink.objects.filter(
user=OuterRef('id'),
org__org_type__in=allowed_org_types
).order_by('-created_at').values('org__title')[:1]

latest_district = UserOrganizationLink.objects.filter(
user=OuterRef('id'),
org__org_type__in=allowed_org_types
).order_by('-created_at').values('org__district__name')[:1]

latest_state = UserOrganizationLink.objects.filter(
user=OuterRef('id'),
org__org_type__in=allowed_org_types
).order_by('-created_at').values('org__district__zone__state__name')[:1]

users = User.objects.filter(
karma_activity_log_user__task__event="launchpad",
karma_activity_log_user__appraiser_approved=True,
id__in=intro_task_completed_users
).annotate(
karma=Subquery(total_karma_subquery, output_field=IntegerField()),
org=Subquery(latest_org_link),
district_name=Subquery(latest_district),
state=Subquery(latest_state),
time_=Max("karma_activity_log_user__created_at"),
).order_by("-karma", "time_")

paginated_queryset = CommonUtils.get_paginated_queryset(
users,
request,
["full_name", "karma", "org", "district_name", "state"]
)

serializer = LaunchpadLeaderBoardSerializer(
paginated_queryset.get("queryset"), many=True
)
return CustomResponse().paginated_response(
data=serializer.data, pagination=paginated_queryset.get("pagination")
)


class BaseAPI(APIView):
def get_authenticated_user(self, request, launchpad_id):
auth_mail = request.query_params.get('current_user', None)
auth_mail = auth_mail[0] if isinstance(auth_mail, list) else auth_mail
if launchpad_id is None:
return None, CustomResponse(general_message="No launchpad id provided").get_failure_response()
if not (auth_user := LaunchPadUsers.objects.filter(email=auth_mail, role=LaunchPadRoles.ADMIN.value).first()):
return None, CustomResponse(general_message="Unauthorized").get_failure_response()
try:
user = LaunchPad.objects.get(launchpad_id=launchpad_id).user
except LaunchPad.DoesNotExist:
return None, CustomResponse(general_message="Invalid Launchpad ID").get_failure_response()
return user, None

class UserProfileAPI(BaseAPI):
def get(self, request, launchpad_id=None):
user, response = self.get_authenticated_user(request, launchpad_id)
if response:
return response
serializer = UserProfileSerializer(user, many=False)
return CustomResponse(response=serializer.data).get_success_response()

class GetSocialsAPI(BaseAPI):
def get(self, request, launchpad_id=None):
user, response = self.get_authenticated_user(request, launchpad_id)
if response:
return response
social_instance = Socials.objects.filter(user_id=user.id).first()
serializer = LinkSocials(instance=social_instance)
return CustomResponse(response=serializer.data).get_success_response()

class UserLevelsAPI(BaseAPI):
def get(self, request, launchpad_id=None):
user, response = self.get_authenticated_user(request, launchpad_id)
if response:
return response
user_levels_link_query = Level.objects.all().order_by("level_order")
serializer = UserLevelSerializer(user_levels_link_query, many=True, context={"user_id": user.id})
return CustomResponse(response=serializer.data).get_success_response()

class UserLogAPI(BaseAPI):
def get(self, request, launchpad_id=None):
user, response = self.get_authenticated_user(request, launchpad_id)
if response:
return response
karma_activity_log = KarmaActivityLog.objects.filter(user=user.id, appraiser_approved=True).order_by("-created_at")
if not karma_activity_log:
return CustomResponse(general_message="No karma details available for user").get_success_response()
serializer = UserLogSerializer(karma_activity_log, many=True)
return CustomResponse(response=serializer.data).get_success_response()
10 changes: 8 additions & 2 deletions api/launchpad/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
from db.user import User
from db.organization import UserOrganizationLink, Organization
from db.task import KarmaActivityLog
from db.launchpad import LaunchPadUsers, LaunchPadUserCollegeLink
from db.launchpad import LaunchPadUsers, LaunchPadUserCollegeLink, LaunchPad
from utils.types import LaunchPadRoles
from utils.utils import DateTimeUtils

class LaunchPadIDSerializer(serializers.ModelSerializer):
class Meta:
model = LaunchPad
fields = ('launchpad_id')


class LaunchpadLeaderBoardSerializer(serializers.ModelSerializer):
rank = serializers.SerializerMethodField()
Expand All @@ -19,10 +24,11 @@ class LaunchpadLeaderBoardSerializer(serializers.ModelSerializer):
org = serializers.CharField(allow_null=True, allow_blank=True)
district_name = serializers.CharField(allow_null=True, allow_blank=True)
state = serializers.CharField(allow_null=True, allow_blank=True)
launchpad_id = LaunchPadIDSerializer(read_only=True)

class Meta:
model = User
fields = ("rank", "full_name", "actual_karma", "karma", "org", "district_name", "state")
fields = ("rank", "full_name", "actual_karma", "karma", "org", "district_name", "state","launchpad_id")

def get_rank(self, obj):
total_karma_subquery = KarmaActivityLog.objects.filter(
Expand Down
5 changes: 5 additions & 0 deletions api/launchpad/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@
path('user-profile/', launchpad_views.UserProfile.as_view()),
path('user-college-data/', launchpad_views.UserBasedCollegeData.as_view()),
path('bulk-user-college-link/', launchpad_views.BulkLaunchpadUser.as_view()),
path('list-participants-admin/', launchpad_views.LaunchPadListAdmin.as_view()),
path('user-details/<str:launchpad_id>/', launchpad_views.UserProfileAPI.as_view()),
path('socials/<str:launchpad_id>/', launchpad_views.GetSocialsAPI.as_view()),
path('user-log/<str:launchpad_id>/', launchpad_views.UserLogAPI.as_view()),
path('get-user-levels/<str:launchpad_id>/', launchpad_views.UserLevelsAPI.as_view()),
]
18 changes: 16 additions & 2 deletions db/launchpad.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models

from django.conf import settings
from db.user import User
from db.organization import Organization


Expand Down Expand Up @@ -30,4 +31,17 @@ class LaunchPadUserCollegeLink(models.Model):

class Meta:
managed = False
db_table = 'launchpad_user_college_link'
db_table = 'launchpad_user_college_link'

class LaunchPad(models.Model):
id = models.CharField(primary_key=True, max_length=36)
user = models.ForeignKey(User, on_delete=models.SET(settings.SYSTEM_ADMIN_ID), related_name="launchpad_user")
launchpad_id = models.CharField(max_length=100, unique=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
created_by = models.ForeignKey(User, on_delete=models.SET(settings.SYSTEM_ADMIN_ID), related_name="launchpad_created_by", db_column='created_by')
updated_by = models.ForeignKey(User,on_delete=models.SET(settings.SYSTEM_ADMIN_ID), related_name="launchpad_updated_by", db_column='updated_by')

class Meta:
managed = False
db_table = 'launchpad'
Loading