Skip to content

Commit a823ed5

Browse files
Srivatsa19Lawful2002Anunaya07Aksh-Bansal-devakshatnema
authored
Gad 2 2025 dashboard integrated (#1356)
* GAD-5: Fix responsiveness (#1125) Co-authored-by: A Anunaya <[email protected]> Co-authored-by: Aksh Bansal <[email protected]> * Implemented the cerate_request, process_request and approve/reject_request use cases. * GAD -5 Dashboard Changes (#1325) * dashboard and usercard updated (#1329) * Fixing ui bugs (#1335) * Changes made --------- Co-authored-by: Harshvardhan Singh <[email protected]> Co-authored-by: A Anunaya <[email protected]> Co-authored-by: Aksh Bansal <[email protected]> Co-authored-by: akshatnema <[email protected]> Co-authored-by: BlackHAWK2001 <[email protected]> Co-authored-by: Arpit Tak <[email protected]> Co-authored-by: SukulSarve <[email protected]>
1 parent 5de2ff2 commit a823ed5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+5632
-529
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def global_vars(request):
2+
return {
3+
'global_var': request.session.get('currentDesignationSelected', 'default_value'),
4+
'global_var2': request.session.get('allDesignations', 'default_value2'),
5+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# custom_middleware.py
2+
from django.contrib.auth.signals import user_logged_in
3+
from django.dispatch import receiver
4+
from applications.globals.models import (ExtraInfo, Feedback, HoldsDesignation,
5+
Issue, IssueImage, DepartmentInfo)
6+
from django.shortcuts import get_object_or_404, redirect, render
7+
8+
def user_logged_in_middleware(get_response):
9+
@receiver(user_logged_in)
10+
def user_logged_in_handler(sender, user, request, **kwargs):
11+
if 'function_executed' not in request.session:
12+
# Run the function only if the flag is not set
13+
# Assuming user is a model with the desired data field, retrieve the data
14+
# For example, if your User model has a field named 'custom_field', you can access it like:
15+
if user.is_authenticated:
16+
desig = list(HoldsDesignation.objects.select_related('user','working','designation').all().filter(working = request.user).values_list('designation'))
17+
print(desig)
18+
b = [i for sub in desig for i in sub]
19+
design = HoldsDesignation.objects.select_related('user','designation').filter(working=request.user)
20+
21+
designation=[]
22+
23+
designation.append(str(user.extrainfo.user_type))
24+
for i in design:
25+
if str(i.designation) != str(user.extrainfo.user_type):
26+
print('-------')
27+
print(i.designation)
28+
print(user.extrainfo.user_type)
29+
print('')
30+
designation.append(str(i.designation))
31+
32+
for i in designation:
33+
print(i)
34+
35+
request.session['currentDesignationSelected'] = designation[0]
36+
request.session['allDesignations'] = designation
37+
print("logged iN")
38+
39+
# Set the flag in the session to indicate that the function has bee+n executed
40+
request.session['function_executed'] = True
41+
42+
def middleware(request):
43+
if request.user.is_authenticated:
44+
user_logged_in_handler(request.user, request.user, request)
45+
response = get_response(request)
46+
return response
47+
48+
return middleware

FusionIIIT/Fusion/settings/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
'django.contrib.auth.middleware.AuthenticationMiddleware',
164164
'django.contrib.messages.middleware.MessageMiddleware',
165165
'django.middleware.clickjacking.XFrameOptionsMiddleware',
166+
'Fusion.middleware.custom_middleware.user_logged_in_middleware',
166167
]
167168

168169
ROOT_URLCONF = 'Fusion.urls'
@@ -178,6 +179,7 @@
178179
'django.template.context_processors.request',
179180
'django.contrib.auth.context_processors.auth',
180181
'django.contrib.messages.context_processors.messages',
182+
'Fusion.context_processors.global_vars',
181183
],
182184
},
183185
},
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Generated by Django 3.1.5 on 2024-03-08 10:23
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('academic_procedures', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='assistantshipclaim',
15+
name='year',
16+
field=models.IntegerField(choices=[(2024, 2024), (2023, 2023)]),
17+
),
18+
migrations.AlterField(
19+
model_name='course_registration',
20+
name='working_year',
21+
field=models.IntegerField(blank=True, choices=[(2024, 2024), (2023, 2023)], null=True),
22+
),
23+
migrations.AlterField(
24+
model_name='finalregistrations',
25+
name='batch',
26+
field=models.IntegerField(default=2024),
27+
),
28+
migrations.AlterField(
29+
model_name='messdue',
30+
name='year',
31+
field=models.IntegerField(choices=[(2024, 2024), (2023, 2023)]),
32+
),
33+
migrations.AlterField(
34+
model_name='register',
35+
name='year',
36+
field=models.IntegerField(default=2024),
37+
),
38+
]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Generated by Django 3.1.5 on 2024-03-08 10:23
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('eis', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='emp_achievement',
15+
name='a_year',
16+
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
17+
),
18+
migrations.AlterField(
19+
model_name='emp_confrence_organised',
20+
name='k_year',
21+
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
22+
),
23+
migrations.AlterField(
24+
model_name='emp_expert_lectures',
25+
name='l_year',
26+
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
27+
),
28+
migrations.AlterField(
29+
model_name='emp_keynote_address',
30+
name='k_year',
31+
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
32+
),
33+
migrations.AlterField(
34+
model_name='emp_mtechphd_thesis',
35+
name='s_year',
36+
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
37+
),
38+
migrations.AlterField(
39+
model_name='emp_patents',
40+
name='p_year',
41+
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
42+
),
43+
migrations.AlterField(
44+
model_name='emp_published_books',
45+
name='pyear',
46+
field=models.IntegerField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name='year'),
47+
),
48+
migrations.AlterField(
49+
model_name='emp_research_papers',
50+
name='year',
51+
field=models.CharField(blank=True, choices=[(1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], max_length=10, null=True),
52+
),
53+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from applications.filetracking.models import File, Tracking
2+
from django.core.files import File as DjangoFile
3+
from rest_framework import serializers
4+
5+
6+
class FileSerializer(serializers.ModelSerializer):
7+
class Meta:
8+
model = File
9+
fields = '__all__'
10+
11+
12+
class TrackingSerializer(serializers.ModelSerializer):
13+
class Meta:
14+
model = Tracking
15+
fields = '__all__'
16+
17+
18+
class FileHeaderSerializer(serializers.ModelSerializer):
19+
'''
20+
This serializes everything except the attachments of a file and whether it is read or not
21+
'''
22+
class Meta:
23+
model = File
24+
exclude = ['upload_file', 'is_read']
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from django.conf.urls import url
2+
from .views import (
3+
CreateFileView,
4+
ViewFileView,
5+
DeleteFileView,
6+
ViewInboxView,
7+
ViewOutboxView,
8+
ViewHistoryView,
9+
ForwardFileView,
10+
GetDesignationsView,
11+
)
12+
13+
urlpatterns = [
14+
url(r'^file/$', CreateFileView.as_view(), name='create_file'),
15+
url(r'^file/(?P<file_id>\d+)/$', ViewFileView.as_view(), name='view_file'),
16+
url(r'^file/(?P<file_id>\d+)/$', DeleteFileView.as_view(), name='delete_file'),
17+
url(r'^inbox/$', ViewInboxView.as_view(), name='view_inbox'),
18+
url(r'^outbox/$', ViewOutboxView.as_view(), name='view_outbox'),
19+
url(r'^history/(?P<file_id>\d+)/$', ViewHistoryView.as_view(), name='view_history'),
20+
url(r'^file/(?P<file_id>\d+)/$', ForwardFileView.as_view(), name='forward_file'),
21+
url(r'^designations/(?P<username>\w+)/$', GetDesignationsView.as_view(), name='get_designations'),
22+
]
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
from rest_framework.views import APIView
2+
from rest_framework.response import Response
3+
from rest_framework import status, permissions
4+
from rest_framework.authentication import TokenAuthentication
5+
from ..models import File
6+
from ..sdk.methods import create_file, view_file, delete_file, view_inbox, view_outbox, view_history, forward_file, get_designations
7+
8+
class CreateFileView(APIView):
9+
authentication_classes = [TokenAuthentication]
10+
permission_classes = [permissions.IsAuthenticated]
11+
12+
def post(self, request):
13+
try:
14+
current_user = request.user.username
15+
current_designation = request.data.get('designation')
16+
receiver_username = request.data.get('receiver_username')
17+
receiver_designation = request.data.get('receiver_designation')
18+
subject = request.data.get('subject')
19+
description = request.data.get('description')
20+
21+
if None in [current_designation, receiver_username, receiver_designation, subject, description]:
22+
return Response({'error': 'One or more required fields are missing.'}, status=status.HTTP_400_BAD_REQUEST)
23+
24+
file_id = create_file(uploader=current_user, uploader_designation=current_designation,
25+
receiver=receiver_username, receiver_designation=receiver_designation, subject=subject, description=description)
26+
27+
return Response({'file_id': file_id}, status=status.HTTP_201_CREATED)
28+
except Exception as e:
29+
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)
30+
31+
32+
class ViewFileView(APIView):
33+
authentication_classes = [TokenAuthentication]
34+
permission_classes = [permissions.IsAuthenticated]
35+
36+
def get(self, request, file_id):
37+
try:
38+
file_details = view_file(int(file_id))
39+
return Response(file_details, status=status.HTTP_200_OK)
40+
except ValueError:
41+
return Response({'error': 'Invalid file ID format.'}, status=status.HTTP_400_BAD_REQUEST)
42+
except File.DoesNotExist:
43+
return Response({'error': 'File not found.'}, status=status.HTTP_404_NOT_FOUND)
44+
except Exception as e:
45+
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)
46+
47+
48+
class DeleteFileView(APIView):
49+
#authentication_classes = [TokenAuthentication]
50+
#permission_classes = [permissions.IsAuthenticated]
51+
52+
def delete(self, request, file_id, *args, **kwargs):
53+
success = delete_file(int(file_id))
54+
if success:
55+
return Response({'message': 'File deleted successfully'},
56+
status=status.HTTP_204_NO_CONTENT)
57+
else:
58+
return Response({'error': 'File not found'},
59+
status=status.HTTP_404_NOT_FOUND)
60+
61+
62+
class ViewInboxView(APIView):
63+
#authentication_classes = [TokenAuthentication]
64+
#permission_classes = [permissions.IsAuthenticated]
65+
66+
def get(self, request, *args, **kwargs):
67+
inbox_files = view_inbox(
68+
request.user.username,
69+
request.query_params.get('designation'),
70+
request.query_params.get('src_module'))
71+
return Response(inbox_files)
72+
73+
74+
class ViewOutboxView(APIView):
75+
#authentication_classes = [TokenAuthentication]
76+
#permission_classes = [permissions.IsAuthenticated]
77+
78+
def get(self, request, *args, **kwargs):
79+
outbox_files = view_outbox(
80+
request.user.username,
81+
request.query_params.get('designation'),
82+
request.query_params.get('src_module'))
83+
return Response(outbox_files)
84+
85+
86+
class ViewHistoryView(APIView):
87+
#authentication_classes = [TokenAuthentication]
88+
#permission_classes = [permissions.IsAuthenticated]
89+
90+
def get(self, request, file_id, *args, **kwargs):
91+
history = view_history(int(file_id))
92+
return Response(history)
93+
94+
95+
class ForwardFileView(APIView):
96+
#authentication_classes = [TokenAuthentication]
97+
#permission_classes = [permissions.IsAuthenticated]
98+
99+
def post(self, request, file_id, *args, **kwargs):
100+
new_tracking_id = forward_file(int(file_id), **request.data)
101+
return Response({'tracking_id': new_tracking_id},
102+
status=status.HTTP_201_CREATED)
103+
104+
105+
class GetDesignationsView(APIView):
106+
#authentication_classes = [TokenAuthentication]
107+
#permission_classes = [permissions.IsAuthenticated]
108+
109+
def get(self, request, username, *args, **kwargs):
110+
user_designations = get_designations(username)
111+
return Response({'designations': user_designations})
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from django.shortcuts import render, get_object_or_404
2+
from django.contrib.auth.models import User
3+
from applications.globals.models import ExtraInfo, HoldsDesignation
4+
5+
6+
def user_check(request):
7+
"""
8+
This function is used to check if the user is a student or not.
9+
Its return type is bool.
10+
@param:
11+
request - contains metadata about the requested page
12+
13+
@Variables:
14+
current_user - get user from request
15+
user_details - extract details of the user from the database
16+
desig_id - check for designation
17+
student - designation for a student
18+
final_user - final designation of the request(our user)
19+
"""
20+
try:
21+
current_user = get_object_or_404(User, username=request.user.username)
22+
user_details = ExtraInfo.objects.select_related('user','department').get(user=request.user)
23+
des = HoldsDesignation.objects.all().select_related().filter(user=request.user).first()
24+
if str(des.designation) == "student":
25+
return True
26+
else:
27+
return False
28+
except Exception as e:
29+
return False
30+
31+
def user_is_student(view_func):
32+
def _wrapped_view(request, *args, **kwargs):
33+
if user_check(request):
34+
return render(request, 'filetracking/fileTrackingNotAllowed.html')
35+
else:
36+
return view_func(request, *args, **kwargs)
37+
return _wrapped_view
38+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
4+
from applications.filetracking.models import File, Tracking
5+
6+
admin.site.register(File)
7+
admin.site.register(Tracking)

0 commit comments

Comments
 (0)