Skip to content

Commit

Permalink
fix flake
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan-tf committed Aug 17, 2024
1 parent c02db2c commit 1d85ba4
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 110 deletions.
7 changes: 6 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[flake8]
max-line-length = 88
ignore = E,F,W
# Remove F811 from admin.py
ignore = E501, E722, W503, F811
per-file-ignores =
home/models/students.py: E402
home/models/admin.py: F811
home/models/__init__.py: F401
78 changes: 30 additions & 48 deletions home/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,55 +766,37 @@ def clean(self, request, queryset):
"""
Clean testing period data
"""
attributes_to_check = [
("period1_short", 0),
("period1_long", 0),
("period2_short", 0),
("period2_long", 0),
("period3_short", 0),
("period3_long", 0),
("period4_short", 0),
("period4_long", 0),
("period5_short", 0),
("period5_long", 0),
("period6_short", 0),
("period6_long", 0),
("period1_high_tea", True),
("period2_high_tea", True),
("period3_high_tea", True),
("period4_high_tea", True),
("period5_high_tea", True),
("period6_high_tea", True),
("period1_bill", 0),
("period2_bill", 0),
("period3_bill", 0),
("period4_bill", 0),
("period5_bill", 0),
("period6_bill", 0),
]

for obj in queryset:
if obj.period1_short == None:
obj.period1_short = 0
if obj.period1_long == None:
obj.period1_long = 0
if obj.period2_short == None:
obj.period2_short = 0
if obj.period2_long == None:
obj.period2_long = 0
if obj.period3_short == None:
obj.period3_short = 0
if obj.period3_long == None:
obj.period3_long = 0
if obj.period4_short == None:
obj.period4_short = 0
if obj.period4_long == None:
obj.period4_long = 0
if obj.period5_short == None:
obj.period5_short = 0
if obj.period5_long == None:
obj.period5_long = 0
if obj.period6_short == None:
obj.period6_short = 0
if obj.period6_long == None:
obj.period6_long = 0
if obj.period1_high_tea == None:
obj.period1_high_tea = True
if obj.period2_high_tea == None:
obj.period2_high_tea = True
if obj.period3_high_tea == None:
obj.period3_high_tea = True
if obj.period4_high_tea == None:
obj.period4_high_tea = True
if obj.period5_high_tea == None:
obj.period5_high_tea = True
if obj.period6_high_tea == None:
obj.period6_high_tea = True
if obj.period1_bill == None:
obj.period1_bill = 0
if obj.period2_bill == None:
obj.period2_bill = 0
if obj.period3_bill == None:
obj.period3_bill = 0
if obj.period4_bill == None:
obj.period4_bill = 0
if obj.period5_bill == None:
obj.period5_bill = 0
if obj.period6_bill == None:
obj.period6_bill = 0
for attr, default_value in attributes_to_check:
if getattr(obj, attr) is None:
setattr(obj, attr, default_value)
obj.save()

def export_as_csv(self, request, queryset):
Expand Down
3 changes: 0 additions & 3 deletions home/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class HomeConfig(AppConfig):

def ready(self):
import socket
import sys

import home.signals

# bind to port 47200, then check for it for every worker
try:
Expand Down
1 change: 0 additions & 1 deletion home/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from allauth.account.forms import SignupForm
from allauth.socialaccount.forms import SignupForm as SocialSignupForm
from django import forms
from django.utils.translation import gettext_lazy as _

Expand Down
1 change: 0 additions & 1 deletion home/models/Semesters/autumn22.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models
from django.utils.timezone import now
from django.utils.translation import gettext as _

from ..caterer import Caterer
Expand Down
1 change: 0 additions & 1 deletion home/models/Semesters/autumn23.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models
from django.utils.timezone import now
from django.utils.translation import gettext as _

from ..caterer import Caterer
Expand Down
1 change: 0 additions & 1 deletion home/models/Semesters/spring23.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models
from django.utils.timezone import now
from django.utils.translation import gettext as _

from ..caterer import Caterer
Expand Down
4 changes: 2 additions & 2 deletions home/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
The `__init__.py` file is used to mark a directory as a Python package, making it possible to import modules and sub-packages from that directory
"""

from .allocation import Allocation, Period, Semester
from .bills import CatererBills, StudentBills
from .cafeteria import Cafeteria
from .caterer import Caterer
from .contacts import Contact
Expand Down Expand Up @@ -40,3 +38,5 @@
TodayRebate,
UnregisteredStudent,
)
from .allocation import Allocation, Period, Semester
from .bills import CatererBills, StudentBills
2 changes: 0 additions & 2 deletions home/models/students.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from django.db import models
from django.utils.timezone import now
from django.utils.translation import gettext as _
Expand Down
12 changes: 7 additions & 5 deletions home/resources.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import logging

from import_export import fields, resources
from import_export.widgets import ForeignKeyWidget

from .models import (
Allocation,
AllocationAutumn22,
AllocationSpring23,
CatererBills,
CatererBillsAutumn22,
CatererBillsSpring23,
Fee,
LongRebate,
Period,
Expand All @@ -19,7 +17,6 @@
StudentBills,
UnregisteredStudent,
)
from .utils.rebate_checker import count

"""
File-name: resources.py
Expand All @@ -32,6 +29,9 @@
handle importing and exporting data.
"""

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


class StudentResource(resources.ModelResource):
def skip_row(self, instance, original, row, import_validation_errors):
Expand Down Expand Up @@ -505,6 +505,7 @@ def dehydrate_allocation1(self, obj):
high_tea = "No High Tea"
return str(allocation.caterer_name) + " " + high_tea
except Exception as e:
logger.error(e)
return "Not yet allocated"

def dehydrate_allocation2(self, obj):
Expand Down Expand Up @@ -772,6 +773,7 @@ def dehydrate_allocation1(self, obj):
high_tea = "No High Tea"
return str(allocation.caterer_name) + " " + high_tea
except Exception as e:
logger.error(e)
return "Not yet allocated"

def dehydrate_allocation2(self, obj):
Expand Down
16 changes: 9 additions & 7 deletions home/signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from datetime import timedelta

from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver

Expand Down Expand Up @@ -74,7 +72,7 @@ def update_short_bill(sender, instance, **kwargs):
end_date = instance.end_date
days = count(start_date, end_date)
print(old_instance.approved, instance.approved)
if instance.approved == True and days > 0:
if instance.approved is True and days > 0:
save_short_bill(
email,
allocation.period,
Expand Down Expand Up @@ -128,13 +126,17 @@ def update_long_bill(sender, instance, **kwargs):
email, instance.start_date, instance.end_date
)
left_start_date = [
period for period, days in days_per_period if type(period) == type(days)
period
for period, days in days_per_period
if isinstance(period, type(days))
]
left_end_date = [
days for period, days in days_per_period if type(period) == type(days)
days
for period, days in days_per_period
if isinstance(period, type(days))
]

if instance.approved == True:
if instance.approved is True:
save_long_bill(email, days_per_period, 1)
long_rebate_mail(
instance.start_date,
Expand All @@ -145,7 +147,7 @@ def update_long_bill(sender, instance, **kwargs):
left_end_date,
instance.reason,
)
elif instance.approved == False:
elif instance.approved is False:
save_long_bill(email, days_per_period, -1)
long_rebate_mail(
instance.start_date,
Expand Down
2 changes: 0 additions & 2 deletions home/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.test import TestCase

# Create your tests here.
4 changes: 1 addition & 3 deletions home/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import include, path, re_path as url
from django.urls import path

from . import views
from .views import *

urlpatterns = [
path("", views.home, name="home"),
Expand Down
2 changes: 1 addition & 1 deletion home/utils/django_email_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def long_rebate_mail(
added="removed from",
reason="",
)
if left_start_date != None:
if left_start_date is not None:
message += left_message.format(
left_start_date=left_start_date, left_end_date=left_end_date
)
Expand Down
3 changes: 0 additions & 3 deletions home/utils/get_rebate_bills.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from ..models import RebateSpring23


def get_rebate_bills(rebate, period):
period = int(period)
if period == 1:
Expand Down
10 changes: 2 additions & 8 deletions home/utils/rebate_bills_saver.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from django.db.models.query import QuerySet

from ..models import (
Allocation,
Caterer,
CatererBills,
LeftLongRebate,
LongRebate,
Period,
Semester,
Student,
StudentBills,
)
Expand Down Expand Up @@ -138,11 +133,10 @@ def save_long_bill(email, days_per_period, j):
break


def update_bills(student, allocation):
def update_bills(email, allocation):
try:
email = student.email
period = allocation.period
rebate_bill = StudentBills.objects.get(email=student, semester=period.semester)
rebate_bill = StudentBills.objects.get(email, semester=period.semester)
sno = period.Sno
days = (period.end_date - period.start_date).days + 1
high_tea = allocation.high_tea
Expand Down
33 changes: 12 additions & 21 deletions home/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import io
import logging
from datetime import date, timedelta

from allauth.socialaccount.models import SocialAccount
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.core.files import File
from django.core.files.storage import default_storage
from django.http import HttpResponseRedirect, JsonResponse
from django.http import JsonResponse
from django.shortcuts import redirect, render
from django.utils.dateparse import parse_date
from django.utils.timezone import now
Expand All @@ -19,7 +16,6 @@
Cafeteria,
Carousel,
Caterer,
CatererBills,
Contact,
Form,
LeftShortRebate,
Expand All @@ -42,9 +38,11 @@
from .utils.get_rebate_bills import get_rebate_bills
from .utils.rebate_checker import is_not_duplicate, max_days_rebate

# Create your views here.
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


# Create your views here.
def home(request):
"""
Display the Home Page :model:`home.models.home`.
Expand Down Expand Up @@ -173,7 +171,7 @@ def rebate(request):
continue
key = str(allocation_id.student_id)
except Exception as e:
print(e)
logger.error(e)
key = "You are not allocated for current period, please contact the dining warden to allocate you to a caterer"
except Student.DoesNotExist:
key = "Signed in account does not does not have any allocation ID"
Expand Down Expand Up @@ -342,7 +340,8 @@ def addLongRebateBill(request):
except Exception as e:
text = "An error occurred while processing your form submission. If you're submitting an application, try compressing it before resubmitting. If the issue persists, please report it to the admin."
print(e)
except:
except Exception as e:
logger.error(e)
text = "Email ID does not exist in the database. Please login using the correct email ID"
request.session["text"] = text
return redirect(request.path)
Expand All @@ -368,7 +367,6 @@ def allocationForm(request):
alloc_form = AllocationForm.objects.filter(active=True).last()
try:
student = Student.objects.filter(email__iexact=str(request.user.email)).last()
key = student.email
text = ""
message = ""
if (alloc_form.start_time and alloc_form.start_time > now()) or (
Expand Down Expand Up @@ -491,19 +489,12 @@ def profile(request):
# else:
# allocation_info = "Not allocated for this period"
try:
if len(socialaccount_obj):
if socialaccount_obj:
picture = socialaccount_obj[0].extra_data["picture"]
except:
else:
picture = "not available"
except (IndexError, KeyError):
picture = "not available"
# if request.method == "POST" and request.user.is_authenticated:
# try:
# student = Student.objects.get(email=str(request.user.email))
# student.name = request.POST["name"]
# student.room_no = request.POST["room_no"]
# student.save()
# text = "Profile Updated Successfully"
# except:
# text = "Email ID does not exist in the database. Please eneter the correct email ID"
context = {
"text": text,
"student": student,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ include_trailing_comma = true
line_length = 88
multi_line_output = 3
known_first_party = ["config"]
skip = ["__init__.py"]

0 comments on commit 1d85ba4

Please sign in to comment.