コード例 #1
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def channel_index(request, format='html'):
  """ the index page for channels, /channel

  should list the channels you administer, the channels you belong to
  and let you create new channels

  if you are not logged in, it should suggest that you log in to create or
  join channels and give a list of public channels
  """
  if not request.user:
    return channel_index_signedout(request, format='html')

  owned_nicks = api.actor_get_channels_admin(
      request.user,
      request.user.nick,
      limit=(CHANNELS_PER_INDEX_PAGE + 1))
  owned_more = len(owned_nicks) > CHANNELS_PER_INDEX_PAGE

  followed_nicks = api.actor_get_channels_member(
      request.user,
      request.user.nick,
      limit=(CHANNELS_PER_INDEX_PAGE + 1))
  followed_more = len(owned_nicks) > CHANNELS_PER_INDEX_PAGE

  channel_nicks = owned_nicks + followed_nicks
  channels = api.channel_get_channels(request.user, channel_nicks)

  owned_channels = [channels[x] for x in owned_nicks if channels[x]]
  for c in owned_channels:
    c.i_am_admin = True

  followed_channels = [
      channels[x] for x in followed_nicks 
          if channels[x] and x not in owned_nicks
  ]
  for c in followed_channels:
    c.i_am_member = True

  try:
    # for the Our Picks section of the sidebar
    ourpicks_channels = api.actor_get_channels_member(request.user, api.ROOT.nick)
    ourpicks_channels = api.channel_get_channels(request.user, ourpicks_channels)  
    ourpicks_channels = [x for x in ourpicks_channels.values() if x]
  except exception.ApiNotFound:
    pass
  
  related_tags = api.channel_get_children_tags(request.user)

  is_admin_user = request.user.nick in settings.ADMINS_POBOX
  
  area = 'channel'
  c = template.RequestContext(request, locals())
  

  if format == 'html':
    t = loader.get_template('channel/templates/index.html')
    return http.HttpResponse(t.render(c))
コード例 #2
0
ファイル: views.py プロジェクト: zhoujh/jaikuengine
def channel_index(request, format='html'):
    """ the index page for channels, /channel

  should list the channels you administer, the channels you belong to
  and let you create new channels

  if you are not logged in, it should suggest that you log in to create or
  join channels and give a list of public channels
  """
    if not request.user:
        return channel_index_signedout(request, format='html')

    owned_nicks = api.actor_get_channels_admin(request.user,
                                               request.user.nick,
                                               limit=(CHANNELS_PER_INDEX_PAGE +
                                                      1))
    owned_more = len(owned_nicks) > CHANNELS_PER_INDEX_PAGE

    followed_nicks = api.actor_get_channels_member(
        request.user, request.user.nick, limit=(CHANNELS_PER_INDEX_PAGE + 1))
    followed_more = len(owned_nicks) > CHANNELS_PER_INDEX_PAGE

    channel_nicks = owned_nicks + followed_nicks
    channels = api.channel_get_channels(request.user, channel_nicks)

    owned_channels = [channels[x] for x in owned_nicks if channels[x]]
    for c in owned_channels:
        c.i_am_admin = True

    followed_channels = [
        channels[x] for x in followed_nicks
        if channels[x] and x not in owned_nicks
    ]
    for c in followed_channels:
        c.i_am_member = True

    try:
        # for the Our Picks section of the sidebar
        ourpicks_channels = api.actor_get_channels_member(
            request.user, api.ROOT.nick)
        ourpicks_channels = api.channel_get_channels(request.user,
                                                     ourpicks_channels)
        ourpicks_channels = [x for x in ourpicks_channels.values() if x]
    except exception.ApiNotFound:
        pass

    area = 'channel'
    c = template.RequestContext(request, locals())

    if format == 'html':
        t = loader.get_template('channel/templates/index.html')
        return http.HttpResponse(t.render(c))
コード例 #3
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def channel_search(request, format='html'):
  q = request.GET.get('q', None)
  page   = util.paging_get_page(request)
  type = request.GET.get('type', None)

  if q is not None:
    actors, size = api.channel_search(request.user, q, page, CHANNELS_PER_PAGE, type)
  else:
    actors, size = [], 0


  for c in actors:
    c.i_am_member = api.actor_is_a_member(request.user, request.user.nick, c.nick)
    c.tags_ref = api.channel_get_tags(request.user, c.tags)
    
  start, end, next, prev, first, last = util.paging(page, CHANNELS_PER_PAGE, size)

  offset_text = 'More'
  area = 'channel'

  base_url = '/channel/search/?q=%s' % q
  
  type_url = ''
  if type is not None:
    type_url = '&type=%s' % type

  channels_member = api.actor_get_channels_member(request.user, request.user.nick,
                                                  limit=(CHANNELS_PER_PAGE + 1))

  c = template.RequestContext(request, locals())
  # TODO(tyler): Other output formats.
  if format == 'html':
    t = loader.get_template('channel/templates/search.html')
    return http.HttpResponse(t.render(c))
コード例 #4
0
ファイル: views.py プロジェクト: zhoujh/jaikuengine
def channel_browse(request, format='html'):
    per_page = CHANNELS_PER_PAGE
    prev_offset, _ = util.page_offset_nick(request)

    # Use +1 to identify if there are more that need to be displayed.
    channel_list = api.channel_browse(request.user, (per_page + 1),
                                      prev_offset)

    actors, more = util.page_actors(request, channel_list, per_page)
    offset_text = 'More'

    # for the Our Picks section of the sidebar
    ourpicks_channels = api.actor_get_channels_member(request.user,
                                                      api.ROOT.nick)
    ourpicks_channels = api.channel_get_channels(request.user,
                                                 ourpicks_channels)
    ourpicks_channels = [x for x in ourpicks_channels.values() if x]

    area = 'channel'
    c = template.RequestContext(request, locals())

    # TODO(tyler): Other output formats.
    if format == 'html':
        t = loader.get_template('channel/templates/browse.html')
        return http.HttpResponse(t.render(c))
コード例 #5
0
ファイル: views.py プロジェクト: hfeeki/jaikuengine
def channel_index_signedout(request, format='html'):
  # for the Our Picks section of the sidebar
  ourpicks_channels = api.actor_get_channels_member(request.user, api.ROOT.nick)
  ourpicks_channels = api.channel_get_channels(request.user, ourpicks_channels)  
  ourpicks_channels = [x for x in ourpicks_channels.values() if x]

  area = 'channel'
  c = template.RequestContext(request, locals())

  if format == 'html':
    t = loader.get_template('channel/templates/index_signedout.html')
    return http.HttpResponse(t.render(c))
コード例 #6
0
ファイル: views.py プロジェクト: zhoujh/jaikuengine
def channel_index_signedout(request, format='html'):
    # for the Our Picks section of the sidebar
    ourpicks_channels = api.actor_get_channels_member(request.user,
                                                      api.ROOT.nick)
    ourpicks_channels = api.channel_get_channels(request.user,
                                                 ourpicks_channels)
    ourpicks_channels = [x for x in ourpicks_channels.values() if x]

    area = 'channel'
    c = template.RequestContext(request, locals())

    if format == 'html':
        t = loader.get_template('channel/templates/index_signedout.html')
        return http.HttpResponse(t.render(c))
コード例 #7
0
ファイル: views.py プロジェクト: hfeeki/jaikuengine
def channel_browse(request, format='html'):
  per_page = CHANNELS_PER_PAGE
  prev_offset, _ = util.page_offset_nick(request)

  # Use +1 to identify if there are more that need to be displayed.
  channel_list = api.channel_browse(request.user, (per_page+1), prev_offset)

  actors, more = util.page_actors(request, channel_list, per_page)
  offset_text = 'More'
  
  # for the Our Picks section of the sidebar
  ourpicks_channels = api.actor_get_channels_member(request.user, api.ROOT.nick)
  ourpicks_channels = api.channel_get_channels(request.user, ourpicks_channels)  
  ourpicks_channels = [x for x in ourpicks_channels.values() if x]

  area = 'channel'
  c = template.RequestContext(request, locals())

  # TODO(tyler): Other output formats.
  if format == 'html':
    t = loader.get_template('channel/templates/browse.html')
    return http.HttpResponse(t.render(c))
コード例 #8
0
ファイル: views.py プロジェクト: jimpick/jaikuengine
def front_front(request):
  # if the user is logged in take them to their overview
  if request.user:
    return HttpResponseRedirect(request.user.url() + "/overview")

  # NOTE: grab a bunch of extra so that we don't ever end up with
  #       less than 5
  per_page = ENTRIES_PER_PAGE * 2

  inbox = api.inbox_get_explore(request.user, limit=per_page)

  # START inbox generation chaos
  # TODO(termie): refacccttttooorrrrr
  entries = api.entry_get_entries(request.user, inbox)
  per_page = per_page - (len(inbox) - len(entries))
  entries, more = util.page_entries(request, entries, per_page)

  stream_keys = [e.stream for e in entries]
  streams = api.stream_get_streams(request.user, stream_keys)

  actor_nicks = [e.owner for e in entries] + [e.actor for e in entries]
  actors = api.actor_get_actors(request.user, actor_nicks)

  # take it back down and don't show a more link
  entries = entries[:ENTRIES_PER_PAGE]
  more = None

  # here comes lots of munging data into shape
  streams = prep_stream_dict(streams, actors)
  entries = prep_entry_list(entries, streams, actors)

  # END inbox generation chaos

  try:
    # Featured Channels -- Ones to which the ROOT user is a member
    featured_channels = api.actor_get_channels_member(
        request.user, api.ROOT.nick, limit=SIDEBAR_FETCH_LIMIT)
    random.shuffle(featured_channels)

    # Just in case any are deleted:
    featured_channels = featured_channels[:2*SIDEBAR_LIMIT]
    featured_channels = api.channel_get_channels(
        request.user, featured_channels)
    featured_channels = [x for x in featured_channels.values() if x]
    featured_channels = featured_channels[:SIDEBAR_LIMIT]

    featured_members = api.actor_get_contacts(
        request.user, api.ROOT.nick, limit=SIDEBAR_FETCH_LIMIT)
    random.shuffle(featured_members)

    # Just in case any are deleted:
    featured_members = featured_members[:2*SIDEBAR_LIMIT]
    featured_members = api.actor_get_actors(request.user, featured_members)
    featured_members = [x for x in featured_members.values() if x]
    featured_members = featured_members[:SIDEBAR_LIMIT]

  except exception.ApiNotFound:
    pass

  root = api.ROOT

  area = 'frontpage'

  t = loader.get_template('front/templates/front.html')
  c = RequestContext(request, locals())

  return HttpResponse(t.render(c));
コード例 #9
0
ファイル: views.py プロジェクト: josezambrana/CollabQ
def actor_mentions(request, nick, format='html'):
  nick = clean.nick(nick)

  view = api.actor_lookup_nick(request.user, nick)

  if not view:
    raise exception.UserDoesNotExistError(nick, request.user)

  if not request.user or view.nick != request.user.nick:
    return http.HttpResponseRedirect(view.url())

  unauth = twitter.is_unauth(request)
  twitter_options = twitter.twitter_options(request)
  if 'twitter' in request.POST:
    if unauth:
      return http.HttpResponseRedirect('/twitter/auth?redirect_to=/%s/mentions' % view.display_nick())
    status = twitter.post_update(request)
    if status:
      flasherror = ["We have experimented some problems trying to post a cc in twitter"]
    
  handled = common_views.handle_view_action(
      request,
      { 
        'entry_remove': request.path,
        'entry_remove_comment': request.path,
        'entry_mark_as_spam': request.path,
        'presence_set': request.path,
        'settings_hide_comments': request.path,
        'post': request.path,
      }
  )
  if handled:
    return handled

  per_page = ENTRIES_PER_PAGE
  offset, prev = util.page_offset(request)

  inbox = api.inbox_get_actor_mentions(request.user,
                                       view.nick,
                                       limit=(per_page + 1), 
                                       offset=offset)

  # START inbox generation chaos
  # TODO(termie): refacccttttooorrrrr
  entries = api.entry_get_entries(request.user, inbox)

  #begin @zero code
  #if view.extra.get('comments_hide', 0):
    # TODO(tyler): This is certainly not the most eloquent way to filter
    # through entries to remove comments.
    # entries = [x for x in entries if not x.stream.endswith('comments')]
  entries = api.filter_entries_mentions(request.user, entries, view.nick)

  per_page = per_page - (len(inbox) - len(entries))
  entries, more = util.page_entries(request, entries, per_page)

  stream_keys = [e.stream for e in entries]
  actor_streams = api.stream_get_actor(request.user, view.nick)
  stream_keys += [s.key().name() for s in actor_streams]
  streams = api.stream_get_streams(request.user, stream_keys)

  contact_nicks = api.actor_get_contacts(request.user, 
                                         view.nick, 
                                         limit=CONTACTS_PER_PAGE)
  actor_nicks = (contact_nicks +
                 [view.nick] +
                 [s.owner for s in streams.values()] +
                 [e.owner for e in entries] +
                 [e.actor for e in entries])
  actors = api.actor_get_actors(request.user, actor_nicks)

  channels = api.actor_get_channels_member(request.user, view.nick,
                                limit=(CHANNELS_PER_PAGE + 1))

  # here comes lots of munging data into shape
  # clear deleted contacts
  contacts = [actors[x] for x in contact_nicks if actors[x]]
  streams = display.prep_stream_dict(streams, actors)
  entries = display.prep_entry_list(entries, streams, actors)

  # END inbox generation chaos
  
  # Check for unconfirmed emails
  unconfirmeds = api.activation_get_actor_email(request.user, view.nick)
  if unconfirmeds:
    unconfirmed_email = unconfirmeds[0].content

  # If not logged in, cannot write
  is_owner = False
  try:
    is_owner = view.nick == request.user.nick
  except:
    pass
  presence = api.presence_get(request.user, view.nick)

  # for sidebar streams
  view_streams = dict([(x.key().name(), streams[x.key().name()])
                       for x in actor_streams])

  channels_count = view.extra.get('channel_count', 0)
  channels_more = channels_count > CHANNELS_PER_PAGE
  followers_count = view.extra.get('follower_count', 0)

  # for sidebar_contacts
  contacts_count = view.extra.get('contact_count', 0)
  contacts_more = contacts_count > CONTACTS_PER_PAGE

  # Config for the template
  green_top = True
  sidebar_green_top = True
  selectable_icons = display.SELECTABLE_ICONS

  area = 'mentions'
  subtab = 'mentions'

  # TODO(tyler/termie):  This conflicts with the global settings import.
  # Also, this seems fishy.  Do none of the settings.* items work in templates?
  import settings
  
  c = template.RequestContext(request, locals())

  if format == 'html':
    t = loader.get_template('actor/templates/mentions.html')
    return http.HttpResponse(t.render(c))
コード例 #10
0
def front_front(request):
  # if the user is logged in take them to their overview
  if request.user:
    url = request.user.url(request=request)
    return HttpResponseRedirect(url + "/overview")

  # NOTE: grab a bunch of extra so that we don't ever end up with
  #       less than 5
  per_page = ENTRIES_PER_PAGE * 2

  inbox = api.inbox_get_explore(request.user, limit=per_page)

  # START inbox generation chaos
  # TODO(termie): refacccttttooorrrrr
  entries = api.entry_get_entries(request.user, inbox)
  per_page = per_page - (len(inbox) - len(entries))
  entries, more = util.page_entries(request, entries, per_page)

  stream_keys = [e.stream for e in entries]
  streams = api.stream_get_streams(request.user, stream_keys)

  actor_nicks = [e.owner for e in entries] + [e.actor for e in entries]
  actors = api.actor_get_actors(request.user, actor_nicks)

  # take it back down and don't show a more link
  entries = entries[:ENTRIES_PER_PAGE]
  more = None

  # here comes lots of munging data into shape
  streams = prep_stream_dict(streams, actors)
  entries = prep_entry_list(entries, streams, actors)

  # END inbox generation chaos

  try:
    # Featured Channels -- Ones to which the ROOT user is a member
    featured_channels = api.actor_get_channels_member(
        request.user, api.ROOT.nick, limit=SIDEBAR_FETCH_LIMIT)
    random.shuffle(featured_channels)

    # Just in case any are deleted:
    featured_channels = featured_channels[:2*SIDEBAR_LIMIT]
    featured_channels = api.channel_get_channels(
        request.user, featured_channels)
    featured_channels = [x for x in featured_channels.values() if x]
    featured_channels = featured_channels[:SIDEBAR_LIMIT]

    featured_members = api.actor_get_contacts(
        request.user, api.ROOT.nick, limit=SIDEBAR_FETCH_LIMIT)
    random.shuffle(featured_members)

    # Just in case any are deleted:
    featured_members = featured_members[:2*SIDEBAR_LIMIT]
    featured_members = api.actor_get_actors(request.user, featured_members)
    featured_members = [x for x in featured_members.values() if x]
    featured_members = featured_members[:SIDEBAR_LIMIT]

  except exception.ApiNotFound:
    pass

  root = api.ROOT

  area = 'frontpage'

  t = loader.get_template('front/templates/front.html')
  c = RequestContext(request, locals())

  return HttpResponse(t.render(c));
コード例 #11
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def hashtag_search(request, tag=''):
  view = request.user

  page = util.paging_get_page(request)

  if view is not None:
    unauth = twitter.is_unauth(request)
    twitter_options = twitter.twitter_options(request)
    if 'twitter' in request.POST:
      if unauth:
        return http.HttpResponseRedirect('/twitter/auth?redirect_to=/%s/overview' % view.display_nick())
      status = twitter.post_update(request)
      if status:
        flasherror = ["We have experimented some problems trying to post a cc in twitter"]

    handled = common_views.handle_view_action(
        request,
        {
          'entry_remove': request.path,
          'entry_remove_comment': request.path,
          'entry_mark_as_spam': request.path,
          'presence_set': request.path,
          'settings_hide_comments': request.path,
          'post': '/%s/overview' % view.display_nick(),
        }
    )
    logging.info('handled: %s' % handled)
    if handled:
      return handled

  q = request.GET.get('q', None)
  if q is not None:
    result = hashtag_re.search(q)
    if result:
      tag = result.groupdict()['tag']
    else:
      tag = q
    
  hashtag_match = tag_re.search(tag)
  if hashtag_match:
    match_dict = hashtag_match.groupdict()
    tag = '#'+match_dict['tag'].lower()

    limit = ENTRIES_PER_PAGE+ENTRIES_PER_PAGE*(page-1)
    more, relations = api.hashtag_get_relations( request.user, tag, limit)
    entries = api.hashtag_get_entries(request.user, [relation.uuid for relation in relations])
    entries = api.entry_get_entries(request.user, [entry.key().name() for entry in entries])

    stream_keys = [e.stream for e in entries]
    try:
      actor_streams = api.stream_get_actor(request.user, view.nick)
    except exception.ApiException:
      actor_streams = []
    except:
      actor_streams = []
      
    stream_keys += [s.key().name() for s in actor_streams]
    streams = api.stream_get_streams(request.user, stream_keys)

    try:
      contact_nicks = api.actor_get_contacts(request.user,
                                           view.nick,
                                           limit=CONTACTS_PER_PAGE)
    except exception.ApiException:
      contact_nicks = []
    except:
      contact_nicks = []

    actor_nicks = (contact_nicks +
                   [s.owner for s in streams.values()] +
                   [e.owner for e in entries] +
                   [e.actor for e in entries])
                   
    actors = api.actor_get_actors(request.user, actor_nicks)

    contacts = [actors[x] for x in contact_nicks if actors[x]]
    streams = display.prep_stream_dict(streams, actors)
    entries = display.prep_entry_list(entries, streams, actors)
    if more:
      last = entries[len(entries)-1].uuid
  else:
    entries = []

    try:
      contact_nicks = api.actor_get_contacts(request.user,
                                           view.nick,
                                           limit=CONTACTS_PER_PAGE)
    except exception.ApiException:
      contact_nicks 

    actor_nicks = (contact_nicks)
    actors = api.actor_get_actors(request.user, actor_nicks)
    contacts = [actors[x] for x in contact_nicks if actors[x]]

  is_owner = True
  if view is not None:
    channels_count = view.extra.get('channel_count', 0)
    channels_more = channels_count > CHANNELS_PER_PAGE
    followers_count = view.extra.get('follower_count', 0)
    contacts_count = view.extra.get('contact_count', 0)
  
    channels = api.actor_get_channels_member(request.user, view.nick,
                                limit=(CHANNELS_PER_PAGE + 1))
    templatebase = 'common/templates/base_sidebar.html'

  else:
    templatebase = 'common/templates/base_single.html'

  green_top = True
  sidebar_green_top = True
  next = page+1
  actor_link = True

  c = template.RequestContext(request, locals())
  t = loader.get_template('hashtag/templates/hashtag_search.html')

  return http.HttpResponse(t.render(c))
コード例 #12
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def channel_twitter(request, nick):
  _nick = nick
  nick = clean.channel(nick)

  view = api.channel_get_safe(request.user, nick)
  if not view:
    return http.HttpResponseRedirect('/hashtag/%s' % _nick)
  
  #twitter
  unauth = twitter.is_unauth(request)
  if 'twitter' in request.POST:
    status = twitter.post_update(request)

  handled = common_views.handle_view_action(
      request,
      {
       'channel_join': request.path,
       'channel_part': request.path,
       'channel_post': request.path,
       }
      )

  if handled:
    return handled

  page = util.paging_get_page(request)
  more = page+1

  try:
    entries = twitter.twitter_search(request, '#%s' % _nick, page)
    twitter_error = False
  except:
    entries = []
    twitter_error = True

  if not twitter_error:
    size_entries = len(entries)

  user_can_post, user_is_admin = _user_permissions(request, view)
  
  for entry in entries:
    entry['source'] =util.htmlentities_decode(entry.get('source'))

  # for sidebar_members
  members_count = view.extra['member_count']
  members_more = members_count > CONTACTS_PER_PAGE
  
  members = api.channel_get_members(request.user, channel=view.nick)
  actors = api.actor_get_actors(request.user, members)
  members = [actors[x] for x in members if actors[x]]

  if(request.user):
    channels = api.actor_get_channels_member(request.user, request.user.nick,
                              limit=(CHANNELS_SIDEBAR + 1))
  else:
    channels = []

  childs = api.channel_get_related(request.user, view)
  
  area = 'channel'
  tab = 'channel-twitter'

  green_top = True
  sidebar_green_top = True

  c = template.RequestContext(request, locals())
  t = loader.get_template('channel/templates/twitter.html')
  return http.HttpResponse(t.render(c))
コード例 #13
0
ファイル: views.py プロジェクト: CollabQ/CollabQ
def channel_history(request, nick, format='html'):
  """ the page for a channel

  if the channel does not exist we go to create channel instead

  should let you join a channel or post to it if you already are a member
  also leave it if you are a member,
  display the posts to this channel and the member list if you are allowed
  to see them

  if you are an admin you should have the options to modify the channel
  """
  tag = nick
  nick = clean.channel(nick)

  view = api.channel_get_safe(request.user, nick)
  if not view:
    return http.HttpResponseRedirect('/hashtag/%s' % tag)

  if not view.is_enabled():
    return http.HttpResponseRedirect('/hashtag/%s' % tag)

  admins = api.channel_get_admins(request.user, channel=view.nick)
  members = api.channel_get_members(request.user, channel=view.nick)

  unauth = twitter.is_unauth(request)
  if 'twitter' in request.POST:
    if unauth:
      return http.HttpResponseRedirect('/twitter/auth?redirect_to=/channel/%s/twitter/' % _nick)
    success = twitter.post_update(request)

    
  handled = common_views.handle_view_action(
      request,
      {'channel_join': request.path,
       'channel_part': request.path,
       'channel_post': request.path,
       'entry_remove': request.path,
       'entry_remove_comment': request.path,
       'entry_mark_as_spam': request.path,
       'subscription_remove': request.path,
       'subscription_request': request.path,
       }
      )
  if handled:
    return handled

  privacy = 'public'

  user_can_post, user_is_admin = _user_permissions(request, view)

  if user_can_post:
    privacy = 'contacts'
    if user_is_admin:
      privacy = 'private'

  per_page = CHANNEL_HISTORY_PER_PAGE
  offset, prev = util.page_offset(request)

  if privacy == 'public':
    inbox = api.inbox_get_actor_public(
        request.user,
        view.nick,
        limit=(per_page + 1),
        offset=offset)
  elif privacy == 'contacts':
    inbox = api.inbox_get_actor_contacts(
        request.user,
        view.nick,
        limit=(per_page + 1),
        offset=offset)
  elif privacy == 'private':
    inbox = api.inbox_get_actor_private(
        api.ROOT,
        view.nick,
        limit=(per_page + 1),
        offset=offset)

  # START inbox generation chaos
  # TODO(termie): refacccttttooorrrrr

  entries = api.entry_get_entries(request.user, inbox)
  # clear out deleted entries
  per_page = per_page - (len(inbox) - len(entries))
  entries, more = util.page_entries(request, entries, per_page)

  stream_keys = [e.stream for e in entries]
  actor_streams = api.stream_get_actor(request.user, view.nick)
  stream_keys += [s.key().name() for s in actor_streams]
  streams = api.stream_get_streams(request.user, stream_keys)

  contact_nicks = api.actor_get_contacts(request.user, view.nick)
  actor_nicks = (contact_nicks +
                 admins +
                 members +
                 [view.nick] +
                 [s.owner for s in streams.values()] +
                 [e.actor for e in entries])
  actors = api.actor_get_actors(request.user, actor_nicks)

  # here comes lots of munging data into shape
  contacts = [actors[x] for x in contact_nicks if actors[x]]
  streams = display.prep_stream_dict(streams, actors)
  entries = display.prep_entry_list(entries, streams, actors)
  admins = [actors[x] for x in admins if actors[x]]
  members = [actors[x] for x in members if actors[x]]

  # END inbox generation chaos

  presence = api.presence_get(request.user, view.nick)

  # for sidebar_members
  members_count = view.extra['member_count']
  members_more = members_count > CONTACTS_PER_PAGE

  # for sidebar_admins
  admins_count = view.extra['admin_count']
  admins_more = admins_count > CONTACTS_PER_PAGE

  # for sidebar My Group POBoxes
  if(request.user):
    channels = api.actor_get_channels_member(request.user, request.user.nick,
                                limit=(CHANNELS_SIDEBAR + 1))
  else:
    channels = []

  channels_count = view.extra.get('channel_count', 0)
  channels_more = channels_count > CHANNELS_PER_PAGE

  childs = api.channel_get_related(request.user, view)

  # config for templates
  green_top = True
  sidebar_green_top = True
  selectable_icons = display.SELECTABLE_ICONS
  actor_link = True


  # for sidebar streams (copied from actor/views.py.  refactor)
  view_streams = dict([(x.key().name(), streams[x.key().name()])
                       for x in actor_streams])
  if request.user:
    # un/subscribe buttons are possible only, when logged in

    # TODO(termie): what if there are quite a lot of streams?
    for stream in view_streams.values():
      stream.subscribed = api.subscription_exists(
          request.user,
          stream.key().name(),
          'inbox/%s/overview' % request.user.nick
          )

  area = 'channel'
  tab = 'local'
  c = template.RequestContext(request, locals())

  if format == 'html':
    t = loader.get_template('channel/templates/history.html')
    return http.HttpResponse(t.render(c))
  elif format == 'json':
    t = loader.get_template('channel/templates/history.json')
    r = util.HttpJsonResponse(t.render(c), request)
    return r
  elif format == 'atom':
    t = loader.get_template('channel/templates/history.atom')
    r = util.HttpAtomResponse(t.render(c), request)
    return r
  elif format == 'rss':
    t = loader.get_template('channel/templates/history.rss')
    r = util.HttpRssResponse(t.render(c), request)
    return r