Skip to content

Commit

Permalink
Merge pull request #1842 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
user mentor
  • Loading branch information
adnankattekaden authored Dec 20, 2023
2 parents 6215aab + e3f316f commit c574720
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 20 deletions.
45 changes: 42 additions & 3 deletions api/register/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uuid
from django.contrib.auth.hashers import make_password
from django.db import transaction
from rest_framework import serializers
Expand All @@ -13,8 +14,8 @@
UserOrganizationLink,
Zone,
)
from db.task import InterestGroup, Level, MucoinInviteLog, UserLvlLink, Wallet
from db.user import Role, Socials, User, UserReferralLink, UserRoleLink, UserSettings
from db.task import InterestGroup, Level, MucoinInviteLog, UserIgLink, UserLvlLink, Wallet
from db.user import Role, Socials, User, UserMentor, UserReferralLink, UserRoleLink, UserSettings
from utils.exception import CustomException
from utils.types import OrganizationType, RoleType
from utils.utils import DateTimeUtils
Expand Down Expand Up @@ -130,6 +131,39 @@ class Meta:
fields = ["user", "organizations", "department", "graduation_year"]


class MentorSerializer(serializers.ModelSerializer):
user = serializers.CharField(required=False)
about = serializers.CharField(required=False)
reason = serializers.CharField(required=False)
hours = serializers.IntegerField(required=False)

def create(self, validated_data):
about = validated_data.get("about", None)
reason = validated_data.get("reason", None)
hours = validated_data.get("hours", None)

UserMentor.objects.create(
user=validated_data["user"],
about=about,
reason=reason,
hours=hours,
created_by=validated_data["user"],
created_at=DateTimeUtils.get_current_utc_time(),
updated_by=validated_data["user"],
updated_at=DateTimeUtils.get_current_utc_time(),
)

class Meta:
model = UserMentor
fields = [
"user",
"about",
"reason",
"hours",
]



class ReferralSerializer(serializers.ModelSerializer):
user = serializers.CharField(required=False)
muid = serializers.CharField(required=False)
Expand Down Expand Up @@ -275,12 +309,12 @@ class Meta:
"district"
]


class RegisterSerializer(serializers.Serializer):
user = UserSerializer()
organization = UserOrgLinkSerializer(required=False)
referral = ReferralSerializer(required=False)
integration = IntegrationSerializer(required=False)
mentor = MentorSerializer(required=False)

def create(self, validated_data):
with transaction.atomic():
Expand All @@ -298,6 +332,10 @@ def create(self, validated_data):
integration.update({"user": user})
IntegrationSerializer().create(integration)

if mentor := validated_data.pop("mentor", None):
mentor["user"] = user
MentorSerializer().create(mentor)

return user

class Meta:
Expand All @@ -307,6 +345,7 @@ class Meta:
"organization",
"referral",
"param",
"mentor",
]


Expand Down
33 changes: 16 additions & 17 deletions db/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from django.core.files.storage import FileSystemStorage
from django.db import models

# from db.task import UserIgLink

from django.conf import settings

from .managers import user_manager
# from .task import UserIgLink
from decouple import config as decouple_config


# fmt: off
# noinspection PyPep8

Expand Down Expand Up @@ -57,21 +57,20 @@ def save(self, *args, **kwargs):
return super().save(*args, **kwargs)


# class UserMentor(models.Model):
# id = models.CharField(primary_key=True, max_length=36)
# user = models.ForeignKey(User, models.DO_NOTHING)
# about = models.CharField(max_length=1000, blank=True, null=True)
# reason = models.CharField(max_length=1000, blank=True, null=True)
# hours = models.IntegerField()
# interest_groups = models.ForeignKey(UserIgLink, models.DO_NOTHING, db_column='interest_groups', blank=True, null=True)
# updated_by = models.ForeignKey(User, models.DO_NOTHING, db_column='updated_by', related_name='usermentor_updated_by_set')
# updated_at = models.DateTimeField(blank=True, null=True)
# created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by', related_name='usermentor_created_by_set')
# created_at = models.DateTimeField(blank=True, null=True)

# class Meta:
# managed = False
# db_table = 'user_mentor'
class UserMentor(models.Model):
id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4)
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_mentor_user')
about = models.CharField(max_length=1000, blank=True, null=True)
reason = models.CharField(max_length=1000, blank=True, null=True)
hours = models.IntegerField()
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by', related_name='user_mentor_updated_by_set')
updated_at = models.DateTimeField(blank=True, null=True)
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='created_by', related_name='user_mentor_created_by_set')
created_at = models.DateTimeField(blank=True, null=True)

class Meta:
managed = False
db_table = 'user_mentor'

class UserReferralLink(models.Model):
id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4)
Expand Down

0 comments on commit c574720

Please sign in to comment.