summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2012-04-10 22:45:44 +0200
committerNicolas Schodet2012-04-10 22:55:38 +0200
commita4b33cda388506356819efa38abf73b9fc3ff1e1 (patch)
treed8355232dd56ac069e47d20785a549325bd7e904
parentb19603ef2c0b15894172708aaf52e62ea519d7ed (diff)
add export action
-rwxr-xr-xstocks.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/stocks.py b/stocks.py
index c122435..f94f786 100755
--- a/stocks.py
+++ b/stocks.py
@@ -137,6 +137,7 @@ class AppCGI:
pass
def run (self):
+ template = AppCGI.template
self.error = None
dirty = False
# Get form content.
@@ -151,7 +152,8 @@ class AppCGI:
self.stocks.load (DEFAULT_DATABASE)
# Make operations.
try:
- if self.mode == 'update' and not self.place:
+ if (self.mode == 'update'
+ or self.action == 'export') and not self.place:
self.mode = None
raise StocksError ("update mode without a place")
if self.mode == 'update' and self.action == 'update':
@@ -174,6 +176,8 @@ class AppCGI:
if from_ != to:
del item.qty[from_]
dirty = True
+ elif self.action == 'export':
+ template = AppCGI.export_template
except StocksError, e:
self.error = str (e)
except ValueError:
@@ -187,10 +191,10 @@ class AppCGI:
places -= set (('main', ))
self.places = sorted (places)
# Done.
- self.output ()
+ self.output (template)
- def output (self):
- t = Template (AppCGI.template, searchList = [ self ])
+ def output (self, template):
+ t = Template (template, searchList = [ self ])
t.stylesheet = AppCGI.stylesheet
print t
@@ -335,6 +339,13 @@ function selortext_hide () {
#end filter
<input type="submit" value="OK" />
</p></form>
+<form><p>
+ <input type="hidden" name="action" value="export" />
+ #filter None
+ Export $select_places("place")
+ #end filter
+ <input type="submit" value="OK" />
+</p></form>
#else
<form><p><input type="submit" value="Leave $mode mode" /></p></form>
#end if
@@ -383,6 +394,18 @@ function selortext_hide () {
</html>
"""
+AppCGI.export_template = u"""\
+Content-Type: text/plain; charset=UTF-8
+
+#filter WebSafe
+ #for $i in $stocks.itersorted
+ #if $place in $i.qty
+$i.cmd,$i.qty[$place],$i.code
+ #end if
+ #end for
+#end filter
+"""
+
if __name__ == '__main__':
a = AppCGI ()
a.run ()