Пример #1
0
def admin_channel_list(request):
  page = 'channel_list'
  title = 'Channels'
  page = util.paging_get_page(request)
  offset = util.paging_get_offset(page, ITEMS_BY_PAGE)
  filter = request.GET.get('filter', 'all')
  
  #owner = api.actor_lookup_nick(request.user, util.get_owner(request))

  new_link = '/admin/channels/new'
  
  size, items = api.admin_get_channels(api.ROOT, ITEMS_BY_PAGE, offset, filter)
  
  start, end, next, prev, first, last = util.paging(page, ITEMS_BY_PAGE, size)
  base_url = '/admin/channels?'
  
  if filter is not None:
    filter_url = '&filter=%s' % filter

  group_menuitem = 'channel'
  menuitem = 'channel-list'

  channel_types = api.get_config_values(api.ROOT, 'channel_type')

  c = template.RequestContext(request, locals())
  return render_to_response('administration/templates/channel_list.html', c)
Пример #2
0
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))
Пример #3
0
def admin_auto(request, action):
  page = util.paging_get_page(request)
  offset = util.paging_get_offset(page, ITEMS_BY_PAGE)
  next = str(int(page)+1)
  redirect_url = 'admin/auto/%s?page=%s' % (action, next)

  action = "administration.actions.%s" % action
  __import__(action)
  action_call = sys.modules[action]

  redirect, output = action_call.process(page, ITEMS_BY_PAGE, offset)

  c = template.RequestContext(request, locals())
  t = loader.get_template('administration/templates/auto.html')
  return http.HttpResponse(t.render(c))
Пример #4
0
def actor_twitter(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:
    # Instead of displaying the twitter tab, redirect to the public-facing page
    return http.HttpResponseRedirect(view.url())

  unauth = twitter.is_unauth(request)
  if unauth:
    return http.HttpResponseRedirect('/twitter/auth?redirect_to=/%s/twitter' % view.display_nick())

  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"]

  logging.info('Twitter request.path: %s' % request.path)
  handled = common_views.handle_view_action(
      request,
      { 
        'post': request.path,
      }
  )
  logging.info('handled: %s' % handled)
  if handled:
    return handled

  more = False
  page = util.paging_get_page(request)
  size_entries = ENTRIES_PER_PAGE+ENTRIES_PER_PAGE*(page-1)

  #Getting Entries
  twitter_error = False
  try:
    user_info, streams = twitter.twitter_get_entries(request, size_entries+1)
  except:
    twitter_error = True

  if not twitter_error:
    if len(streams) > ENTRIES_PER_PAGE:
      streams = streams[0:-1]
      entry_id = streams[size_entries-1].id
      more = page+1
      size_stream = len(streams)

  green_top = True
  sidebar_green_top = True
  area = 'actor-twitter'
  subtab = 'twitter'
  
  c = template.RequestContext(request, locals())

  if format == 'html':
    t = loader.get_template('actor/templates/twitter_tab.html')
    return http.HttpResponse(t.render(c))
Пример #5
0
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))
Пример #6
0
def channel_browse(request, format='html', tagkey=None):
  per_page = CHANNELS_PER_PAGE
  page = util.paging_get_page(request)
  filter = util.paging_filter(request)
  type = util.paging_type(request)

  if request.user:
    view = request.user
    owner = api.actor_lookup_nick(view, util.get_owner(request))
  else:
    view = api.ROOT
    owner = api.actor_lookup_nick(view, view.nick)

  nick = view.nick

  if filter == 'member':
    actors, size = api.channel_browse_tagkey(view, per_page, page, tagkey, type, nick)
  else:
    actors, size = api.channel_browse_tagkey(view, per_page, page, tagkey, type)

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

  if tagkey is not None:
    base_url = '/channel/browse%s?' % tagkey
    breadcrumb = channel_helper.get_breadcrumb(view, tagkey)
  else:
    base_url = '/channel?'
    
  filter_url = util.paging_url(filter, nick, owner.nick)

  type_url = ''
  if type is not None:
    type_url = '&type=%s' % type

  countries = api.tags_get_countries(view, util.get_metadata('DEFAULT_TAG'))

  if request.user:
    country_tag = request.user.extra.get('country_tag', '/tag_geo/North America/United States')
  else:
    country_tag = '/tag_geo/North America/United States'

  channel_nicks, other = api.channel_browse_tagkey(view, 5, 1, country_tag)

  related_tags = api.channel_get_children_tags(view, tagkey)    
  related_tags = api.channel_get_tags(view, related_tags)

  show_tags_url = True
  
  channel_types = util.get_metadata('CHANNEL_TYPES')

  area = 'channel'
  
  c = template.RequestContext(request, locals())
  # TODO(tyler): Other output formats.
  if format == 'html':
    t = loader.get_template('channel/templates/browse_tag.html')
    return http.HttpResponse(t.render(c))
Пример #7
0
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))