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 9, 2023
2 parents 6b3e4de + c19cc7e commit d77fff0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 41 deletions.
3 changes: 2 additions & 1 deletion alter-scripts/alter-1.42.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
from decouple import config

from connection import execute
from utils.types import OrganizationType

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

from collections import defaultdict
from utils.types import OrganizationType


def clg_levels_check():
Expand Down
6 changes: 4 additions & 2 deletions api/dashboard/events/events_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Meta:
model = Events
fields = "__all__"


class EventsCUDSerializer(serializers.ModelSerializer):
class Meta:
model = Events
Expand All @@ -29,8 +30,9 @@ def update(self, instance, validated_data):
user_id = self.context.get("user_id")

instance.name = validated_data.get("name", instance.name)
instance.description = validated_data.get("description", instance.description)
instance.updated_by_id = user_id
instance.updated_at = DateTimeUtils.get_current_utc_time()
instance.save()
return instance

return instance
13 changes: 5 additions & 8 deletions api/dashboard/events/events_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from rest_framework.views import APIView
from utils.permission import CustomizePermission, JWTUtils, role_required

from db.task import Events
from utils.permission import CustomizePermission, JWTUtils
from utils.response import CustomResponse
from utils.types import RoleType
from utils.utils import CommonUtils
from .events_serializer import EventsCUDSerializer, EventsListSerializer
from db.task import Events


class EventAPI(APIView):
Expand All @@ -30,7 +30,6 @@ def get(self, request):
)
)


def post(self, request):
user_id = JWTUtils.fetch_user_id(request)

Expand All @@ -52,7 +51,6 @@ def post(self, request):
return CustomResponse(
general_message=serializer.errors,
).get_failure_response()


def put(self, request, event_id):
user_id = JWTUtils.fetch_user_id(request)
Expand Down Expand Up @@ -80,10 +78,9 @@ def put(self, request, event_id):
return CustomResponse(
message=serializer.errors
).get_failure_response()


def delete(self, request, event_id):

events = Events.objects.filter(id=event_id).first()

if events is None:
Expand All @@ -95,4 +92,4 @@ def delete(self, request, event_id):

return CustomResponse(
general_message=f"{events.name} Deleted Successfully"
).get_success_response()
).get_success_response()
83 changes: 53 additions & 30 deletions api/dashboard/profile/profile_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from db.user import User, UserSettings, Socials
from utils.exception import CustomException
from utils.permission import JWTUtils
from utils.types import OrganizationType, RoleType, MainRoles
from utils.utils import DateTimeUtils
from utils.types import OrganizationType, RoleType, MainRoles, WebHookActions, WebHookCategory
from utils.utils import DateTimeUtils, DiscordWebhooks

BE_DOMAIN_NAME = decouple_config('BE_DOMAIN_NAME')

Expand All @@ -35,8 +35,10 @@ class Meta:

class UserProfileSerializer(serializers.ModelSerializer):
joined = serializers.DateTimeField(source="created_at")
level = serializers.CharField(source="user_lvl_link_user.level.name", default=None)
is_public = serializers.BooleanField(source="user_settings_user.is_public", default=None)
level = serializers.CharField(
source="user_lvl_link_user.level.name", default=None)
is_public = serializers.BooleanField(
source="user_settings_user.is_public", default=None)
karma = serializers.IntegerField(source="wallet_user.karma", default=None)
roles = serializers.SerializerMethodField()
college_id = serializers.SerializerMethodField()
Expand Down Expand Up @@ -72,7 +74,8 @@ class Meta:

def get_percentile(self, obj):
try:
user_count = Wallet.objects.filter(karma__lt=obj.wallet_user.karma).count()
user_count = Wallet.objects.filter(
karma__lt=obj.wallet_user.karma).count()
usr_count = User.objects.all().count()
return 0 if usr_count == 0 else (user_count * 100) / usr_count
except Exception as e:
Expand All @@ -95,7 +98,8 @@ def get_college_id(self, obj):
def get_org_district_id(self, obj):
org_type = OrganizationType.COMPANY.value if MainRoles.MENTOR.value in self.get_roles(
obj) else OrganizationType.COLLEGE.value
user_org_link = obj.user_organization_link_user.filter(org__org_type=org_type).first()
user_org_link = obj.user_organization_link_user.filter(
org__org_type=org_type).first()
return user_org_link.org.district.id if user_org_link and hasattr(user_org_link.org, 'district') else None

def get_college_code(self, obj):
Expand Down Expand Up @@ -125,7 +129,8 @@ def get_rank(self, obj):
ranks = (
Wallet.objects.filter(karma__gte=user_karma)
.exclude(
Q(user__user_role_link_user__role__title__in=[RoleType.ENABLER.value, RoleType.MENTOR.value])
Q(user__user_role_link_user__role__title__in=[
RoleType.ENABLER.value, RoleType.MENTOR.value])
).order_by('-karma')
)

Expand All @@ -149,14 +154,14 @@ def get_interest_groups(self, obj):
if KarmaActivityLog.objects.filter(
task__ig=ig_link.ig, user=obj, appraiser_approved=True
)
.aggregate(Sum("karma"))
.get("karma__sum")
is None
.aggregate(Sum("karma"))
.get("karma__sum")
is None
else KarmaActivityLog.objects.filter(
task__ig=ig_link.ig, user=obj, appraiser_approved=True
)
.aggregate(Sum("karma"))
.get("karma__sum")
.aggregate(Sum("karma"))
.get("karma__sum")
)
interest_groups.append(
{"id": ig_link.ig.id, "name": ig_link.ig.name, "karma": total_ig_karma}
Expand All @@ -173,13 +178,16 @@ class Meta:

def get_tasks(self, obj):
user_id = self.context.get("user_id")
user_lvl = UserLvlLink.objects.filter(user__id=user_id).first().level.level_order
user_igs = UserIgLink.objects.filter(user__id=user_id).values_list("ig__name", flat=True)
user_lvl = UserLvlLink.objects.filter(
user__id=user_id).first().level.level_order
user_igs = UserIgLink.objects.filter(
user__id=user_id).values_list("ig__name", flat=True)
tasks = TaskList.objects.filter(level=obj)

data = []
for task in tasks:
completed = KarmaActivityLog.objects.filter(user=user_id, task=task, appraiser_approved=True).exists()
completed = KarmaActivityLog.objects.filter(
user=user_id, task=task, appraiser_approved=True).exists()
if task.active or completed:
data.append(
{
Expand All @@ -203,7 +211,8 @@ class UserRankSerializer(ModelSerializer):

class Meta:
model = User
fields = ("first_name", "last_name", "role", "rank", "karma", "interest_groups")
fields = ("first_name", "last_name", "role",
"rank", "karma", "interest_groups")

def get_role(self, obj):
roles = self.context.get("roles")
Expand All @@ -226,7 +235,8 @@ def get_rank(self, obj):
).count()
else:
ranks = (
Wallet.objects.filter(karma__gte=user_karma, user__user_role_link_user__verified=True)
Wallet.objects.filter(
karma__gte=user_karma, user__user_role_link_user__verified=True)
.exclude(
Q(
user__user_role_link_user__role__title__in=[
Expand Down Expand Up @@ -258,7 +268,8 @@ class Meta:

def update(self, instance, validated_data):
user_id = JWTUtils.fetch_user_id(self.context.get("request"))
instance.is_public = validated_data.get("is_public", instance.is_public)
instance.is_public = validated_data.get(
"is_public", instance.is_public)
instance.updated_by_id = user_id
instance.updated_at = DateTimeUtils.get_current_utc_time()
instance.save()
Expand Down Expand Up @@ -298,7 +309,8 @@ def update(self, instance, validated_data):
for org_data in community_data
]

UserOrganizationLink.objects.bulk_create(user_organization_links)
UserOrganizationLink.objects.bulk_create(
user_organization_links)

return super().update(instance, validated_data)

Expand Down Expand Up @@ -374,17 +386,28 @@ def update(self, instance, validated_data):
def create_karma_activity_log(task_title, karma_value):
task = TaskList.objects.filter(title=task_title).first()
if task:
KarmaActivityLog.objects.create(
task_id=task.id,
karma=karma_value,
user_id=user_id,
updated_by_id=user_id,
created_by_id=user_id,
peer_approved=True,
peer_approved_by_id=user_id,
appraiser_approved_by_id=user_id,
appraiser_approved=True,
)
if karma_value > 0:
KarmaActivityLog.objects.create(
task_id=task.id,
karma=karma_value,
user_id=user_id,
updated_by_id=user_id,
created_by_id=user_id,
peer_approved=True,
peer_approved_by_id=user_id,
appraiser_approved_by_id=user_id,
appraiser_approved=True,
)

dl = WebHookActions.SEPARATOR.value
discord_id = User.objects.get(id=user_id).discord_id
value = f"{task.hashtag}{dl}{karma_value}{dl}{discord_id}{dl}{task.id}"

DiscordWebhooks.general_updates(
WebHookCategory.KARMA_INFO.value,
WebHookActions.UPDATE.value,
value
)
Wallet.objects.filter(user_id=user_id).update(
karma=F("karma") + karma_value,
updated_by_id=user_id
Expand Down
1 change: 1 addition & 0 deletions utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class WebHookCategory(Enum):
USER_NAME = 'user-name'
USER_PROFILE = 'user-profile'
BULK_ROLE = 'bulk-role'
KARMA_INFO = 'karma-info'


class RefferalType(Enum):
Expand Down

0 comments on commit d77fff0

Please sign in to comment.