def set_quota(): """Change quota of a user Returns ------- json users: updated users error: True if error, else False errorMessage: the error message of error, else an empty string """ data = request.get_json() try: local_auth = LocalAuth(current_app, session) local_auth.set_quota(data['quota'], data['username']) all_users = local_auth.get_all_users() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'users': [], 'error': True, 'errorMessage': str(e) }), 500 return jsonify({'users': all_users, 'error': False, 'errorMessage': ''})
def get_top_annotation(self): """Get top annotator and top group Returns ------- dict list of top 3 users and groups, error and error message """ error = False error_message = [] top_users = [] top_groups = [] nb = self.get_number_of_groups() liste_temp = [0] * nb userList = LocalAuth.get_all_users(self) for element in userList: """We don't want Admin in the ranking""" if element['group'] is not None: dico = {} dico["username"] = element['username'] dico["score"] = element['total_annotation'] top_users.append(dico) """sums the annotations for each group""" index = element['group'] - 1 liste_temp[ index] = liste_temp[index] + element['total_annotation'] """get the group name""" groups_names = self.get_groups_names() for i, element in enumerate(liste_temp): dico = {} dico["name"] = groups_names['groups_names'][i] dico["score"] = element top_groups.append(dico) top_groups = sorted(top_groups, key=lambda k: k['score'], reverse=True) top_users = sorted(top_users, key=lambda k: k['score'], reverse=True) return { 'top_users': top_users[:3], 'top_groups': top_groups[:3], 'error': error, 'errorMessage': error_message }
def get_users(): """Get all users Returns ------- json users: list of all users info error: True if error, else False errorMessage: the error message of error, else an empty string """ try: local_auth = LocalAuth(current_app, session) all_users = local_auth.get_all_users() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'users': [], 'error': True, 'errorMessage': str(e) }), 500 return jsonify({'users': all_users, 'error': False, 'errorMessage': ''})