def post_content_view(request): """ 发送信息 URL[POST]: /chat/post_content/ :param request: conversation_id, content_type, content """ data = get_data_from_request(request) receiver_id = int(data.get('receiver_id')) conversation_id = data.get('conversation_id') if not receiver_id and not conversation_id: return json_http_error('参数错误') conversation_id = conversation_id or get_conversation_id_by_user_ids( [receiver_id, request.user.id]) content = data['content_json'] if content['type'] == 'image': if not is_image_valid(content['url']): return json_http_error('请文明发言!') elif content['type'] == 'text': if not is_content_valid(content['text']): return json_http_error('请文明发言!') content_str = json.dumps(content) chat_record = create_chat_record_db(conversation_id, content_str, request.user.id) # 发推送、更新badge、 ConversationMessageManager.add_message(receiver_id, request.user.id, conversation_id, content) return json_http_success()
def set_my_profile_view(request): """ 设置我的资料接口 URL[POST]: /user_info/my_profile/edit/ :param request: sex, avatar, location, nickname, birthday, signature, wechat_no, show_wechat_no :return: """ post_data = get_data_from_request(request) sex = post_data.get('sex') avatar = post_data.get('avatar') location = post_data.get('location') nickname = post_data.get('nickname') if nickname and not is_content_valid(nickname): return json_http_error(u'nickname 不合法') if avatar and not is_image_valid(avatar): return json_http_error(u'avatar 不合法') birthday = post_data.get('birthday') wechat_no = post_data.get('wechat_no') show_wechat_no = post_data.get('show_wechat_no') if show_wechat_no is not None: show_wechat_no = bool(int(show_wechat_no)) signature = post_data.get('signature') if birthday: birthday = str_to_datetime(birthday) user_info = update_my_profile_db(request.user, sex, avatar, location, nickname, wechat_no, show_wechat_no, signature, birthday) return json_http_success() if user_info else json_http_error()
def post_footprint_view(request): """ 发布踪踪动态 URL[POST]: /footprint/create/ :param request: :return: """ post_data = get_data_from_request(request) latitude = post_data.get('lat') longitude = post_data.get('lon') location = post_data.get('location') content = post_data['content'] if content and not is_content_valid(content): return json_http_error('请注意用词') image_list = post_data['image_list'] if isinstance(image_list, str): image_list = json.loads(image_list) for image in image_list: logging.info('{}{}'.format(image, type(image))) if not is_image_valid(image): return json_http_error('请文明发言') hide = bool(int(post_data.get('hide', 0))) footprint = create_footprint_db(request.user, content, latitude, longitude, location, image_list, hide) if latitude and longitude: add_user_location(footprint.id, longitude, latitude) return json_http_success()
def comment_footprint_view(request): """ URL[POST]: /footprint/comment/ 评论footprint,目前只能评论主贴 :param request: :return: """ post_data = get_data_from_request(request) footprint_id = post_data['footprint_id'] comment = post_data['comment'] if not is_content_valid(comment): return json_http_error('请注意用词') success = create_comment_db(request.user, footprint_id, comment) if success: comment_num = update_comment_num_db(footprint_id) return json_http_success({'comment_num': comment_num}) return json_http_error()
def post_footprint_view(request): """ 发布踪踪动态 求助帖的发布与 V1 的帖子不同之处只有一点: 需要传递商家 id URL[POST]: /footprint/create/ :param request: :return: """ post_data = get_data_from_request(request) latitude = post_data.get('lat') longitude = post_data.get('lon') location = post_data.get('location') content = post_data['content'] if content and not is_content_valid(content): return json_http_error('请注意用词') image_list = post_data['image_list'] if isinstance(image_list, str): image_list = json.loads(image_list) for image in image_list: logging.info('{}{}'.format(image, type(image))) if not is_image_valid(image): return json_http_error('请文明发言') hide = bool(int(post_data.get('hide', 0))) # @zhanghu 在这里校验下是不是帮助贴 club = get_club_by_id_db(int(post_data.get('club_id', 0))) if not club: footprint = create_footprint_db(request.user, content, latitude, longitude, location, image_list, hide, PostType.NOTE, 0) else: # 找到金额最大的优惠券模板, 或者是一个普适券(注意, 如果找不到优惠券, 仍然降级为 NOTE 类型的足迹) target_template_id = get_template_id_by_club(club) post_type = PostType.HELP if target_template_id > 0 else PostType.NOTE footprint = create_footprint_db(request.user, content, latitude, longitude, location, image_list, hide, post_type, target_template_id) if latitude and longitude: add_user_location(footprint.id, longitude, latitude) return json_http_success({'footprint_id': footprint.id})