Skip to content

Commit

Permalink
Merge pull request #1187 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
minor fix in registration
  • Loading branch information
adnankattekaden authored Oct 6, 2023
2 parents 6fd3798 + b1b0e24 commit a086c09
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 41 deletions.
3 changes: 2 additions & 1 deletion api/common/common_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def get(self, request):
).annotate(karma_earned=Sum('user__karma_activity_log_user__task__karma',
filter=Q(user__karma_activity_log_user__task__ig=F('circle__ig'))))

paginated_queryset = CommonUtils.get_paginated_queryset(student_info, request, search_fields=[],
paginated_queryset = CommonUtils.get_paginated_queryset(student_info, request,
search_fields=['first_name', 'last_name', 'mu_id'],
sort_fields={'name': 'name'})

student_info_data = StudentInfoSerializer(paginated_queryset.get('queryset'), many=True).data
Expand Down
14 changes: 7 additions & 7 deletions api/common/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from . import common_views

urlpatterns=[
path('lc-dashboard/', common_views.LcDashboardAPI.as_view()),
path('lc-report/', common_views.LcReportAPI.as_view()),
path('<str:log_type>/',common_views.CommonAPI.as_view()),
path('view/<str:log_type>/',common_views.ViewCommonAPI.as_view()),
path('clear/<str:log_type>/',common_views.ClearCommonAPI.as_view()),
]
urlpatterns = [
path('lc-dashboard/', common_views.LcDashboardAPI.as_view()),
path('lc-report/', common_views.LcReportAPI.as_view()),
path('<str:log_type>/', common_views.CommonAPI.as_view()),
path('view/<str:log_type>/', common_views.ViewCommonAPI.as_view()),
path('clear/<str:log_type>/', common_views.ClearCommonAPI.as_view()),
]
8 changes: 7 additions & 1 deletion api/dashboard/lc/dash_lc_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class LearningCircleMainSerializer(serializers.ModelSerializer):

class Meta:
model = LearningCircle
fields = ['name', 'ig_name', 'member_count', 'members', 'meet_place', 'meet_time']
fields = ['name', 'ig_name', 'member_count', 'members', 'meet_place', 'meet_time', 'lead_name']

def get_lead_name(self, obj):
return UserCircleLink.objects.filter(circle=obj, accepted=1, lead=True).first().user.fullname
Expand All @@ -364,15 +364,21 @@ class LearningCircleDataSerializer(serializers.ModelSerializer):
interest_group = serializers.SerializerMethodField()
college = serializers.SerializerMethodField()
learning_circle = serializers.SerializerMethodField()
students = serializers.SerializerMethodField()

class Meta:
model = LearningCircle
fields = [
"interest_group",
"college",
"learning_circle",
"students"
]

def get_students(self, obj):

None

def get_learning_circle(self, obj):
return LearningCircle.objects.all().count()

Expand Down
2 changes: 0 additions & 2 deletions api/dashboard/task/dash_task_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class Meta:


class TaskModifySerializer(serializers.ModelSerializer):
created_by = serializers.CharField(required=False)

class Meta:
model = TaskList
fields = (
Expand Down
33 changes: 26 additions & 7 deletions api/dashboard/task/dash_task_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)


class TaskApi(APIView):
class TaskListAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required(
Expand All @@ -26,15 +26,12 @@ class TaskApi(APIView):
RoleType.ASSOCIATE.value,
]
)
def get(self, request, task_id=None):
def get(self, request):
try:
task_queryset = TaskList.objects.select_related(
"created_by", "updated_by", "channel", "type", "level", "ig", "org"
).all()

if task_id:
task_queryset = task_queryset.get(pk=task_id)

paginated_queryset = CommonUtils.get_paginated_queryset(
task_queryset,
request,
Expand Down Expand Up @@ -89,6 +86,27 @@ def get(self, request, task_id=None):
except TaskList.DoesNotExist as e:
return CustomResponse(general_message=str(e)).get_failure_response()


class TaskAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required(
[
RoleType.ADMIN.value,
RoleType.FELLOW.value,
RoleType.ASSOCIATE.value,
]
)
def get(self, request, task_id):
try:
task_queryset = TaskList.objects.get(pk=task_id)

task_serializer = TaskModifySerializer(task_queryset, many=False)
return CustomResponse(response=task_serializer.data).get_success_response()

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

@role_required(
[
RoleType.ADMIN.value,
Expand Down Expand Up @@ -123,13 +141,14 @@ def put(self, request, task_id): # edit

task = TaskList.objects.get(pk=task_id)

serializer = TaskModifySerializer(task, data=request.data)
serializer = TaskModifySerializer(task, data=request.data, partial=True)
if not serializer.is_valid():
return CustomResponse(message=serializer.errors).get_failure_response()

serializer.save()

return CustomResponse(
general_message="Task edited successfully"
general_message=serializer.data
).get_success_response()

except TaskList.DoesNotExist as e:
Expand Down
4 changes: 2 additions & 2 deletions api/dashboard/task/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
path('level/', dash_task_view.LevelDropdownAPI.as_view()),
path('task-types/', dash_task_view.TaskTypesDropDownAPI.as_view()),

path('', dash_task_view.TaskApi.as_view()), # list task, create
path('', dash_task_view.TaskListAPI.as_view()), # list task, create
path('csv/', dash_task_view.TaskListCSV.as_view()), # CSV
path('<str:task_id>/', dash_task_view.TaskApi.as_view()), # get task, edit, delete
path('<str:task_id>/', dash_task_view.TaskAPI.as_view()), # get task, edit, delete

path('import/', dash_task_view.ImportTaskListCSV.as_view()),
path('events/', dash_task_view.EventDropDownApi.as_view()),
Expand Down
2 changes: 2 additions & 0 deletions api/dashboard/user/dash_user_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class UserVerificationSerializer(serializers.ModelSerializer):
discord_id = serializers.ReadOnlyField(source="user.discord_id")
mu_id = serializers.ReadOnlyField(source="user.mu_id")
email = serializers.ReadOnlyField(source="user.email")
mobile = serializers.ReadOnlyField(source="user.mobile")
role_title = serializers.ReadOnlyField(source="role.title")

class Meta:
Expand All @@ -238,6 +239,7 @@ class Meta:
"role_id",
"role_title",
"email",
"mobile",
]


Expand Down
7 changes: 5 additions & 2 deletions api/dashboard/user/dash_user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,14 @@ def get(self, request):
queryset = CommonUtils.get_paginated_queryset(
user_queryset,
request,
["user__first_name", "user__last_name", "role__title"],
{
search_fields=["user__first_name", "user__last_name", "user__mobile", "user__email", "user__mu_id",
"role__title"],
sort_fields={
"first_name": "user__first_name",
"role_title": "role__title",
"muid": "user__mu_id",
"email": "user__email",
"mobile": "user__mobile",
},
)
serializer = dash_user_serializer.UserVerificationSerializer(
Expand Down
12 changes: 8 additions & 4 deletions api/register/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ class Meta:

class UserDetailSerializer(serializers.ModelSerializer):
role = serializers.SerializerMethodField()
fullname = serializers.CharField(source="user.fullname")
fullname = serializers.SerializerMethodField()

def get_fullname(self, obj):
if obj.last_name is None:
return obj.first_name

return f"{obj.first_name} {obj.last_name}"

def get_role(self, obj):
role_link = obj.user_role_link_user.filter(
Expand Down Expand Up @@ -175,7 +181,6 @@ def create(self, validated_data):
)
validated_data.pop("invite_code", None) or validated_data.pop("mu_id", None)
return super().create(validated_data)



class IntegrationSerializer(serializers.Serializer):
Expand Down Expand Up @@ -216,7 +221,6 @@ def create(self, validated_data):
return kkem_link



class UserSerializer(serializers.ModelSerializer):
role = serializers.PrimaryKeyRelatedField(
queryset=Role.objects.all(), required=False, write_only=True
Expand Down Expand Up @@ -268,7 +272,7 @@ class Meta:
"integration",
"referral"
]


class RegisterSerializer(serializers.Serializer):
user = UserSerializer()
Expand Down
20 changes: 5 additions & 15 deletions db/learning_circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,17 @@ class LearningCircle(models.Model):
id = models.CharField(primary_key=True, max_length=36)
name = models.CharField(max_length=255, unique=True)
circle_code = models.CharField(unique=True, max_length=36)
ig = models.ForeignKey(
InterestGroup, on_delete=models.CASCADE, blank=True, null=True
)
ig = models.ForeignKey(InterestGroup, on_delete=models.CASCADE, blank=True, null=True)
org = models.ForeignKey(Organization, on_delete=models.CASCADE, blank=True, null=True)
meet_place = models.CharField(max_length=255, blank=True, null=True)
meet_time = models.CharField(max_length=10, blank=True, null=True)
day = models.CharField(max_length=20, blank=True, null=True)
note = models.CharField(max_length=500, blank=True, null=True)
updated_by = models.ForeignKey(
User,
models.DO_NOTHING,
db_column="updated_by",
related_name="learning_circle_updated_by",
)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column="updated_by",
related_name="learning_circle_updated_by")
updated_at = models.DateTimeField()
created_by = models.ForeignKey(
User,
models.DO_NOTHING,
db_column="created_by",
related_name="learning_circle_created_by",
)
created_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column="created_by",
related_name="learning_circle_created_by")
created_at = models.DateTimeField()

class Meta:
Expand Down

0 comments on commit a086c09

Please sign in to comment.