def get(self, request, format=None): if not EVENTS_ENABLED: events = None return api_error(status.HTTP_404_NOT_FOUND, 'Events not enabled.') try: page = int(request.GET.get('page', '')) except ValueError: page = 1 try: per_page = int(request.GET.get('per_page', '')) except ValueError: per_page = 25 start = (page - 1) * per_page count = per_page email = request.user.username events = get_user_activities(email, start, count) events_list = [] for e in events: d = dict(op_type=e.op_type) d['repo_id'] = e.repo_id d['repo_name'] = e.repo_name d['obj_type'] = e.obj_type d['commit_id'] = e.commit_id d['path'] = e.path d['name'] = '' if e.path == '/' else os.path.basename(e.path) d['author_email'] = e.op_user d['author_name'] = email2nickname(e.op_user) d['author_contact_email'] = email2contact_email(e.op_user) try: size = int(request.GET.get('size', 36)) except ValueError as e: size = 36 url, is_default, date_uploaded = api_avatar_url(e.op_user, size) d['avatar_url'] = request.build_absolute_uri(url) d['time_relative'] = translate_seahub_time( utc_to_local(e.timestamp)) if e.op_type == 'clean-up-trash': d['days'] = e.days elif e.op_type == 'rename' and e.obj_type == 'repo': d['old_repo_name'] = e.old_repo_name elif e.op_type == 'move' and e.obj_type in ['dir', 'file']: d['old_path'] = e.old_path elif e.op_type == 'rename' and e.obj_type in ['dir', 'file']: d['old_path'] = e.old_path d['old_name'] = os.path.basename(e.old_path) events_list.append(d) ret = {'events': events_list} return Response(ret)
def get(self, request, format=None): if not EVENTS_ENABLED: events = None return api_error(status.HTTP_404_NOT_FOUND, 'Events not enabled.') try: page = int(request.GET.get('page', '')) except ValueError: page = 1 try: per_page = int(request.GET.get('per_page', '')) except ValueError: per_page = 25 start = (page - 1) * per_page count = per_page email = request.user.username try: events = get_user_activities(email, start, count) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) events_list = [] for e in events: d = dict(op_type=e.op_type) d['repo_id'] = e.repo_id d['repo_name'] = e.repo_name d['obj_type'] = e.obj_type d['commit_id'] = e.commit_id d['path'] = e.path d['name'] = '' if e.path == '/' else os.path.basename(e.path) d['author_email'] = e.op_user d['author_name'] = email2nickname(e.op_user) d['author_contact_email'] = email2contact_email(e.op_user) try: avatar_size = int(request.GET.get('avatar_size', 72)) except ValueError as e: avatar_size = 72 url, is_default, date_uploaded = api_avatar_url(e.op_user, avatar_size) d['avatar_url'] = request.build_absolute_uri(url) d['time'] = utc_datetime_to_isoformat_timestr(e.timestamp) if e.op_type == 'clean-up-trash': d['days'] = e.days elif e.op_type == 'rename' and e.obj_type == 'repo': d['old_repo_name'] = e.old_repo_name elif e.op_type == 'move' and e.obj_type in ['dir', 'file']: d['old_path'] = e.old_path elif e.op_type == 'rename' and e.obj_type in ['dir', 'file']: d['old_path'] = e.old_path d['old_name'] = os.path.basename(e.old_path) elif e.op_type == 'publish': d['old_path'] = e.old_path elif d['name'].endswith('(draft).md'): if e.op_type in ('create', 'edit') and e.obj_type == 'file': try: draft = Draft.objects.filter(username=e.op_user, origin_repo_id=e.repo_id, draft_file_path=e.path) if draft: draft = draft[0] d['draft_id'] = draft.id else: Draft.DoesNotExist except Draft.DoesNotExist: pass events_list.append(d) ret = { 'events': events_list } return Response(ret)
def get(self, request): if not DTABLE_EVENTS_ENABLED: return api_error(status.HTTP_400_BAD_REQUEST, 'Events not enabled.') try: page = int(request.GET.get('page', '')) except ValueError: page = 1 try: per_page = int(request.GET.get('per_page', '')) except ValueError: per_page = 25 start = (page - 1) * per_page count = per_page username = request.user.username try: activity_list = get_user_activities(username, start, count) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) dtable_uuid_name_map = dict() dtable_uuid_list = list() for activity in activity_list: if activity.dtable_uuid not in dtable_uuid_name_map: dtable_uuid_list.append(activity.dtable_uuid) if dtable_uuid_list: dtables = DTables.objects.filter(uuid__in=dtable_uuid_list, deleted=False) for dtable in dtables: dtable_uuid_name_map[dtable.uuid.hex] = dtable.name activities = [] for activity in activity_list: activity_dict = dict(dtable_uuid=activity.dtable_uuid) activity_dict['dtable_name'] = dtable_uuid_name_map[activity.dtable_uuid] if activity.dtable_uuid in dtable_uuid_name_map else '' activity_dict['row_id'] = activity.row_id activity_dict['op_type'] = activity.op_type activity_dict['author_email'] = activity.op_user activity_dict['author_name'] = email2nickname(activity.op_user) activity_dict['author_contact_email'] = email2contact_email(activity.op_user) activity_dict['op_time'] = utc_datetime_to_isoformat_timestr(activity.op_time) activity_dict['table_id'] = activity.table_id activity_dict['table_name'] = activity.table_name activity_dict['row_name'] = getattr(activity, "row_name", "") # compatible with previous data activity_dict['row_data'] = activity.row_data activity_dict['op_app'] = activity.op_app try: avatar_size = int(request.GET.get('avatar_size', 72)) except ValueError: avatar_size = 72 url, is_default, date_uploaded = api_avatar_url(activity.op_user, avatar_size) activity_dict['avatar_url'] = url if activity_dict['op_app']: activity_dict['app_avatar_url'] = api_app_avatar_url()[0] activities.append(activity_dict) return Response({'activities': activities})
def get(self, request, format=None): if not EVENTS_ENABLED: events = None return api_error(status.HTTP_404_NOT_FOUND, 'Events not enabled.') try: page = int(request.GET.get('page', '')) except ValueError: page = 1 try: per_page = int(request.GET.get('per_page', '')) except ValueError: per_page = 25 start = (page - 1) * per_page count = per_page email = request.user.username try: events = get_user_activities(email, start, count) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) events_list = [] for e in events: d = dict(op_type=e.op_type) d['repo_id'] = e.repo_id d['repo_name'] = e.repo_name d['obj_type'] = e.obj_type d['commit_id'] = e.commit_id d['path'] = e.path d['name'] = '' if e.path == '/' else os.path.basename(e.path) d['author_email'] = e.op_user d['author_name'] = email2nickname(e.op_user) d['author_contact_email'] = email2contact_email(e.op_user) try: avatar_size = int(request.GET.get('avatar_size', 72)) except ValueError as e: avatar_size = 72 url, is_default, date_uploaded = api_avatar_url(e.op_user, avatar_size) d['avatar_url'] = request.build_absolute_uri(url) d['time'] = utc_datetime_to_isoformat_timestr(e.timestamp) if e.op_type == 'clean-up-trash': d['days'] = e.days elif e.op_type == 'rename' and e.obj_type == 'repo': d['old_repo_name'] = e.old_repo_name elif e.op_type == 'move' and e.obj_type in ['dir', 'file']: d['old_path'] = e.old_path elif e.op_type == 'rename' and e.obj_type in ['dir', 'file']: d['old_path'] = e.old_path d['old_name'] = os.path.basename(e.old_path) elif e.op_type == 'publish': d['old_path'] = e.old_path elif d['name'].endswith('(draft).md'): if e.op_type in ('create', 'edit') and e.obj_type == 'file': try: draft = Draft.objects.get(username=e.op_user, origin_repo_id=e.repo_id, draft_file_path=e.path) d['draft_id'] = draft.id except Draft.DoesNotExist: pass events_list.append(d) ret = { 'events': events_list } return Response(ret)