示例#1
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))
示例#2
0
def actor_overview(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 overview, redirect to the public-facing page
    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/overview' % 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('Overview request.path: %s' % request.path)
  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,
      }
  )
  logging.info('handled: %s' % handled)
  if handled:
    return handled

  per_page = ENTRIES_PER_PAGE
  offset, prev = util.page_offset(request)
  
  inbox = api.inbox_get_actor_overview(request.user,
                                       view.nick,
                                       limit=(per_page + 1),
                                       offset=offset)

  actor_streams = api.stream_get_actor(request.user, view.nick)
  entries, more = helper.get_inbox_entries(request, inbox, False, per_page, True, view)
  contacts, channels, streams, entries = helper.assemble_inbox_data(request, entries, actor_streams, view)

  latest = api.inbox_get_actor_private(request.user, view.nick, per_page)
  latest = api.entry_get_entries(request.user, latest)
  if len(latest) > 0:
    latest = latest[0]
    
  # Check for unconfirmed emails
  unconfirmeds = api.activation_get_actor_email(request.user, view.nick)
  if unconfirmeds:
    unconfirmed_email = unconfirmeds[0].content

  first_time, emailform = api.is_first_time(request.user, view.nick)
  loadmodal = first_time

  # 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])

  #@begin zero code OVERVIEW
  # for sidebar info
  channels_count = view.extra.get('channel_count', 0)
  channels_more = channels_count > CHANNELS_PER_PAGE
  followers_count = view.extra.get('follower_count', 0)
  #@end

  # 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
  actor_link = True

  area = 'home'
  subtab = 'overview'

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

  if format == 'html':
    t = loader.get_template('actor/templates/overview.html')
    r = http.HttpResponse(t.render(c))
  elif format == 'json':
    t = loader.get_template('actor/templates/overview.json')
    r = util.HttpJsonResponse(t.render(c), request)
  elif format == 'atom':
    t = loader.get_template('actor/templates/overview.atom')
    r = util.HttpAtomResponse(t.render(c), request)
  elif format == 'rss':
    t = loader.get_template('actor/templates/overview.rss')
    r = util.HttpRssResponse(t.render(c), request)
  return r
示例#3
0
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))
示例#4
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))