Add tag to card model and creator and retain stock cross edits

This commit is contained in:
2017-10-17 18:51:38 +02:00
parent dcd89b391c
commit f43f7cefcc
3 changed files with 13 additions and 7 deletions
+3 -2
View File
@@ -16,14 +16,15 @@ class Card(Model):
description = ""
steps = []
effects = []
cost = "free action"
cost = ""
power = None
cp = None
gp = None#gold
flags = []
notes = ""#not shown, but used to keep track of things
copies_owned = 1
tag = ""
def has_flag(self, flag):
return flag.lower() in map(lambda x: x.lower(), self.flags)
+6 -2
View File
@@ -9,6 +9,7 @@
<form id="cardform" action="preview" method="post" target="preview">
<a href="../" style="opacity:0.6;">Return to cardlist</a>
<input type="hidden" name="copies_owned" value="$card.copies_owned">
<ul>
<li>
Title:<br>
@@ -87,11 +88,14 @@
<br>
<input type="submit" name="save" value="Save as">
->
<input type="text" name="filename" size="15" value="$escape_html($card.filename)" placeholder="filename">
<input type="text" name="filename" value="$escape_html($card.filename)" placeholder="filename">
<input type="submit" name="delete" value="Delete">
<br>
<br>
</li>
<li>
Tag:
<input type="text" name="tag" value="$escape_html($card.tag)">
</li>
</ul>
</form>
+4 -3
View File
@@ -19,10 +19,9 @@ async def show_cardlist(request, template={}):
if "action" in request.form and "filename" in request.form:
with card.open_file(request.form.get("filename")) as c:
if request.form.get("action") == "increment_stock":
c.copies_owned += 1
c.copies_owned = int(c.copies_owned) + 1
elif request.form.get("action") == "decrement_stock":
c.copies_owned -= 1
c.copies_owned = int(c.copies_owned) - 1
cards = card.from_dir(config.carddir)
sorting_key = None
@@ -42,6 +41,8 @@ async def show_cardlist(request, template={}):
cards = sorted(cards, key=lambda x: -int(x.copies_owned))
elif sorting_key == "title":
cards = sorted(cards, key=lambda x: x.title.lower())
elif sorting_key == "tag":
cards = sorted(cards, key=lambda x: x.tag or "\0")
sum_cp = sum(int(i.copies_owned) * int(i.cp or 0) for i in cards)
sum_copies = sum(int(i.copies_owned) for i in cards)