def create_user_profile(self, args):
     self.log.debug("create_user_profile: %r" % args)
     try:
         u_id = g.user.id
         user = User.objects.get(id=u_id)
         user.profile = UserProfile(**args)
         user.save()
         return user.dic()
     except Exception as e:
         self.log.debug(e)
         return internal_server_error("failed to create user profile")
 def update_user_profile(self, args):
     self.log.debug("update_user_profile")
     try:
         u_id = args["user_id"]
         user = User.objects.get(id=u_id)
         user.profile = UserProfile(**args)
         user.save()
         return user.dic()
     except Exception as e:
         self.log.debug(e)
         return internal_server_error("failed to update user profile")
Exemplo n.º 3
0
 def get_user_profile(self, user_id):
     user = User.objects.get(id=user_id)
     if not user:
         return not_found("user {} not found".format(user_id))
     profile = User.objects.get(id=user_id).profile
     if profile:
         return user.dic()
     # if user do not create profile, create default
     user.profile = UserProfile()
     user.save()
     return user.dic()
Exemplo n.º 4
0
 def update_user_avatar_url(user, url):
     if not user.profile:
         user.profile = UserProfile()
     user.profile.avatar_url = url
     user.save()
     return True