Skip to content

Commit

Permalink
formatting and unused files cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dougpenny committed Aug 11, 2024
1 parent cc55e91 commit 34d499b
Show file tree
Hide file tree
Showing 55 changed files with 1,716 additions and 1,230 deletions.
3 changes: 0 additions & 3 deletions api/admin.py

This file was deleted.

3 changes: 0 additions & 3 deletions api/models.py

This file was deleted.

18 changes: 15 additions & 3 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@


class ExistingOrderMenuItemSerializer(serializers.ModelSerializer):
cost = serializers.DecimalField(max_digits=None, decimal_places=2, coerce_to_string=False)
cost = serializers.DecimalField(
max_digits=None, decimal_places=2, coerce_to_string=False
)

class Meta:
model = MenuItem
Expand All @@ -43,11 +45,21 @@ class Meta:


class MenuItemSerializer(serializers.ModelSerializer):
cost = serializers.DecimalField(max_digits=None, decimal_places=2, coerce_to_string=False)
cost = serializers.DecimalField(
max_digits=None, decimal_places=2, coerce_to_string=False
)

class Meta:
model = MenuItem
fields = ["app_only", "category", "cost", "id", "name", "sequence", "short_name"]
fields = [
"app_only",
"category",
"cost",
"id",
"name",
"sequence",
"short_name",
]


class MenuLineItemSerializer(serializers.ModelSerializer):
Expand Down
3 changes: 0 additions & 3 deletions api/tests.py

This file was deleted.

31 changes: 19 additions & 12 deletions cafeteria/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
from cafeteria.models import GradeLevel, LunchPeriod, School, Weekday


TokenAdmin.raw_id_fields = ['user']
TokenAdmin.raw_id_fields = ["user"]


@admin.register(GradeLevel)
class GradeLevelAdmin(admin.ModelAdmin):
fields = ['display_name', 'value', 'lunch_period', 'school']
list_filter = ['school', 'lunch_period']
list_display = ('__str__', 'value', 'school')
fields = ["display_name", "value", "lunch_period", "school"]
list_filter = ["school", "lunch_period"]
list_display = ("__str__", "value", "school")

def has_add_permission(self, request):
return False
Expand All @@ -34,16 +35,22 @@ def has_delete_permission(self, request, obj=None):

@admin.register(LunchPeriod)
class LunchPeriodAdmin(admin.ModelAdmin):
fields = ['display_name', 'floating_staff', 'start_time', 'teacher_distributes', 'sort_order']
list_display = ('__str__', 'start_time', 'floating_staff', 'teacher_distributes')
fields = [
"display_name",
"floating_staff",
"start_time",
"teacher_distributes",
"sort_order",
]
list_display = ("__str__", "start_time", "floating_staff", "teacher_distributes")


@admin.register(School)
class SchoolAdmin(admin.ModelAdmin):
fields = ['display_name', 'active', 'name', 'school_number']
readonly_fields = ['name', 'school_number']
list_filter = ['active']
list_display = ('__str__', 'school_number', 'active')
fields = ["display_name", "active", "name", "school_number"]
readonly_fields = ["name", "school_number"]
list_filter = ["active"]
list_display = ("__str__", "school_number", "active")

def has_add_permission(self, request):
return False
Expand All @@ -54,8 +61,8 @@ def has_delete_permission(self, request, obj=None):

@admin.register(Weekday)
class WeekdayAdmin(admin.ModelAdmin):
fields = ['name', 'abbreviation']
list_display = ['name', 'abbreviation']
fields = ["name", "abbreviation"]
list_display = ["name", "abbreviation"]

def has_add_permission(self, request):
return False
Expand Down
4 changes: 2 additions & 2 deletions cafeteria/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class CafeteriaConfig(AppConfig):
name = 'cafeteria'
verbose_name = 'Cafeteria Administration'
name = "cafeteria"
verbose_name = "Cafeteria Administration"
103 changes: 51 additions & 52 deletions cafeteria/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os, unicodedata
import os
import unicodedata

from django.utils import timezone

Expand All @@ -9,63 +10,61 @@


def generate_username(email):
# Using Python 3 and Django 1.11+, usernames can contain alphanumeric
# (ascii and unicode), _, @, +, . and - characters. So we normalize
# it and slice at 150 characters.
return unicodedata.normalize('NFKC', email)[:150]
# Using Python 3 and Django 1.11+, usernames can contain alphanumeric
# (ascii and unicode), _, @, +, . and - characters. So we normalize
# it and slice at 150 characters.
return unicodedata.normalize("NFKC", email)[:150]


def powerschool_logout(request):
redirect_url = os.getenv('POWERSCHOOL_URL') + 'guardian/home.html?ac=logoff'
return redirect_url
redirect_url = os.getenv("POWERSCHOOL_URL") + "guardian/home.html?ac=logoff"
return redirect_url


class PowerSchoolGuardianOIDC(OIDCAuthenticationBackend):
def update_students(self, profile):
client = Powerschool()
students = client.students_for_guardian(profile.user_dcid)
profile.children.clear()
for student in students:
try:
profile.children.add(Profile.objects.get(student_dcid=student))
except:
pass
def update_students(self, profile):
client = Powerschool()
students = client.students_for_guardian(profile.user_dcid)
profile.children.clear()
for student in students:
try:
profile.children.add(Profile.objects.get(student_dcid=student))
except:
pass

def create_user(self, claims):
user = super(PowerSchoolGuardianOIDC, self).create_user(claims)
user.first_name = claims.get("given_name", "")
user.last_name = claims.get("family_name", "")
user.save()
profile = Profile(
last_sync=timezone.now(),
role=Profile.GUARDIAN,
active=True,
user_dcid=claims.get("ps_dcid"),
user=user,
)
profile.save()
self.update_students(profile)

def create_user(self, claims):
user = super(PowerSchoolGuardianOIDC, self).create_user(claims)
user.first_name = claims.get('given_name', '')
user.last_name = claims.get('family_name', '')
user.save()
profile = Profile(
last_sync = timezone.now(),
role = Profile.GUARDIAN,
active = True,
user_dcid = claims.get('ps_dcid'),
user = user
)
profile.save()
self.update_students(profile)

return user

return user

def update_user(self, user, claims):
user.first_name = claims.get('given_name', '')
user.last_name = claims.get('family_name', '')
user.save()
if user.profile:
user.profile.last_sync = timezone.now()
user.profile.save()
else:
profile = Profile(
last_sync = timezone.now(),
role = Profile.GUARDIAN,
active = True,
user_dcid = claims.get('ps_dcid'),
user = user
)
profile.save()
self.update_students(user.profile)
return user
def update_user(self, user, claims):
user.first_name = claims.get("given_name", "")
user.last_name = claims.get("family_name", "")
user.save()
if user.profile:
user.profile.last_sync = timezone.now()
user.profile.save()
else:
profile = Profile(
last_sync=timezone.now(),
role=Profile.GUARDIAN,
active=True,
user_dcid=claims.get("ps_dcid"),
user=user,
)
profile.save()
self.update_students(user.profile)

return user
10 changes: 7 additions & 3 deletions cafeteria/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@

def admin_access_allowed(func):
"""
Decorator for views that checks that the user is a memeber of the
Decorator for views that checks that the user is a memeber of the
admin staff group in Django Admin. If not, the user is redirected
to the 'home' page for the site and a warning message is displayed.
"""

@wraps(func)
def wrapper(request, *args, **kwargs):
if request.user.is_staff:
return func(request, *args, **kwargs)
else:
from django.contrib import messages
messages.warning(request, 'You do not have permission to access this page.')

messages.warning(request, "You do not have permission to access this page.")
from django.shortcuts import redirect
return redirect('home')

return redirect("home")

return wrapper
Loading

0 comments on commit 34d499b

Please sign in to comment.