Skip to content

Commit

Permalink
Merge branch 'next' into openapi-spec
Browse files Browse the repository at this point in the history
  • Loading branch information
krestenlaust committed May 17, 2024
2 parents 581a215 + 97879a3 commit 51ba904
Show file tree
Hide file tree
Showing 35 changed files with 502 additions and 160 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ omit =
*/migrations/*
treo/wsgi.py
*/apps.py
stregsystem/vipps_api.py
source = .
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
- name: Black Code Formatter
uses: lgeiger/black-action@v1.0.1
with:
args: --check --target-version py36 --line-length 120 --skip-string-normalization --exclude '(migrations|urls\.py)' stregsystem stregreport kiosk
args: --check --target-version py311 --line-length 120 --skip-string-normalization --exclude '(migrations|urls\.py)' stregsystem stregreport kiosk
2 changes: 1 addition & 1 deletion .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.6.9", "3.7.17", "3.11.5"] # 3.6.9 is what is running on prod
python-version: ["3.10.14", "3.11.9"] # 3.11.9 is what is running on prod

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ htmlcov/

# ignore mobilepay api token
stregsystem/management/commands/tokens.json
stregsystem/*-tokens.json
stregsystem/*-tokens.json.bak

# ignore default log file location
stregsystem.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Python Environment
For windows using Anaconda and virtual environments:
1. Download and install Anaconda
2. In a shell:
- `conda create -n stregsystem python=3.6`
- `conda create -n stregsystem python=3.11`
- `activate stregsystem`
- `pip install -r requirements.txt`
3. ???
Expand Down
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Django==2.2.28
Pillow==8.3.2
Coverage==4.4.1
pytz==2021.3
freezegun==0.3.15
Django-Select2==5.11.1
django-debug-toolbar==1.11.1
requests==2.24.0
qrcode==6.1
Django==4.2.13
Pillow==10.3.0
Coverage==7.5.1
pytz==2024.1
freezegun==1.5.1
Django-Select2==8.1.2
django-debug-toolbar==4.3.0
requests==2.31.0
qrcode==7.4.2
2 changes: 2 additions & 0 deletions stregreport/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def ranks_for_year(request, year):

FORMAT = '%d/%m/%Y kl. %H:%M'
last_year = year - 1
next_year = year + 1
from_time = fjule_party(year - 1)
to_time = fjule_party(year)
kr_stat_list = sale_money_rank(from_time, to_time)
Expand All @@ -355,6 +356,7 @@ def ranks_for_year(request, year):
from_time_string = from_time.strftime(FORMAT)
to_time_string = to_time.strftime(FORMAT)
current_date = timezone.now()
show_next_year = year < current_date.year
is_ongoing = current_date > from_time and current_date <= to_time
return render(request, 'admin/stregsystem/report/ranks.html', locals())

Expand Down
24 changes: 12 additions & 12 deletions stregsystem/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
from stregsystem.utils import make_active_productlist_query, make_inactive_productlist_query


def refund(modeladmin, request, queryset):
for obj in queryset:
transaction = PayTransaction(obj.price)
obj.member.rollback(transaction)
obj.member.save()
queryset.delete()


refund.short_description = "Refund selected"


class SaleAdmin(admin.ModelAdmin):
list_filter = ('room', 'timestamp')
list_display = (
Expand All @@ -30,7 +41,7 @@ class SaleAdmin(admin.ModelAdmin):
'timestamp',
'get_price_display',
)
actions = ['refund']
actions = [refund]
search_fields = ['^member__username', '=product__id', 'product__name']
valid_lookups = 'member'
autocomplete_fields = ['member', 'product']
Expand Down Expand Up @@ -85,17 +96,6 @@ def get_price_display(self, obj):
get_price_display.admin_order_field = "price"


def refund(modeladmin, request, queryset):
for obj in queryset:
transaction = PayTransaction(obj.price)
obj.member.rollback(transaction)
obj.member.save()
queryset.delete()


refund.short_description = "Refund selected"


def toggle_active_selected_products(modeladmin, request, queryset):
"toggles active on products, also removes deactivation date."
# This is horrible since it does not use update, but update will
Expand Down
24 changes: 24 additions & 0 deletions stregsystem/fixtures/testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@
]
}
},
{
"model": "stregsystem.product",
"pk": 42,
"fields": {
"name": "Fadøl, en is og et søm\"",
"price": 3000,
"active": true,
"deactivate_date": null,
"rooms": [
1
]
}
},
{
"model": "stregsystem.product",
"pk": 13,
Expand Down Expand Up @@ -144,6 +157,17 @@
"price": 300
}
},
{
"model": "stregsystem.sale",
"pk": 3,
"fields": {
"member": 1,
"product": 42,
"room": 1,
"timestamp": "2017-03-13T13:38:10.573+00:00",
"price": 300
}
},
{
"model": "auth.user",
"pk": 1,
Expand Down
52 changes: 51 additions & 1 deletion stregsystem/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@


from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.mime.text import MIMEText
from django.conf import settings
from django.template.loader import render_to_string
from django.utils.html import escape
from django.utils import timezone
from stregsystem.templatetags.stregsystem_extras import money
from stregsystem.utils import rows_to_csv

logger = logging.getLogger(__name__)

Expand All @@ -30,7 +33,49 @@ def send_payment_mail(member, amount, mobilepay_comment):
)


def send_template_mail(member, target_template: str, context: dict, subject: str):
data_sent = {}


def send_userdata_mail(member):
from .models import Payment, Sale, MobilePayment

now = timezone.now()
td = now - timezone.timedelta(minutes=5)
if member.id in data_sent.keys() and data_sent[member.id] > td:
return False
data_sent[member.id] = now

sales: list[Sale] = member.sale_set.order_by("timestamp")
payments: list[Payment] = member.payment_set.order_by("timestamp")
mobilepayments: list[MobilePayment] = member.mobilepayment_set.order_by("timestamp")
mobilepay_payments: list[Payment] = [mobilepayment.payment for mobilepayment in mobilepayments]

sales_csv = rows_to_csv(
[["Timestamp", "Name", "Price"]] + [[sale.timestamp, sale.product.name, sale.price] for sale in sales]
)
payments_csv = rows_to_csv(
[["Timestamp", "Amount", "Is Mobilepay"]]
+ [[payment.timestamp, payment.amount, payment in mobilepay_payments] for payment in payments]
)
userdata_csv = rows_to_csv(
[
["Id", "Name", "First name", "Last name", "Email", "Registration year"],
[member.id, member.username, member.firstname, member.lastname, member.email, member.year],
]
)

send_template_mail(
member,
"send_csv.html",
{**vars(member), "fember": member.username},
f'{member.username} has requested their user data!',
{"sales.csv": sales_csv.encode(), "payments.csv": payments_csv.encode(), "userdata.csv": userdata_csv.encode()},
)
member.save()
return True


def send_template_mail(member, target_template: str, context: dict, subject: str, attachments: dict = {}):
msg = MIMEMultipart()
msg['From'] = 'treo@fklub.dk'
msg['To'] = member.email
Expand All @@ -41,6 +86,11 @@ def send_template_mail(member, target_template: str, context: dict, subject: str
if hasattr(settings, 'TEST_MODE'):
return

for name, attachment in attachments.items():
attachment = MIMEApplication(attachment, Name=name)
attachment['Content-Disposition'] = f'attachment; filename={name}'
msg.attach(attachment)

try:
smtpObj = smtplib.SMTP('localhost', 25)
smtpObj.sendmail('treo@fklub.dk', member.email, msg.as_string())
Expand Down
Loading

0 comments on commit 51ba904

Please sign in to comment.