Add guild bank.

This commit is contained in:
Casper V. Kristensen 2020-01-12 04:46:56 +01:00
parent d88c4632cd
commit a729d76f02
Signed by: caspervk
GPG key ID: 289CA03790535054
2046 changed files with 15102 additions and 0 deletions

0
drakul/bank/__init__.py Executable file
View file

23
drakul/bank/admin.py Executable file
View file

@ -0,0 +1,23 @@
from django.contrib import admin
from .models import Item, ItemTransaction, MoneyTransaction
@admin.register(Item)
class DatabaseItemAdmin(admin.ModelAdmin):
list_display = ["id", "name", "icon", "quality", "klass", "sub_klass"]
list_display_links = ["id", "name"]
search_fields = ["id", "name", "icon", "quality", "klass", "sub_klass"]
@admin.register(ItemTransaction)
class ItemTransactionAdmin(admin.ModelAdmin):
list_display = ["date", "item", "quantity", "balance"]
list_display_links = ["item"]
search_fields = ["date", "item__name"]
@admin.register(MoneyTransaction)
class MoneyTransactionAdmin(admin.ModelAdmin):
list_display = ["date", "amount", "balance"]
search_fields = ["date"]

5
drakul/bank/apps.py Executable file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class BankConfig(AppConfig):
name = "drakul.bank"

15
drakul/bank/forms.py Normal file
View file

@ -0,0 +1,15 @@
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout, Field
from django import forms
class BankImportForm(forms.Form):
import_string = forms.CharField(widget=forms.Textarea)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
Field("import_string"),
Submit("submit", "Import", css_class="btn btn-block btn-primary")
)

View file

@ -0,0 +1,54 @@
# Generated by Django 3.0.2 on 2020-01-12 04:34
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Item',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('icon', models.CharField(max_length=50)),
('quality', models.PositiveSmallIntegerField(choices=[(0, 'Poor'), (1, 'Common'), (2, 'Uncommon'), (3, 'Rare'), (4, 'Epic'), (5, 'Legendary'), (6, 'Artifact')])),
('klass', models.PositiveSmallIntegerField(choices=[(0, 'Consumables'), (1, 'Containers'), (2, 'Weapons'), (4, 'Armor'), (6, 'Projectiles'), (7, 'Trade Goods'), (9, 'Recipes'), (11, 'Quiver'), (12, 'Quest Items'), (15, 'Miscellaneous')])),
('sub_klass', models.SmallIntegerField()),
],
options={
'ordering': ['id'],
},
),
migrations.CreateModel(
name='MoneyTransaction',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField(auto_now=True)),
('amount', models.IntegerField()),
('balance', models.PositiveIntegerField()),
],
options={
'ordering': ['-date'],
},
),
migrations.CreateModel(
name='ItemTransaction',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField(auto_now=True)),
('quantity', models.SmallIntegerField()),
('balance', models.PositiveSmallIntegerField()),
('item', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transactions', to='bank.Item')),
],
options={
'ordering': ['-date', 'item'],
},
),
]

View file

@ -0,0 +1,22 @@
# Generated by Django 3.0.2 on 2020-01-11 04:19
from django.db import migrations
def add_genesis_money_transaction(apps, schema_editor):
"""
https://docs.djangoproject.com/en/3.0/topics/migrations/#data-migrations
"""
MoneyTransaction = apps.get_model("bank", "MoneyTransaction")
MoneyTransaction.objects.create(amount=0, balance=0)
class Migration(migrations.Migration):
dependencies = [
('bank', '0001_initial'),
]
operations = [
migrations.RunPython(add_genesis_money_transaction),
]

File diff suppressed because it is too large Load diff

View file

124
drakul/bank/models.py Executable file
View file

@ -0,0 +1,124 @@
import operator
from functools import reduce
from django.db import models
from django.db.models import Max, Q
class Item(models.Model):
name = models.CharField(
max_length=255
)
icon = models.CharField(
max_length=50
)
QUALITY_POOR = 0
QUALITY_COMMON = 1
QUALITY_UNCOMMON = 2
QUALITY_RARE = 3
QUALITY_EPIC = 4
QUALITY_LEGENDARY = 5
QUALITY_ARTIFACT = 6
QUALITY_CHOICES = [
(QUALITY_POOR, "Poor"),
(QUALITY_COMMON, "Common"),
(QUALITY_UNCOMMON, "Uncommon"),
(QUALITY_RARE, "Rare"),
(QUALITY_EPIC, "Epic"),
(QUALITY_LEGENDARY, "Legendary"),
(QUALITY_ARTIFACT, "Artifact"),
]
quality = models.PositiveSmallIntegerField(
choices=QUALITY_CHOICES
)
KLASS_CONSUMABLES = 0
KLASS_CONTAINERS = 1
KLASS_WEAPONS = 2
KLASS_ARMOR = 4
KLASS_PROJECTILES = 6
KLASS_TRADE_GOODS = 7
KLASS_RECIPES = 9
KLASS_QUIVER = 11
KLASS_QUEST_ITEMS = 12
KLASS_MISCELLANEOUS = 15
KLASS_CHOICES = [
(KLASS_CONSUMABLES, "Consumables"),
(KLASS_CONTAINERS, "Containers"),
(KLASS_WEAPONS, "Weapons"),
(KLASS_ARMOR, "Armor"),
(KLASS_PROJECTILES, "Projectiles"),
(KLASS_TRADE_GOODS, "Trade Goods"),
(KLASS_RECIPES, "Recipes"),
(KLASS_QUIVER, "Quiver"),
(KLASS_QUEST_ITEMS, "Quest Items"),
(KLASS_MISCELLANEOUS, "Miscellaneous"),
]
klass = models.PositiveSmallIntegerField(
choices=KLASS_CHOICES
)
sub_klass = models.SmallIntegerField(
# TODO: Should be choices field with proper names like 'klass'.
# Saving all (without using it) for now, so we have the option of migrating in the future.
# NOTE: Sub-classes can be negative!
)
class Meta:
ordering = ["id"]
def __str__(self):
return self.name
class ItemTransactionQuerySet(models.QuerySet):
def current_items(self):
# TODO: If we were using postgres we could use 'ItemTransaction.objects.order_by("-date").distinct("item")'
if not self.exists():
return self.none()
return self.filter(
reduce(
operator.or_,
(Q(**item) & ~Q(balance=0)
for item in self.values("item").annotate(date=Max("date")))
)
)
class ItemTransaction(models.Model):
objects = ItemTransactionQuerySet.as_manager()
date = models.DateTimeField(auto_now=True)
item = models.ForeignKey(
Item,
related_name="transactions",
on_delete=models.PROTECT
)
quantity = models.SmallIntegerField()
balance = models.PositiveSmallIntegerField()
class Meta:
ordering = ["-date", "item"]
def __str__(self) -> str:
return f"{self.date}: {self.quantity}x {self.item}"
class MoneyTransactionQuerySet(models.QuerySet):
def current_money(self):
return self.latest("date")
class MoneyTransaction(models.Model):
objects = MoneyTransactionQuerySet.as_manager()
date = models.DateTimeField(auto_now=True)
amount = models.IntegerField()
balance = models.PositiveIntegerField()
class Meta:
ordering = ["-date"]
def __str__(self) -> str:
return f"{self.date}: {self.amount}"

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 645 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 683 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Some files were not shown because too many files have changed in this diff Show more