def post(self): try: user_id = self.get_argument('user_id') avatar = self.get_argument('avatar') except MissingArgumentError: return self.error(MISSING_PARAMS) group_user_info = FlowerUser.get_by_user(user_id) if not group_user_info: return self.error(FLOWER_USER_INFO_NOT_SET) try: group_user_info.update(avatar=avatar) except Exception as e: logger.error(u'更新群组用户头像信息失败。Error:[%s]' % e) return self.error(SYSTEM_ERROR) if UserChatStatus.is_flower_identity(user_id): rong_client.user_refresh(user_id, portrait_uri=init_pic_url(avatar)) return self.render({ 'status': 0, 'data': { 'portraitUri': init_pic_url(avatar), } })
def post(self): try: user_id = self.get_argument('user_id', '') avatar_url = self.get_argument('avatar') except (MissingArgumentError): return self.error(MISSING_PARAMS) user = User.get(user_id) if not user: return self.error(USER_NOT_FOUND) try: avatar = json.loads(avatar_url)[0] except: avatar = avatar_url user.update(avatar=avatar) if UserChatStatus.is_flower_identity(user_id): rong_client.user_refresh(user_id, portrait_uri=init_pic_url(avatar)) return self.render({ 'status': 0, 'data': { 'avatar': init_pic_url(avatar) } })
def jsonify(self): from starmachine.model.user import User user = User.get(self.user_id) return { 'user': { 'id': user.id, 'name': user.user_name, 'avatar': user.avatar_url, }, 'name': self.name, 'telephone': self.telephone, 'id_card': self.id_card, 'id_card_front': init_pic_url(self.id_card_front), 'id_card_back': init_pic_url(self.id_card_back), 'status': self.status, 'reason': self.reason, 'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S') }
def post(self): group_id = self.get_argument('group_id') group = Group.get(group_id) avatar = self.get_argument('avatar') group.update(avatar=avatar) return self.render({ 'status': 0, 'data': { 'portraitUri': init_pic_url(avatar), } })
def jsonify(self, user=None): from starmachine.model.content.content_like import ContentLiked from starmachine.model.content.vote import VoteResult data = { 'id': self.id, 'creator': { 'id': self.creator.id, 'name': self.creator.user_name, 'avatar': self.creator.avatar_url, }, 'text': self.text if self.text else None, 'video': self.video if self.video else None, 'create_time': self.create_time if isinstance(self.create_time, basestring) else self.create_time.strftime('%Y-%m-%d %H:%M:%S'), 'content_type': POSTS_TYPE, 'reward_amount': self.reward_amount, 'like_amount': self.like_amount, 'comment_amount': self.comment_amount, 'reward_user_amount': self.reward_user_amount, 'robed_user_amount': 0, } if self.images: image_urls = [] images = json.loads(self.images) for image in images: image_url = init_pic_url(image) image_urls.append(image_url) data['images'] = image_urls else: data['images'] = [] if user: data.update({ 'has_liked': bool(ContentLiked.has_liked(self.id, user.id)), 'has_robed': False, 'has_delivery': False, }) return data
def get(self): target_user_id = self.get_argument('target_user_id') user_background = UserBackground.get_by_user(target_user_id) if not user_background: return self.render({ 'status': 0, 'data': '', }) # if not user_background: # return self.error(USER_BACKGROUND_NOT_FOUND) return self.render({ 'status': 0, 'data': init_pic_url(user_background.short_url), })
def get(self): user_id = self.get_argument('user_id') room_id = self.get_argument('room_id') user_room_background = UserRoomBackground.get_by_user_room(user_id, room_id) if not user_room_background: return self.render({ 'status': 0, 'data': '', }) # if not user_room_background: # return self.error(USER_ROOM_BACKGROUND_NOT_FOUND) return self.render({ 'status': 0, 'data': init_pic_url(user_room_background.short_url), })
def jsonify(self, user=None): data = { 'id': self.id, 'creator': { 'id': self.creator.id, 'name': self.creator.user_name, 'avatar': self.creator.avatar_url, }, 'content_type': WELFARE_TYPE, 'price': float(self.price), 'count': self.count, 'name': self.name, 'welfare_type': self.welfare_type, 'start_time': self.start_time.strftime('%Y-%m-%d %H:%M:%S'), 'deadline': self.deadline.strftime('%Y-%m-%d %H:%M:%S'), 'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S'), 'reward_amount': self.reward_amount, 'like_amount': self.like_amount, 'comment_amount': self.comment_amount, 'reward_user_amount': self.reward_user_amount, 'robed_user_amount': self.robed_user_amount, 'star_fund_pay_amount': float(self.price) * self.count + self.count * WELFARE_POSTAGE, 'expired': self.expired, } if self.images: image_urls = [] images = json.loads(self.images) for image in images: image_url = init_pic_url(image) image_urls.append(image_url) data['images'] = image_urls else: data['images'] = [] if user: welfare_order = WelfareOrder.get_by_welfare_and_user(self.id, user.id) data.update({ 'has_liked': bool(ContentLiked.has_liked(self.id, user.id)), 'has_robed': True if welfare_order else False, 'has_delivery': True if welfare_order and welfare_order.status == WELFARE_ORDER_DELIVER else False, }) return data
def post(self): try: user_id = self.get_argument('user_id', '') avatar_url = self.get_argument('avatar_url') room_id = self.get_argument('room_id') except (MissingArgumentError, KeyError): return self.error(MISSING_PARAMS) room = Room.get(room_id) if not room: return self.error(ROOM_NOT_FOUND) try: avatar = json.loads(avatar_url)[0] except: avatar = avatar_url room.update(avatar=avatar) return self.render({ 'status': 0, 'data': { 'avatar': init_pic_url(avatar) } })
def avatar_url(self): return init_pic_url(self.avatar)