Skip to content

Commit

Permalink
feat: add office location for special org teams
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhruv9449 committed Mar 29, 2024
1 parent 4f6370d commit 20e40c0
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
FAQ,
SpecialFile,
)
from student_welfare_backend.users.api.serializers import UserLoginSerializer
from student_welfare_backend.users.api.serializers import UserDetailSerializer


class UserOrganizationRelationSerializer(serializers.ModelSerializer):
user = UserLoginSerializer()
user = UserDetailSerializer()

class Meta:
model = UserOrganizationRelation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ class OrganizationViewSet(ReadOnlyModelViewSet):
search_fields = ["name"]
ordering_fields = ["name"]
ordering = ["name"]
special_organization_types = ["student_welfare", "student_council", "greviance_cell"]

def get_serializer_class(self):
if self.action == "list":
if (self.action == "list") and (
self.request.query_params.get("type", None) not in self.special_organization_types
):
return OrganizationSerializer

return OrganizationDetailSerializer


class SpecialOrganizationsAPIView(APIView):
authentication_classes = []
Expand All @@ -66,13 +70,13 @@ def get(request):
{"detail": "Please provide a type parameter"},
status=status.HTTP_400_BAD_REQUEST,
)

if organization_type not in ["student_welfare", "student_council", "greviance_cell"]:
return Response(
{"detail": "Invalid type parameter"},
status=status.HTTP_400_BAD_REQUEST,
)

organizations = Organization.objects.filter(type=organization_type).order_by("-name").all()
if len(organizations) == 0:
return Response(
Expand All @@ -96,15 +100,20 @@ class OrganizationAdminViewSet(ModelViewSet):
search_fields = ["name"]
ordering_fields = ["name"]
ordering = ["name"]
special_organization_types = ["student_welfare", "student_council", "greviance_cell"]

def get_serializer_class(self):
if self.action == "list":
if (self.action == "list") and (
self.request.query_params.get("type", None) not in self.special_organization_types
):
return OrganizationSerializer

return OrganizationDetailSerializer


class OrganizationBulkUploadView(BaseBulkUploadView):
csv_type = "organization"


class OrganizationBulkDownloadView(BaseBulkDownloadView):
csv_type = "organization"
csv_type = "organization"
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class Meta:
fields = ["username", "name", "is_faculty", "verified"]


class SWTeamSerializer(serializers.ModelSerializer):
role = serializers.SerializerMethodField()

class UserDetailSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = [
Expand All @@ -32,19 +30,10 @@ class Meta:
"email",
"phone_no",
"is_faculty",
"role",
"tenure",
"office_location",
]

def get_role(self, obj):
if obj.is_dsw:
return "dsw"
elif obj.is_adsw:
return "adsw"
elif obj.is_faculty:
return "faculty"
else:
return "student"


class UserAdminSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
UserAdminViewset,
UserBulkUploadView,
UserBulkDownloadView,
SWTeamView,
)
from rest_framework_simplejwt.views import TokenRefreshView

Expand All @@ -28,7 +27,6 @@
VerifyResetPasswordOTPView.as_view(),
name="verify_reset_password_otp",
),
path("sw_team/", SWTeamView.as_view(), name="sw_team"),
path("admin/users/bulk_upload/", UserBulkUploadView.as_view(), name="user_bulk_upload"),
path("admin/users/bulk_download/", UserBulkDownloadView.as_view(), name="user_bulk_download"),
]
Expand Down
13 changes: 0 additions & 13 deletions student_welfare_backend/student_welfare_backend/users/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
UserLoginSerializer,
UserAdminSerializer,
UserAdminListSerializer,
SWTeamSerializer,
)
from student_welfare_backend.customs.permissions import IsDSW, IsADSW
from student_welfare_backend.customs.views import BaseBulkUploadView, BaseBulkDownloadView
Expand Down Expand Up @@ -294,18 +293,6 @@ def post(request):
return Response({"detail": "Password reset successful!"}, status=HTTPStatus.OK)


class SWTeamView(APIView):
authentication_classes = []
permission_classes = []

@staticmethod
def get(request):
sw_team = User.objects.filter(Q(is_dsw=True) | Q(is_adsw=True))

serializer = SWTeamSerializer(sw_team, many=True)
return Response(status=status.HTTP_200_OK, data=serializer.data)


class UserAdminViewset(ModelViewSet):
queryset = User.objects.all()
permission_classes = [IsAuthenticated, IsDSW | IsADSW]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.10 on 2024-03-29 16:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0006_user_is_adsw'),
]

operations = [
migrations.AddField(
model_name='user',
name='office_location',
field=models.CharField(blank=True, max_length=255, verbose_name='Office location of the user'),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class User(AbstractUser):
is_faculty = models.BooleanField(_("User is faculty"), default=False)
is_dsw = models.BooleanField(_("User is DSW"), default=False)
is_adsw = models.BooleanField(_("User is ADSW"), default=False)
office_location = models.CharField(_("Office location of the user"), blank=True, max_length=255)

def get_absolute_url(self):
"""Get url for user's detail view.
Expand Down

0 comments on commit 20e40c0

Please sign in to comment.