Example #1
0
 def get(self, template_variables={}):
     user_info = self.current_user
     user_id = user_info["uid"]
     avatar_name = "%s" % uuid.uuid5(uuid.NAMESPACE_DNS, str(user_id))
     gravatar = Gravatar(user_info["email"])
     avatar_96x96 = gravatar.get_image(size=96, filetype_extension=False)
     avatar_48x48 = gravatar.get_image(size=48, filetype_extension=False)
     avatar_32x32 = gravatar.get_image(size=32, filetype_extension=False)
     usr_home = os.path.expanduser('~')
     print usr_home
     urllib.urlretrieve(
         avatar_96x96,
         usr_home + "/www/tuila/static/avatar/b_%s.png" % avatar_name)
     urllib.urlretrieve(
         avatar_48x48,
         usr_home + "/www/tuila/static/avatar/m_%s.png" % avatar_name)
     urllib.urlretrieve(
         avatar_32x32,
         usr_home + "/www/tuila/static/avatar/s_%s.png" % avatar_name)
     result = self.user_model.set_user_avatar_by_uid(
         user_id, "%s.png" % avatar_name)
     template_variables["success_message"] = [u"用户头像更新成功"]
     # update `updated`
     updated = self.user_model.set_user_base_info_by_uid(
         user_id, {"updated": time.strftime('%Y-%m-%d %H:%M:%S')})
     template_variables["user_info"] = user_info
     template_variables["gen_random"] = gen_random
     template_variables["wallpaper"] = self.get_wallpaper()
     self.render("user/setting_avatar.html", **template_variables)
Example #2
0
    def get(self, template_variables={}):
        user_info = self.current_user
        user_id = user_info['_id']
        avatar_name = '%s' % uuid.uuid5(uuid.NAMESPACE_DNS, str(user_id))
        gravatar = Gravatar(user_info['email'])
        avatar_96x96 = gravatar.get_image(size=96, filetype_extension=False)
        avatar_48x48 = gravatar.get_image(size=48, filetype_extension=False)
        avatar_32x32 = gravatar.get_image(size=32, filetype_extension=False)
        urllib.urlretrieve(avatar_96x96,
                           './static/avatar/b_%s.png' % avatar_name)
        urllib.urlretrieve(avatar_48x48,
                           './static/avatar/m_%s.png' % avatar_name)
        urllib.urlretrieve(avatar_32x32,
                           './static/avatar/s_%s.png' % avatar_name)
        updated = yield self.application.user_model.set_user_base_info_by_uid(
            user_id, {
                'avatar': '%s.png' % avatar_name,
                'updated': time.strftime('%Y-%m-%d %H:%M:%S')
            })

        template_variables['success_message'] = ['Avatar update successfully']
        template_variables['user_info'] = user_info
        template_variables['gen_random'] = gen_random

        self.render('user/setting_avatar.html', **template_variables)
Example #3
0
def gravatar(request):
	data={}
	avatar_name = "%s" % uuid.uuid5(uuid.NAMESPACE_DNS, str(request.user.id))
	email = request.user.email
	gravatar = Gravatar(email)
	avatar_96x96 = gravatar.get_image(size = 96, filetype_extension = False)
	avatar_48x48 = gravatar.get_image(size = 48, filetype_extension = False)
	avatar_32x32 = gravatar.get_image(size = 32, filetype_extension = False)
	urllib.urlretrieve(avatar_96x96, settings.STATIC_ROOT + "avatar/b_%s.png" % avatar_name)
	urllib.urlretrieve(avatar_48x48, settings.STATIC_ROOT + "avatar/m_%s.png" % avatar_name)
	urllib.urlretrieve(avatar_32x32, settings.STATIC_ROOT + "avatar/s_%s.png" % avatar_name)
	# 每个人根据其id数字生成唯一的头像名称 不管是自己上传的还是gravatar获得的
	request.user.userprofile.avatar = avatar_name
	request.user.userprofile.save()#保存更新时间 虽然人的头像还是以前额名字

	return render_to_response('avatar.html',data,context_instance=RequestContext(request))
Example #4
0
 def get(self, template_variables = {}):
     user_info = self.current_user
     user_id = user_info["uid"]
     avatar_name = "%s" % uuid.uuid5(uuid.NAMESPACE_DNS, str(user_id))
     gravatar = Gravatar(user_info["email"])
     avatar_96x96 = gravatar.get_image(size = 96, filetype_extension = False)
     avatar_48x48 = gravatar.get_image(size = 48, filetype_extension = False)
     avatar_32x32 = gravatar.get_image(size = 32, filetype_extension = False)
     urllib.urlretrieve(avatar_96x96, "./static/avatar/b_%s.png" % avatar_name)
     urllib.urlretrieve(avatar_48x48, "./static/avatar/m_%s.png" % avatar_name)
     urllib.urlretrieve(avatar_32x32, "./static/avatar/s_%s.png" % avatar_name)
     result = self.user_model.set_user_avatar_by_uid(user_id, "%s.png" % avatar_name)
     template_variables["success_message"] = [u"用户头像更新成功"]
     # update `updated`
     updated = self.user_model.set_user_base_info_by_uid(user_id, {"updated": time.strftime('%Y-%m-%d %H:%M:%S')})
     template_variables["user_info"] = user_info
     template_variables["gen_random"] = gen_random
     self.render("user/setting_avatar.html", **template_variables)