예제 #1
0
def channel_members(request, nick=None, format='html'):
  nick = clean.channel(nick)

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

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

  handled = common_views.handle_view_action(
      request,
      { 'actor_add_contact': request.path,
        'actor_remove_contact': request.path, })
  if handled:
    return handled

  per_page = CONTACTS_PER_PAGE
  offset, prev = util.page_offset_nick(request)

  follower_nicks = api.channel_get_members(request.user,
                                           view.nick,
                                           limit=(per_page + 1),
                                           offset=offset)
  actor_nicks = follower_nicks
  actors = api.actor_get_actors(request.user, actor_nicks)
  # clear deleted actors
  actors = dict([(k, v) for k, v in actors.iteritems() if v])
  per_page = per_page - (len(follower_nicks) - len(actors))

  whose = "%s's" % view.display_nick()

  # here comes lots of munging data into shape
  actor_tiles = [actors[x] for x in follower_nicks if x in actors]

  actor_tiles_count = view.extra.get('member_count', 0)
  actor_tiles, actor_tiles_more = util.page_actors(request,
                                                   actor_tiles,
                                                   per_page)

  area = 'channels'

  c = template.RequestContext(request, locals())

  # TODO: Other output formats.
  if format == 'html':
    t = loader.get_template('channel/templates/members.html')
    return http.HttpResponse(t.render(c))
예제 #2
0
파일: views.py 프로젝트: zhoujh/jaikuengine
def channel_members(request, nick=None, format='html'):
    nick = clean.channel(nick)

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

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

    handled = common_views.handle_view_action(
        request, {
            'actor_add_contact': request.path,
            'actor_remove_contact': request.path,
        })
    if handled:
        return handled

    per_page = CONTACTS_PER_PAGE
    offset, prev = util.page_offset_nick(request)

    follower_nicks = api.channel_get_members(request.user,
                                             view.nick,
                                             limit=(per_page + 1),
                                             offset=offset)
    actor_nicks = follower_nicks
    actors = api.actor_get_actors(request.user, actor_nicks)
    # clear deleted actors
    actors = dict([(k, v) for k, v in actors.iteritems() if v])
    per_page = per_page - (len(follower_nicks) - len(actors))

    whose = "%s's" % view.display_nick()

    # here comes lots of munging data into shape
    actor_tiles = [actors[x] for x in follower_nicks if x in actors]

    actor_tiles_count = view.extra.get('member_count', 0)
    actor_tiles, actor_tiles_more = util.page_actors(request, actor_tiles,
                                                     per_page)

    area = 'channels'

    c = template.RequestContext(request, locals())

    if format == 'html':
        t = loader.get_template('channel/templates/members.html')
        return http.HttpResponse(t.render(c))
예제 #3
0
파일: views.py 프로젝트: hfeeki/jaikuengine
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
  """
  nick = clean.channel(nick)

  view = api.actor_lookup_nick(request.user, nick)
  if not view:
    return http.HttpResponseRedirect('/channel/create?channel=%s' % nick)

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

  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 = False
  user_is_admin = False
  if not request.user:
    pass
  elif api.channel_has_admin(request.user, view.nick, request.user.nick):
    privacy = 'private'
    user_can_post = True
    user_is_admin = True
  elif api.channel_has_member(request.user, view.nick, request.user.nick):
    privacy = 'contacts'
    user_can_post = True

  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

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


  # 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'
  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
예제 #4
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))
예제 #5
0
파일: views.py 프로젝트: zhoujh/jaikuengine
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
  """
    nick = clean.channel(nick)

    view = api.actor_lookup_nick(request.user, nick)
    if not view:
        return http.HttpResponseRedirect('/channel/create?channel=%s' % nick)

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

    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 = False
    user_is_admin = False
    if not request.user:
        pass
    elif api.channel_has_admin(request.user, view.nick, request.user.nick):
        privacy = 'private'
        user_can_post = True
        user_is_admin = True
    elif api.channel_has_member(request.user, view.nick, request.user.nick):
        privacy = 'contacts'
        user_can_post = True

    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

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

    # 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'
    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