From a4b33cda388506356819efa38abf73b9fc3ff1e1 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 10 Apr 2012 22:45:44 +0200 Subject: add export action --- stocks.py | 31 +++++++++++++++++++++++++++---- 1 file 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

+

+ + #filter None + Export $select_places("place") + #end filter + +

#else

#end if @@ -383,6 +394,18 @@ function selortext_hide () { """ +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 () -- cgit v1.2.3