Skip to content

Commit

Permalink
Merge pull request #1705 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
karma_last_update_at [fix]
  • Loading branch information
adnankattekaden authored Dec 2, 2023
2 parents 452cb10 + 0f2fd2d commit 3ef1afd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 39 deletions.
6 changes: 4 additions & 2 deletions api/dashboard/affiliation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from db.organization import OrgAffiliation
from utils.utils import DateTimeUtils


class AffiliationListSerializer(serializers.ModelSerializer):
created_by = serializers.CharField(source="created_by.fullname")
updated_by = serializers.CharField(source="updated_by.fullname")
Expand All @@ -19,6 +20,7 @@ def get_organization_count(self,obj):




class AffiliationCUDSerializer(serializers.ModelSerializer):
class Meta:
model = OrgAffiliation
Expand All @@ -39,5 +41,5 @@ def update(self, instance, validated_data):
instance.updated_by_id = user_id
instance.updated_at = DateTimeUtils.get_current_utc_time()
instance.save()
return instance

return instance
8 changes: 4 additions & 4 deletions api/dashboard/campus/campus_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get(self, request):
karma=F("wallet_user__karma"),
level=F("user_lvl_link_user__level__name"),
join_date=F("created_at"),
last_karma_gained=F("wallet_user__karma_last_update_at"),
last_karma_gained=F("wallet_user__karma_last_updated_at"),
department=F('user_organization_link_user__department__title'),
graduation_year=F("user_organization_link_user__graduation_year"),
is_alumni=F('user_organization_link_user__is_alumni'),
Expand Down Expand Up @@ -155,7 +155,7 @@ def get(self, request):
karma=F("wallet_user__karma"),
level=F("user_lvl_link_user__level__name"),
join_date=F("created_at"),
last_karma_gained=F("wallet_user__karma_last_update_at"),
last_karma_gained=F("wallet_user__karma_last_updated_at"),
department=F('user_organization_link_user__department__title'),
graduation_year=F("user_organization_link_user__graduation_year"),
is_alumni=F('user_organization_link_user__is_alumni'),
Expand Down Expand Up @@ -234,7 +234,7 @@ def get(self, request):
karma=F("wallet_user__karma"),
level=F("user_lvl_link_user__level__name"),
join_date=F("created_at"),
last_karma_gained=F("wallet_user__karma_last_update_at"),
last_karma_gained=F("wallet_user__karma_last_updated_at"),
department=F('user_organization_link_user__department__title'),
graduation_year=F("user_organization_link_user__graduation_year"),
is_alumni=F('user_organization_link_user__is_alumni'),
Expand Down Expand Up @@ -268,7 +268,7 @@ def get(self, request):
karma=F("wallet_user__karma"),
level=F("user_lvl_link_user__level__name"),
join_date=F("created_at"),
last_karma_gained=F("wallet_user__karma_last_update_at"),
last_karma_gained=F("wallet_user__karma_last_updated_at"),
department=F('user_organization_link_user__department__title'),
graduation_year=F("user_organization_link_user__graduation_year"),
is_alumni=F('user_organization_link_user__is_alumni'),
Expand Down
2 changes: 1 addition & 1 deletion api/dashboard/campus/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_active_members(self, obj):
return obj.org.user_organization_link_org.filter(
verified=True,
user__wallet_user__isnull=False,
user__wallet_user__karma_last_update_at__gte=last_month,
user__wallet_user__karma_last_updated_at__gte=last_month,
).count()

def get_total_karma(self, obj):
Expand Down
2 changes: 1 addition & 1 deletion api/dashboard/lc/dash_lc_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def validate_attendees(self, attendees):
])
wallet = Wallet.objects.filter(user_id=user).first()
wallet.karma += Lc.KARMA.value
wallet.karma_last_update_at = DateTimeUtils.get_current_utc_time()
wallet.karma_last_updated_at = DateTimeUtils.get_current_utc_time()
wallet.updated_at = DateTimeUtils.get_current_utc_time()
wallet.save()
return attendees
Expand Down
33 changes: 17 additions & 16 deletions api/dashboard/organisation/organisation_views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import uuid
from django.db.models import F, Prefetch, Sum
from rest_framework.views import APIView

from openpyxl import load_workbook
from tempfile import NamedTemporaryFile
from io import BytesIO
from tempfile import NamedTemporaryFile

from django.db.models import F, Prefetch, Sum
from django.http import FileResponse
from openpyxl import load_workbook
from rest_framework.views import APIView

from db.organization import (
Department,
Expand All @@ -18,7 +18,6 @@
from utils.response import CustomResponse
from utils.types import OrganizationType, RoleType, WebHookActions, WebHookCategory
from utils.utils import CommonUtils, DiscordWebhooks, ImportCSV

from .serializers import (
AffiliationCreateUpdateSerializer,
AffiliationSerializer,
Expand Down Expand Up @@ -81,8 +80,8 @@ def put(self, request, org_code):
serializer.save()

if (
request.data.get("title") != old_title
and old_type == OrganizationType.COMMUNITY.value
request.data.get("title") != old_title
and old_type == OrganizationType.COMMUNITY.value
):
DiscordWebhooks.general_updates(
WebHookCategory.COMMUNITY.value,
Expand All @@ -92,8 +91,8 @@ def put(self, request, org_code):
)

if (
request.data.get("orgType") != OrganizationType.COMMUNITY.value
and old_type == OrganizationType.COMMUNITY.value
request.data.get("orgType") != OrganizationType.COMMUNITY.value
and old_type == OrganizationType.COMMUNITY.value
):
DiscordWebhooks.general_updates(
WebHookCategory.COMMUNITY.value,
Expand All @@ -102,8 +101,8 @@ def put(self, request, org_code):
)

if (
old_type != OrganizationType.COMMUNITY.value
and request.data.get("orgType") == OrganizationType.COMMUNITY.value
old_type != OrganizationType.COMMUNITY.value
and request.data.get("orgType") == OrganizationType.COMMUNITY.value
):
title = request.data.get("title") or old_title
DiscordWebhooks.general_updates(
Expand Down Expand Up @@ -525,9 +524,10 @@ def post(self, request):
serializer.errors
).get_failure_response()


class OrganisationBaseTemplateAPI(APIView):
authentication_classes = [CustomizePermission]

def get(self, request):
wb = load_workbook('./api/dashboard/organisation/assets/organisation_base_template.xlsx')
ws = wb['Data Definitions']
Expand All @@ -546,13 +546,14 @@ def get(self, request):
ws.cell(row=row, column=col_num, value=value)
# Save the file
with NamedTemporaryFile() as tmp:
tmp.close() # with statement opened tmp, close it so wb.save can open it
tmp.close() # with statement opened tmp, close it so wb.save can open it
wb.save(tmp.name)
with open(tmp.name, 'rb') as f:
f.seek(0)
new_file_object = f.read()
return FileResponse(BytesIO(new_file_object), as_attachment=True, filename='organisation_base_template.xlsx')



class OrganisationImportAPI(APIView):
authentication_classes = [CustomizePermission]

Expand Down Expand Up @@ -705,4 +706,4 @@ def post(self, request):

return CustomResponse(
response={"Success": success_data, "Failed": error_rows}
).get_success_response()
).get_success_response()
35 changes: 20 additions & 15 deletions api/dashboard/task/dash_task_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from io import BytesIO
from django.http import FileResponse


class TaskListAPI(APIView):
authentication_classes = [CustomizePermission]

Expand All @@ -32,7 +33,6 @@ class TaskListAPI(APIView):
]
)
def get(self, request):

task_queryset = TaskList.objects.select_related(
"created_by",
"updated_by",
Expand Down Expand Up @@ -183,7 +183,7 @@ def delete(self, request, task_id): # delete

return CustomResponse(
general_message="Task deleted successfully"
).get_success_response()
).get_success_response()


class TaskListCSV(APIView):
Expand Down Expand Up @@ -303,7 +303,7 @@ def post(self, request):
error_rows.append(row)
excel_data.remove(row)
continue

level = row.get("level")
channel = row.get("channel")
task_type = row.get("type")
Expand Down Expand Up @@ -400,7 +400,7 @@ def post(self, request):
row["created_by_id"] = user_id
row["created_at"] = DateTimeUtils.get_current_utc_time()
row["active"] = True
row["channel_id"] = channel_id or None
row["channel_id"] = channel_id or None
row["type_id"] = task_type_id
row["level_id"] = level_id or None
row["ig_id"] = ig_id or None
Expand All @@ -412,7 +412,7 @@ def post(self, request):
if task_list_serializer.is_valid():
task_list_serializer.save()
for task_data in task_list_serializer.data:
success_data.append({
success_data.append({
'hashtag': task_data.get('hashtag', ''),
'title': task_data.get('title', ''),
'description': task_data.get('description', ''),
Expand Down Expand Up @@ -549,9 +549,10 @@ def get(self, request):
response=events
).get_success_response()


class TaskBaseTemplateAPI(APIView):
authentication_classes = [CustomizePermission]

def get(self, request):
wb = load_workbook('./api/dashboard/task/assets/task_base_template.xlsx')
ws = wb['Data Definitions']
Expand All @@ -576,24 +577,28 @@ def get(self, request):
ws.cell(row=row, column=col_num, value=value)
# Save the file
with NamedTemporaryFile() as tmp:
tmp.close() # with statement opened tmp, close it so wb.save can open it
tmp.close() # with statement opened tmp, close it so wb.save can open it
wb.save(tmp.name)
with open(tmp.name, 'rb') as f:
f.seek(0)
new_file_object = f.read()
return FileResponse(BytesIO(new_file_object), as_attachment=True, filename='task_base_template.xlsx')



class TaskTypeCrudAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required(
[
RoleType.ADMIN.value,
]
)
def get(self,request):
taskType=TaskType.objects.all()
def get(self, request):
taskType = TaskType.objects.all()
paginated_queryset = CommonUtils.get_paginated_queryset(
taskType, request, [ "title"],{"title":"title","updated_by":"updated_by","created_by":"created_by","updated_at":"updated_at","created_at":"created_at"}
taskType, request, ["title"],
{"title": "title", "updated_by": "updated_by", "created_by": "created_by", "updated_at": "updated_at",
"created_at": "created_at"}
)
serializer = TasktypeSerializer(
paginated_queryset.get("queryset"), many=True
Expand All @@ -602,7 +607,7 @@ def get(self,request):
return CustomResponse().paginated_response(
data=serializer.data, pagination=paginated_queryset.get("pagination")
)

@role_required([RoleType.ADMIN.value])
def post(self, request):
user_id = JWTUtils.fetch_user_id(request)
Expand All @@ -616,7 +621,7 @@ def post(self, request):
).get_success_response()

return CustomResponse(general_message=serializer.errors).get_failure_response()

@role_required([RoleType.ADMIN.value])
def delete(self, request, task_type_id):
taskType = TaskType.objects.filter(id=task_type_id).first()
Expand All @@ -628,14 +633,14 @@ def delete(self, request, task_type_id):
return CustomResponse(
general_message=f"{taskType.title} Deleted Successfully"
).get_success_response()

@role_required([RoleType.ADMIN.value])
def put(self, request, task_type_id):
taskType = TaskType.objects.filter(id=task_type_id).first()
if taskType is None:
return CustomResponse(general_message="task type not found").get_failure_response()
serializer = TaskTypeCreateUpdateSerializer(
taskType, data=request.data, context={"request": request}
taskType, data=request.data, context={"request": request}
)
if serializer.is_valid():
serializer.save()
Expand Down

0 comments on commit 3ef1afd

Please sign in to comment.