Skip to content

Commit

Permalink
Merge branch 'dev-server' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
shaheenhyderk committed Dec 24, 2023
2 parents 3e5fa5e + 5c9e5d6 commit 48b4b40
Show file tree
Hide file tree
Showing 59 changed files with 1,139 additions and 573 deletions.
103 changes: 103 additions & 0 deletions alter-scripts/alter-1.43.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import os
import sys
import uuid
from decouple import config

import django

from connection import execute

os.chdir('..')
sys.path.append(os.getcwd())
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mulearnbackend.settings')
django.setup()

#order of socials table must be same as socials list
socials = [
"github",
"facebook",
"instagram",
"linkedin",
"dribble",
"behance",
"stackoverflow",
"medium",
"hackerrank"
]

def get_task_list(hashtag: str):
task_id = execute(f"""
SELECT id
FROM task_list
WHERE hashtag = '{hashtag}';
""")
return task_id[0][0] if task_id else None

def create_social_task():
user_id = config("SYSTEM_ADMIN_ID")
for ele in socials:
social = f"social_{ele}"

if get_task_list(f"#social_{ele}"):
continue

id = uuid.uuid4()
task_type = execute(f"""
SELECT id
FROM task_type
WHERE title = 'Mentor';
""")
execute(f"""
INSERT INTO task_list (id, hashtag, title, karma, type_id, updated_by, updated_at, created_by, created_at)
VALUES ('{id}', '#{social}', '{social}', 20, '{task_type[0][0]}', '{user_id}', now(), '{user_id}', now());
""")

def alter_task_message_id():
execute("""
ALTER TABLE karma_activity_log MODIFY COLUMN task_message_id VARCHAR(36)
""")

def give_karma(user_id, task_id):
id = uuid.uuid4()

log_id = execute(f"""
SELECT id
FROM karma_activity_log
WHERE user_id = '{user_id}' AND task_id = '{task_id}';
""")

if not log_id:
execute(f"""
INSERT INTO karma_activity_log (id, task_id, karma, user_id, updated_by, created_by, peer_approved, peer_approved_by, appraiser_approved_by, appraiser_approved, task_message_id, updated_at, created_at)
VALUES ('{id}', '{task_id}', 20, '{user_id}', '{user_id}', '{user_id}', true, '{user_id}', '{user_id}', true, null, now(), now());
""")
execute(f"""
UPDATE wallet SET karma = karma + 20 WHERE user_id = '{user_id}';
""")

def automate_socials_karma():
results = execute(f"""
SELECT
u.id, github, facebook, instagram, linkedin, dribble, behance, stackoverflow, medium, hackerrank
FROM
user AS u
INNER JOIN
socials AS s ON s.user_id = u.id;
"""
)

for result in results:
for idx, data in enumerate(result[1:]):
social = f"#social_{socials[idx]}"
if data and data != "":
if result[0] == '3a77f992-a8c9-4ca3-8e00-8f1eaaf91d0c':
print(socials[idx])
task_id = get_task_list(social)
give_karma(result[0], task_id)

if __name__ == '__main__':
alter_task_message_id()
create_social_task()
automate_socials_karma()
execute("UPDATE system_setting SET value = '1.43', updated_at = now() WHERE `key` = 'db.version';")

36 changes: 14 additions & 22 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def get(self, request):
total_no_enrollment = (UserCircleLink.objects.filter(accepted=True,
user__user_organization_link_user__org__org_type=OrganizationType.COLLEGE.value,
created_at__gt=date).values(
first_name=F("user__first_name"),
last_name=F("user__last_name"),
full_name=F("user__full_name"),
email=F("user__email"),
muid=F("user__muid"),
circle_name=F("circle__name"),
Expand Down Expand Up @@ -88,8 +87,7 @@ def get(self, request):
# user__user_organization_link_user__org__org_type=OrganizationType.COLLEGE.value).count()
total_no_enrollment = (UserCircleLink.objects.filter(accepted=True,
user__user_organization_link_user__org__org_type=OrganizationType.COLLEGE.value).values(
first_name=F("user__first_name"),
last_name=F("user__last_name"),
full_name=F("user__full_name"),
email=F("user__email"),
muid=F("user__muid"),
circle_name=F("circle__name"),
Expand Down Expand Up @@ -158,8 +156,7 @@ def get(self, request):
student_info = (UserCircleLink.objects.filter(accepted=True,
user__user_organization_link_user__org__org_type=OrganizationType.COLLEGE.value,
created_at__date=date).values(
first_name=F("user__first_name"),
last_name=F("user__last_name"),
full_name=F("user__full_name"),
muid=F("user__muid"),
circle_name=F("circle__name"),
circle_ig=F("circle__ig__name"),
Expand Down Expand Up @@ -190,8 +187,7 @@ def get(self, request):
user__user_organization_link_user__org__org_type=OrganizationType.COLLEGE.value,
)
.values(
first_name=F("user__first_name"),
last_name=F("user__last_name"),
full_name=F("user__full_name"),
muid=F("user__muid"),
circle_name=F("circle__name"),
circle_ig=F("circle__ig__name"),
Expand Down Expand Up @@ -220,9 +216,9 @@ def get(self, request):
paginated_queryset = CommonUtils.get_paginated_queryset(
student_info,
request,
search_fields=["first_name", "last_name", "muid", "circle_name", 'circle_ig', "organisation",
search_fields=["full_name", "muid", "circle_name", 'circle_ig', "organisation",
"karma_earned"],
sort_fields={"first_name": "first_name", "last_name": "last_name", "muid": "muid",
sort_fields={"full_name": "full_name", "muid": "muid",
"circle_name": "circle_name",
"circle_ig": "circle_ig", "organisation": "organisation", "dwms_id": "dwms_id",
"karma_earned": "karma_earned"},
Expand All @@ -246,8 +242,7 @@ def get(self, request):
user__user_organization_link_user__org__org_type=OrganizationType.COLLEGE.value,
)
.values(
first_name=F("user__first_name"),
last_name=F("user__last_name"),
full_name=F("user__full_name"),
muid=F("user__muid"),
circle_name=F("circle__name"),
circle_ig=F("circle__ig__name"),
Expand Down Expand Up @@ -366,8 +361,7 @@ class LearningCircleEnrollment(APIView):
def get(self, request):
total_no_enrollment = (UserCircleLink.objects.filter(accepted=True,
user__user_organization_link_user__org__org_type=OrganizationType.COLLEGE.value).values(
first_name=F("user__first_name"),
last_name=F("user__last_name"),
full_name=F("user__full_name"),
email=F("user__email"),
muid=F("user__muid"),
circle_name=F("circle__name"),
Expand Down Expand Up @@ -397,9 +391,9 @@ def get(self, request):
paginated_queryset = CommonUtils.get_paginated_queryset(
total_no_enrollment,
request,
search_fields=["first_name", "last_name", "email", "muid", "circle_name", "district", "circle_ig",
search_fields=["full_name", "email", "muid", "circle_name", "district", "circle_ig",
"organisation", "karma_earned"],
sort_fields={"first_name": "first_name", "last_name": "last_name", "email": "email", "muid": "muid",
sort_fields={"full_name": "full_name", "email": "email", "muid": "muid",
"circle_name": "circle_name", "district": "district", "circle_ig": "circle_ig",
"organisation": "organisation", "dwms_id": "dwms_id", "karma_earned": "karma_earned"},
is_pagination=True)
Expand All @@ -414,8 +408,7 @@ class LearningCircleEnrollmentCSV(APIView):
def get(self, request):
total_no_enrollment = (UserCircleLink.objects.filter(accepted=True,
user__user_organization_link_user__org__org_type=OrganizationType.COLLEGE.value).values(
first_name=F("user__first_name"),
last_name=F("user__last_name"),
full_name=F("user__full_name"),
email=F("user__email"),
muid=F("user__muid"),
circle_name=F("circle__name"),
Expand Down Expand Up @@ -446,9 +439,9 @@ def get(self, request):
paginated_queryset = CommonUtils.get_paginated_queryset(
total_no_enrollment,
request,
search_fields=["first_name", "last_name", "email", "muid", "circle_name", "district", "circle_ig",
search_fields=["full_name", "email", "muid", "circle_name", "district", "circle_ig",
"organisation", "karma_earned"],
sort_fields={"first_name": "first_name", "last_name": "last_name", "email": "email", "muid": "muid",
sort_fields={"full_name": "full_name", "email": "email", "muid": "muid",
"circle_name": "circle_name", "district": "district", "circle_ig": "circle_ig",
"organisation": "organisation", "dwms_id": "dwms_id", "karma_earned": "karma_earned"},
is_pagination=False)
Expand Down Expand Up @@ -546,8 +539,7 @@ def get(self, request):
).values(
userid=F('user__id'),
muid=F('user__muid'),
first_name=F('user__first_name'),
last_name=F('user__last_name'),
full_name=F('user__full_name'),
).annotate(
ig_karma=Sum('karma')
).order_by('-ig_karma')[:100]
Expand Down
14 changes: 6 additions & 8 deletions api/common/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


class StudentInfoSerializer(serializers.Serializer):
first_name = serializers.CharField()
last_name = serializers.CharField()
full_name = serializers.CharField()
muid = serializers.CharField()
circle_name = serializers.CharField()
circle_ig = serializers.CharField()
Expand All @@ -21,8 +20,7 @@ class CollegeInfoSerializer(serializers.Serializer):


class LearningCircleEnrollmentSerializer(serializers.Serializer):
first_name = serializers.CharField()
last_name = serializers.CharField()
full_name = serializers.CharField()
muid = serializers.CharField()
email = serializers.CharField()
dwms_id = serializers.CharField(allow_null=True)
Expand All @@ -37,19 +35,19 @@ class UserLeaderboardSerializer(serializers.ModelSerializer):
interest_groups = serializers.SerializerMethodField()
organizations = serializers.SerializerMethodField()
karma = serializers.IntegerField(source="wallet_user.karma")
fullname = serializers.SerializerMethodField()
full_name = serializers.SerializerMethodField()

class Meta:
model = User
fields = (
'fullname',
'full_name',
"karma",
"interest_groups",
"organizations",
)

def get_fullname(self, obj):
return obj.fullname
def get_full_name(self, obj):
return obj.full_name

def get_organizations(self, obj):
return obj.user_organization_link_user.all().values_list("org__title", flat=True)
Expand Down
7 changes: 4 additions & 3 deletions api/dashboard/affiliation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@


class AffiliationListSerializer(serializers.ModelSerializer):
created_by = serializers.CharField(source="created_by.fullname")
updated_by = serializers.CharField(source="updated_by.fullname")
created_by = serializers.CharField(source="created_by.full_name")
updated_by = serializers.CharField(source="updated_by.full_name")
organization_count = serializers.SerializerMethodField()

class Meta:
model = OrgAffiliation
fields = ['id', 'title', 'organization_count', 'created_by', 'updated_by', 'updated_at', 'created_at']
fields = ['id', 'title', 'organization_count',
'created_by', 'updated_by', 'updated_at', 'created_at']

def get_organization_count(self, obj):
return obj.organization_affiliation.count()
Expand Down
Loading

0 comments on commit 48b4b40

Please sign in to comment.