Add guild bank.
0
drakul/bank/__init__.py
Executable file
23
drakul/bank/admin.py
Executable 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
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BankConfig(AppConfig):
|
||||
name = "drakul.bank"
|
15
drakul/bank/forms.py
Normal 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")
|
||||
)
|
54
drakul/bank/migrations/0001_initial.py
Normal 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'],
|
||||
},
|
||||
),
|
||||
]
|
22
drakul/bank/migrations/0002_add_genesis_money_transaction.py
Normal 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),
|
||||
]
|
14565
drakul/bank/migrations/0003_add_wow_items.py
Normal file
0
drakul/bank/migrations/__init__.py
Normal file
124
drakul/bank/models.py
Executable 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}"
|
BIN
drakul/bank/static/img/currency/copper.png
Normal file
After Width: | Height: | Size: 677 B |
BIN
drakul/bank/static/img/currency/gold.png
Normal file
After Width: | Height: | Size: 645 B |
BIN
drakul/bank/static/img/currency/silver.png
Normal file
After Width: | Height: | Size: 683 B |
BIN
drakul/bank/static/img/icons/ability_ambush.png
Normal file
After Width: | Height: | Size: 8.8 KiB |
BIN
drakul/bank/static/img/icons/ability_backstab.png
Normal file
After Width: | Height: | Size: 8.8 KiB |
BIN
drakul/bank/static/img/icons/ability_bullrush.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
drakul/bank/static/img/icons/ability_cheapshot.png
Normal file
After Width: | Height: | Size: 9 KiB |
BIN
drakul/bank/static/img/icons/ability_criticalstrike.png
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
drakul/bank/static/img/icons/ability_defend.png
Normal file
After Width: | Height: | Size: 8.4 KiB |
BIN
drakul/bank/static/img/icons/ability_devour.png
Normal file
After Width: | Height: | Size: 7.8 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_aquaticform.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_bash.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_catform.png
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_catformattack.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_challangingroar.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_cower.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_dash.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_demoralizingroar.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_disembowel.png
Normal file
After Width: | Height: | Size: 6 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_enrage.png
Normal file
After Width: | Height: | Size: 9.4 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_maul.png
Normal file
After Width: | Height: | Size: 8.7 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_rake.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_ravage.png
Normal file
After Width: | Height: | Size: 5 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_supriseattack.png
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_swipe.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
drakul/bank/static/img/icons/ability_druid_travelform.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
BIN
drakul/bank/static/img/icons/ability_dualwield.png
Normal file
After Width: | Height: | Size: 5 KiB |
BIN
drakul/bank/static/img/icons/ability_ensnare.png
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
drakul/bank/static/img/icons/ability_eyeoftheowl.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
drakul/bank/static/img/icons/ability_fiegndead.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
drakul/bank/static/img/icons/ability_ghoulfrenzy.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
drakul/bank/static/img/icons/ability_golemstormbolt.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
drakul/bank/static/img/icons/ability_golemthunderclap.png
Normal file
After Width: | Height: | Size: 8.7 KiB |
BIN
drakul/bank/static/img/icons/ability_gouge.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
drakul/bank/static/img/icons/ability_hibernation.png
Normal file
After Width: | Height: | Size: 7.2 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_aimedshot.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 8.1 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_beastcall.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_beastcall02.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_beastsoothe.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_beasttaming.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_beasttraining.png
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_criticalshot.png
Normal file
After Width: | Height: | Size: 8.7 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_eagleeye.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_mendpet.png
Normal file
After Width: | Height: | Size: 7.2 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pathfinding.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_bat.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_bear.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_boar.png
Normal file
After Width: | Height: | Size: 8 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_cat.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_crab.png
Normal file
After Width: | Height: | Size: 7.9 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_crocolisk.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_gorilla.png
Normal file
After Width: | Height: | Size: 9 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_hyena.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_owl.png
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_raptor.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_scorpid.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_spider.png
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_tallstrider.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_turtle.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_vulture.png
Normal file
After Width: | Height: | Size: 8 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_windserpent.png
Normal file
After Width: | Height: | Size: 8 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_pet_wolf.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_quickshot.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_runningshot.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_snipershot.png
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
drakul/bank/static/img/icons/ability_hunter_swiftstrike.png
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
drakul/bank/static/img/icons/ability_impalingbolt.png
Normal file
After Width: | Height: | Size: 8.8 KiB |
BIN
drakul/bank/static/img/icons/ability_kick.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
BIN
drakul/bank/static/img/icons/ability_marksmanship.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
drakul/bank/static/img/icons/ability_meleedamage.png
Normal file
After Width: | Height: | Size: 6.3 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_blackdirewolf.png
Normal file
After Width: | Height: | Size: 7.9 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_blackpanther.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_jungletiger.png
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_mechastrider.png
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_mountainram.png
Normal file
After Width: | Height: | Size: 8.7 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_nightmarehorse.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_pinktiger.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_raptor.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_ridinghorse.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_undeadhorse.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_whitedirewolf.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
drakul/bank/static/img/icons/ability_mount_whitetiger.png
Normal file
After Width: | Height: | Size: 7.2 KiB |
BIN
drakul/bank/static/img/icons/ability_parry.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
drakul/bank/static/img/icons/ability_physical_taunt.png
Normal file
After Width: | Height: | Size: 7.8 KiB |
BIN
drakul/bank/static/img/icons/ability_piercedamage.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
drakul/bank/static/img/icons/ability_poisonarrow.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
drakul/bank/static/img/icons/ability_poisons.png
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
drakul/bank/static/img/icons/ability_poisonsting.png
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
drakul/bank/static/img/icons/ability_racial_avatar.png
Normal file
After Width: | Height: | Size: 9.7 KiB |
BIN
drakul/bank/static/img/icons/ability_racial_bearform.png
Normal file
After Width: | Height: | Size: 7.6 KiB |