Closed pythononwheels closed 12 years ago
Really made that one cleaner. Here the new action as an example:
def new( self, powdict ):
""" Standard PoW action to create a new record """
self.model.__init__()
dict = powdict["REQ_PARAMETERS"]
for key in dict:
curr_type = self.model.get_column_type(key)
if curr_type == type(sqlalchemy.types.BLOB()) or curr_type == type(sqlalchemy.types.BINARY()):
ofiledir = os.path.normpath("./public/img/")
print "key: ", key
if pow_web_lib.get_form_binary_data( key, dict, ofiledir):
# if form contains file data AND file could be written, update model
self.model.set(key, dict[key].filename )
else:
# dont update model
print " ##### ________>>>>>>> BINARY DATA but couldnt update model"
else:
self.model.set(key, dict[key])
self.model.create()
powdict["FLASHTEXT"] ="Yep, record successfully created."
powdict["FLASHTYPE"] ="success"
spectmpl = string.capitalize(self.model.modelname) + "_message.tmpl"
return self.render(special_tmpl=spectmpl , model=self.model, powdict=powdict)
def new( self, powdict ):
""" Standard PoW action to create a new record """
self.model.__init__()
self.model = pow_web_lib.set_text_or_binary_form_data(self.model, powdict, "./public/img/")
self.model.create()
powdict["FLASHTEXT"] ="Yep, record successfully created."
powdict["FLASHTYPE"] ="success"
spectmpl = string.capitalize(self.model.modelname) + "_message.tmpl"
return self.render(special_tmpl=spectmpl , model=self.model, powdict=powdict)
move complexity into BaseController