From 105ddc04096939620ce929e9da07801f24e6fe07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller=20=28ChaoticByte=29?= Date: Thu, 13 Apr 2023 21:06:06 +0200 Subject: [PATCH 01/33] Removed 'User: ' prefix in user panel to get more space for the username and balance --- app/locales/de/LC_MESSAGES/django.mo | Bin 3543 -> 3513 bytes app/locales/de/LC_MESSAGES/django.po | 6 +----- app/templates/userpanel.html | 9 ++------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/app/locales/de/LC_MESSAGES/django.mo b/app/locales/de/LC_MESSAGES/django.mo index 76e345b24588b6c782488239b385736378b82c35..9bbfd05f0edcc8ef85efb156f920675466a7fec2 100644 GIT binary patch delta 1115 zcmXZb&r6g+9LMqR`aGMatLCbesYQyhwyx#x)Pr8k3{5P^TS7~R2oENLRwiphc^2+~~-CD9@9B&9+JL7_yd_s3><=6TJ`J~Q)uzVqzY^5yc>X4IcHN;|cJ zx)m}T#95CUW!pE)#vMF?d)SD-@Fd2=W~Z9KM4^Q%u>c#K-EMpk6+jZT(KuG(Q{=KY+~WB5xSujx zqfx@Z1`?5NqXO7R1#pNLF^|=vn7{~jqn;Z;1#$;-@jfbfqsUYnLuGanFX1%S;tG1~ zZ{KMsmAgn*Z67u9H*%Tf{9iB!wP6JHhEdnAa>ktXsQJyPKsvFSW9>q%mt-@o^9WNN zG{$Hs@>$eTEV&2PQ5o29<6C%>{vm3E9wyPWepE*8qUI-28J$A*w3lxDHR|Z*Q0soo z<@`_6`0O6oasI_KjF)mAGJ%S`2WxNuweUFV!+qxZi+Gv-DxSq%WGVBAt_%yX7Gro0 zZ%4?#A|K_ZlsrM5@pELZ1#W!C_0w3#_yRWJCN^V~FH=X?i`uXs74R@BLnEm59-@w9 z0`&q@H)tp&FWkT@R3I~`iD^`-=P?Txk)u5RpunoBF=~78$-5A$5B9v`P-77Gd&{os zXG#mTm8#d$)=j|!ziX(0mWqN%)W(7esYSbplq~)J>^|OkpLg%vckg-UzIht^5X*cj@J5ZJ zh1g2`2$&tm7eOu@i=J67E@2J^vd#8j2=nkDZos3cai=gJ&tf6=p~ep*r#<1KanEs` zS;nThDW>BsZo~!TwBKAb@n2_@)z{OmKuuhaQ9SHSy8bRy0{y6ku3{P9Ku&war54B6 z+8MKXZi?vmiezMqs02KoRsvzH#26M}0wb72jXQ%%q!+`OMip-enaZx9Dm#J{(H`J- ze2mqsZ|}I#1AkB@T|o`Z3;mxUigZ~qYFrs=;Y!q-?r`m9XTo^|mB2C7b4iS|y(dxg z4YF896J6#;`+p7f22-dlnMM8n1yzafu73&JY3DOo3v?n~){Uyn1=RC{sLI|%*0lSs ze+;#SufpuVCVo%HCj90G{BstuADii~akio|@5F7`gPM2*58!RrevLJ>=dc7`F0?)tHD-|1I2{qeGbwbI}{$Lhbb^@~k~{{gbZ!4D0BhK_&1L8*v$%uz@dCTbM#E zd>)nf0IE_$sCloS=0?4{9y`ENX@;kgkC-fJsC6t2>C9kbhRqF{=yMfR@R0Y#_ tr(-9fym)UbC+dj3#Quo|Z#>KE=uf35?&P*-hgws80~ar)(*DQD{3@m3W|9B^ diff --git a/app/locales/de/LC_MESSAGES/django.po b/app/locales/de/LC_MESSAGES/django.po index c7b1011..23307a8 100644 --- a/app/locales/de/LC_MESSAGES/django.po +++ b/app/locales/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-02-17 22:11+0100\n" +"POT-Creation-Date: 2023-04-13 20:50+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Julian Müller (ChaoticByte)\n" "Language: DE\n" @@ -226,10 +226,6 @@ msgstr "Senden" msgid "You are not allowed to view this site." msgstr "Dir fehlt die Berechtigung, diese Seite anzuzeigen." -#: app/templates/userpanel.html:9 app/templates/userpanel.html:11 -msgid "User" -msgstr "Benutzer" - #: app/templates/userpanel.html:15 app/templates/userpanel.html:17 msgid "Balance" msgstr "Saldo" diff --git a/app/templates/userpanel.html b/app/templates/userpanel.html index 159dcf5..baa384b 100644 --- a/app/templates/userpanel.html +++ b/app/templates/userpanel.html @@ -3,13 +3,8 @@
- - - {% if user.first_name != "" %} - {% translate "User" %}: {{ user.first_name }} {{ user.last_name }} ({{ user.username }}) - {% else %} - {% translate "User" %}: {{ user.username }} - {% endif %} + {% if user.first_name != "" %} + {{ user.first_name }} {{ user.last_name }} ({{ user.username }}){% else %}{{ user.username }}{% endif %}  -  {% if user.balance < 0.01 %} {% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }} From 5ab0d1088f149022f9032b488959e18ce81e8d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller=20=28ChaoticByte=29?= Date: Thu, 13 Apr 2023 21:19:11 +0200 Subject: [PATCH 02/33] Added 'Hide from userlist' to user settings --- app/admin.py | 10 +++++++--- app/migrations/0003_user_hide_from_userlist.py | 17 +++++++++++++++++ app/models.py | 1 + app/views.py | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 app/migrations/0003_user_hide_from_userlist.py diff --git a/app/admin.py b/app/admin.py index 0d37821..4e8da52 100644 --- a/app/admin.py +++ b/app/admin.py @@ -43,20 +43,24 @@ class CustomUserAdmin(UserAdmin): fieldsets_ = list((*UserAdmin.fieldsets,)) fieldsets_.insert(1, ( + "Visibility", + {"fields": ("hide_from_userlist",)}, + )) + fieldsets_.insert(2, ( "Balance", {"fields": ("balance", "allow_order_with_negative_balance")}, )) - fieldsets_.insert(2, ( + fieldsets_.insert(3, ( "Supply", {"fields": ("allowed_to_supply",)}, )) - fieldsets_.insert(3, ( + fieldsets_.insert(4, ( "Profile Picture", {"fields": ("profile_picture_filename",)}, )) fieldsets = tuple(fieldsets_) - list_display = ["username", "balance", "is_active", "allow_order_with_negative_balance"] + list_display = ["username", "balance", "allow_order_with_negative_balance", "is_active", "hide_from_userlist"] def get_actions(self, request): # remove the "delete_selected" action because it breaks some functionality actions = super().get_actions(request) diff --git a/app/migrations/0003_user_hide_from_userlist.py b/app/migrations/0003_user_hide_from_userlist.py new file mode 100644 index 0000000..7ffa0e8 --- /dev/null +++ b/app/migrations/0003_user_hide_from_userlist.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.6 on 2023-04-13 19:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("app", "0002_setup"), + ] + + operations = [ + migrations.AddField( + model_name="user", + name="hide_from_userlist", + field=models.BooleanField(default=False), + ), + ] diff --git a/app/models.py b/app/models.py index ddfd302..5978a47 100644 --- a/app/models.py +++ b/app/models.py @@ -13,6 +13,7 @@ class User(AbstractUser): allow_order_with_negative_balance = models.BooleanField(default=False) profile_picture_filename = models.CharField(default="default.svg", max_length=25) allowed_to_supply = models.BooleanField(default=False) + hide_from_userlist = models.BooleanField(default=False) def delete(self, *args, **kwargs): self.balance = 0 diff --git a/app/views.py b/app/views.py index 7f3ea30..07fd072 100644 --- a/app/views.py +++ b/app/views.py @@ -25,7 +25,7 @@ from .models import RegisterTransaction def login_page(request): - userlist = get_user_model().objects.filter(is_superuser=False).filter(is_active=True).order_by("username") + userlist = get_user_model().objects.filter(hide_from_userlist=False).filter(is_active=True).order_by("username") if request.method == "POST": form = AuthenticationForm(request.POST) username = request.POST['username'] From 2bab323b8634a09d0aab414f08aa67f00e8bcf7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller=20=28ChaoticByte=29?= Date: Fri, 14 Apr 2023 20:48:01 +0200 Subject: [PATCH 03/33] Implemented 'custom forms' to replace individual scripts for deposit and supply forms --- app/static/js/{deposit.js => custom_form.js} | 12 +++--- app/static/js/supply.js | 39 -------------------- app/templates/deposit.html | 8 ++-- app/templates/supply.html | 10 ++--- 4 files changed, 15 insertions(+), 54 deletions(-) rename app/static/js/{deposit.js => custom_form.js} (78%) delete mode 100644 app/static/js/supply.js diff --git a/app/static/js/deposit.js b/app/static/js/custom_form.js similarity index 78% rename from app/static/js/deposit.js rename to app/static/js/custom_form.js index c2b6785..a29f07b 100644 --- a/app/static/js/deposit.js +++ b/app/static/js/custom_form.js @@ -1,15 +1,15 @@ document.addEventListener("DOMContentLoaded", () => { // elements - let depositForm = document.getElementById("depositform"); + let customForm = document.getElementById("customform"); let statusInfo = document.getElementById("statusinfo"); - let depositSubmitButton = document.getElementById("depositsubmitbtn"); + let submitButton = document.getElementById("submitbtn"); // event listener for deposit form // this implements a custom submit method - depositForm.addEventListener("submit", (event) => { - depositSubmitButton.disabled = true; + customForm.addEventListener("submit", (event) => { + submitButton.disabled = true; event.preventDefault(); // Don't do the default submit action! let xhr = new XMLHttpRequest(); - let formData = new FormData(depositForm); + let formData = new FormData(customForm); xhr.addEventListener("load", (event) => { status_ = event.target.status; response_ = event.target.responseText; @@ -28,7 +28,7 @@ document.addEventListener("DOMContentLoaded", () => { statusInfo.innerText = "An error occured. Redirecting in 5 seconds..."; window.setTimeout(() => { window.location.replace("/") }, 5000); }) - xhr.open("POST", "/api/deposit"); + xhr.open("POST", customForm.action); xhr.send(formData); }); }); diff --git a/app/static/js/supply.js b/app/static/js/supply.js deleted file mode 100644 index 04021e0..0000000 --- a/app/static/js/supply.js +++ /dev/null @@ -1,39 +0,0 @@ -document.addEventListener("DOMContentLoaded", () => { - // elements - let supplyDescriptionElement = document.getElementById("supplydescription"); - let supplyPriceElement = document.getElementById("supplyprice"); - let supplyFormElement = document.getElementById("supplyform"); - let statusInfoElement = document.getElementById("statusinfo"); - let supplySubmitButton = document.getElementById("supplysubmitbtn"); - // custom submit method - supplyFormElement.addEventListener("submit", (event) => { - supplySubmitButton.disabled = true; - event.preventDefault(); // Don't do the default submit action! - if (isNaN(parseFloat(supplyPriceElement.value)) || supplyDescriptionElement.value == "") { - statusInfoElement.innerText = "Please enter a description and price." - supplySubmitButton.disabled = false; - } - let xhr = new XMLHttpRequest(); - let formData = new FormData(supplyFormElement); - xhr.addEventListener("load", (event) => { - status_ = event.target.status; - response_ = event.target.responseText; - if (status_ == 200 && response_ == "success") { - statusInfoElement.innerText = "Success."; - window.location.replace("/"); - } - else { - statusInfoElement.classList.add("errortext"); - statusInfoElement.innerText = "An error occured."; - window.setTimeout(() => { window.location.reload() }, 5000); - } - }) - xhr.addEventListener("error", (event) => { - statusInfoElement.classList.add("errortext"); - statusInfoElement.innerText = "An error occured."; - window.setTimeout(() => { window.location.reload() }, 5000); - }) - xhr.open("POST", "/api/supply"); - xhr.send(formData); - }); -}); diff --git a/app/templates/deposit.html b/app/templates/deposit.html index 9334b3c..bbce3e1 100644 --- a/app/templates/deposit.html +++ b/app/templates/deposit.html @@ -12,13 +12,13 @@ {% endblock %} {% block content %} -
+ {% csrf_token %}

{% translate "Deposit" %}

{% translate "Amount" %} {{ currency_suffix }}: - +
@@ -28,9 +28,9 @@
- + {% endblock %} \ No newline at end of file diff --git a/app/templates/supply.html b/app/templates/supply.html index f907f2d..4f656c2 100644 --- a/app/templates/supply.html +++ b/app/templates/supply.html @@ -9,28 +9,28 @@ {% block content %} {% if user.is_superuser or user.allowed_to_supply %} -
+ {% csrf_token %}

{% translate "Supply" %}

{% translate "Description" %}: - +
{% translate "Price" %} ({{ currency_suffix }}): - +
- + {% else %}
From 8702233934ea71e53a847b1229672e07d8275333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller=20=28ChaoticByte=29?= Date: Fri, 14 Apr 2023 23:47:12 +0200 Subject: [PATCH 04/33] Added feature to transfer money to another account + some minor improvements --- app/db_queries.py | 15 ++++- app/locales/de/LC_MESSAGES/django.mo | Bin 3513 -> 3704 bytes app/locales/de/LC_MESSAGES/django.po | 40 ++++++++---- .../0004_registertransaction_is_transfer.py | 17 +++++ app/models.py | 13 ++-- app/static/css/main.css | 2 +- app/templates/registration/login.html | 2 + app/templates/transfer.html | 60 ++++++++++++++++++ app/templates/userpanel.html | 1 + app/urls.py | 2 + app/views.py | 42 +++++++++--- 11 files changed, 164 insertions(+), 30 deletions(-) create mode 100644 app/migrations/0004_registertransaction_is_transfer.py create mode 100644 app/templates/transfer.html diff --git a/app/db_queries.py b/app/db_queries.py index 93a2727..c10b85e 100644 --- a/app/db_queries.py +++ b/app/db_queries.py @@ -45,21 +45,30 @@ def select_history(user, language_code="en") -> list: result = _db_select(f""" select concat( + price_sum, '{settings.CURRENCY_SUFFIX} - ', product_name, ' (', content_litres::real, -- converting to real removes trailing zeros - 'l) x ', amount, ' - ', price_sum, '{settings.CURRENCY_SUFFIX}') as "text", + 'l) x ', amount) as "text", datetime from app_order where user_id = {user_id} - union + union select - concat('Deposit: +', transaction_sum, '{settings.CURRENCY_SUFFIX}') as "text", + concat(transaction_sum, '{settings.CURRENCY_SUFFIX} - Deposit') as "text", datetime from app_userdeposits_view where user_id = {user_id} + union + + select + concat(transaction_sum, '{settings.CURRENCY_SUFFIX} - ', comment) as "text", + datetime + from app_registertransaction + where user_id = {user_id} and is_transfer = true + order by datetime desc fetch first 30 rows only; """) diff --git a/app/locales/de/LC_MESSAGES/django.mo b/app/locales/de/LC_MESSAGES/django.mo index 9bbfd05f0edcc8ef85efb156f920675466a7fec2..9ad7ad461d4d79a5ce679d7d73db94e66efd4f59 100644 GIT binary patch delta 1490 zcmYk+TS!zv9LMol-Mp+@rj?g8+cM2d-b(Y9l%N@6MOGFRh2*i!_9Ux85w%3wQb~2UjQ4N}K0)388u^)NF1l|9 zlZ*+QSVmn&Lo%jd9_q$w)W8ka9k`JCVbs7uT!a^_L$-YcwSWj}yfM^-?{NiAB0n?3 zrI`6m483Y7#idwX}%GTTl-kM-Awr7f+)GI){v5E}`zbf?CKBDgw7{{h{@-^%?5< z7Z}!quPEet2o-9;DQ43^zpxIcQEyVtMO#&m>feQm%s$(G3|pz6M@=w+TKHR3q&}ja zpF&0YuaEdMr%5H=>c~RvZ3SxJW=z8l+aI)E#B|#4SVyfBs2BKxdH5YQeloMyVg{<- zjzxIDPy90|T&96VnGwvyM_7pCxEy~XKa2d3Hz*p>q=B?8`O$`XmQ&tHE+K0Rw2eAL ztI7HttI4Hg-dA5s*kn=AAB5h1e$wg{0VSOcy`>_fZBPXCEw3Thkd=zavwMyDOci#e zoH=H%ibNGzhc7@bGn?nas>2aY+V7Ro3a+)~V$|8tb}8kOQzPHJS3N0Bp&qxlKTs0b z6Y6yPyPeQ*DDHP+yK|(cug7r*hCAac)1zG`S_o`E={jd3H{(ZR(_5T@(AWdF*I|qn o=R{Ya-*LMfH`0`})8lIn_I1;Flwoi9+qn0CznNDap7ekE2Sy)^asU7T delta 1315 zcmZA1%}Z2K7{~Ev9A749Mr+E-d@C&*o5nJ=7h9wY70MS#uw8<86)}aGkiBrDKcLOU zqD9zdRv8roMi5B*YLU1Kgg{D#h`@!psJ_4Pxan}u{hWKa_uS_`&zV`Tep}@)CJLvF zc7|R}UkaHG;!KzmZMo2_1Xr*af8hyS$8DG@GTV;rsQY@b90zbGUPj%2134_qN%uX+ zsF`m$1{F-q;SO9t4*SkY3;%Hb!8q6DM4^Riunb$Aoo;>*6@Z6&(Ky!N9ptbloKpBK zf9;!nV6cmcc_boRMg_2j3Sa{dV3gGon8p}(qVDTQ1u}%CIEqSM26@!RP?^1jjW~r( z_zuIo-@Y+WDp!%L+8XM?-^gJW*<3J!dSMLpg$Z|E?@T(IQO~!b0y&Efl=U2HJ&%`Z zovY|~Fc@Q?$Y)Tcc;jyPh|0jcn_t57TyLOW(9J^(tq+xvVbt>;Dx;IgJME#He~c>K z3)H&rOR4{E2A|yxE6%^ThxrQXA=9YHyYUeAqZS@VZQQ%=dKQmxJ%@X76qWh=4;AnwRE9=S z>s>*WWCHa8lRg8bX%r6vq&lP8w#v}o}?=adZDtV-Tr@TW}=?1 zAk?&>^|SO3b7IYWQ|+{qRhzA*;Ogi~t4gJ&0M(RAwd0#uJD#K~gZfHkNKL74%#X~f zocgH!`u!_iYO2>()0ZBkx3~$VN=+%&#yU+`8MGIU(e=Nfdg@o9mZmFvRL5%RDZ0vZ uif&z=cYWg8P3y`)uBYf;C|D@|8GI^f%~eKTg>zq{1EHWJej#`o|MCyDt7lvQ diff --git a/app/locales/de/LC_MESSAGES/django.po b/app/locales/de/LC_MESSAGES/django.po index 23307a8..855cd09 100644 --- a/app/locales/de/LC_MESSAGES/django.po +++ b/app/locales/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-04-13 20:50+0200\n" +"POT-Creation-Date: 2023-04-14 23:37+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Julian Müller (ChaoticByte)\n" "Language: DE\n" @@ -33,20 +33,21 @@ msgstr "Ein Fehler ist aufgetreten. Bitte ab- und wieder anmelden." msgid "Drinks - Deposit" msgstr "Getränke - Einzahlen" -#: app/templates/deposit.html:17 app/templates/userpanel.html:23 +#: app/templates/deposit.html:17 app/templates/userpanel.html:18 msgid "Deposit" msgstr "Einzahlen" -#: app/templates/deposit.html:19 +#: app/templates/deposit.html:19 app/templates/transfer.html:43 msgid "Amount" msgstr "Summe" #: app/templates/deposit.html:30 app/templates/order.html:54 #: app/templates/registration/login.html:28 app/templates/supply.html:29 +#: app/templates/transfer.html:54 msgid "cancel" msgstr "Abbrechen" -#: app/templates/deposit.html:31 +#: app/templates/deposit.html:31 app/templates/transfer.html:55 msgid "confirm" msgstr "Bestätigen" @@ -54,7 +55,7 @@ msgstr "Bestätigen" msgid "Drinks - History" msgstr "Getränke - Verlauf" -#: app/templates/history.html:10 app/templates/userpanel.html:30 +#: app/templates/history.html:10 app/templates/userpanel.html:25 msgid "History" msgstr "Verlauf" @@ -164,7 +165,7 @@ msgstr "Wähle deinen Account" msgid "Drinks - Statistics" msgstr "Getränke - Statistiken" -#: app/templates/statistics.html:10 app/templates/userpanel.html:31 +#: app/templates/statistics.html:10 app/templates/userpanel.html:26 msgid "Statistics" msgstr "Statistiken" @@ -206,7 +207,7 @@ msgstr "Tag" msgid "Drinks - Supply" msgstr "Getränke - Beschaffung" -#: app/templates/supply.html:14 app/templates/userpanel.html:36 +#: app/templates/supply.html:14 app/templates/userpanel.html:32 msgid "Supply" msgstr "Beschaffung" @@ -226,19 +227,36 @@ msgstr "Senden" msgid "You are not allowed to view this site." msgstr "Dir fehlt die Berechtigung, diese Seite anzuzeigen." -#: app/templates/userpanel.html:15 app/templates/userpanel.html:17 +#: app/templates/transfer.html:6 +#| msgid "Drinks - Order" +msgid "Drinks - Transfer" +msgstr "Getränke - Geld senden" + +#: app/templates/transfer.html:17 +msgid "Transfer Money" +msgstr "Geld senden" + +#: app/templates/transfer.html:19 +msgid "Recipient" +msgstr "Empfänger" + +#: app/templates/userpanel.html:10 app/templates/userpanel.html:12 msgid "Balance" msgstr "Saldo" -#: app/templates/userpanel.html:24 +#: app/templates/userpanel.html:19 msgid "Logout" msgstr "Abmelden" -#: app/templates/userpanel.html:27 +#: app/templates/userpanel.html:22 msgid "Account" msgstr "Account" -#: app/templates/userpanel.html:38 +#: app/templates/userpanel.html:30 +msgid "Transfer" +msgstr "Geld senden" + +#: app/templates/userpanel.html:34 msgid "Change Password" msgstr "Passwort ändern" diff --git a/app/migrations/0004_registertransaction_is_transfer.py b/app/migrations/0004_registertransaction_is_transfer.py new file mode 100644 index 0000000..550b353 --- /dev/null +++ b/app/migrations/0004_registertransaction_is_transfer.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.6 on 2023-04-14 20:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("app", "0003_user_hide_from_userlist"), + ] + + operations = [ + migrations.AddField( + model_name="registertransaction", + name="is_transfer", + field=models.BooleanField(default=False), + ), + ] diff --git a/app/models.py b/app/models.py index 5978a47..842f889 100644 --- a/app/models.py +++ b/app/models.py @@ -59,30 +59,29 @@ class RegisterTransaction(models.Model): old_transaction_sum = models.DecimalField(max_digits=6, decimal_places=2, default=0.00) datetime = models.DateTimeField(default=timezone.now) is_user_deposit = models.BooleanField(default=False) + is_transfer = models.BooleanField(default=False) comment = models.TextField(default=" ") user = models.ForeignKey(User, on_delete=models.CASCADE) def save(self, *args, **kwargs): if self._state.adding: - if self.is_user_deposit == True: # update user balance + if self.is_user_deposit or self.is_transfer: # update user balance self.user.balance += self.transaction_sum self.user.save() self.old_transaction_sum = self.transaction_sum super().save(*args, **kwargs) else: - # update register transaction - sum_diff = self.transaction_sum - self.old_transaction_sum # update user balance - if self.is_user_deposit == True: - ub_sum_diff = self.transaction_sum - self.old_transaction_sum - self.user.balance += ub_sum_diff + if self.is_user_deposit or self.is_transfer: + self.user.balance += self.transaction_sum - self.old_transaction_sum self.user.save() + # update register transaction self.old_transaction_sum = self.transaction_sum super().save(*args, **kwargs) def delete(self, *args, **kwargs): # update user deposit - if self.is_user_deposit: + if self.is_user_deposit or self.is_transfer: self.user.balance -= self.transaction_sum self.user.save() super().delete(*args, kwargs) diff --git a/app/static/css/main.css b/app/static/css/main.css index afdd6c6..338fb35 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -50,7 +50,7 @@ input[type="number"]::-webkit-inner-spin-button { display: none; } -input[type="text"], input[type="password"], input[type="number"] { +input[type="text"], input[type="password"], input[type="number"], select { padding: .6rem .8rem; text-align: center; font-size: 1rem; diff --git a/app/templates/registration/login.html b/app/templates/registration/login.html index 837dc70..c9ba292 100644 --- a/app/templates/registration/login.html +++ b/app/templates/registration/login.html @@ -48,6 +48,8 @@ {{ user_.last_name }}, {% endif %} {{ user_.first_name }} + {% elif user_.last_name %} + {{ user_.last_name }} {% else %} {{ user_.username }} {% endif %} diff --git a/app/templates/transfer.html b/app/templates/transfer.html new file mode 100644 index 0000000..74c13f4 --- /dev/null +++ b/app/templates/transfer.html @@ -0,0 +1,60 @@ +{% extends "baselayout.html" %} + +{% load i18n %} + +{% block title %} +{% translate "Drinks - Transfer" %} +{% endblock %} + +{% block headAdditional %} + + +{% endblock %} + +{% block content %} +
+ {% csrf_token %} +

{% translate "Transfer Money" %}

+
+ {% translate "Recipient" %}: + + + +
+
+ {% translate "Amount" %} {{ currency_suffix }}: + + + +
+
+ +
+ + + +
+ + +{% endblock %} \ No newline at end of file diff --git a/app/templates/userpanel.html b/app/templates/userpanel.html index baa384b..4423150 100644 --- a/app/templates/userpanel.html +++ b/app/templates/userpanel.html @@ -27,6 +27,7 @@ {% if user.is_superuser or user.is_staff %} Admin Panel {% endif %} + {% translate "Transfer" %} {% if user.is_superuser or user.allowed_to_supply %} {% translate "Supply" %} {% endif %} diff --git a/app/urls.py b/app/urls.py index f6f8cc4..1fa379d 100644 --- a/app/urls.py +++ b/app/urls.py @@ -10,6 +10,7 @@ urlpatterns = [ path('history/', views.history), path('deposit/', views.deposit), path('statistics/', views.statistics), + path('transfer/', views.transfer), path('supply/', views.supply), path('accounts/login/', views.login_page, name="login"), path('accounts/logout/', auth_views.LogoutView.as_view(), name='logout'), @@ -19,5 +20,6 @@ urlpatterns = [ # API # path('api/order-drink', views.api_order_drink), path('api/deposit', views.api_deposit), + path('api/transfer', views.api_transfer), path('api/supply', views.api_supply) ] diff --git a/app/views.py b/app/views.py index 07fd072..d604e63 100644 --- a/app/views.py +++ b/app/views.py @@ -50,7 +50,6 @@ def login_page(request): "user_list": userlist }) - @login_required def index(request): context = { @@ -58,7 +57,6 @@ def index(request): } return render(request, "index.html", context) - @login_required def history(request): context = { @@ -66,7 +64,6 @@ def history(request): } return render(request, "history.html", context) - @login_required def order(request, drinkid): try: @@ -76,7 +73,6 @@ def order(request, drinkid): except Drink.DoesNotExist: return HttpResponseRedirect("/") - @login_required def deposit(request): return render(request, "deposit.html", {}) @@ -91,17 +87,19 @@ def statistics(request): } return render(request, "statistics.html", context) +@login_required +def transfer(request): + userlist = get_user_model().objects.filter(hide_from_userlist=False).filter(is_active=True).order_by("username") + return render(request, "transfer.html", {"user_list": userlist}) @login_required def supply(request): return render(request, "supply.html") - @login_required def redirect_home(request): return HttpResponseRedirect("/") - # API for XHR requests # @login_required @@ -123,7 +121,6 @@ def api_order_drink(request): print(f"An exception occured while processing an order: User: {user.username} - Exception: {e}", file=sys.stderr) return HttpResponse(b"", status=500) - @login_required def api_deposit(request): # check request -> deposit @@ -140,9 +137,38 @@ def api_deposit(request): return HttpResponse("success", status=200) else: raise Exception("Deposit amount too big or small.") except Exception as e: - print(f"An exception occured while processing a transaction: User: {user.username} - Exception: {e}", file=sys.stderr) + print(f"An exception occured while processing a deposit transaction: User: {user.username} - Exception: {e}", file=sys.stderr) return HttpResponse(b"", status=500) +@login_required +def api_transfer(request): + # check request -> transfer + user = request.user + try: + recipient = get_user_model().objects.get(id=int(request.POST["recipientuser"])) + if recipient.id == user.id: + raise Exception(f"User {user.username} tried to transfer to themself.") + amount = decimal.Decimal(request.POST["transferamount"]) + if 0.00 < amount <= user.balance: + print("sender:", user.username) + print("recipient:", recipient.username) + print("amount:", amount) + # create transaction + RegisterTransaction.objects.create( + transaction_sum=-amount, + comment=f"Transfer to {recipient.username}", + is_transfer=True, + user=user) + RegisterTransaction.objects.create( + transaction_sum=amount, + comment=f"Transfer from {user.username}", + is_transfer=True, + user=recipient) + return HttpResponse("success", status=200) + else: raise Exception("Transfer amount too big or small.") + except Exception as e: + print(f"An exception occured while processing a transfer transaction: User: {user.username} - Exception: {e}", file=sys.stderr) + return HttpResponse(b"", status=500) @login_required def api_supply(request): From ac59aa0baa64d602587ce4cf2ed1216230df2576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller=20=28ChaoticByte=29?= Date: Sat, 15 Apr 2023 10:01:56 +0200 Subject: [PATCH 05/33] Improved history page and spacing between values and currency suffix + minor improvements to css --- app/db_queries.py | 20 +++++++++++--------- app/models.py | 6 +++--- app/static/css/main.css | 13 ++++++++----- app/templates/globalmessage.html | 2 +- app/templates/history.html | 8 ++++---- app/templates/userpanel.html | 6 +++--- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/app/db_queries.py b/app/db_queries.py index c10b85e..656bbda 100644 --- a/app/db_queries.py +++ b/app/db_queries.py @@ -2,6 +2,7 @@ from django.conf import settings from django.db import connection +from django.utils.translation import gettext COMBINE_ALPHABET = "abcdefghijklmnopqrstuvwxyz" @@ -44,11 +45,13 @@ def select_history(user, language_code="en") -> list: user_id = user.pk result = _db_select(f""" select + price_sum as "sum", concat( - price_sum, '{settings.CURRENCY_SUFFIX} - ', - product_name, ' (', - content_litres::real, -- converting to real removes trailing zeros - 'l) x ', amount) as "text", + product_name, + ' (', + content_litres::real, -- converting to real removes trailing zeros + 'l) x ', amount + ) as "text", datetime from app_order where user_id = {user_id} @@ -56,7 +59,8 @@ def select_history(user, language_code="en") -> list: union select - concat(transaction_sum, '{settings.CURRENCY_SUFFIX} - Deposit') as "text", + transaction_sum as "sum", + '{gettext("Deposit")}' as "text", datetime from app_userdeposits_view where user_id = {user_id} @@ -64,7 +68,8 @@ def select_history(user, language_code="en") -> list: union select - concat(transaction_sum, '{settings.CURRENCY_SUFFIX} - ', comment) as "text", + transaction_sum as "sum", + comment as "text", datetime from app_registertransaction where user_id = {user_id} and is_transfer = true @@ -73,9 +78,6 @@ def select_history(user, language_code="en") -> list: fetch first 30 rows only; """) result = [list(row) for row in result] - if language_code == "de": # reformat for german translation - for row in result: - row[0] = row[0].replace(".", ",") return result diff --git a/app/models.py b/app/models.py index 842f889..681a433 100644 --- a/app/models.py +++ b/app/models.py @@ -44,7 +44,7 @@ class Drink(models.Model): super().save() def __str__(self): - return f"{self.product_name} ({float(self.content_litres):.2f}l) - {self.price}{settings.CURRENCY_SUFFIX}" + return f"{self.product_name} ({float(self.content_litres):.2f}l) - {self.price} {settings.CURRENCY_SUFFIX}" class RegisterTransaction(models.Model): @@ -86,7 +86,7 @@ class RegisterTransaction(models.Model): self.user.save() super().delete(*args, kwargs) - def __str__(self): return f"{self.transaction_sum}{settings.CURRENCY_SUFFIX} by {self.user}" + def __str__(self): return f"{self.transaction_sum} {settings.CURRENCY_SUFFIX} by {self.user}" class Order(models.Model): @@ -134,7 +134,7 @@ class Order(models.Model): drink.save() super().delete(*args, **kwargs) - def __str__(self): return f"{self.drink.product_name} ({float(self.drink.content_litres):.2f}l) x {self.amount} - {self.price_sum}{settings.CURRENCY_SUFFIX}" + def __str__(self): return f"{self.drink.product_name} ({float(self.drink.content_litres):.2f}l) x {self.amount} - {self.price_sum} {settings.CURRENCY_SUFFIX}" class Global(models.Model): diff --git a/app/static/css/main.css b/app/static/css/main.css index 338fb35..2abaa0d 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -127,7 +127,6 @@ th { .globalmessage > div { width: 96%; - text-align: center; word-break: keep-all; word-wrap: break-word; box-sizing: border-box; @@ -140,10 +139,6 @@ th { gap: 1rem; } -.userinfo { - text-align: center; -} - .userinfo > span { vertical-align: middle; } @@ -232,6 +227,14 @@ main { flex-wrap: wrap; } +.text-align-right { + text-align: right; +} + +.text-align-center { + text-align: center; +} + .gap-1rem { gap: 1rem; } diff --git a/app/templates/globalmessage.html b/app/templates/globalmessage.html index 9b33850..4ec0067 100644 --- a/app/templates/globalmessage.html +++ b/app/templates/globalmessage.html @@ -1,5 +1,5 @@ {% if global_message != "" %} -
+
{{ global_message }}
{% endif %} \ No newline at end of file diff --git a/app/templates/history.html b/app/templates/history.html index 89d689a..c94f17e 100644 --- a/app/templates/history.html +++ b/app/templates/history.html @@ -11,13 +11,13 @@ {% if history %} - - + {% for h in history %} - - + + + {% endfor %}
{% translate "last 30 actions" %}{% translate "last 30 actions" %}
{{ h.0 }}{{ h.1 }}{{ h.0 }} {{ currency_suffix }}{{ h.1 }}{{ h.2 }}
diff --git a/app/templates/userpanel.html b/app/templates/userpanel.html index 4423150..a436a98 100644 --- a/app/templates/userpanel.html +++ b/app/templates/userpanel.html @@ -2,14 +2,14 @@ {% load static %}
-
+
{% if user.first_name != "" %} {{ user.first_name }} {{ user.last_name }} ({{ user.username }}){% else %}{{ user.username }}{% endif %}  -  {% if user.balance < 0.01 %} - {% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }} + {% translate "Balance" %}: {{ user.balance }} {{ currency_suffix }} {% else %} - {% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }} + {% translate "Balance" %}: {{ user.balance }} {{ currency_suffix }} {% endif %}
From 880f7f6cc816b6369bc87f5dec28788beda172f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller=20=28ChaoticByte=29?= Date: Sat, 15 Apr 2023 11:20:02 +0200 Subject: [PATCH 06/33] Changed the appearance of the dropdown button in the userpanel --- app/locales/de/LC_MESSAGES/django.mo | Bin 3704 -> 3672 bytes app/locales/de/LC_MESSAGES/django.po | 4 ---- app/static/css/main.css | 3 --- app/templates/userpanel.html | 4 +--- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/app/locales/de/LC_MESSAGES/django.mo b/app/locales/de/LC_MESSAGES/django.mo index 9ad7ad461d4d79a5ce679d7d73db94e66efd4f59..d7435cb07bae255287ca6bfa885580bd2e060d15 100644 GIT binary patch delta 1345 zcmZA1J4jbi9Ki8o{Vg@$nVFBw%zwTrwS1Hz4MGvrP}mrO7z8y0K{n*wiX4KV2NXd= zAZ9}$Gz1L}5<%1yG-Qh)n1kS8LK1zyf6ssE@c-S@DLW`mFQ?}zl$#589Lq+I^hSb!&&4P=DD=tuS`7& zp^~R6XsAP1)`c!)0A0u+HsBDJ<4r8YarC(-=z^Z3nR$%`_zq3t3_9^Fn&Howhl^Ou z{9%QgH0IFSg3V~hbLfBe&{eJXe^eNi^1=?={lSa;a zDn9U)*^cptZ|Dw6xo}3I2A!Z2%}8%-KZU2MUqlCK%9&Cq+a|3@^#bI4R-CAR-5 z;QT$)GV-1|bF8G^gLXU<9mbv1Z$%$OC(%sIU=w~qCs@X#xEAYOtfrNEKUU#oWDOxH zB>%g(8Ka+ge?c>mExWn#I85>XvTm?!-^0k?18XzNlu54Te2L8)5NV&lWRdy3JTUagZ?EeZ)p# h%bveypDpQl(~7<E--;see@AUCICe delta 1377 zcmYk+OGs5g7{KvSuW!q;GR>PkO!HAbO7oSFiy|a~iYzEZj3;hjBSxjgH6mNpu2JXn*g}0YBn;oI`%$FNY?^ z57}I`p&3_W2QsrTfKFr(oybYtgu_^dx3L5tqW3*VC-e%<%rq9^ESk*E=s0s|roUqW zCb zH=NXDkt(#qc}BCN-`Il-=$o{1aH)FH>xaGAe zi2O5VC?nrqs6yAa4efX@mg8W&J{-Mfh77|3o=&diP!hV`T^WV`|(&Gi{8PV zwBJv0($2{TbZzt4L3UV-zDYTn!fJGYdUVO!(KqQrGu9vLN6`tMLZ3T>F2xA)WrtB@ zrPJAKL-$`g1M04& yw76YOtD7TJT<;B;3T}<(P3Ycmxhyq=dm!`=4V@nyxiD3q`#6!GsmvDMO#BBW(qR4o diff --git a/app/locales/de/LC_MESSAGES/django.po b/app/locales/de/LC_MESSAGES/django.po index 855cd09..fe0dc95 100644 --- a/app/locales/de/LC_MESSAGES/django.po +++ b/app/locales/de/LC_MESSAGES/django.po @@ -248,10 +248,6 @@ msgstr "Saldo" msgid "Logout" msgstr "Abmelden" -#: app/templates/userpanel.html:22 -msgid "Account" -msgstr "Account" - #: app/templates/userpanel.html:30 msgid "Transfer" msgstr "Geld senden" diff --git a/app/static/css/main.css b/app/static/css/main.css index 2abaa0d..ee35724 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -320,10 +320,7 @@ main { } .dropdownbutton { - width: fit-content; z-index: 190; - text-align: center; - justify-content: center; } .dropdownlist { diff --git a/app/templates/userpanel.html b/app/templates/userpanel.html index a436a98..0042800 100644 --- a/app/templates/userpanel.html +++ b/app/templates/userpanel.html @@ -18,9 +18,7 @@ {% translate "Deposit" %} {% translate "Logout" %}