Skip to content

Commit

Permalink
Merge branch 'gtech-mulearn:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
aswanthabam authored Oct 12, 2024
2 parents 8b1f7c6 + d111839 commit 95a605c
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 7 deletions.
45 changes: 44 additions & 1 deletion api/dashboard/user/dash_user_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.db import transaction
from rest_framework import serializers

from db.organization import Organization, UserOrganizationLink
from db.organization import Department, Organization, UserOrganizationLink
from db.task import UserIgLink
from db.user import User, UserRoleLink
from utils.permission import JWTUtils
Expand Down Expand Up @@ -383,3 +383,46 @@ def update(self, instance, validated_data):
)

return super().update(instance, validated_data)
class UserOrgLinkSerializer(serializers.ModelSerializer):
department = serializers.PrimaryKeyRelatedField(
queryset=Department.objects.all(), required=False
)
graduation_year = serializers.CharField(required=False)
organization = serializers.PrimaryKeyRelatedField(
queryset=Organization.objects.all(), many=False, required=True
)
is_alumni=serializers.BooleanField(required=False)

def create(self, validated_data):
department = validated_data.get("department", None)
graduation_year = validated_data.get("graduation_year", None)
is_alumni=validated_data.get("is_alumni",False)
is_college = lambda org: org.org_type == OrganizationType.COLLEGE.value
user_id=self.context.get('user')

return UserOrganizationLink.objects.create(
user=user_id,
org=validated_data.get("organization"),
created_by=user_id,
created_at=DateTimeUtils.get_current_utc_time(),
verified=True,
department=department if is_college(validated_data.get("organization")) else None,
graduation_year=graduation_year if is_college(validated_data.get("organization")) else None,
is_alumni=is_alumni if is_college(validated_data.get("organization")) else None,
)



class Meta:
model = UserOrganizationLink
fields = [ "organization", "department", "graduation_year","is_alumni"]

class GetUserLinkSerializer(serializers.ModelSerializer):
org_id=serializers.CharField(source='org.id')
org_title=serializers.CharField(source='org.title')
dept_id = serializers.CharField(source='department.id', allow_null=True, required=False)
dept_title=serializers.CharField(source='department.title', allow_null=True, required=False)
is_alumni=serializers.BooleanField()
class Meta:
model = UserOrganizationLink
fields=["org_id","org_title","dept_id","dept_title","is_alumni"]
28 changes: 27 additions & 1 deletion api/dashboard/user/dash_user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
from django.db.models import Q
from rest_framework.views import APIView

from db.organization import UserOrganizationLink
from db.user import ForgotPassword, User, UserRoleLink
from utils.permission import CustomizePermission, JWTUtils, role_required
from utils.response import CustomResponse
from utils.types import RoleType, WebHookActions, WebHookCategory
from utils.types import OrganizationType, RoleType, WebHookActions, WebHookCategory
from utils.utils import CommonUtils, DateTimeUtils, DiscordWebhooks, send_template_mail
from . import dash_user_serializer
from django.core.cache import cache
Expand Down Expand Up @@ -372,3 +373,28 @@ def post(self, request):
return CustomResponse(
response={"user_id": user.id, "profile_pic": uploaded_file_url}
).get_success_response()


class UserAddOrgAPI(APIView):
def post(self,request):
user = User.objects.filter(id=JWTUtils.fetch_user_id(request)).first()
if user is None:
return CustomResponse(
general_message="No user data available"
).get_failure_response()
serializer=dash_user_serializer.UserOrgLinkSerializer(data=request.data,context={'user':user})
if(serializer.is_valid()):
serializer.save()
return CustomResponse(general_message="organisation linked successfully").get_success_response()
return CustomResponse(response=serializer.errors).get_failure_response()
def get(self,request):
user = User.objects.filter(id=JWTUtils.fetch_user_id(request)).first()
if user is None:
return CustomResponse(
general_message="No user data available"
).get_failure_response()

links = UserOrganizationLink.objects.filter(user=user,org__org_type=OrganizationType.COLLEGE.value).select_related('org','department')
serializer=dash_user_serializer.GetUserLinkSerializer(instance=links,many=True)
return CustomResponse(response=serializer.data).get_success_response()

2 changes: 2 additions & 0 deletions api/dashboard/user/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
path('verification/csv/', dash_user_views.UserVerificationCSV.as_view(), name='csv-verification'),
path('verification/<str:link_id>/', dash_user_views.UserVerificationAPI.as_view(), name='edit-verification'),
path('verification/<str:link_id>/', dash_user_views.UserVerificationAPI.as_view(), name='delete-verification'),
path('organization/',dash_user_views.UserAddOrgAPI.as_view(),name="user-org-link"),
path('organization/list',dash_user_views.UserAddOrgAPI.as_view(),name="get-user-org-link"),

path('info/', dash_user_views.UserInfoAPI.as_view()),
path('forgot-password/', dash_user_views.ForgotPasswordAPI.as_view(), name="forgot-password"),
Expand Down
4 changes: 2 additions & 2 deletions api/register/register_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def post(self, request):
# data=data.get("user"), context={"request": request}
# )

create_user = serializers.RegisterSerializer(
data=data, context={"request": request}
create_user = serializers.UserSerializer(
data=data.pop("user"), context={"request": request}
)

if not create_user.is_valid():
Expand Down
2 changes: 1 addition & 1 deletion api/register/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

urlpatterns = [
path("", register_views.RegisterDataAPI.as_view()),
path("validate/", register_views.UserRegisterValidateAPI.as_view()),
# path("validate/", register_views.UserRegisterValidateAPI.as_view()),
path("role/list/", register_views.RoleAPI.as_view()),
path("colleges/", register_views.CollegesAPI.as_view()),
path("department/list/", register_views.DepartmentAPI.as_view()),
Expand Down
3 changes: 1 addition & 2 deletions db/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ class UserOrganizationLink(models.Model):
related_name='user_organization_link_department')
graduation_year = models.CharField(max_length=10, blank=True, null=True)
verified = models.BooleanField()
is_alumni = models.IntegerField(blank=True, null=True, default=False)
is_alumni = models.BooleanField(blank=True, null=True, default=False)
created_by = models.ForeignKey(User, on_delete=models.SET(settings.SYSTEM_ADMIN_ID), db_column='created_by',
related_name='user_organization_link_created_by')
created_at = models.DateTimeField(auto_now_add=True)

class Meta:
managed = False
db_table = 'user_organization_link'
Expand Down

0 comments on commit 95a605c

Please sign in to comment.