Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Django-constance for dynamic settings #460

Draft
wants to merge 4 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ pytz==2024.1
freezegun==1.5.1
Django-Select2==8.1.2
django-debug-toolbar==4.3.0
django-constance==3.1.0
requests==2.31.0
qrcode==7.4.2
3 changes: 2 additions & 1 deletion stregsystem/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime

from constance import config
from django import forms

from stregsystem.models import MobilePayment, Member
Expand Down Expand Up @@ -28,7 +29,7 @@ def __init__(self, *args, **kwargs):

class QRPaymentForm(forms.Form):
member = forms.CharField(max_length=16)
amount = forms.DecimalField(min_value=50, decimal_places=2, required=False)
amount = forms.DecimalField(min_value=int(config.MINIMUM_PAYMENT_STREGOERE) / 100, decimal_places=2, required=False)


class PurchaseForm(forms.Form):
Expand Down
4 changes: 2 additions & 2 deletions stregsystem/templates/stregsystem/menu_userpay.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<td align="center">
<b>{{amount | floatformat:2}} kr.</b>
<br /><br />
<a href="mobilepay://send?phone=90601&comment={{ member.username }}&amount={{ amount }}">
<a href="mobilepay://send?phone={{ myshop_number }}&comment={{ member.username }}&amount={{ amount }}">
{% mobilepay_qr member.username amount %}
</a>
</td>
Expand All @@ -46,7 +46,7 @@
<td align="center">
<b>Valgfrit beløb</b>
<br /><br />
<a href="mobilepay://send?phone=90601&comment={{ member.username }}">
<a href="mobilepay://send?phone={{ myshop_number }}&comment={{ member.username }}">
{% mobilepay_qr member.username %}
</a>
<br />
Expand Down
5 changes: 3 additions & 2 deletions stregsystem/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from copy import deepcopy
from unittest.mock import patch

from constance import config
import pytz
from django.utils.dateparse import parse_datetime
import stregsystem.parser as parser
Expand Down Expand Up @@ -1656,7 +1657,7 @@ def test_ignore_lt_50_20(self):
def test_ignore_lt_50_49(self):
comment = 'tester'
MobilePayment.objects.create(
amount=4999,
amount=int(config.MINIMUM_PAYMENT_STREGOERE) - 1,
comment=comment,
timestamp=parse_datetime("2022-05-16T13:51:08.8574424+01:00"),
transaction_id='156E027485173228',
Expand All @@ -1672,7 +1673,7 @@ def test_ignore_lt_50_49(self):
def test_approve_gte_50(self):
comment = 'tester'
MobilePayment.objects.create(
amount=5000,
amount=int(config.MINIMUM_PAYMENT_STREGOERE),
comment=comment,
timestamp=parse_datetime("2022-05-16T13:51:09.8574424+01:00"),
transaction_id='156E027485173229',
Expand Down
6 changes: 5 additions & 1 deletion stregsystem/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import csv

from constance import config
from django.utils.dateparse import parse_datetime
from django.conf import settings
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -76,7 +77,10 @@ def make_unprocessed_member_filled_mobilepayment_query() -> QuerySet:
from stregsystem.models import MobilePayment # import locally to avoid circular import

return MobilePayment.objects.filter(
Q(payment__isnull=True) & Q(status=MobilePayment.UNSET) & Q(amount__gte=5000) & Q(member__isnull=False)
Q(payment__isnull=True)
& Q(status=MobilePayment.UNSET)
& Q(amount__gte=int(config.MINIMUM_PAYMENT_STREGOERE))
& Q(member__isnull=False)
)


Expand Down
5 changes: 4 additions & 1 deletion stregsystem/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
from typing import List

from constance import config
import pytz
from pytz import UTC
from collections import Counter
Expand Down Expand Up @@ -281,6 +282,8 @@ def menu_userpay(request, room_id, member_id):

amounts = sorted(amounts)

myshop_number = config.VIPPS_MYSHOP_NUMBER

return render(request, 'stregsystem/menu_userpay.html', locals())


Expand Down Expand Up @@ -504,7 +507,7 @@ def qr_payment(request):
if not form.is_valid():
return HttpResponseBadRequest("Invalid input for MobilePay QR code generation")

query = {'phone': '90601', 'comment': form.cleaned_data.get('member')}
query = {'phone': config.VIPPS_MYSHOP_NUMBER, 'comment': form.cleaned_data.get('member')}

if form.cleaned_data.get("amount") is not None:
query['amount'] = form.cleaned_data.get("amount")
Expand Down
4 changes: 2 additions & 2 deletions stregsystem/vipps_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime, timedelta, date
from django.utils.dateparse import parse_datetime

from constance import config
from requests.auth import HTTPBasicAuth
import requests
from pathlib import Path
Expand All @@ -17,7 +17,7 @@ class AccountingAPI(object):
tokens_file_backup = (Path(__file__).parent / 'vipps-tokens.json.bak').as_posix()
tokens = None

myshop_number = 90601
myshop_number = config.VIPPS_MYSHOP_NUMBER
logger = logging.getLogger(__name__)

@classmethod
Expand Down
13 changes: 13 additions & 0 deletions treo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
# Application definition

INSTALLED_APPS = [
'constance',
'constance.backends.database',
'stregsystem',
'stregreport',
'kiosk',
Expand Down Expand Up @@ -249,3 +251,14 @@
}
}
}

CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'

CONSTANCE_CONFIG = {
'VIPPS_MYSHOP_NUMBER': ('90601', 'MobilePay Myshop Number'),
'MINIMUM_PAYMENT_STREGOERE': (5000, 'Minimum Pay Amount in Stregoere'),
}

CONSTANCE_CONFIG_FIELDSETS = {
'Accounting': ('VIPPS_MYSHOP_NUMBER', 'MINIMUM_PAYMENT_STREGOERE',),
}
Loading