diff --git a/FusionIIIT/Fusion/context_processors.py b/FusionIIIT/Fusion/context_processors.py new file mode 100644 index 000000000..54566d56e --- /dev/null +++ b/FusionIIIT/Fusion/context_processors.py @@ -0,0 +1,5 @@ +def global_vars(request): + return { + 'global_var': request.session.get('currentDesignationSelected', 'default_value'), + 'global_var2': request.session.get('allDesignations', 'default_value2'), + } \ No newline at end of file diff --git a/FusionIIIT/Fusion/middleware/custom_middleware.py b/FusionIIIT/Fusion/middleware/custom_middleware.py new file mode 100644 index 000000000..f77873534 --- /dev/null +++ b/FusionIIIT/Fusion/middleware/custom_middleware.py @@ -0,0 +1,48 @@ +# custom_middleware.py +from django.contrib.auth.signals import user_logged_in +from django.dispatch import receiver +from applications.globals.models import (ExtraInfo, Feedback, HoldsDesignation, + Issue, IssueImage, DepartmentInfo) +from django.shortcuts import get_object_or_404, redirect, render + +def user_logged_in_middleware(get_response): + @receiver(user_logged_in) + def user_logged_in_handler(sender, user, request, **kwargs): + if 'function_executed' not in request.session: + # Run the function only if the flag is not set + # Assuming user is a model with the desired data field, retrieve the data + # For example, if your User model has a field named 'custom_field', you can access it like: + if user.is_authenticated: + desig = list(HoldsDesignation.objects.select_related('user','working','designation').all().filter(working = request.user).values_list('designation')) + print(desig) + b = [i for sub in desig for i in sub] + design = HoldsDesignation.objects.select_related('user','designation').filter(working=request.user) + + designation=[] + + designation.append(str(user.extrainfo.user_type)) + for i in design: + if str(i.designation) != str(user.extrainfo.user_type): + print('-------') + print(i.designation) + print(user.extrainfo.user_type) + print('') + designation.append(str(i.designation)) + + for i in designation: + print(i) + + request.session['currentDesignationSelected'] = designation[0] + request.session['allDesignations'] = designation + print("logged iN") + + # Set the flag in the session to indicate that the function has bee+n executed + request.session['function_executed'] = True + + def middleware(request): + if request.user.is_authenticated: + user_logged_in_handler(request.user, request.user, request) + response = get_response(request) + return response + + return middleware \ No newline at end of file diff --git a/FusionIIIT/Fusion/settings/common.py b/FusionIIIT/Fusion/settings/common.py index b98ea6960..fabe81ec2 100644 --- a/FusionIIIT/Fusion/settings/common.py +++ b/FusionIIIT/Fusion/settings/common.py @@ -163,6 +163,7 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'Fusion.middleware.custom_middleware.user_logged_in_middleware', ] ROOT_URLCONF = 'Fusion.urls' @@ -178,6 +179,7 @@ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'Fusion.context_processors.global_vars', ], }, }, diff --git a/FusionIIIT/applications/eis/views.py b/FusionIIIT/applications/eis/views.py index 76a4532c2..656eee099 100644 --- a/FusionIIIT/applications/eis/views.py +++ b/FusionIIIT/applications/eis/views.py @@ -275,10 +275,12 @@ # Main profile landing view def profile(request, username=None): + print("eis",username) user = get_object_or_404(User, username=username) if username else request.user + extra_info = get_object_or_404(ExtraInfo, user=user) - if extra_info.user_type != 'faculty': - return redirect('/') +# if extra_info.user_type != 'fx': +# return redirect('/') pf = extra_info.id form = ConfrenceForm() diff --git a/FusionIIIT/applications/feeds/views.py b/FusionIIIT/applications/feeds/views.py index 4ef9c62c9..fea8f5f42 100644 --- a/FusionIIIT/applications/feeds/views.py +++ b/FusionIIIT/applications/feeds/views.py @@ -689,6 +689,7 @@ def profile(request, string): string- user's username @variables """ + print("user is this", request) if request.method == "POST": profile = Profile.objects.select_related().all().filter(user=request.user) Pr = None diff --git a/FusionIIIT/applications/globals/api/urls.py b/FusionIIIT/applications/globals/api/urls.py index 72d32c89e..46ebd1ea0 100644 --- a/FusionIIIT/applications/globals/api/urls.py +++ b/FusionIIIT/applications/globals/api/urls.py @@ -7,6 +7,7 @@ url(r'^auth/login/', views.login, name='login-api'), url(r'^auth/logout/', views.logout, name='logout-api'), # generic profile endpoint + #code of corresponding view is modifiedtemporary because of mismatched designations url(r'^profile/(?P.+)/', views.profile, name='profile-api'), # current user profile url(r'^profile/', views.profile, name='profile-api'), diff --git a/FusionIIIT/applications/globals/api/views.py b/FusionIIIT/applications/globals/api/views.py index 12d78e088..3f30c1028 100644 --- a/FusionIIIT/applications/globals/api/views.py +++ b/FusionIIIT/applications/globals/api/views.py @@ -76,12 +76,15 @@ def profile(request, username=None): user = get_object_or_404(User, username=username) if username else request.user user_detail = serializers.UserSerializer(user).data profile = serializers.ExtraInfoSerializer(user.extrainfo).data + + print(user) + if profile['user_type'] == 'student': student = user.extrainfo.student skills = serializers.HasSerializer(student.has_set.all(),many=True).data education = serializers.EducationSerializer(student.education_set.all(), many=True).data course = serializers.CourseSerializer(student.course_set.all(), many=True).data - experience = serializers.ExperienceSerializer(student.experience_set.all(), many=True).data + experience = serializers.ExperienceSerializer(student.experience_set.all(), many=True).datap project = serializers.ProjectSerializer(student.project_set.all(), many=True).data achievement = serializers.AchievementSerializer(student.achievement_set.all(), many=True).data publication = serializers.PublicationSerializer(student.publication_set.all(), many=True).data @@ -102,6 +105,7 @@ def profile(request, username=None): } return Response(data=resp, status=status.HTTP_200_OK) elif profile['user_type'] == 'faculty': + print(username) return redirect('/eis/api/profile/' + (username+'/' if username else '')) @api_view(['PUT']) diff --git a/FusionIIIT/applications/globals/migrations/0002_auto_20231116_2323.py b/FusionIIIT/applications/globals/migrations/0002_auto_20231116_2323.py new file mode 100644 index 000000000..51f5a76b5 --- /dev/null +++ b/FusionIIIT/applications/globals/migrations/0002_auto_20231116_2323.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.5 on 2023-11-16 23:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('globals', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='extrainfo', + name='user_status', + field=models.CharField(choices=[('NEW', 'NEW'), ('PRESENT', 'PRESENT')], default='PRESENT', max_length=50), + ), + ] diff --git a/FusionIIIT/applications/globals/urls.py b/FusionIIIT/applications/globals/urls.py index f8d82ee71..2dea4e77d 100644 --- a/FusionIIIT/applications/globals/urls.py +++ b/FusionIIIT/applications/globals/urls.py @@ -23,5 +23,6 @@ # Endpoint to reset all passwords in DEV environment url(r'^resetallpass/$', views.reset_all_pass, name='resetallpass'), # API urls - url(r'^api/', include('applications.globals.api.urls')) + url(r'^api/', include('applications.globals.api.urls')), + url(r'^update_global_variable/$', views.update_global_variable, name='update_global_var'), ] diff --git a/FusionIIIT/applications/globals/views.py b/FusionIIIT/applications/globals/views.py index a7f3886c9..3b992f6f8 100644 --- a/FusionIIIT/applications/globals/views.py +++ b/FusionIIIT/applications/globals/views.py @@ -1,3 +1,4 @@ +from audioop import reverse import json from django.contrib.auth import logout @@ -740,21 +741,26 @@ def dashboard(request): } # a=HoldsDesignation.objects.select_related('user','working','designation').filter(designation = user) + print(context) + print(type(user.extrainfo.user_type)) if(request.user.get_username() == 'director'): return render(request, "dashboard/director_dashboard2.html", {}) elif( "dean_rspc" in designation): return render(request, "dashboard/dashboard.html", context) - elif user.extrainfo.user_type != 'student': + elif user.extrainfo.user_type != "student": + print ("inside") designat = HoldsDesignation.objects.select_related().filter(user=user) response = {'designat':designat} context.update(response) return render(request, "dashboard/dashboard.html", context) else: + print ("inside2") + return render(request, "dashboard/dashboard.html", context) @login_required(login_url=LOGIN_URL) -def profile(request, username=None): +def profile(request, username=None): """ Generic endpoint for views. If it's a faculty, redirects to /eis/profile/* @@ -766,18 +772,80 @@ def profile(request, username=None): username: Username of the user. If None, displays the profile of currently logged-in user """ - user = get_object_or_404(User, Q(username=username)) if username else request.user + print(username) + user = get_object_or_404(User, Q(username=username)) if username else request.user editable = request.user == user + print("editable",editable) profile = get_object_or_404(ExtraInfo, Q(user=user)) + print("profile",profile) if(str(user.extrainfo.user_type)=='faculty'): + print("profile") return HttpResponseRedirect('/eis/profile/' + (username if username else '')) if(str(user.extrainfo.department)=='department: Academics'): + print("profile2") return HttpResponseRedirect('/aims') - current = HoldsDesignation.objects.select_related('user','working','designation').filter(Q(working=user, designation__name="student")) + + array = [ + "student", + "CC convenor", + "Mechatronic convenor", + "mess_committee", + "mess_convener", + "alumini", + "Electrical_AE", + "Electrical_JE", + "Civil_AE", + "Civil_JE", + "co-ordinator", + "co co-ordinator", + "Convenor", + "Convener", + "cc1convener", + "CC2 convener", + "mess_convener_mess2", + "mess_committee_mess2" +] + + # queryset = HoldsDesignation.objects.select_related('user','working','designation').filter(Q(working=user)) + + # for obj in queryset: + # designation_name = obj.designation.name + # print("designation_name",designation_name) + + # design = False + # if designation_name in array: + # design = True + # print("design",design) + # print("designation_name",designation_name) + # if design: + # current = HoldsDesignation.objects.select_relapted('user','working','designation').filter(Q(working=user, designation__name=designation_name)) + # for obj in current: + # obj.designation.name = obj.designation.name.replace(designation_name, 'student') + + designation_name = "" + design = False + + current = HoldsDesignation.objects.select_related('user', 'working', 'designation').filter(Q(working=user)) + + for obj in current: + designation_name = obj.designation.name + if designation_name in array: + design = True + break + + if design: + current = HoldsDesignation.objects.filter(working=user, designation__name=designation_name) + for obj in current: + obj.designation.name = obj.designation.name.replace(designation_name, 'student') + + print(user.extrainfo.user_type) + print("current",current) if current: + print("profile3") student = get_object_or_404(Student, Q(id=profile.id)) + print("student",student) if editable and request.method == 'POST': if 'studentapprovesubmit' in request.POST: 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 +1047,7 @@ def profile(request, username=None): return render(request, "globals/student_profile4.html", context) if 'achievementsubmit' in request.POST or 'deleteach' in request.POST: return render(request, "globals/student_profile5.html", context) + print("context",context) return render(request, "globals/student_profile.html", context) else: return redirect("/") @@ -1176,4 +1245,15 @@ def search(request): if len(search_results) == 0: search_results = [] context = {'sresults':search_results} - return render(request, "globals/search.html", context) + return render(request, "globals/search.html", context), + +@login_required(login_url=LOGIN_URL) +def update_global_variable(request): + if request.method == 'POST': + selected_option = request.POST.get('dropdown') + request.session['currentDesignationSelected'] = selected_option + print(selected_option) + print(request.session['currentDesignationSelected']) + return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) + # Redirect to home if not a POST request or some issue occurs + return HttpResponseRedirect(reverse('home')) diff --git a/FusionIIIT/applications/scholarships/urls.py b/FusionIIIT/applications/scholarships/urls.py index fd5a3516f..77a292977 100755 --- a/FusionIIIT/applications/scholarships/urls.py +++ b/FusionIIIT/applications/scholarships/urls.py @@ -17,5 +17,6 @@ url(r'^getConvocationFlag/$', views.getConvocationFlag, name='getConvocationFlag'), url(r'^getContent/$', views.getContent, name='getContent'), url(r'^updateEndDate/$', views.updateEndDate, name='updateEndDate'), + url(r'^deleteRelease/$', views.deleteRelease, name='deleteRelease'), ] diff --git a/FusionIIIT/applications/scholarships/views.py b/FusionIIIT/applications/scholarships/views.py index 5f547149f..ef91287d0 100755 --- a/FusionIIIT/applications/scholarships/views.py +++ b/FusionIIIT/applications/scholarships/views.py @@ -3,6 +3,7 @@ from operator import or_ from functools import reduce +from django.http import JsonResponse from django.contrib import messages from django.contrib.auth.decorators import login_required from django.http import HttpResponse, HttpResponseRedirect @@ -26,6 +27,9 @@ # Create your views here. + + + @login_required(login_url='/accounts/login') def spacs(request): convener = Designation.objects.get(name='spacsconvenor') @@ -70,6 +74,8 @@ def spacs(request): @login_required(login_url='/accounts/login') def convener_view(request): + print(request) + try: convener = Designation.objects.get(name='spacsconvenor') hd = HoldsDesignation.objects.get( @@ -77,8 +83,11 @@ def convener_view(request): except: return HttpResponseRedirect('/logout') if request.method == 'POST': + print("this is a check for post request") if 'Submit' in request.POST: + print("this is a check for post xfhjgisdfkhlsjk request") award = request.POST.get('type') + print("award " + award) programme = request.POST.get('programme') batch = request.POST.get('batch') from_date = request.POST.get('From') @@ -98,14 +107,27 @@ def convener_view(request): ) # It updates the student Notification table on the spacs head sending the mcm invitation - if batch == 'all': + if batch == 'All': active_batches = range(datetime.datetime.now().year - 4 , datetime.datetime.now().year + 1) - query = reduce(or_, (Q(id__id__startswith=batch) for batch in active_batches)) + # active_batches=str(active_batches) + # active_batches.split(',') + print(active_batches) + querybatch = [] + for curbatch in active_batches: + if curbatch > 2019: + curbatch=curbatch%2000 + querybatch.append(curbatch) + print( active_batches) + query = reduce(or_, (Q(id__id__startswith=batch) for batch in querybatch)) + print(query) recipient = Student.objects.filter(programme=programme).filter(query) else: - recipient = Student.objects.filter(programme=programme, id__id__startswith=batch) + if(int(batch)>2019): + curbatch=int(batch)%2000 + recipient = Student.objects.filter(programme=programme, id__id__startswith=curbatch) # Notification starts + print(recipient) convenor = request.user for student in recipient: scholarship_portal_notif(convenor, student.id.user, 'award_' + award) # Notification @@ -124,9 +146,9 @@ def convener_view(request): notification_convocation_flag=True, invite_convocation_accept_flag=False) for student in recipient]) # Notification ends - + print(batch) messages.success(request, - award + ' applications are invited successfully for ' + batch + ' batch(es)') + award + ' applications are invited successfully for ' + str(batch) + ' batch(es)') return HttpResponseRedirect('/spacs/convener_view') elif 'Email' in request.POST: @@ -257,6 +279,7 @@ def convener_view(request): @login_required(login_url='/accounts/login') def student_view(request): + if request.method == 'POST': if 'Submit_MCM' in request.POST: return submitMCM(request) @@ -382,37 +405,52 @@ def convenerCatalogue(request): context['result'] = 'Failure' return HttpResponse(json.dumps(context), content_type='convenerCatalogue/json') + + +#below function is refactored and changed as it is not used by the user interface +#it will be changed later for other testing and download of winners def getWinners(request): + # Extract parameters from the request award_name = request.GET.get('award_name') batch_year = int(request.GET.get('batch')) programme_name = request.GET.get('programme') - award = Award_and_scholarship.objects.get(award_name=award_name) - winners = Previous_winner.objects.select_related('student','award_id').filter( + + # Get the Award_and_scholarship object based on the provided award name + try: + award = Award_and_scholarship.objects.get(award_name=award_name) + except Award_and_scholarship.DoesNotExist: + return JsonResponse({'result': 'Failure', 'message': 'Award not found'}) + + # Query for previous winners based on the provided criteria + winners = Previous_winner.objects.select_related('student__extra_info').filter( year=batch_year, award_id=award, programme=programme_name) - context = {} - context['student_name'] = [] - context['student_program'] = [] - context['roll'] = [] -# If-Else Condition for previous winner if there is or no data in the winner table + context = { + 'result': 'Success', + 'winners': [], + } + + # Process the winners if any found if winners: for winner in winners: - - extra_info = ExtraInfo.objects.get(id=winner.student_id) - student_id = Student.objects.get(id=extra_info) + # Fetch extra information for the student + extra_info = winner.student.extra_info student_name = extra_info.user.first_name student_roll = winner.student_id - student_program = student_id.programme - context['student_name'].append(student_name) - context['roll'].append(student_roll) - context['student_program'].append(student_program) - - context['result'] = 'Success' + student_program = winner.student.programme + + # Append student details to the context + context['winners'].append({ + 'student_name': student_name, + 'roll': student_roll, + 'student_program': student_program, + }) else: context['result'] = 'Failure' + context['message'] = 'No winners found for the provided criteria' - return HttpResponse(json.dumps(context), content_type='getWinners/json') + return JsonResponse(context) def get_MCM_Flag(request): # Here we are extracting mcm_flag x = Notification.objects.select_related('student_id','release_id').filter(student_id=request.user.extrainfo.id) @@ -431,7 +469,7 @@ def get_MCM_Flag(request): # Here we are extracting mcm_flag # return HttpResponseRedirect('/spacs/student_view') def getConvocationFlag(request): # Here we are extracting convocation_flag - x = Notification.objects.filter(student_id=request.user.extrainfo.id) + x = Notification.objects.select_related('student_id', 'release_id').filter(student_id=request.user.extrainfo.id) for i in x: i.invite_convocation_accept_flag = True i.save() @@ -481,6 +519,18 @@ def updateEndDate(request): context['result'] = 'Failure' return HttpResponse(json.dumps(context), content_type='updateEndDate/json') +def deleteRelease(request): + print("deleteRelease") + id = request.GET.get('id') + is_deleted = Release.objects.filter(pk=id).delete() + request.session['last_clicked'] = "Release_deleted" + context = {} + if is_deleted: + context['result'] = 'Success' + else: + context['result'] = 'Failure' + return HttpResponse(json.dumps(context), content_type='deleteRelease/json') + def getAwardId(request): award = request.POST.get('award') a = Award_and_scholarship.objects.get(award_name=award).id @@ -1020,6 +1070,7 @@ def sendConvenerRenderRequest(request, additionalParams={}): def sendStudentRenderRequest(request, additionalParams={}): context = getCommonParams(request) + ch = Constants.BATCH time = Constants.TIME mother_occ = Constants.MOTHER_OCC_CHOICES @@ -1041,7 +1092,30 @@ def sendStudentRenderRequest(request, additionalParams={}): x_notif_con_flag = False for dates in release: if checkDate(dates.startdate, dates.enddate): - if dates.award == 'Merit-cum-Means Scholarship' and dates.batch == str(request.user.extrainfo.student)[0:4] and dates.programme == request.user.extrainfo.student.programme: + curBatch = dates.batch + checkBatch = str(request.user.extrainfo.student)[0:4] + batchCondition = False + if checkBatch[2] >= "A" and checkBatch[2] <= "Z": + if(curBatch == 'All'): + batchRange = range(datetime.datetime.now().year - 4, datetime.datetime.now().year + 1) + for batches in batchRange : + if int(checkBatch[0:2]) == batches % 2000: + batchCondition = True + elif curBatch == checkBatch: + batchCondition = True + else: + if(curBatch == 'All'): + batchRange = range(datetime.datetime.now().year - 4, datetime.datetime.now().year + 1) + for batch in batchRange: + if str(checkBatch) == batch: + batchCondition = True + elif curBatch == checkBatch: + True + print("bye") + + + print(curBatch, checkBatch) + if dates.award == 'Merit-cum-Means Scholarship' and batchCondition and dates.programme == request.user.extrainfo.student.programme: x_notif_mcm_flag = True if no_of_mcm_filled > 0: update_mcm_flag = True @@ -1081,7 +1155,7 @@ def sendStudentRenderRequest(request, additionalParams={}): context.update(additionalParams) return render(request, 'scholarshipsModule/scholarships_student.html',context) -def sendStaffRenderRequest(request, additionalParams={}): +def sendStaffRenderRequest(request, additionalParams={}): context = getCommonParams(request) context.update(additionalParams) return render(request, 'scholarshipsModule/scholarships_staff.html', context) diff --git a/FusionIIIT/notification/views.py b/FusionIIIT/notification/views.py index 0480575b8..4d55c2b9b 100644 --- a/FusionIIIT/notification/views.py +++ b/FusionIIIT/notification/views.py @@ -148,6 +148,8 @@ def scholarship_portal_notif(sender, recipient, type): if type.startswith('award'): s = type.split('_') + # print("psss") + # print(type, s) verb = "Invitation to apply for " + s[1] elif type == 'Accept_MCM': verb = "Your Mcm form has been accepted " diff --git a/FusionIIIT/templates/academic_procedures/academic.html b/FusionIIIT/templates/academic_procedures/academic.html old mode 100755 new mode 100644 index 6b04a54fb..35eebf446 --- a/FusionIIIT/templates/academic_procedures/academic.html +++ b/FusionIIIT/templates/academic_procedures/academic.html @@ -22,6 +22,39 @@ } + + {% endblock css %} @@ -30,13 +63,12 @@ {% include 'dashboard/navbar.html' %} {% endblock %} -
+
- {% comment %}The left-margin segment!{% endcomment %} -
+ {% comment %}The left-rail segment starts here!{% endcomment %} -
+
{% comment %}The user image card starts here!{% endcomment %} {% block usercard %} {% include 'globals/usercard.html' %} @@ -46,8 +78,8 @@
{% comment %}The Tab-Menu starts here!{% endcomment %} -