Exemple #1
0
    def post(self):
        if self.request.files:
            
            file = self.request.files['avatar'][0]
            people = People.query.get(self.current_user.id)
            
            if file:
                rawname = file.get('filename')
                dstname = str(int(time.time()))+'.'+rawname.split('.').pop()
                dstname = dstname.lower()
                thbname = "thb_%d_s_%s" % (people.id, dstname)
                large_thbname = "thb_%d_l_%s" % (people.id, dstname)
                # write a file
                # src = "./static/upload/src/"+dstname
                # file(src,'w+').write(f['body'])
                
                tf = tempfile.NamedTemporaryFile(delete=False)
                tf.write(file['body'])
                tf.seek(0)
                 
                # create normal file
                # img = Image.open(src)

                avatar_file_path = options.static_avatar_path + '/' + thbname
                large_avatar_file_path = options.static_avatar_path + '/' + large_thbname
                
                img = Image.open(tf.name)

                img.thumbnail((120,120),resample=1)
                
                img.save(avatar_file_path)
                
                #large_img = Image.open(tf.name)
                #large_img.thumbnail((300,300), resample=1)
                #large_img.save(large_avatar_file_path)
                
                tf.close()
                os.remove(tf.name)
                avatar_url = options.static_avatar_url + '/' + thbname
                large_avatar_url = options.static_avatar_url + '/' + large_thbname
                people.avatar = avatar_url
                #people.large_avatar = "/static/avatar/" + large_thbname
                complex_cache.hdel('h:people', people.id)
                db.session.add(people)
                db.session.commit()
                
                
                
                return self.redirect('/account/setting')
Exemple #2
0
 def clear_people_cache(self,people_id):
     complex_cache.hdel(options.site_cache_prefix+'h:people', people_id)