Skip to content

Commit c29708d

Browse files
Merge pull request #1 from kishankoushal/gad-5_2021
Gad 5 2021
2 parents 58a32b0 + f27a5a4 commit c29708d

File tree

15 files changed

+632
-268
lines changed

15 files changed

+632
-268
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
},

FusionIIIT/applications/globals/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
# Endpoint to reset all passwords in DEV environment
2424
url(r'^resetallpass/$', views.reset_all_pass, name='resetallpass'),
2525
# API urls
26-
url(r'^api/', include('applications.globals.api.urls'))
26+
url(r'^api/', include('applications.globals.api.urls')),
27+
url(r'^update_global_variable/$', views.update_global_variable, name='update_global_var'),
2728
]

FusionIIIT/applications/globals/views.py

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,21 +740,26 @@ def dashboard(request):
740740

741741
}
742742
# a=HoldsDesignation.objects.select_related('user','working','designation').filter(designation = user)
743+
print(context)
744+
print(type(user.extrainfo.user_type))
743745
if(request.user.get_username() == 'director'):
744746
return render(request, "dashboard/director_dashboard2.html", {})
745747
elif( "dean_rspc" in designation):
746748
return render(request, "dashboard/dashboard.html", context)
747-
elif user.extrainfo.user_type != 'student':
749+
elif user.extrainfo.user_type != "student":
750+
print ("inside")
748751
designat = HoldsDesignation.objects.select_related().filter(user=user)
749752
response = {'designat':designat}
750753
context.update(response)
751754
return render(request, "dashboard/dashboard.html", context)
752755
else:
756+
print ("inside2")
757+
753758
return render(request, "dashboard/dashboard.html", context)
754759

755760

756761
@login_required(login_url=LOGIN_URL)
757-
def profile(request, username=None):
762+
def profile(request, username=None):
758763
"""
759764
Generic endpoint for views.
760765
If it's a faculty, redirects to /eis/profile/*
@@ -768,16 +773,76 @@ def profile(request, username=None):
768773
"""
769774
user = get_object_or_404(User, Q(username=username)) if username else request.user
770775

771-
772776
editable = request.user == user
777+
print("editable",editable)
773778
profile = get_object_or_404(ExtraInfo, Q(user=user))
779+
print("profile",profile)
774780
if(str(user.extrainfo.user_type)=='faculty'):
781+
print("profile")
775782
return HttpResponseRedirect('/eis/profile/' + (username if username else ''))
776783
if(str(user.extrainfo.department)=='department: Academics'):
784+
print("profile2")
777785
return HttpResponseRedirect('/aims')
778-
current = HoldsDesignation.objects.select_related('user','working','designation').filter(Q(working=user, designation__name="student"))
786+
787+
array = [
788+
"student",
789+
"CC convenor",
790+
"Mechatronic convenor",
791+
"mess_committee",
792+
"mess_convener",
793+
"alumini",
794+
"Electrical_AE",
795+
"Electrical_JE",
796+
"Civil_AE",
797+
"Civil_JE",
798+
"co-ordinator",
799+
"co co-ordinator",
800+
"Convenor",
801+
"Convener",
802+
"cc1convener",
803+
"CC2 convener",
804+
"mess_convener_mess2",
805+
"mess_committee_mess2"
806+
]
807+
808+
# queryset = HoldsDesignation.objects.select_related('user','working','designation').filter(Q(working=user))
809+
810+
# for obj in queryset:
811+
# designation_name = obj.designation.name
812+
# print("designation_name",designation_name)
813+
814+
# design = False
815+
# if designation_name in array:
816+
# design = True
817+
# print("design",design)
818+
# print("designation_name",designation_name)
819+
# if design:
820+
# current = HoldsDesignation.objects.select_relapted('user','working','designation').filter(Q(working=user, designation__name=designation_name))
821+
# for obj in current:
822+
# obj.designation.name = obj.designation.name.replace(designation_name, 'student')
823+
824+
designation_name = ""
825+
design = False
826+
827+
current = HoldsDesignation.objects.select_related('user', 'working', 'designation').filter(Q(working=user))
828+
829+
for obj in current:
830+
designation_name = obj.designation.name
831+
if designation_name in array:
832+
design = True
833+
break
834+
835+
if design:
836+
current = HoldsDesignation.objects.filter(working=user, designation__name=designation_name)
837+
for obj in current:
838+
obj.designation.name = obj.designation.name.replace(designation_name, 'student')
839+
840+
print(user.extrainfo.user_type)
841+
print("current",current)
779842
if current:
843+
print("profile3")
780844
student = get_object_or_404(Student, Q(id=profile.id))
845+
print("student",student)
781846
if editable and request.method == 'POST':
782847
if 'studentapprovesubmit' in request.POST:
783848
status = PlacementStatus.objects.select_related('notify_id','unique_id__id__user','unique_id__id__department').filter(pk=request.POST['studentapprovesubmit']).update(invitation='ACCEPTED', timestamp=timezone.now())
@@ -979,6 +1044,7 @@ def profile(request, username=None):
9791044
return render(request, "globals/student_profile4.html", context)
9801045
if 'achievementsubmit' in request.POST or 'deleteach' in request.POST:
9811046
return render(request, "globals/student_profile5.html", context)
1047+
print("context",context)
9821048
return render(request, "globals/student_profile.html", context)
9831049
else:
9841050
return redirect("/")
@@ -1176,4 +1242,15 @@ def search(request):
11761242
if len(search_results) == 0:
11771243
search_results = []
11781244
context = {'sresults':search_results}
1179-
return render(request, "globals/search.html", context)
1245+
return render(request, "globals/search.html", context),
1246+
1247+
@login_required(login_url=LOGIN_URL)
1248+
def update_global_variable(request):
1249+
if request.method == 'POST':
1250+
selected_option = request.POST.get('dropdown')
1251+
request.session['currentDesignationSelected'] = selected_option
1252+
print(selected_option)
1253+
print(request.session['currentDesignationSelected'])
1254+
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
1255+
# Redirect to home if not a POST request or some issue occurs
1256+
return HttpResponseRedirect(reverse('home'))

FusionIIIT/applications/notifications_extension/api/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
office_module_DeanRSPC_notif,
3232
research_procedures_notif)
3333

34-
# import user
34+
3535

3636
class LeaveModuleNotificationAPIView(APIView):
3737
def post(self, request, *args, **kwargs):

FusionIIIT/applications/notifications_extension/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ def delete(request, slug=None):
99
notification = get_object_or_404(
1010
Notification, recipient=request.user, id=notification_id)
1111
notification.delete()
12-
return HttpResponseRedirect('/')
12+
previous_page = request.META.get('HTTP_REFERER', '/')
13+
# Redirect to the previous page or the home page if the referrer is not available
14+
return HttpResponseRedirect(previous_page)
1315
# return HttpResponseRedirect('dashboard/')
1416
def mark_as_read_and_redirect(request, slug=None):
1517
notification_id = slug2id(slug)

FusionIIIT/notification/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from django.shortcuts import render
22
from requests import Response
33
from notifications.signals import notify
4-
54
# Create your views here.
65

76
def leave_module_notif(sender, recipient, type, date=None):

FusionIIIT/templates/academic_procedures/academic.html

100755100644
Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,39 @@
2222
}
2323

2424
</style>
25+
26+
<style>
27+
.dashboard-container {
28+
margin: 0 3rem;
29+
display: grid;
30+
gap: 3rem;
31+
grid-template-columns: 1fr;
32+
}
33+
34+
.card-container {
35+
display: flex;
36+
flex-direction: column;
37+
align-items: center;
38+
}
39+
40+
@media (min-width:800px) {
41+
.dashboard-container {
42+
grid-template-columns: 3fr 7fr;
43+
}
44+
.module-container {
45+
grid-column: 1/-1;
46+
}
47+
}
48+
49+
@media (min-width:1200px) {
50+
.dashboard-container {
51+
grid-template-columns: 3fr 7fr 3fr;
52+
}
53+
.module-container {
54+
grid-column:auto;
55+
}
56+
}
57+
</style>
2558
{% endblock css %}
2659

2760

@@ -30,13 +63,12 @@
3063
{% include 'dashboard/navbar.html' %}
3164
{% endblock %}
3265

33-
<div class="ui stackable doubling grid">
66+
<div class="dashboard-container">
3467

35-
{% comment %}The left-margin segment!{% endcomment %}
36-
<div class="column"></div>
68+
3769

3870
{% comment %}The left-rail segment starts here!{% endcomment %}
39-
<div class="three wide column">
71+
<div class="card-container">
4072
{% comment %}The user image card starts here!{% endcomment %}
4173
{% block usercard %}
4274
{% include 'globals/usercard.html' %}
@@ -46,8 +78,8 @@
4678
<div class="ui divider"></div>
4779

4880
{% comment %}The Tab-Menu starts here!{% endcomment %}
49-
<div class="ui huge fluid vertical pointing menu" id="vtab"
50-
style="max-width: 320px;">
81+
<div class="ui huge fluid vertical pointing menu" style="max-width: 25rem;">
82+
5183
{% if student_flag %}
5284
<a class="active item" data-tab="one">
5385
<B>Current Semester</B>

FusionIIIT/templates/dashboard/dashboard.html

100755100644
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
{% comment %}The Tab-Menu starts here!{% endcomment %}
4242
<div class="ui huge fluid vertical pointing menu" style="max-width: 320px;">
4343

44-
<a class="item disabled" href="{% url 'globals:profile' %}">
45-
View Professional Profile
44+
<a class="item" href="{% url 'globals:profile' %}">
45+
View Professional Profile
4646
<i class="right floated chevron right icon"></i>
4747
</a>
4848
{% if "dean_rspc" in designation %}
@@ -62,11 +62,12 @@
6262
{% comment %}The Tab-Menu ends here!{% endcomment %}
6363

6464

65-
{% if 'student' != request.user.extrainfo.user_type %}
65+
{% if 'student' == request.user.extrainfo.user_type %}
6666

6767
{% comment %}The Tab-Menu starts here!{% endcomment %}
6868
<div class="ui huge fluid vertical pointing menu" style="max-width: 320px;">
69-
<a class="item disabled" href="/hr2/administrativeProfile">
69+
<a class="item
70+
" href="/hr2/administrativeProfile">
7071
View Administrative Profile
7172
<i class="right floated chevron right icon"></i>
7273
</a>
@@ -77,7 +78,7 @@
7778

7879
{% comment %}The Tab-Menu starts here!{% endcomment %}
7980

80-
81+
8182
{% if request.user.extrainfo.user_type == 'faculty' %}
8283
{%for desig in designat%}
8384
{% if 'hradmin' == desig.designation.name %}

0 commit comments

Comments
 (0)