def list_group_events(context, request):

  author = context.author
  author_group = context.author_group

  me_asm = data_access.author_service_map.query_asm_by_author_and_service(
      author.id,
      data_access.service.name_to_id('me'))

  db_session = db.Session()

  events = []
  for event, asm, author in db_session. \
          query(ServiceEvent, AuthorServiceMap, Author). \
          join(AuthorServiceMap, ServiceEvent.author_service_map_id == AuthorServiceMap.id). \
          join(AuthorGroupMap, AuthorServiceMap.author_id == AuthorGroupMap.author_id). \
          join(Author, AuthorServiceMap.author_id == Author.id). \
          filter(AuthorGroupMap.author_group_id == author_group.id). \
          filter(ServiceEvent.correlation_id == None). \
          order_by(ServiceEvent.create_time.desc()). \
          limit(200):

    ''' filter well-known and instagram photo albums so they
        don't appear in the timeline
    '''
    if (event.type_id == ServiceObjectType.PHOTO_ALBUM_TYPE and
        (event.service_id == data_access.service.name_to_id('me') or
         event.service_id == data_access.service.name_to_id('instagram'))):
      continue

    event_obj = createServiceEvent(request, event, me_asm, asm, author)
    if event_obj:
      events.append(event_obj)

  return {'events': events, 'paging': {'prev': None, 'next': None}}
def get_events(author_service_context, request):
  author = author_service_context.author
  asm = author_service_context.author_service_map

  me_asm = data_access.author_service_map.query_asm_by_author_and_service(
      author.id,
      data_access.service.name_to_id('me'))

  # get the query parameters
  since_date, since_service_id, since_event_id = miapi.controllers.parse_page_param(
      request.params.get('since'))
  until_date, until_service_id, until_event_id = miapi.controllers.parse_page_param(
      request.params.get('until'))

  page_limit = min(int(request.params.get('count', miapi.tim_config['api']['default_page_limit'])),
                   int(miapi.tim_config['api']['max_page_limit']))

  service_events = data_access.service_event.query_service_events_page_by_service(
      author.id,
      asm.service_id,
      page_limit,
      since_date=since_date,
      since_service_id=since_service_id,
      since_event_id=since_event_id,
      until_date=until_date,
      until_service_id=until_service_id,
      until_event_id=until_event_id)

  prev_link = None
  next_link = None
  events = []
  for service_event in service_events:
    event_obj = createServiceEvent(request, service_event, me_asm, asm, author)
    if event_obj:
      events.append(event_obj)

      param_value = miapi.controllers.create_page_param(
          service_event.create_time,
          service_event.service_id,
          service_event.event_id)

      if prev_link is None:
        prev_link = request.resource_url(
            author_service_context,
            query={'since': param_value, 'count': page_limit})
      next_link = request.resource_url(
          author_service_context,
          query={'until': param_value, 'count': page_limit})

  return {'entries': events,
          'paging': {'prev': prev_link, 'next': next_link}}