diff --git a/home/adapters/account_adapter.py b/home/adapters/account_adapter.py index 1836d02..6eb6d73 100644 --- a/home/adapters/account_adapter.py +++ b/home/adapters/account_adapter.py @@ -13,11 +13,6 @@ def should_send_confirmation_mail(self, request, email_address): def clean_email(self, email): RestrictedList = Student.objects.all().values_list("email") - # try: - # Student.objects.get(email=email) - # return email - # except Exception as e: - # ValidationError('You are not a registered student. Please contact admin.') if email.endswith("iiti.ac.in"): raise ValidationError( "Please login with your IITI email ID through google login only." diff --git a/home/admin.py b/home/admin.py index 1df9b78..3d85fa2 100644 --- a/home/admin.py +++ b/home/admin.py @@ -1018,7 +1018,6 @@ class about_Admin(admin.ModelAdmin): "period5_bills", "period6_bills", ), - # "description": "%s" % CATERER_BILL_DESC_TEXT, } @@ -1040,7 +1039,6 @@ class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): "period5_bills", "period6_bills", ), - # "description": "%s" % CATERER_BILL_DESC_TEXT, }, ), ) diff --git a/home/models/home.py b/home/models/home.py index fa640de..29be4d2 100644 --- a/home/models/home.py +++ b/home/models/home.py @@ -56,21 +56,3 @@ def __str__(self): class Meta: verbose_name = "Update" verbose_name_plural = "Updates" - - -# class Photos(models.Model): -# """ -# Stores All phtographs on the bottom of the Home page -# """ -# image = models.ImageField(_("Photographs on Home page"), upload_to="static/images") -# poc = models.CharField(_("Point of Contact"), max_length=30, default='', -# help_text="This contains the name of the person in the photograph") -# occupation = models.CharField(_("Occupation"), max_length=50, default='', -# help_text="This contains the occupation of the person in the photograph") - -# def __str__(self): -# return "Home Page Photographs" - -# class Meta: -# verbose_name = " General Photographs" -# verbose_name_plural = " General Photographs" diff --git a/home/utils/month.py b/home/utils/month.py index ee9eb58..6cd2ac2 100644 --- a/home/utils/month.py +++ b/home/utils/month.py @@ -14,17 +14,14 @@ def fill_periods(email, start_date, end_date): print(f"Start date: {start_date}, End date: {end_date}") current_date = start_date days_per_period = [] - student = Student.objects.filter(email=email).last() + student = Student.objects.filter(email__iexact=email).last() for period in Period.objects.all(): if ( period.start_date <= current_date <= period.end_date and period.start_date <= end_date and Allocation.objects.filter(period=period, email=student).exists() ): - days_in_period = min( - (period.end_date - current_date).days + 1, - (end_date - current_date).days + 1, - ) + days_in_period = (min(period.end_date, end_date) - current_date).days + 1 days_per_period.append((period, days_in_period)) current_date = current_date + timedelta(days=days_in_period) diff --git a/home/utils/rebate_checker.py b/home/utils/rebate_checker.py index 84f39e4..fde97f6 100644 --- a/home/utils/rebate_checker.py +++ b/home/utils/rebate_checker.py @@ -12,7 +12,7 @@ def count(start, end): def is_not_duplicate(student, new_rebate_start, new_rebate_end): """Checks if these dates are already applied for rebate""" try: - for short_rebate in Rebate.objects.filter(email=student).all(): + for short_rebate in Rebate.objects.filter(email__iexact=student).all(): if ( short_rebate.start_date < new_rebate_start @@ -23,7 +23,7 @@ def is_not_duplicate(student, new_rebate_start, new_rebate_end): < short_rebate.end_date ): return False - for short_rebate in LeftShortRebate.objects.filter(email=student).all(): + for short_rebate in LeftShortRebate.objects.filter(email__iexact=student).all(): if ( short_rebate.start_date < new_rebate_start @@ -34,7 +34,7 @@ def is_not_duplicate(student, new_rebate_start, new_rebate_end): < short_rebate.end_date ): return False - for long_rebate in LongRebate.objects.filter(email=student).all(): + for long_rebate in LongRebate.objects.filter(email__iexact=student).all(): if ( long_rebate.end_date > new_rebate_start diff --git a/home/views.py b/home/views.py index 5dc4aad..d5b3309 100644 --- a/home/views.py +++ b/home/views.py @@ -84,20 +84,6 @@ def rules(request): return render(request, "rules.html", params) -# def caterer(request, name): -# """ -# Display the Caterer Page :model:`home.models.caterer`. - -# *Template:* - -# :template:`home/caterer.html` - -# """ -# caterer = Caterer.objects.get(name=name, visible=True) -# context = {"caterer": caterer} -# return render(request, "caterer.html", context) - - def menu(request): """ Display the menu along with caterer information on a single page. @@ -186,7 +172,7 @@ def rebate(request): try: period_obj = next( period - for period in Period.objects.all() + for period in Period.objects.all().order_by("start_date") if period.end_date > date.today() + timedelta(1) ) allocation = Allocation.objects.filter(email=student, period=period_obj).first() @@ -213,7 +199,7 @@ def rebate(request): message = "Form needs to be filled atleast 2 days prior the comencement of leave." elif not is_not_duplicate(student, start_date, end_date): message = "You have already applied for rebate during this duration" - elif 0 < rebate_days < 2: + elif rebate_days < 2: message = "Min no of days for rebate is 2" else: additional_message = "" @@ -494,7 +480,8 @@ def profile(request): socialaccount_obj = SocialAccount.objects.filter( provider="google", user_id=request.user.id ) - picture = student.photo.url if student.photo else None + if student: + picture = student.photo.url if student.photo else None allocation: Allocation | None = Allocation.objects.filter(email=student).last() show_allocated_enabled = False if allocation and allocation.period: @@ -516,6 +503,8 @@ def profile(request): if not picture and socialaccount_obj: picture = socialaccount_obj[0].extra_data["picture"] except (IndexError, KeyError): + logger.warning(socialaccount_obj[0]) + logger.warning(socialaccount_obj[0].extra_data) logger.error("No picture found") semesters = Semester.objects.all() context = {