Skip to content

Commit

Permalink
Merge pull request #1363 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
kkem ig
  • Loading branch information
adnankattekaden authored Oct 18, 2023
2 parents e58f252 + 853b080 commit 83e0cf3
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 31 deletions.
26 changes: 14 additions & 12 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from collections import defaultdict

from django.db.models import Sum, F, Case, When, Value, CharField, Count, Q
from django.db.models.functions import Coalesce
from rest_framework.views import APIView
Expand All @@ -11,28 +13,28 @@
from utils.types import IntegrationType, OrganizationType
from utils.utils import CommonUtils
from .serializer import StudentInfoSerializer
from collections import defaultdict


class LcDashboardAPI(APIView):

def get(self, request):
date = request.GET.get('date')
if date:
learning_circle_count = LearningCircle.objects.filter(created_at__gt=date).count()
total_no_enrollment = UserCircleLink.objects.filter(accepted=True, created_at__gt=date).count()
circle_count_by_ig = LearningCircle.objects.filter(created_at__gt=date).values(
ig_name=F('ig__name')).annotate(total_circles=Count('id'),
total_users=Count('ig__learningcircle__usercirclelink__user',
distinct=True))
unique_user_count = UserCircleLink.objects.filter(accepted=True, created_at__gt=date).values(
'user').distinct().count()
else:
learning_circle_count = LearningCircle.objects.all().count()
total_no_enrollment = UserCircleLink.objects.filter(accepted=True).count()
circle_count_by_ig = LearningCircle.objects.all().values(ig_name=F('ig__name')).annotate(
total_circles=Count('id'), total_users=Count('ig__learningcircle__usercirclelink__user', distinct=True))

unique_user_count = UserCircleLink.objects.filter(accepted=True).values('user').distinct().count()
total_no_enrollment = UserCircleLink.objects.filter(accepted=True).count()
query = InterestGroup.objects.annotate(
total_circles=Count('learningcircle'),
total_users=Count('learningcircle__usercirclelink__user', distinct=True)
).values('name', 'total_circles', 'total_users')
circle_count_by_ig = query.values('name').order_by('name').annotate(
total_circles=Count('learningcircle', distinct=True),
total_users=Count('learningcircle__usercirclelink__user', distinct=True)
)
unique_user_count = UserCircleLink.objects.filter(accepted=True).values('user').distinct().count()

return CustomResponse(response={'lc_count': learning_circle_count, 'total_enrollment': total_no_enrollment,
'circle_count_by_ig': circle_count_by_ig,
'unique_users': unique_user_count}).get_success_response()
Expand Down
7 changes: 6 additions & 1 deletion api/dashboard/campus/campus_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from utils.utils import CommonUtils, DateTimeUtils
from .dash_campus_helper import get_user_college_link
from utils.permission import CustomizePermission, JWTUtils, role_required
from utils.exception import CustomException


class CampusDetailsAPI(APIView):
Expand Down Expand Up @@ -223,5 +224,9 @@ def get(self, request):

serializer = serializers.WeeklyKarmaSerializer(user_org_link)
return CustomResponse(response=serializer.data).get_success_response()

except Exception as e:
return CustomResponse(response=str(e)).get_failure_response()
raise CustomException(
detail='somthing went wrong',
status_code=403
)
6 changes: 6 additions & 0 deletions api/dashboard/organisation/organisation_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,15 @@ def get(self, request, org_code):
"id",
"title",
"code",
affiliation_uuid=F("affiliation__id"),
affiliation_name=F("affiliation__title"),
district_uuid=F("district__id"),
district_name=F("district__name"),
zone_uuid=F("district__zone__id"),
zone_name=F("district__zone__name"),
state_uuid=F("district__zone__state__id"),
state_name=F("district__zone__state__name"),
country_uuid=F("district__zone__state__country__id"),
country_name=F("district__zone__state__country__name"),
).annotate(
karma=Sum(
Expand Down
44 changes: 38 additions & 6 deletions api/dashboard/profile/profile_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from utils.utils import DiscordWebhooks
from . import profile_serializer
from .profile_serializer import LinkSocials
import logging




class UserProfileEditView(APIView):
Expand Down Expand Up @@ -56,19 +59,39 @@ class UserIgEditView(APIView):

def get(self, request):
user_id = JWTUtils.fetch_user_id(request)
user_ig = InterestGroup.objects.filter(user_ig_link_ig__user_id=user_id).all()
serializer = profile_serializer.UserIgListSerializer(user_ig, many=True)
return CustomResponse(response=serializer.data).get_success_response()

user_ig = InterestGroup.objects.filter(
user_ig_link_ig__user_id=user_id
).all()

serializer = profile_serializer.UserIgListSerializer(
user_ig,
many=True
)

return CustomResponse(
response=serializer.data
).get_success_response()

def patch(self, request):

logger = logging.getLogger(__name__)

try:
user_id = JWTUtils.fetch_user_id(request)
user = User.objects.get(id=user_id)

serializer = profile_serializer.UserIgEditSerializer(
user, data=request.data, partial=True
user,
data=request.data,
partial=True
)

if not serializer.is_valid():
return CustomResponse(response=serializer.errors).get_failure_response()
return CustomResponse(
response=serializer.errors
).get_failure_response()

serializer.save()
DiscordWebhooks.general_updates(
WebHookCategory.USER.value,
Expand All @@ -78,8 +101,17 @@ def patch(self, request):
return CustomResponse(
general_message="Interest Group edited successfully"
).get_success_response()

except ValueError as e:
return CustomResponse(
general_message=str(e)
).get_failure_response()

except Exception as e:
return CustomResponse(general_message=str(e)).get_failure_response()
logger.exception("An error occurred: %s", str(e))
return CustomResponse(
general_message="Somthing went wrong"
).get_failure_response()


class UserProfileAPI(APIView):
Expand Down
4 changes: 1 addition & 3 deletions api/dashboard/task/dash_task_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def post(self, request): # create
return CustomResponse(message=serializer.errors).get_failure_response()

serializer.save()
return CustomResponse(
general_message="Task Created Successfully"
).get_success_response()
return CustomResponse(general_message="Task Created Successfully").get_success_response()


class TaskAPI(APIView):
Expand Down
32 changes: 24 additions & 8 deletions api/url_shortener/url_shortener_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,32 @@ def delete(self, request, url_id):
general_message="Url deleted successfully.."
).get_success_response()

class UrlAnalayticsAPI(APIView):
def get(self, request,url_id):

class UrlAnalyticsAPI(APIView):
def get(self, request, url_id):
url_shortener_object = UrlShortener.objects.get(id=url_id)
url_data = UrlShortenerTracker.objects.filter(url_shortener_id=url_shortener_object.id)

url_data = UrlShortenerTracker.objects.filter(
url_shortener_id=url_shortener_object.id
)

print(url_data)
location_data = UrlShortenerTracker.objects.filter(url_shortener=url_shortener_object) \
.values('city', 'region', 'country')

location_data = UrlShortenerTracker.objects.filter(
url_shortener=url_shortener_object
).values(
'city',
'region',
'country'
)
print(location_data)
# Browsers through which users accessed
browsers_data = UrlShortenerTracker.objects.filter(url_shortener=url_shortener_object) \
.values('browser').count()

# Browsers through which users accessed
browsers_data = UrlShortenerTracker.objects.filter(
url_shortener=url_shortener_object
).values(
'browser'
).count()

print(browsers_data)

2 changes: 1 addition & 1 deletion api/url_shortener/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
path('list/', url_shortener_view.UrlShortenerAPI.as_view()),
path('delete/<str:url_id>/', url_shortener_view.UrlShortenerAPI.as_view()),

path('get-analytics/<str:url_id>/', url_shortener_view.UrlAnalayticsAPI.as_view()),
path('get-analytics/<str:url_id>/', url_shortener_view.UrlAnalyticsAPI.as_view()),
]
3 changes: 3 additions & 0 deletions mulearnbackend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import decouple
from decouple import config

import logging


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand Down

0 comments on commit 83e0cf3

Please sign in to comment.