Exemplo n.º 1
0
  def create_item(self, form):
    item = self.cls()

    for field in item.properties():
      if field[0] != '_':
        item.__setattr__(field, self.get_value(form, field, Formdb.type(item, field)))

    return item
Exemplo n.º 2
0
  def processPostData(self):
    form = self.request.params
  # no id_field => _key should be used
    key_name = '_key' if not self.cls.id_field else self.cls.id_field
    my_id = cgi.escape(form[key_name]) if form.has_key(key_name) else None
    item = self.cls.retrieve(self.cls, my_id) if my_id else None
    if not item:
      item = self.create_item(form)
    else:
      self.update_item(form, item)

    logging.info("Processed entity with Key = " + my_id)
    for field in item._properties.keys():
      logging.info(field + " = " + str(getattr(item, field)))
    
    for field in item._properties.keys():
      if Formdb.type(item, field) == 'Date' and getattr(item, field):
        item.__setattr__(field + "_str", getattr(item, field).strftime("%d/%m/%Y"))
    
    return item
Exemplo n.º 3
0
 def update_item(self, form, item):
   for field in item._properties.keys():
     value = self.get_value(form, field, Formdb.type(item, field))
     if value:
       item.__setattr__(field, value)