Ejemplo n.º 1
0
    def process_data(self, controller):
        from google.appengine.api import memcache
        memcache.flush_all()

        obj = controller.content
        v = controller.form.validate_result
        replace_body = True
        for k in v:
            if k == 'body' and not v[k]:
                replace_body = False
            else:
                setattr(obj, k, v[k])
        if replace_body:
            f = controller.request.body_file.vars["body"]
            v['content_type'] = detect_imagetype(v['body'])
            i = images.Image(v['body'])
            v['width'], v['height'] = i.width, i.height
            v['filename'] = f.filename
        if not v.get('name', None) and v.get('filename'):
            v['name'] = v['filename']
        if not v.get('title', None):
            v['title'] = v['name']
        obj.modified_at = datetime.now()
        obj.put()
        obj.sync_path(obj.get_path())

        controller.set_state(FC.INITIAL)
        controller.redirect(obj.get_parent().get_path()+'/list')
Ejemplo n.º 2
0
 def add_new_object(cls, v, ins):
     """
     A method to obtain new object
     """
     from aha import Config
     config = Config()
     f = ins.request.body_file.vars["body"]
     v['content_type'] = guess_type(f.filename)[0]
     v['filename'] = f.filename
     if not v.get('name', None):
         v['name'] = v['filename']
     if not v.get('title', None):
         v['title'] = v['name']
     cu = config.auth_obj().get_user(ins)
     v['creator'] = cu.get('nickname', '') or cu.get('email', '')
     d = {}
     [d.update({str(k): v[k]}) for k in v]
     o = cls.MODEL(**d)
     o.put()
     return o
Ejemplo n.º 3
0
 def add_new_object(cls, v, ins):
     """
     A method to obtain new object
     """
     from aha import Config
     config = Config()
     f = ins.request.body_file.vars["body"]
     v['content_type'] = detect_imagetype(v['body'])
     i = images.Image(v['body'])
     v['width'], v['height'] = i.width, i.height
     v['filename'] = f.filename
     if not v.get('name', None):
         v['name'] = v['filename']
     if not v.get('title', None):
         v['title'] = v['name']
     cu = config.auth_obj().get_user(ins)
     v['creator'] = cu.get('nickname', '') or cu.get('nickname', '')
     d = {}
     [d.update({str(k): v[k]}) for k in v]
     o = cls.MODEL(**d)
     o.put()
     return o