1111from django .utils .timezone import now
1212
1313from home .models import (
14+ SDC ,
1415 About ,
1516 Allocation ,
1617 AllocationForm ,
2122 Form ,
2223 LeftShortRebate ,
2324 LongRebate ,
25+ Menu ,
2426 Period ,
2527 Rebate ,
2628 Rule ,
3032 StudentBills ,
3133 UnregisteredStudent ,
3234 Update ,
33- Menu ,
34- SDC ,
3535)
3636
3737from .utils .get_rebate_bills import get_rebate_bills
@@ -97,6 +97,7 @@ def rules(request):
9797# context = {"caterer": caterer}
9898# return render(request, "caterer.html", context)
9999
100+
100101def menu (request ):
101102 """
102103 Display the menu along with caterer information on a single page.
@@ -105,15 +106,13 @@ def menu(request):
105106 caterers = Caterer .objects .filter (visible = True )
106107
107108 context = {
108- "menus" : list (menus ),
109+ "menus" : list (menus ),
109110 "caterers" : caterers ,
110111 }
111112
112113 return render (request , "menu.html" , context )
113114
114115
115-
116-
117116def links (request ):
118117 """
119118 Display the Forms Page :model:`home.models.links`.
@@ -477,12 +476,25 @@ def profile(request):
477476
478477 :template:`home/profile.html`
479478 """
480- text = ""
481479 student = Student .objects .filter (email__iexact = str (request .user .email )).last ()
480+ if request .method == "POST" and request .user .is_authenticated :
481+ if student :
482+ try :
483+ logger .debug (request .FILES )
484+ file = request .FILES ["profile-picture" ]
485+ student .photo = file
486+ student .save ()
487+ except Exception as e :
488+ logger .error (e )
489+ if url_has_allowed_host_and_scheme (request .path , allowed_hosts = None ):
490+ return redirect (request .path )
491+ else :
492+ return redirect ("/" )
493+ text = ""
482494 socialaccount_obj = SocialAccount .objects .filter (
483495 provider = "google" , user_id = request .user .id
484496 )
485- picture = "not available"
497+ picture = student . photo . url if student . photo else None
486498 allocation : Allocation | None = Allocation .objects .filter (email = student ).last ()
487499 show_allocated_enabled = False
488500 if allocation and allocation .period :
@@ -501,12 +513,10 @@ def profile(request):
501513 "Jain" : "Yes" if allocation .jain else "No" ,
502514 }
503515 try :
504- if socialaccount_obj :
516+ if not picture and socialaccount_obj :
505517 picture = socialaccount_obj [0 ].extra_data ["picture" ]
506- else :
507- picture = "not available"
508518 except (IndexError , KeyError ):
509- picture = "not available"
519+ logger . error ( "No picture found" )
510520 semesters = Semester .objects .all ()
511521 context = {
512522 "text" : text ,
@@ -545,13 +555,12 @@ def rebate_data(request):
545555 return JsonResponse (rebate_data )
546556
547557
548-
549558def sdc_list (request ):
550559 """
551560 View to display the list of SDC members categorized by year and position.
552561 """
553- positions = ["Head" , "Advisory" , "Member" ]
554- years = [2024 , 2025 ]
562+ positions = ["Head" , "Advisory" , "Member" ]
563+ years = [2024 , 2025 ]
555564 sdc_members = SDC .objects .all ()
556565
557566 context = {
@@ -560,4 +569,3 @@ def sdc_list(request):
560569 "sdc_members" : sdc_members ,
561570 }
562571 return render (request , "sdc.html" , context )
563-
0 commit comments