-
Notifications
You must be signed in to change notification settings - Fork 982
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7939417
commit 087fadf
Showing
40 changed files
with
2,841 additions
and
1,531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from rest_framework import permissions | ||
from django.shortcuts import get_object_or_404 | ||
from applications.academic_information.models import ExtraInfo | ||
from applications.globals.models import User | ||
|
||
|
||
class IsFacultyStaffOrReadOnly(permissions.BasePermission): | ||
""" | ||
Custom permission to only allow faculty and staff to edit it. | ||
""" | ||
|
||
def has_permission(self, request, view): | ||
# Read permissions are allowed to any request, | ||
# so we'll always allow GET, HEAD or OPTIONS requests. | ||
if request.method in permissions.SAFE_METHODS: | ||
return True | ||
#only faculty and staff are able to make post request | ||
return not request.user.holds_designations.filter(designation__name='student').exists() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from rest_framework import serializers | ||
from applications.department.models import Announcements | ||
from applications.academic_information.models import Spi, Student | ||
from applications.globals.models import (Designation, ExtraInfo, | ||
HoldsDesignation,Faculty) | ||
from applications.eis.models import (faculty_about, emp_research_projects) | ||
|
||
|
||
class AnnouncementSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Announcements | ||
fields = ('__all__') | ||
|
||
extra_kwargs = { | ||
'maker_id': {'required': False} | ||
} | ||
|
||
def create(self, validated_data): | ||
user = self.context['request'].user | ||
user_info = ExtraInfo.objects.all().select_related('user','department').filter(user=user).first() | ||
validated_data['maker_id'] = user_info | ||
return Announcements.objects.create(**validated_data) | ||
|
||
class ExtraInfoSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = ExtraInfo | ||
fields = ('__all__') | ||
|
||
class SpiSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Spi | ||
fields = ('__all__') | ||
|
||
class StudentSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Student | ||
fields = ('__all__') | ||
|
||
class DesignationSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Designation | ||
fields = ('__all__') | ||
|
||
class HoldsDesignationSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = HoldsDesignation | ||
fields = ('__all__') | ||
|
||
class FacultySerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Faculty | ||
fields = ('__all__') | ||
|
||
class faculty_aboutSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = faculty_about | ||
fields = ('__all__') | ||
|
||
class emp_research_projectsSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = emp_research_projects | ||
fields = ('__all__') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.conf.urls import url | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
url(r'announcements/$', views.ListCreateAnnouncementView.as_view(),name='announcements'), | ||
url(r'dep-main/$', views.DepMainAPIView.as_view(), name='depmain'), | ||
url(r'fac-view/$', views.FacAPIView.as_view(), name='facapi'), | ||
url(r'staff-view/$',views.StaffAPIView.as_view(),name='staffapi'), | ||
url(r'all-students/(?P<bid>[0-9]+)/$', views.AllStudentsAPIView.as_view() ,name='all_students') | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
from rest_framework import generics | ||
from rest_framework.views import APIView | ||
from applications.department.models import Announcements | ||
from applications.academic_information.models import Spi, Student | ||
from applications.globals.models import (Designation, ExtraInfo, | ||
HoldsDesignation,Faculty) | ||
from applications.eis.models import (faculty_about, emp_research_projects) | ||
from .serializers import (AnnouncementSerializer,ExtraInfoSerializer,SpiSerializer,StudentSerializer,DesignationSerializer | ||
,HoldsDesignationSerializer,FacultySerializer,faculty_aboutSerializer,emp_research_projectsSerializer) | ||
from rest_framework.permissions import IsAuthenticated | ||
from .permissions import IsFacultyStaffOrReadOnly | ||
from django.http import JsonResponse | ||
from django.shortcuts import get_object_or_404, render, redirect | ||
from django.contrib.auth.models import User | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from django.contrib.auth.decorators import login_required | ||
from django.urls import reverse | ||
from datetime import date | ||
from notification.views import department_notif | ||
|
||
|
||
class ListCreateAnnouncementView(generics.ListCreateAPIView): | ||
queryset = Announcements.objects.all() | ||
serializer_class = AnnouncementSerializer | ||
permission_classes = (IsAuthenticated, IsFacultyStaffOrReadOnly) | ||
|
||
|
||
class DepMainAPIView(APIView): | ||
def get(self, request): | ||
user = request.user | ||
usrnm = get_object_or_404(User, username=user.username) | ||
user_info = ExtraInfo.objects.all().select_related('user', 'department').filter(user=usrnm).first() | ||
ann_maker_id = user_info.id | ||
user_info = ExtraInfo.objects.all().select_related('user', 'department').get(id=ann_maker_id) | ||
|
||
fac_view = user.holds_designations.filter(designation__name='faculty').exists() | ||
student = user.holds_designations.filter(designation__name='student').exists() | ||
staff = user.holds_designations.filter(designation__name='staff').exists() | ||
|
||
context = browse_announcements() | ||
context_f = faculty() | ||
user_designation = "" | ||
|
||
if fac_view: | ||
user_designation = "faculty" | ||
elif student: | ||
user_designation = "student" | ||
else: | ||
user_designation = "staff" | ||
|
||
# serailizing the data | ||
# announcements_serailizer = AnnouncementSerializer(context, many=True) | ||
|
||
|
||
response_data = { | ||
"user_designation": user_designation, | ||
"announcements": context, | ||
"fac_list": context_f | ||
} | ||
|
||
|
||
return Response(data = response_data, status=status.HTTP_200_OK) | ||
# return Response(data = response_data, status=status.HTTP_200_OK) | ||
|
||
class FacAPIView(APIView): | ||
def get(self,request): | ||
usrnm = get_object_or_404(User, username=request.user.username) | ||
user_info = ExtraInfo.objects.all().select_related('user','department').filter(user=usrnm).first() | ||
|
||
|
||
context = browse_announcements() | ||
|
||
|
||
# Serialize the data into JSON formats | ||
data = { | ||
"user_designation": user_info.user_type, | ||
"announcements": list(context.values()), # Assuming 'context' is a dictionary | ||
} | ||
|
||
return Response(data) | ||
|
||
class StaffAPIView(APIView): | ||
def get(self,request): | ||
usrnm = get_object_or_404(User, username=request.user.username) | ||
user_info = ExtraInfo.objects.all().select_related('user','department').filter(user=usrnm).first() | ||
|
||
|
||
context = browse_announcements() | ||
|
||
|
||
# Serialize the data into JSON formats | ||
data = { | ||
"user_designation": user_info.user_type, | ||
"announcements": list(context.values()), # Assuming 'context' is a dictionary | ||
} | ||
|
||
return Response(data) | ||
|
||
class AllStudentsAPIView(APIView): | ||
def get(self,request,bid): | ||
print(self.request.query_params) | ||
# bid = self.request.query_params.get() | ||
|
||
# Decode bid into filter criteria | ||
filter_criteria = decode_bid(bid) | ||
if not filter_criteria: | ||
return Response({'detail': 'Invalid bid value'}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
# Apply additional department filter since it seems fixed | ||
filter_criteria['id__department__name'] = 'CSE' | ||
|
||
student_list1 = Student.objects.order_by('id').filter( | ||
id__user_type='student', | ||
**filter_criteria | ||
).select_related('id') | ||
|
||
# paginator = Paginator(student_list1, 25, orphans=5) | ||
# page_number = request.GET.get('page') | ||
# student_list = paginator.get_page(page_number) | ||
|
||
# Serialize the queryset | ||
serializer = StudentSerializer(student_list1, many=True) | ||
serialized_data = serializer.data | ||
|
||
# Create a response dictionary | ||
response_data = {'student_list': serialized_data} | ||
|
||
return Response(response_data) | ||
|
||
|
||
def decode_bid(bid): | ||
"""Decodes the bid structure into programme, batch, and department (if applicable).""" | ||
try: | ||
department_code = bid[0] | ||
programme = { | ||
'1': 'B.Tech', | ||
'2': 'M.Tech', | ||
'3': 'PhD', # Assuming there are more departments | ||
}[department_code] | ||
batch = 2021 - len(bid) + 1 | ||
return {'programme': programme, 'batch': batch} | ||
except (IndexError, KeyError): | ||
return None # Handle malformed bid values | ||
|
||
def browse_announcements(): | ||
""" | ||
This function is used to browse Announcements Department-Wise | ||
made by different faculties and admin. | ||
@variables: | ||
cse_ann - Stores CSE Department Announcements | ||
ece_ann - Stores ECE Department Announcements | ||
me_ann - Stores ME Department Announcements | ||
sm_ann - Stores SM Department Announcements | ||
all_ann - Stores Announcements intended for all Departments | ||
context - Dictionary for storing all above data | ||
""" | ||
cse_ann = Announcements.objects.filter(department="CSE") | ||
ece_ann = Announcements.objects.filter(department="ECE") | ||
me_ann = Announcements.objects.filter(department="ME") | ||
sm_ann = Announcements.objects.filter(department="SM") | ||
all_ann = Announcements.objects.filter(department="ALL") | ||
|
||
# serailizing the data | ||
cse_ann_serialized = AnnouncementSerializer(cse_ann, many=True) | ||
ece_ann_serialized = AnnouncementSerializer(ece_ann, many=True) | ||
me_ann_serialized = AnnouncementSerializer(me_ann, many=True) | ||
sm_ann_serialized = AnnouncementSerializer(sm_ann, many=True) | ||
all_ann_serialized = AnnouncementSerializer(all_ann, many=True) | ||
|
||
context = { | ||
"cse" : cse_ann_serialized.data, | ||
"ece" : ece_ann_serialized.data, | ||
"me" : me_ann_serialized.data, | ||
"sm" : sm_ann_serialized.data, | ||
"all" : all_ann_serialized.data | ||
} | ||
|
||
return context | ||
|
||
def faculty(): | ||
""" | ||
This function is used to Return data of Faculties Department-Wise. | ||
@variables: | ||
cse_f - Stores data of faculties from CSE Department | ||
ece_f - Stores data of faculties from ECE Department | ||
me_f - Stores data of faculties from ME Department | ||
sm_f - Stores data of faculties from ME Department | ||
context_f - Stores all above variables in Dictionary | ||
""" | ||
cse_f=ExtraInfo.objects.filter(department__name='CSE',user_type='faculty') | ||
ece_f=ExtraInfo.objects.filter(department__name='ECE',user_type='faculty') | ||
me_f=ExtraInfo.objects.filter(department__name='ME',user_type='faculty') | ||
sm_f=ExtraInfo.objects.filter(department__name='SM',user_type='faculty') | ||
staff=ExtraInfo.objects.filter(user_type='staff') | ||
|
||
# serailizing the data | ||
cse_f = ExtraInfoSerializer(cse_f, many=True) | ||
ece_f = ExtraInfoSerializer(ece_f, many=True) | ||
me_f = ExtraInfoSerializer(me_f, many=True) | ||
sm_f = ExtraInfoSerializer(sm_f, many=True) | ||
staff = ExtraInfoSerializer(staff, many=True) | ||
|
||
|
||
context_f = { | ||
"cse_f" : cse_f.data, | ||
"ece_f" : ece_f.data, | ||
"me_f" : me_f.data, | ||
"sm_f" : sm_f.data, | ||
"staff" : staff.data, | ||
} | ||
return context_f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.