Skip to content

Commit cc6f935

Browse files
rebate fixes and logging for photo (#129)
* rebate fixes and logging for photo * nit fix
1 parent 4437a9c commit cc6f935

File tree

6 files changed

+11
-50
lines changed

6 files changed

+11
-50
lines changed

home/adapters/account_adapter.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ def should_send_confirmation_mail(self, request, email_address):
1313

1414
def clean_email(self, email):
1515
RestrictedList = Student.objects.all().values_list("email")
16-
# try:
17-
# Student.objects.get(email=email)
18-
# return email
19-
# except Exception as e:
20-
# ValidationError('You are not a registered student. Please contact admin.')
2116
if email.endswith("iiti.ac.in"):
2217
raise ValidationError(
2318
"Please login with your IITI email ID through google login only."

home/admin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,6 @@ class about_Admin(admin.ModelAdmin):
10181018
"period5_bills",
10191019
"period6_bills",
10201020
),
1021-
# "description": "%s" % CATERER_BILL_DESC_TEXT,
10221021
}
10231022

10241023

@@ -1040,7 +1039,6 @@ class about_Admin(ImportExportModelAdmin, admin.ModelAdmin):
10401039
"period5_bills",
10411040
"period6_bills",
10421041
),
1043-
# "description": "%s" % CATERER_BILL_DESC_TEXT,
10441042
},
10451043
),
10461044
)

home/models/home.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,3 @@ def __str__(self):
5656
class Meta:
5757
verbose_name = "Update"
5858
verbose_name_plural = "Updates"
59-
60-
61-
# class Photos(models.Model):
62-
# """
63-
# Stores All phtographs on the bottom of the Home page
64-
# """
65-
# image = models.ImageField(_("Photographs on Home page"), upload_to="static/images")
66-
# poc = models.CharField(_("Point of Contact"), max_length=30, default='',
67-
# help_text="This contains the name of the person in the photograph")
68-
# occupation = models.CharField(_("Occupation"), max_length=50, default='',
69-
# help_text="This contains the occupation of the person in the photograph")
70-
71-
# def __str__(self):
72-
# return "Home Page Photographs"
73-
74-
# class Meta:
75-
# verbose_name = " General Photographs"
76-
# verbose_name_plural = " General Photographs"

home/utils/month.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ def fill_periods(email, start_date, end_date):
1414
print(f"Start date: {start_date}, End date: {end_date}")
1515
current_date = start_date
1616
days_per_period = []
17-
student = Student.objects.filter(email=email).last()
17+
student = Student.objects.filter(email__iexact=email).last()
1818
for period in Period.objects.all():
1919
if (
2020
period.start_date <= current_date <= period.end_date
2121
and period.start_date <= end_date
2222
and Allocation.objects.filter(period=period, email=student).exists()
2323
):
24-
days_in_period = min(
25-
(period.end_date - current_date).days + 1,
26-
(end_date - current_date).days + 1,
27-
)
24+
days_in_period = (min(period.end_date, end_date) - current_date).days + 1
2825
days_per_period.append((period, days_in_period))
2926
current_date = current_date + timedelta(days=days_in_period)
3027

home/utils/rebate_checker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def count(start, end):
1212
def is_not_duplicate(student, new_rebate_start, new_rebate_end):
1313
"""Checks if these dates are already applied for rebate"""
1414
try:
15-
for short_rebate in Rebate.objects.filter(email=student).all():
15+
for short_rebate in Rebate.objects.filter(email__iexact=student).all():
1616
if (
1717
short_rebate.start_date
1818
< new_rebate_start
@@ -23,7 +23,7 @@ def is_not_duplicate(student, new_rebate_start, new_rebate_end):
2323
< short_rebate.end_date
2424
):
2525
return False
26-
for short_rebate in LeftShortRebate.objects.filter(email=student).all():
26+
for short_rebate in LeftShortRebate.objects.filter(email__iexact=student).all():
2727
if (
2828
short_rebate.start_date
2929
< new_rebate_start
@@ -34,7 +34,7 @@ def is_not_duplicate(student, new_rebate_start, new_rebate_end):
3434
< short_rebate.end_date
3535
):
3636
return False
37-
for long_rebate in LongRebate.objects.filter(email=student).all():
37+
for long_rebate in LongRebate.objects.filter(email__iexact=student).all():
3838
if (
3939
long_rebate.end_date
4040
> new_rebate_start

home/views.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,6 @@ def rules(request):
8484
return render(request, "rules.html", params)
8585

8686

87-
# def caterer(request, name):
88-
# """
89-
# Display the Caterer Page :model:`home.models.caterer`.
90-
91-
# *Template:*
92-
93-
# :template:`home/caterer.html`
94-
95-
# """
96-
# caterer = Caterer.objects.get(name=name, visible=True)
97-
# context = {"caterer": caterer}
98-
# return render(request, "caterer.html", context)
99-
100-
10187
def menu(request):
10288
"""
10389
Display the menu along with caterer information on a single page.
@@ -186,7 +172,7 @@ def rebate(request):
186172
try:
187173
period_obj = next(
188174
period
189-
for period in Period.objects.all()
175+
for period in Period.objects.all().order_by("start_date")
190176
if period.end_date > date.today() + timedelta(1)
191177
)
192178
allocation = Allocation.objects.filter(email=student, period=period_obj).first()
@@ -213,7 +199,7 @@ def rebate(request):
213199
message = "Form needs to be filled atleast 2 days prior the comencement of leave."
214200
elif not is_not_duplicate(student, start_date, end_date):
215201
message = "You have already applied for rebate during this duration"
216-
elif 0 < rebate_days < 2:
202+
elif rebate_days < 2:
217203
message = "Min no of days for rebate is 2"
218204
else:
219205
additional_message = ""
@@ -494,7 +480,8 @@ def profile(request):
494480
socialaccount_obj = SocialAccount.objects.filter(
495481
provider="google", user_id=request.user.id
496482
)
497-
picture = student.photo.url if student.photo else None
483+
if student:
484+
picture = student.photo.url if student.photo else None
498485
allocation: Allocation | None = Allocation.objects.filter(email=student).last()
499486
show_allocated_enabled = False
500487
if allocation and allocation.period:
@@ -516,6 +503,8 @@ def profile(request):
516503
if not picture and socialaccount_obj:
517504
picture = socialaccount_obj[0].extra_data["picture"]
518505
except (IndexError, KeyError):
506+
logger.warning(socialaccount_obj[0])
507+
logger.warning(socialaccount_obj[0].extra_data)
519508
logger.error("No picture found")
520509
semesters = Semester.objects.all()
521510
context = {

0 commit comments

Comments
 (0)