예제 #1
0
파일: views.py 프로젝트: hfeeki/jaikuengine
def api_keys(request):

  # special case this because we want to redirect to the edit page
  if 'oauth_generate_consumer' in request.POST:
    action = 'oauth_generate_consumer'
    (called, rv) = common_views.call_api_from_request(request, action)
    return util.RedirectFlash(rv.url(), messages.flash(action))

  handled = common_views.handle_view_action(
      request,
      {}
  )
  if handled:
    return handled

  # Get list of consumer tokenss for this actor
  consumer_tokens = api.oauth_get_actor_consumers(request.user,
                                                  request.user.nick)

  # TODO(termie): Get list of access tokens this actor has given others
  access_tokens = []

  # for templates
  full_page = 'Keys'
  page = 'keys'
  area = 'api'

  c = template.RequestContext(request, locals())
  t = loader.get_template('api/templates/keys.html')
  return http.HttpResponse(t.render(c))
예제 #2
0
파일: views.py 프로젝트: zhoujh/jaikuengine
def api_keys(request):

    # special case this because we want to redirect to the edit page
    if 'oauth_generate_consumer' in request.POST:
        action = 'oauth_generate_consumer'
        (called, rv) = common_views.call_api_from_request(request, action)
        return util.RedirectFlash(rv.url(), messages.flash(action))

    handled = common_views.handle_view_action(request, {})
    if handled:
        return handled

    # Get list of consumer tokenss for this actor
    consumer_tokens = api.oauth_get_actor_consumers(request.user,
                                                    request.user.nick)

    # TODO(termie): Get list of access tokens this actor has given others
    access_tokens = []

    # for templates
    full_page = 'Keys'
    page = 'keys'
    area = 'api'

    c = template.RequestContext(request, locals())
    t = loader.get_template('api/templates/keys.html')
    return http.HttpResponse(t.render(c))
예제 #3
0
파일: views.py 프로젝트: webatat/webatat
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)

  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 = _get_inbox_entries(request, inbox)
  contacts, channels, streams, entries = _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

  # for sidebar streams
  view_streams = _get_sidebar_streams(actor_streams, streams, request.user)

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

  # for sidebar channels
  channels_count = view.extra.get('channel_count', 0)
  channels_more = channels_count > CHANNELS_PER_PAGE

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

  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')
    return util.HttpJsonResponse(t.render(c), request)
  elif format == 'atom':
    t = loader.get_template('actor/templates/history.atom')
    return util.HttpAtomResponse(t.render(c), request)
  elif format == 'rss':
    t = loader.get_template('actor/templates/history.rss')
    return util.HttpRssResponse(t.render(c), request)
예제 #4
0
파일: views.py 프로젝트: seckyn/jaikuengine
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)

    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 = _get_inbox_entries(request, inbox)
    contacts, channels, streams, entries = _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

    # for sidebar streams
    view_streams = _get_sidebar_streams(actor_streams, streams, request.user)

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

    # for sidebar channels
    channels_count = view.extra.get('channel_count', 0)
    channels_more = channels_count > CHANNELS_PER_PAGE

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

    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')
        return util.HttpJsonResponse(t.render(c), request)
    elif format == 'atom':
        t = loader.get_template('actor/templates/history.atom')
        return util.HttpAtomResponse(t.render(c), request)
    elif format == 'rss':
        t = loader.get_template('actor/templates/history.rss')
        return util.HttpRssResponse(t.render(c), request)
예제 #5
0
파일: views.py 프로젝트: zhoujh/jaikuengine
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)

    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)

    # 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]
    try:
        actor_streams = api.stream_get_actor(request.user, view.nick)
    except exception.ApiException:
        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 = []

    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)

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

    # END inbox generation chaos

    # 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

    # for sidebar streams
    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)

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

    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
예제 #6
0
파일: views.py 프로젝트: hfeeki/jaikuengine
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)

  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)

  # 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]
  try:
    actor_streams = api.stream_get_actor(request.user, view.nick)
  except exception.ApiException:
    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 = []

  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)

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

  # END inbox generation chaos

  # 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

  # for sidebar streams
  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
          )


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

  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