Skip to content

Commit

Permalink
Add closed message and general improvements
Browse files Browse the repository at this point in the history
- add an admin field for a custom closed message
- move site configuration to django-solo
- update Tailwind CSS library
  • Loading branch information
dougpenny committed Aug 17, 2024
1 parent 67482f3 commit a766e9f
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 74 deletions.
8 changes: 6 additions & 2 deletions cafeteria/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# admin.py
#
# Copyright (c) 2022 Doug Penny
# Copyright (c) 2024 Doug Penny
# Licensed under MIT
#
# See LICENSE.md for license information
Expand All @@ -13,8 +13,9 @@
from django.contrib import admin

from rest_framework.authtoken.admin import TokenAdmin
from solo.admin import SingletonModelAdmin

from cafeteria.models import GradeLevel, LunchPeriod, School, Weekday
from cafeteria.models import GradeLevel, LunchPeriod, School, Weekday, SiteConfiguration


TokenAdmin.raw_id_fields = ["user"]
Expand Down Expand Up @@ -69,3 +70,6 @@ def has_add_permission(self, request):

def has_delete_permission(self, request, obj=None):
return False


admin.site.register(SiteConfiguration, SingletonModelAdmin)
32 changes: 23 additions & 9 deletions cafeteria/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class GeneralForm(forms.Form):
format="%H:%M",
attrs={
"class": "shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md",
"readonly": "true",
"type": "time",
"disabled": "true",
},
),
)
Expand All @@ -25,21 +25,35 @@ class GeneralForm(forms.Form):
},
)
)
closed_for_summer = forms.NullBooleanField(
closed_for_break = forms.NullBooleanField(
widget=forms.RadioSelect(
attrs={
"x-model": "onBreak",
},
choices=[
(True, "Yes"),
(False, "No"),
]
(True, "Yes"),
],
)
)
closed_message = forms.CharField(
required=False,
widget=forms.Textarea(
attrs={
"class": "shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md",
"rows": 4,
"placeholder": "Enter a closed message here...",
"type": "text",
}
),
)
debt_limit = forms.DecimalField(
required=False,
widget=forms.NumberInput(
attrs={
"type": "number",
"class": "shadow-sm pl-7 focus:ring-blue-500 focus:border-blue-500 block sm:text-sm border-gray-300 rounded-md",
"placeholder": "0.00",
"type": "number",
}
),
decimal_places=2,
Expand All @@ -48,35 +62,35 @@ class GeneralForm(forms.Form):
required=False,
widget=forms.TextInput(
attrs={
"type": "text",
"class": "shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md",
"type": "text",
}
),
)
balance_export_path = forms.CharField(
widget=forms.TextInput(
attrs={
"type": "text",
"class": "shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md",
"type": "text",
}
)
)
current_year = forms.CharField(
required=False,
widget=forms.TextInput(
attrs={
"type": "text",
"class": "shadow-sm focus:ring-blue-500 focus:border-blue-500 block sm:text-sm border-gray-300 rounded-md",
"type": "text",
}
),
)
new_card_fee = forms.DecimalField(
required=False,
widget=forms.NumberInput(
attrs={
"type": "number",
"class": "shadow-sm pl-7 focus:ring-blue-500 focus:border-blue-500 block sm:text-sm border-gray-300 rounded-md",
"placeholder": "0.00",
"type": "number",
}
),
decimal_places=2,
Expand Down
7 changes: 3 additions & 4 deletions cafeteria/management/commands/balanceaudit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# balanceaudit.py
#
# Copyright (c) 2022 Doug Penny
# Copyright (c) 2024 Doug Penny
# Licensed under MIT
#
# See LICENSE.md for license information
Expand All @@ -18,8 +18,7 @@
from django.template.loader import render_to_string
from django.utils import timezone

from constance import config

from cafeteria.models import SiteConfiguration
from profiles.models import Profile
from transactions.models import Transaction

Expand Down Expand Up @@ -82,7 +81,7 @@ def audit_current_balance(self, profile_id: int):
return None

def email_audit_report(self, incorrect_balances: List):
recipients_list = config.REPORTS_EMAIL.split(",")
recipients_list = SiteConfiguration.get_solo().reports_email.split(",")
context = {"time": timezone.now(), "items": incorrect_balances}
html_message = render_to_string(
"email/balance_audit_report.html", context=context
Expand Down
8 changes: 4 additions & 4 deletions cafeteria/management/commands/process_eoy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# process_eoy.py
#
# Copyright (c) 2022 Doug Penny
# Copyright (c) 2024 Doug Penny
# Licensed under MIT
#
# See LICENSE.md for license information
Expand All @@ -12,8 +12,7 @@

from django.core.management.base import BaseCommand

from constance import config

from cafeteria.models import SiteConfiguration
from cafeteria.operations import end_of_year_process
from profiles.models import Profile

Expand All @@ -22,6 +21,7 @@ class Command(BaseCommand):
help = "Complete the end of year process in preparation for the next school year."

def add_arguments(self, parser):
config = SiteConfiguration.get_solo()
parser.add_argument(
"-p",
"--profile",
Expand All @@ -31,7 +31,7 @@ def add_arguments(self, parser):
parser.add_argument(
"-y",
"--year",
default=config.CURRENT_YEAR,
default=config.current_year,
type=str,
help='Override the currently set school year; used when creating the rollover balance transaction. For example, entering 2019-2020 here would result in a transaction description of "Ending balance from the 2019-2020 school year."',
)
Expand Down
31 changes: 31 additions & 0 deletions cafeteria/migrations/0018_siteconfiguration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 5.1 on 2024-08-17 15:09

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('cafeteria', '0017_lunchperiod_floating_staff'),
]

operations = [
migrations.CreateModel(
name='SiteConfiguration',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('balance_export_path', models.CharField(blank=True, help_text='File path to which current balance export files should be saved.', max_length=255)),
('closed_for_break', models.BooleanField(default=False, help_text='Is the cafeteria closed for a school break or holiday?')),
('current_year', models.CharField(help_text='The current school year.', max_length=10)),
('debt_limit', models.FloatField(default=0.0, help_text='The debt limit at which point users are prevented from ordering.')),
('new_card_fee', models.FloatField(default=0.0, help_text='The fee charged for a new lunch card.')),
('order_close_time', models.TimeField(default=datetime.time(8, 15), help_text='The time orders should stop being accepted.')),
('order_open_time', models.TimeField(default=datetime.time(0, 0), help_text='The time orders should start being accepted.')),
('reports_email', models.CharField(blank=True, help_text='The email addresses, comma seperated, to which system reports should be sent.')),
],
options={
'verbose_name': 'Site Configuration',
},
),
]
18 changes: 18 additions & 0 deletions cafeteria/migrations/0019_siteconfiguration_closed_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1 on 2024-08-17 18:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('cafeteria', '0018_siteconfiguration'),
]

operations = [
migrations.AddField(
model_name='siteconfiguration',
name='closed_message',
field=models.CharField(blank=True, help_text='The message to be displayed with the cafeteria is closed for a break or holiday.'),
),
]
43 changes: 43 additions & 0 deletions cafeteria/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from datetime import time

from django.db import models
from solo.models import SingletonModel


class GradeLevel(models.Model):
Expand Down Expand Up @@ -77,3 +80,43 @@ class Weekday(models.Model):

def __str__(self):
return self.name


class SiteConfiguration(SingletonModel):
balance_export_path = models.CharField(
blank=True,
help_text="File path to which current balance export files should be saved.",
max_length=255,
)
closed_for_break = models.BooleanField(
default=False,
help_text="Is the cafeteria closed for a school break or holiday?",
)
closed_message = models.CharField(
blank=True,
help_text="The message to be displayed with the cafeteria is closed for a break or holiday.",
)
current_year = models.CharField(help_text="The current school year.", max_length=10)
debt_limit = models.FloatField(
default=0.00,
help_text="The debt limit at which point users are prevented from ordering.",
)
new_card_fee = models.FloatField(
default=0.00, help_text="The fee charged for a new lunch card."
)
order_close_time = models.TimeField(
default=time(8, 15), help_text="The time orders should stop being accepted."
)
order_open_time = models.TimeField(
default=time(0, 0), help_text="The time orders should start being accepted."
)
reports_email = models.CharField(
blank=True,
help_text="The email addresses, comma seperated, to which system reports should be sent.",
)

def __str__(self):
return "Site Configuration"

class Meta:
verbose_name = "Site Configuration"
4 changes: 2 additions & 2 deletions cafeteria/pdfgenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path
from typing import Dict, List

from constance import config
from reportlab import platypus
from reportlab.graphics.barcode import qr
from reportlab.lib.enums import TA_CENTER
Expand All @@ -17,6 +16,7 @@
from django.http import FileResponse
from django.utils import timezone

from cafeteria.models import SiteConfiguration
from menu.models import MenuItem
from profiles.models import Profile
from transactions.models import MenuLineItem
Expand Down Expand Up @@ -328,7 +328,7 @@ def lunch_card_for_users(profiles: List[Profile]) -> FileResponse:
data.append(platypus.FrameBreak("misc-frame"))
data.append(
platypus.Paragraph(
"NRCA Cafeteria<br/>Lunch Card<br/><br/>{}".format(config.CURRENT_YEAR),
f"NRCA Cafeteria<br/>Lunch Card<br/><br/>{SiteConfiguration.get_solo().current_year}",
normal_style,
)
)
Expand Down
Loading

0 comments on commit a766e9f

Please sign in to comment.