diff --git a/buyer/admin.py b/buyer/admin.py index d153908..ce28c4f 100644 --- a/buyer/admin.py +++ b/buyer/admin.py @@ -1,6 +1,8 @@ from django.contrib import admin from buyer.models import Card -# Register your models here. +class CardAdmin(admin.ModelAdmin): + list_display = ["number", "purchased", "delivered"] + ordering = ["delivered"] -admin.site.register(Card) \ No newline at end of file +admin.site.register(Card, CardAdmin) diff --git a/buyer/views.py b/buyer/views.py index 79f6d6a..c07ad6e 100644 --- a/buyer/views.py +++ b/buyer/views.py @@ -7,6 +7,7 @@ import random from dbsettings.views import getValue from buyer.models import Card import time +from smsauth.views import sendSMS def getCard(allow_buy=False): unused = Card.objects.filter(delivered=None) # pylint: disable=E1101 @@ -70,4 +71,8 @@ def buyCard(): time.sleep(15) - return Card() \ No newline at end of file + return Card() + +def sendStatus(): + status = len(Card.objects.filter(delivered=None)) + return sendSMS("A Paysafecard has been sold. There are %i remaining in stock." % status, getValue("buyer.recipient")) diff --git a/frontend/templates/frontend/card.html b/frontend/templates/frontend/card.html index 656495a..10566a3 100644 --- a/frontend/templates/frontend/card.html +++ b/frontend/templates/frontend/card.html @@ -1 +1 @@ -Die Kartennummer lautet: {{ object.card.number }} \ No newline at end of file +Die Kartennummer lautet: {{ object.card.number | stringformat:"016d" }} diff --git a/frontend/views.py b/frontend/views.py index 7897a82..c3d5d81 100644 --- a/frontend/views.py +++ b/frontend/views.py @@ -7,7 +7,7 @@ from django.utils import timezone from datetime import timedelta from django.http import Http404 from smsauth.views import requestToken -from buyer.views import getCard +from buyer.views import getCard, sendStatus from ledger.models import Payment def makeCardURL(card): @@ -39,4 +39,5 @@ class CardView(LoginRequiredMixin, DetailView): raise Http404() obj.card.delivered = timezone.now() obj.card.save() + sendStatus() return obj diff --git a/ledger/admin.py b/ledger/admin.py index 155cdd6..69f15a0 100644 --- a/ledger/admin.py +++ b/ledger/admin.py @@ -1,6 +1,15 @@ from django.contrib import admin from ledger.models import Payment +from django.utils import timezone -# Register your models here. +def repay(modeladmin, request, queryset): + queryset.update(repayment=timezone.now()) -admin.site.register(Payment) \ No newline at end of file +repay.short_description = "Mark selected payments as repaid" + +class PaymentAdmin(admin.ModelAdmin): + list_display = ["description", "amount", "date", "repayment"] + ordering = ["date"] + actions = [repay] + +admin.site.register(Payment, PaymentAdmin) diff --git a/requirements.txt b/requirements.txt index aa6f655..2e94ef8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ selenium bs4 twilio +django-bulk-admin diff --git a/smsauth/views.py b/smsauth/views.py index 02be5e3..d102fd4 100644 --- a/smsauth/views.py +++ b/smsauth/views.py @@ -23,8 +23,8 @@ def useToken(token): def requestToken(): token = generateToken() storeToken(token) - return sendSMS("Bitte verwende diesen Code, um deine Bestellung zu bestätigen: %s" % token) + return sendSMS("Bitte verwende diesen Code, um deine Bestellung zu bestätigen: %s" % token, getValue("smsauth.recipient")) -def sendSMS(text): +def sendSMS(text, recipient): client = Client(getValue("smsauth.twilio.sid"), getValue("smsauth.twilio.token")) - return client.messages.create(body=text, from_=getValue("smsauth.twilio.number"), to=getValue("smsauth.recipient")) \ No newline at end of file + return client.messages.create(body=text, from_=getValue("smsauth.twilio.number"), to=recipient) diff --git a/susioma/settings.py b/susioma/settings.py index d4e6e3c..987e20e 100644 --- a/susioma/settings.py +++ b/susioma/settings.py @@ -98,7 +98,7 @@ AUTH_PASSWORD_VALIDATORS = [ LANGUAGE_CODE = 'de-at' -TIME_ZONE = 'UTC' +TIME_ZONE = 'Europe/Vienna' USE_I18N = True @@ -111,6 +111,7 @@ USE_TZ = True # https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = '/var/www/html/static/' # Custom settings for Susioma project diff --git a/uwsgi.sh b/uwsgi.sh new file mode 100755 index 0000000..d93d3f3 --- /dev/null +++ b/uwsgi.sh @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/local/bin/uwsgi --http 127.0.0.1:8000 --module susioma.wsgi --uid 1001 --processes 8