def get_chats(user_id): """get the chats by user_id return the chaters' info and numbers of unread messages """ qs = Chat.objects.filter(models.Q(user_1=user_id) | models.Q(user_2=user_id)) qs = qs.order_by("-importance", "-latest_time") blocked = BlockHelper.get_block_list(user_id) chats = [] for chat in qs: others = UserHelper.get_user(chat.user_1 + chat.user_2 - user_id) others = UserHelper.user_filter(others) if others is None: continue othername = others['username'] if othername in blocked: continue unread = chat.unread_count if chat.latest_sender == user_id: unread = 0 chats.append({ 'user' : others, 'unread' : unread, 'time' : date_to_string(chat.latest_time) }) return chats
def get_info(package): """process the request of getting user's info """ params = package.get('params') username = params.get(ParamType.UsernameWithDefault) if username is None: user = package.get('user') else: user = UserHelper.get_user_by_username(username) if user is None: return Response.error_response("No User") user = UserHelper.user_filter(user) permission_public = user.get('permission') user_id = user.get('id') school_id = PermissionHelper.get_user_school(user_id) if school_id == 0: if permission_public >= 8: permission_private = permission_public else: permission_private = -1 schoolname = 'public area' else: permission_private = PermissionHelper.get_permission( user_id, school_id) school = SchoolHelper.get_school(school_id) if school is None: schoolname = '-' else: schoolname = school.get('schoolname') download = ProgramHelper.count_user_downloadlog(user_id) del user['permission'] user.update({ 'school_name': schoolname, 'permission_public': permission_public, 'permission_private': permission_private, 'download': download }) return Response.success_response({'user': user})
def check_session(package): """process the request of check session """ user = package.get('user') user = UserHelper.user_filter(user) if user is None: return Response.success_response({'user': None}) user_id = user.get('id') permission_public = user.get('permission') del user['permission'] school_id = PermissionHelper.get_user_school(user_id) if school_id == 0: school_name = 'public area' if permission_public > 4: permission_private = permission_public else: permission_private = -1 else: school = SchoolHelper.get_school(school_id) if school is None: school_name = '-' else: school_name = school.get('schoolname') permission_private = PermissionHelper.get_permission( user_id, school_id) school = { 'id': school_id, 'name': school_name, } ret_user = { 'username': user.get('username'), 'school': school, 'permission_private': permission_private, 'permission_public': permission_public } return Response.success_response({'user': ret_user})