This repository has been archived by the owner on Jul 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # config.toml.example # config.yml.example
- Loading branch information
Showing
11 changed files
with
173 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ lint: | |
|
||
.PHONY: unit | ||
unit: | ||
poetry run python manage.py migrate | ||
poetry run pytest | ||
|
||
.PHONY: package | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
from autodonate.lib.models import Item, Payment, PaymentProcess | ||
|
||
|
||
admin.site.register(Item) | ||
admin.site.register(Payment) | ||
admin.site.register(PaymentProcess) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""The file is responsible for registering new global variables in templates.""" | ||
|
||
__all__ = ["register_variable", "global_variables"] | ||
|
||
VALUES: dict[str, str | bool] = {} | ||
|
||
|
||
def register_variable(name: str, value: str | bool) -> None: | ||
"""Add a new global variable. | ||
Args: | ||
name: variable name (upper case) | ||
value: variable value | ||
""" | ||
VALUES[name] = value | ||
|
||
|
||
def global_variables(request) -> dict[str, str | bool]: | ||
"""Return a dictionary of all global variables. | ||
Called on every render() by Django itself. | ||
""" | ||
return VALUES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Basic objects of donations, items.""" | ||
|
||
from django.db.models import ( | ||
Model, | ||
SmallIntegerField, | ||
FloatField, | ||
TextField, | ||
BooleanField, | ||
ForeignKey, | ||
CASCADE, | ||
CharField, | ||
TimeField, | ||
) | ||
from autodonate.lib.utils.rcon import Rcon | ||
|
||
|
||
class Item(Model): | ||
"""Model for the given item""" | ||
|
||
currency = SmallIntegerField( | ||
choices=[(0, "RUB"), (1, "UAH"), (2, "USD"), (3, "EUR")], null=True | ||
) | ||
price = FloatField(null=True) | ||
rcon_command = TextField(null=True) | ||
require_nick = BooleanField(default=False) | ||
|
||
|
||
class PaymentProcess(Model): | ||
"""Model for pending item payment""" | ||
|
||
# TODO: Add more fields | ||
item = ForeignKey(Item, on_delete=CASCADE) | ||
nickname = CharField(max_length=32, null=True) | ||
timestamp = TimeField(auto_now_add=True) | ||
|
||
def cleanup_nickname(self) -> None: | ||
self.nickname = ( | ||
self.nickname.replace(" ", "") | ||
.replace("'", "") | ||
.replace('"', "") | ||
.replace(",", "") | ||
.replace(".", "") | ||
.replace("`", "") | ||
) | ||
self.save() | ||
|
||
|
||
class Payment(Model): | ||
"""Model for finished item payment""" | ||
|
||
process = ForeignKey(PaymentProcess, on_delete=CASCADE) | ||
timestamp = TimeField(auto_now_add=True) | ||
|
||
def format_rcon(self) -> str: | ||
self.process.cleanup_nickname() | ||
if not self.process.item.rcon_command: | ||
raise ValueError("Item.rcon_command required.") | ||
return str( | ||
self.process.item.rcon_command.format( | ||
nickname=self.process.nickname | ||
) | ||
) | ||
|
||
def issue(self) -> str: | ||
return Rcon.run(self.format_rcon()) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Here will be our template tags in future.""" | ||
|
||
from django import template | ||
|
||
register = template.Library() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from autodonate.lib.context_processors import ( | ||
register_variable, | ||
global_variables, | ||
) | ||
|
||
|
||
def test_add_global(): | ||
register_variable("TEST", True) | ||
assert global_variables(None)["TEST"] is True | ||
register_variable("TEST", "123") | ||
assert global_variables(None)["TEST"] == "123" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from autodonate.lib.models import * | ||
from os import system | ||
|
||
|
||
def test_donation(): | ||
i = Item( | ||
currency=0, | ||
price=99.9, | ||
rcon_command="test {nickname}", | ||
require_nick=True, | ||
) | ||
i.save() | ||
|
||
pp = PaymentProcess(item=i, nickname="cof ob,") | ||
pp.save() | ||
pp.cleanup_nickname() | ||
assert pp.nickname == "cofob" | ||
|
||
p = Payment(process=pp) | ||
p.save() | ||
assert p.format_rcon() == "test cofob" |