diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 051bcde..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Julian Müller (ChaoticByte) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3c2aac4 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,363 @@ +``` +MIT License + +Copyright (c) 2021 Julian Müller (ChaoticByte) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` + +# Additional licenses for included Software and Assets + +## Simple Keyboard + +Source: https://github.com/hodgef/simple-keyboard + +``` +MIT License + +Copyright (c) 2019 Francisco Hodge and project contributors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` + +## Inter (Font) + +Source: https://github.com/rsms/inter/ + +``` +Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION AND CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. +``` + +## Material Design Icons + +Source: https://github.com/google/material-design-icons +Files: +- `./app/static/material-icons/*` +- `./data/profilepictures/default.svg` + +``` + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +``` diff --git a/app/admin.py b/app/admin.py index 0d37821..4513ff0 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) @@ -91,9 +95,7 @@ class CustomRegisterAdmin(admin.ModelAdmin): return actions def delete_selected_new(self, request, queryset): - #print(queryset) for supply in queryset: - #print(order) supply.delete() if queryset.count() < 2: self.message_user(request, f"Revoked {queryset.count()} supply.") @@ -117,9 +119,7 @@ class CustomOrderAdmin(admin.ModelAdmin): return actions def delete_selected_new(self, request, queryset): - #print(queryset) for order in queryset: - #print(order) order.delete() self.message_user(request, f"Revoked {queryset.count()} order(s).") delete_selected_new.short_description = "Revoke selected orders" diff --git a/app/db_queries.py b/app/db_queries.py index 93a2727..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,29 +45,39 @@ def select_history(user, language_code="en") -> list: user_id = user.pk result = _db_select(f""" select + price_sum as "sum", concat( - product_name, ' (', - content_litres::real, -- converting to real removes trailing zeros - 'l) x ', amount, ' - ', price_sum, '{settings.CURRENCY_SUFFIX}') 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} - union + union select - concat('Deposit: +', transaction_sum, '{settings.CURRENCY_SUFFIX}') as "text", + transaction_sum as "sum", + '{gettext("Deposit")}' as "text", datetime from app_userdeposits_view where user_id = {user_id} + union + + select + transaction_sum as "sum", + 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; """) 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/locales/de/LC_MESSAGES/django.mo b/app/locales/de/LC_MESSAGES/django.mo index 76e345b..d7435cb 100644 Binary files a/app/locales/de/LC_MESSAGES/django.mo and b/app/locales/de/LC_MESSAGES/django.mo differ diff --git a/app/locales/de/LC_MESSAGES/django.po b/app/locales/de/LC_MESSAGES/django.po index c7b1011..fe0dc95 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-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,23 +227,32 @@ 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/transfer.html:6 +#| msgid "Drinks - Order" +msgid "Drinks - Transfer" +msgstr "Getränke - Geld senden" -#: app/templates/userpanel.html:15 app/templates/userpanel.html:17 +#: 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 -msgid "Account" -msgstr "Account" +#: app/templates/userpanel.html:30 +msgid "Transfer" +msgstr "Geld senden" -#: app/templates/userpanel.html:38 +#: app/templates/userpanel.html:34 msgid "Change Password" msgstr "Passwort ändern" 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/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 ddfd302..681a433 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 @@ -43,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): @@ -58,35 +59,34 @@ 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) - 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 afdd6c6..ab3f24a 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -1,7 +1,22 @@ +/* Font */ + +@font-face { + font-family: "Inter"; + src: url('/static/fonts/Inter-Regular.ttf'); + font-weight: normal; + font-style: normal; +} +@font-face { + font-family: "Inter"; + src: url('/static/fonts/Inter-Bold.ttf'); + font-weight: bold; + font-style: normal; +} + /* Variables */ :root { - --font-family: 'Liberation Sans', sans-serif; + --font-family: "Inter"; --color: #fafafa; --color-error: #ff682c; --bg-page-color: #222222; @@ -50,7 +65,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; @@ -60,6 +75,19 @@ input[type="text"], input[type="password"], input[type="number"] { border-bottom: 1px solid var(--border-color); border-radius: var(--border-radius); background: var(--bg-color); + font-family: "Inter"; +} + +select { + appearance: none; + -webkit-appearance: none; + -moz-appearance: none; + height: 2.5rem; + background-image: url("/static/material-icons/arrow-drop-down.svg"); + background-repeat: no-repeat; + background-position: right; + background-size: 1.5rem; + padding-right: 1.8rem; } table { @@ -127,7 +155,6 @@ th { .globalmessage > div { width: 96%; - text-align: center; word-break: keep-all; word-wrap: break-word; box-sizing: border-box; @@ -141,7 +168,7 @@ th { } .userinfo { - text-align: center; + font-size: 1.05rem; } .userinfo > span { @@ -159,6 +186,10 @@ th { gap: .5rem; } +.userpanel-buttons > .button, .userpanel-buttons button { + height: 1.2rem; +} + .userbalancewarn { color: var(--color-error); font-weight: bold; @@ -232,6 +263,14 @@ main { flex-wrap: wrap; } +.text-align-right { + text-align: right; +} + +.text-align-center { + text-align: center; +} + .gap-1rem { gap: 1rem; } @@ -317,10 +356,12 @@ main { } .dropdownbutton { - width: fit-content; z-index: 190; - text-align: center; - justify-content: center; +} + +.dropdownbutton > img { + width: auto; + height: 100%; } .dropdownlist { @@ -333,6 +374,7 @@ main { margin-top: 3.2rem; opacity: 0%; transition: opacity 100ms; + box-shadow: 0 .25rem 1rem #00000090; } .dropdownchoice { @@ -366,7 +408,7 @@ main { } .customnumberinput { - height: 2.2rem; + height: 2.5rem; } .customnumberinput button { @@ -504,4 +546,9 @@ main { .drinks-list { width: 90%; } + .dropdownlist { + width: 14rem; + right: calc(50vw - 7rem); + left: auto; + } } diff --git a/app/static/css/simple-keyboard_dark.css b/app/static/css/simple-keyboard_dark.css index 16bfec5..e380b77 100644 --- a/app/static/css/simple-keyboard_dark.css +++ b/app/static/css/simple-keyboard_dark.css @@ -5,6 +5,7 @@ width: 50rem; max-width: 100%; background: transparent; + font-family: "Inter"; } .simple-keyboard.darkTheme .hg-button { height: 50px; diff --git a/app/static/fonts/Inter-Bold.ttf b/app/static/fonts/Inter-Bold.ttf new file mode 100644 index 0000000..8e82c70 Binary files /dev/null and b/app/static/fonts/Inter-Bold.ttf differ diff --git a/app/static/fonts/Inter-Regular.ttf b/app/static/fonts/Inter-Regular.ttf new file mode 100644 index 0000000..8d4eebf Binary files /dev/null and b/app/static/fonts/Inter-Regular.ttf differ 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/static/material-icons/arrow-drop-down.svg b/app/static/material-icons/arrow-drop-down.svg new file mode 100644 index 0000000..051a82d --- /dev/null +++ b/app/static/material-icons/arrow-drop-down.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/static/material-icons/menu.svg b/app/static/material-icons/menu.svg new file mode 100644 index 0000000..91b846d --- /dev/null +++ b/app/static/material-icons/menu.svg @@ -0,0 +1 @@ + \ No newline at end of file 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 @@
{% translate "cancel" %} - +
- + {% endblock %} \ No newline at end of file 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/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/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 %}
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 159dcf5..7d2d015 100644 --- a/app/templates/userpanel.html +++ b/app/templates/userpanel.html @@ -2,19 +2,14 @@ {% load static %}
-
- - - {% 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 }} + {% translate "Balance" %}: {{ user.balance }} {{ currency_suffix }} {% else %} - {% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }} + {% translate "Balance" %}: {{ user.balance }} {{ currency_suffix }} {% endif %}
@@ -23,15 +18,14 @@ {% translate "Deposit" %} {% translate "Logout" %}