示例#1
0
文件: views.py 项目: CollabQ/CollabQ
def explore_recent(request, format="html"):
  if request.user:
    view = request.user
    logging.info("entering here")
    #twitter
    unauth = twitter.is_unauth(request)
    if 'twitter' in request.POST:
      if unauth:
        return http.HttpResponseRedirect('/twitter/auth?redirect_to=/')
      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,
          'actor_add_contact': request.path,
          'actor_remove_contact': request.path,
          'post': request.path,
          'presence_set': request.path,
        }
    )
    if handled:
      return handled

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

  inbox = api.inbox_get_explore(request, limit=(per_page + 1),
                                offset=offset)

  entries, more = helper.get_inbox_entries(request, inbox)
  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)
                                              
  # here comes lots of munging data into shape
  entries = prep_entry_list(entries, streams, actors)

  if request.user:
    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)
    contacts_more = contacts_count > CONTACTS_PER_PAGE
    contact_nicks = api.actor_get_contacts_safe(request.user,
                                              view.nick,
                                              limit=CONTACTS_PER_PAGE)
    contacts = api.actor_get_actors(request.user, contact_nicks)
    contacts = [contacts[x] for x in contact_nicks if contacts[x]]

    green_top = True
    sidebar_green_top = True
  # END inbox generation chaos

  area = 'explore'
  actor_link = True
  
  c = template.RequestContext(request, locals())

  if format == 'html':
    t = loader.get_template('explore/templates/recent.html')
    return http.HttpResponse(t.render(c));
  elif format == 'json':
    t = loader.get_template('explore/templates/recent.json')
    r = util.HttpJsonResponse(t.render(c), request)
    return r
  elif format == 'atom':
    t = loader.get_template('explore/templates/recent.atom')
    r = util.HttpAtomResponse(t.render(c), request)
    return r
  elif format == 'rss':
    t = loader.get_template('explore/templates/recent.rss')
    r = util.HttpRssResponse(t.render(c), request)
    return r
示例#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_direct_messages(request, inbox='inbox'):
  logging.info('actor_direct_messages inbox: %s' % inbox)

  if not request.user:
    redirect_to = '/login?redirect_to=/inbox'
    if inbox == 'sent':
      redirect_to = '/login?redirect_to=/inbox/sent'
    return http.HttpResponseRedirect(redirect_to)
  
  view = request.user
  logging.info('View is: %s' % view)

  handled = common_views.handle_view_action(
      request,
      {
        'dm': '/inbox/sent',
        'dm_delete': request.path,
      }
  )
  if handled:
    return handled

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

  if inbox == 'inbox':
    inbox_inbox = api.inbox_get_actor_inbox(request.user, request.user.nick,
                                            limit=(per_page + 1), offset=offset)
  elif inbox == 'sent':
    inbox_inbox = api.inbox_get_actor_sent(request.user, request.user.nick,
                                          limit=(per_page + 1), offset=offset)
  
  actor_streams = api.stream_get_actor_safe(request.user, request.user.nick)
  
  entries, more = helper.get_inbox_entries(request, inbox_inbox, True)
  entries = api.inbox_mark_unreaded(request.user, entries)
  
  contacts, channels, streams, entries = helper.assemble_inbox_data(request,
                                                              entries,
                                                              actor_streams,
                                                              request.user)
  
  friends_keys = api.actor_get_followers(view, view.nick, limit=200)
  friends_refs = api.actor_get_actors(view, friends_keys)

  fs = friends_refs.items()
  fs.sort()
  
  reply = request.REQUEST.get('reply', None)
  reply = clean.nick(reply)
  try:
    reply_ref = api.actor_get_safe(api.ROOT, reply)
  except:
    reply_ref = None

  if reply in friends_keys:
    let_send = True
  else:
    let_send = False

  friends = [value for key, value in fs]
  
  green_top = True
  sidebar_green_top = True
  subtab = 'dm'
  
  # 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)
  contacts_count = view.extra.get('contact_count', 0)
  contacts_more = contacts_count > CONTACTS_PER_PAGE
  
  c = template.RequestContext(request, locals())
  t = loader.get_template('actor/templates/direct_messages.html')
  return http.HttpResponse(t.render(c))
示例#4
0
def actor_history(request, nick=None, format='html'):
  nick = clean.nick(nick)
  view = api.actor_lookup_nick(request.user, nick)

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

  #twitter
  unauth = twitter.is_unauth(request)
  if 'twitter' in request.POST:
    if unauth:
      return http.HttpResponseRedirect('/twitter/auth?redirect_to=/')
    status = twitter.post_update(request)
    if status:
      flasherror = ["We have experimented some problems trying to post a cc in twitter"]
    
  called_subscribe, sub_ref = common_views.call_api_from_request(
      request, 'subscription_request')
  if called_subscribe:
    if sub_ref.state == 'subscribed':
      message = 'Subscribed.'
    else:
      message = 'Subscription requested.'
    return util.RedirectFlash(view.url(), message)

  handled = common_views.handle_view_action(
      request,
      { 'entry_remove': request.path,
        'entry_remove_comment': request.path,
        'entry_mark_as_spam': request.path,
        'subscription_remove': view.url(),
        'actor_add_contact': request.path,
        'actor_remove_contact': request.path,
        'post': request.path,
        'presence_set': request.path,
      }
  )
  if handled:
    return handled

  privacy = 'public'
  if request.user:
    if view.nick == request.user.nick:
      privacy = 'private'
    # ROOT because we care whether or not request.user is a contact of
    # the view user's, not whether the request.user can see the contacts
    elif api.actor_has_contact(api.ROOT, view.nick, request.user.nick):
      privacy = 'contacts'

  # we're going to hide a bunch of stuff if this user is private and we
  # aren't allowed to see
  user_is_private = False
  if view.privacy < models.PRIVACY_PUBLIC and privacy == 'public':
    user_is_private = True

  per_page = ENTRIES_PER_PAGE
  offset, prev = util.page_offset(request)
  
  if privacy == 'public':
    if user_is_private:
      inbox = []
    else:
      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(request.user, view.nick,
                                        limit=(per_page + 1), offset=offset)

  actor_streams = api.stream_get_actor_safe(request.user, view.nick)

  entries, more = helper.get_inbox_entries(request, inbox)
  contacts, channels, streams, entries = helper.assemble_inbox_data(request,
                                                              entries,
                                                              actor_streams,
                                                              view)

  # If not logged in, cannot write
  is_owner = request.user and view.nick == request.user.nick

  try:
    presence = api.presence_get(request.user, view.nick)
    presence_stream = api.stream_get_presence(request.user, view.nick)
    last_entry = api.entry_get_last(request.user, presence_stream.keyname())
    view.last_entry = last_entry
  except exception.ApiException:
    pass


  # for add/remove contact
  if request.user:
    user_is_contact = api.actor_has_contact(request.user,
                                            request.user.nick,
                                            view.nick)
    view.my_contact = user_is_contact
  else:
    user_is_contact = False

  show_dm_link = False
  if request.user:
    friends_keys = api.actor_get_followers(api.ROOT, request.user.nick, limit=200)
    if view.nick in friends_keys:
      show_dm_link = True

  #@begin zero code HISTORY
  # 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
  area = 'user'
  subtab = 'profile'
  hide_avatar = True

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

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