Beispiel #1
0
  def test_settings_change_avatar(self):
    nick = 'obligated'
    self.login(nick)

    nick = clean.nick(nick)
    old_avatar = api.actor_get(api.ROOT, nick).extra.get('icon',
                                                         'avatar_default')

    # TODO(teemu): add more tests for different file types (gif and jpg).
    # Alternatively, test those against api.avatar_upload.
    r = self.client.post('/user/obligated/settings/photo',
                         {
                           'avatar': 'default/animal_9',
                           '_nonce' :
                              util.create_nonce('obligated', 'change_photo'),
                         })
    r = self.assertRedirectsPrefix(r, '/user/obligated/settings/photo')

    new_avatar = api.actor_get(api.ROOT, nick).extra.get('icon',
                                                         'avatar_default')
    self.assertNotEquals(old_avatar, new_avatar)

    self.assertContains(r, 'Avatar changed')
    self.assertTemplateUsed(r, 'actor/templates/settings_photo.html')
    self.assertTemplateUsed(r, 'common/templates/flash.html')
Beispiel #2
0
 def setUp(self):
   super(NotificationTest, self).setUp()
   self.popular = api.actor_get(api.ROOT, '*****@*****.**')
   self.unpopular = api.actor_get(api.ROOT, '*****@*****.**')
   self.girlfriend = api.actor_get(api.ROOT, '*****@*****.**')
   self.boyfriend = api.actor_get(api.ROOT, '*****@*****.**')
   self.otherboyfriend = api.actor_get(api.ROOT, '*****@*****.**')
   self.channel = api.channel_get(api.ROOT, '#[email protected]')
   self.popular_entry = api.entry_get(
       api.ROOT, 'stream/[email protected]/presence/12345')
   self.girlfriend_entry = api.entry_get(
       api.ROOT, 'stream/[email protected]/presence/16961')
   self.channel_entry = api.entry_get(
       api.ROOT, 'stream/#[email protected]/presence/13345')
Beispiel #3
0
    def test_start_stop(self):
        actor_pre_ref = api.actor_get(api.ROOT, 'hermit')
        self.assertEqual(actor_pre_ref.extra.get('im_notify', False), False)

        r = self.sign_in(self.from_jid, 'hermit')

        self.send(self.from_jid, 'start')

        actor_post_ref = api.actor_get(api.ROOT, 'hermit')
        self.assertEqual(actor_post_ref.extra.get('im_notify', False), True)

        self.send(self.from_jid, 'stop')

        actor_last_ref = api.actor_get(api.ROOT, 'hermit')
        self.assertEqual(actor_last_ref.extra.get('im_notify', False), False)
Beispiel #4
0
  def test_start_stop(self):
    actor_pre_ref = api.actor_get(api.ROOT, 'hermit')
    self.assertEqual(actor_pre_ref.extra.get('im_notify', False), False)
  
    r = self.sign_in(self.from_jid, 'hermit')

    self.send(self.from_jid, 'start')

    actor_post_ref = api.actor_get(api.ROOT, 'hermit')
    self.assertEqual(actor_post_ref.extra.get('im_notify', False), True)

    self.send(self.from_jid, 'stop')
    
    actor_last_ref = api.actor_get(api.ROOT, 'hermit')
    self.assertEqual(actor_last_ref.extra.get('im_notify', False), False)
Beispiel #5
0
def common_design_update(request, nick):
    view = api.actor_get(api.ROOT, nick)
    if request.POST:
        try:
            validate.nonce(request, 'update_design')

            color = request.POST.get('bg_color')
            repeat = request.POST.get('bg_repeat', 'no-repeat')
            if not repeat:
                repeat = ''

            img = request.FILES.get('bg_image')
            img_url = None
            if img:
                img_url = api.background_upload(request.user, nick, img.read())
            api.background_set_actor(request.user, nick, img_url, color,
                                     repeat)
            return util.RedirectFlash(view.url() + '/settings/design',
                                      'design updated')
        except:
            exception.handle_exception(request)

    if request.GET and 'restore' in request.GET:
        api.background_clear_actor(request.user, nick)
        return util.RedirectFlash(view.url() + '/settings/design',
                                  'design updated')

    return None
Beispiel #6
0
def actor_invite(request, nick, format='html'):
  nick = clean.nick(nick)

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

  if not request.user or view.nick != request.user.nick:
    # Bounce the user to their own page (avoids any confusion for the wrong
    # nick in the url).  Perhaps unnecessary.
    return http.HttpResponseRedirect(
        '%s/invite' % request.user.url())
  
  handled = common_views.handle_view_action(
      request,
      { 'invite_request_email': request.path, })
  if handled:
    return handled

  if request.user and request.user.nick == view.nick:
    whose = 'Your'
  else:
    whose = "%s's" % view.display_nick()

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

  if format == 'html':
    t = loader.get_template('actor/templates/invite.html')
    return http.HttpResponse(t.render(c))
Beispiel #7
0
 def setUp(self):
   super(NotificationTest, self).setUp()
   self.popular = api.actor_get(api.ROOT, '*****@*****.**')
   self.unpopular = api.actor_get(api.ROOT, '*****@*****.**')
   self.girlfriend = api.actor_get(api.ROOT, '*****@*****.**')
   self.boyfriend = api.actor_get(api.ROOT, '*****@*****.**')
   self.otherboyfriend = api.actor_get(api.ROOT, '*****@*****.**')
   self.channel = api.channel_get(api.ROOT, '#[email protected]')
   self.popular_entry = api.entry_get(
       api.ROOT, 'stream/[email protected]/presence/12345')
   self.girlfriend_entry = api.entry_get(
       api.ROOT, 'stream/[email protected]/presence/16961')
   self.channel_entry = api.entry_get(
       api.ROOT, 'stream/#[email protected]/presence/13345')
   self.pshb_endpoints = [x.target for x in api.pshb_get_firehoses(api.ROOT)
                          if x.state == 'subscribed']
Beispiel #8
0
def common_design_update(request, nick):
  view = api.actor_get(api.ROOT, nick)
  if request.POST:
    try:
      validate.nonce(request, 'update_design')

      color = request.POST.get('bg_color')
      repeat = request.POST.get('bg_repeat', 'no-repeat')
      if not repeat:
        repeat = ''

      img = request.FILES.get('bg_image')
      img_url = None
      if img:
        img_url = api.background_upload(request.user,
                                        nick,
                                        img.read())
      api.background_set_actor(request.user,
                               nick,
                               img_url,
                               color,
                               repeat)
      return util.RedirectFlash(view.url() + '/settings/design',
                                'design updated')
    except:
      exception.handle_exception(request)

  if request.GET and 'restore' in request.GET:
      api.background_clear_actor(request.user, nick)
      return util.RedirectFlash(view.url() + '/settings/design',
                                'design updated')

  return None
Beispiel #9
0
  def test_task_post_process_any(self):
    """ test that api.post creates a task and additional calls resume
    """
    nick = '*****@*****.**'
    uuid = 'HOWNOW'
    message = 'BROWNCOW'

    actor_ref = api.actor_get(api.ROOT, nick)

    # DROP
    old_max = api.MAX_FOLLOWERS_PER_INBOX
    api.MAX_FOLLOWERS_PER_INBOX = 1

    try:
      entry_ref = api.post(actor_ref, nick=nick, uuid=uuid, message=message)
      self.assertEqual(entry_ref.extra['title'], message)
    
      # make sure we can repeat
      two_entry_ref = api.post(actor_ref, nick=nick, uuid=uuid, message=message)
      self.assertEqual(entry_ref.uuid, two_entry_ref.uuid)
    
      # and that task_process_any works
      # and run out the queue
      for i in range(5):
        api.task_process_any(api.ROOT, nick)
      
      self.assertRaises(exception.ApiNoTasks,
                        lambda: api.task_process_actor(api.ROOT, nick))
    finally:
      api.MAX_FOLLOWERS_PER_INBOX = old_max  
Beispiel #10
0
def api_task_queue(request):
  """Process a queued task.
  
  A task will look like:
    actor
    action
    action_id
    progress
    args (picked list)
    kw (pickled dict)
  
  It will map to an api call (action) that will be called with 
  (actor, _task_ref=task_ref, *args, **kw) as arguments.
  """
  try:
    task_ref = api.Task.from_request(request)
  except Exception:
    logging.exception('Unhandled exception while building task ref')
    logging.warning('request.post %s', request.POST)
    return http.HttpResponse('')

  try:
    actor_ref = api.actor_get(api.ROOT, task_ref.actor)
    method_ref = api.PublicApi.get_method(task_ref.action)
    method_ref(actor_ref, _task_ref=task_ref, *task_ref.args, **task_ref.kw)
  except exception.Error:
    logging.exception('Unexpected error while processing queue:')
  return http.HttpResponse('')
Beispiel #11
0
    def get_email_for_inboxes(self, entry_ref, inboxes):
        subscribers_ref = self.get_actors_for_inboxes(inboxes)
        email_aliases = []
        parent_entry_ref = api.entry_get_safe(api.ROOT, entry_ref.entry)
        owners = [entry_ref.owner, entry_ref.actor]
        if parent_entry_ref:
            owners.extend((parent_entry_ref.owner, parent_entry_ref.actor))

        for subscriber_ref in subscribers_ref:
            # Only email if you are directly involved in the stream
            if subscriber_ref.nick not in owners:
                exists = api.subscription_exists(
                    api.ROOT, entry_ref.entry,
                    'inbox/%s/overview' % subscriber_ref.nick)
                if not exists:
                    continue
            if not subscriber_ref.extra.get('email_notify'):
                continue
            email = api.email_get_actor(api.ROOT, subscriber_ref.nick)
            if not email:
                continue
            actor_ref = api.actor_get(api.ROOT, entry_ref.actor)
            if subscriber_ref.nick == actor_ref.nick:
                continue
            email_aliases.append(email)
        return set(email_aliases)
Beispiel #12
0
    def test_notify_on_post(self):
        actor_ref = api.actor_get(api.ROOT, 'popular')
        api.post(actor_ref, nick='popular', message='la la la')
        self.exhaust_queue('popular')

        # should notify popular and unpopular
        self.assertEqual(len(xmpp.outbox), 2)
Beispiel #13
0
  def get_email_for_inboxes(self, entry_ref, inboxes):
    subscribers_ref = self.get_actors_for_inboxes(inboxes)
    email_aliases = []
    parent_entry_ref = api.entry_get_safe(api.ROOT, entry_ref.entry)
    owners = [entry_ref.owner, entry_ref.actor]
    if parent_entry_ref:
      owners.extend((parent_entry_ref.owner, parent_entry_ref.actor))

    for subscriber_ref in subscribers_ref:
      # Only email if you are directly involved in the stream
      if subscriber_ref.nick not in owners:
        exists = api.subscription_exists(
            api.ROOT,
            entry_ref.entry,
            'inbox/%s/overview' % subscriber_ref.nick)
        if not exists:
          continue
      if not subscriber_ref.extra.get('email_notify'):
        continue
      email = api.email_get_actor(api.ROOT, subscriber_ref.nick)
      if not email:
        continue
      actor_ref = api.actor_get(api.ROOT, entry_ref.actor)
      if subscriber_ref.nick == actor_ref.nick:
        continue
      email_aliases.append(email)
    return set(email_aliases)
Beispiel #14
0
def install_rootuser(request):
    # requires an admin
    user = users.get_current_user()
    if not user:
        return http.HttpResponseRedirect(users.create_login_url('/install'))
    else:
        if not users.is_current_user_admin():
            return http.HttpResponseRedirect('/')

    try:
        root_user = api.actor_get(api.ROOT, settings.ROOT_NICK)
    except:
        root_user = None

    if request.POST:
        try:
            logging.warning('Making root user: %s', settings.ROOT_NICK)
            validate.nonce(request, 'create_root')
            root_user = api.user_create_root(api.ROOT)
            return util.RedirectFlash('/install', 'Root user created')
        except:
            exception.handle_exception(request)

    redirect_to = '/'

    c = template.RequestContext(request, locals())
    t = loader.get_template('install/templates/rootuser.html')
    return http.HttpResponse(t.render(c))
Beispiel #15
0
def install_rootuser(request):
  # requires an admin
  user = users.get_current_user()
  if not user:
    return http.HttpResponseRedirect(users.create_login_url('/install'))
  else:
    if not users.is_current_user_admin():
      return http.HttpResponseRedirect('/')
  
  try:
    root_user = api.actor_get(api.ROOT, settings.ROOT_NICK)
  except:
    root_user = None

  if request.POST:
    try:
      logging.warning('Making root user: %s', settings.ROOT_NICK)
      #validate.nonce(request, 'create_root')
      root_user = api.user_create_root(api.ROOT)
      return util.RedirectFlash('/install', 'Root user created')
    except:
      exception.handle_exception(request)

  redirect_to = '/'

  c = template.RequestContext(request, locals())    
  t = loader.get_template('rootuser.html')
  return http.HttpResponse(t.render(c))
Beispiel #16
0
  def test_notify_on_post(self):
    actor_ref = api.actor_get(api.ROOT, 'popular')
    api.post(actor_ref, nick='popular', message='la la la')
    self.exhaust_queue('popular')

    # should notify popular and unpopular
    self.assertEqual(len(xmpp.outbox), 2)
Beispiel #17
0
    def test_login_user_cleanup(self):
        log = "broken"
        pwd = self.passwords[clean.nick(log)]

        actor_ref_pre = api.actor_get(api.ROOT, log)
        self.assert_(not actor_ref_pre.normalized_nick)
        self.assertRaises(exception.ApiException, api.stream_get_presence, api.ROOT, log)
        self.assertRaises(exception.ApiException, api.stream_get_comment, api.ROOT, log)

        r = self.client.post("/login", {"log": log, "pwd": pwd})
        r = self.assertRedirectsPrefix(r, "/user/broken/overview")

        actor_ref_post = api.actor_get(api.ROOT, log)
        self.assert_(actor_ref_post.normalized_nick)
        self.assert_(api.stream_get_presence(api.ROOT, log))
        self.assert_(api.stream_get_comment(api.ROOT, log))
Beispiel #18
0
def common_design_update(request, success="/", nick=None):
  if not nick:
    nick = request.user.nick
  view = api.actor_get(api.ROOT, nick)
  if request.POST:
    try:
      validate.nonce(request, 'update_design')

      color = request.POST.get('bg_color')
      repeat = request.POST.get('bg_repeat', 'no-repeat')
      if not repeat:
        repeat = ''

      img = request.FILES.get('bg_image')
      img_url = None
      if img:
        img_url = api.background_upload(request.user,
                                        nick,
                                        img.read())
      api.background_set_actor(request.user,
                               nick,
                               img_url,
                               color,
                               repeat)
      return util.RedirectFlash(success,
                                'Thiết lập về màu nền/ảnh nền đã được cập nhật lại.')
    except:
      exception.handle_exception(request)

  if request.GET and 'restore' in request.GET:
      api.background_clear_actor(request.user, nick)
      return util.RedirectFlash(success,
                                'Thiết lập ảnh nền/màu nền đã được khôi phục về trạng thái mặc định.')

  return None
Beispiel #19
0
 def test_xmlrpc_with_legacy_key(self):
   self.overrides = test_util.override(API_ALLOW_LEGACY_AUTH=True)
   popular_ref = api.actor_get(api.ROOT, 'popular')
   personal_key = legacy.generate_personal_key(popular_ref)
   params = {'user': '******',
             'personal_key': personal_key,
             'nick': 'popular'}
   self.assert_valid_actor_get_response(params)
Beispiel #20
0
def authenticate_user_personal_key(nick, key):
  actor_ref = api.actor_get(api.ROOT, nick)
  check_key = generate_personal_key(actor_ref)

  if check_key != key:
    return None

  actor_ref.access_level = api.WRITE_ACCESS
  return actor_ref
Beispiel #21
0
    def test_login_user_cleanup(self):
        log = 'broken'
        pwd = self.passwords[clean.nick(log)]

        actor_ref_pre = api.actor_get(api.ROOT, log)
        self.assert_(not actor_ref_pre.normalized_nick)
        self.assertRaises(exception.ApiException, api.stream_get_presence,
                          api.ROOT, log)
        self.assertRaises(exception.ApiException, api.stream_get_comment,
                          api.ROOT, log)

        r = self.client.post('/login', {'log': log, 'pwd': pwd})
        r = self.assertRedirectsPrefix(r, '/user/broken/overview')

        actor_ref_post = api.actor_get(api.ROOT, log)
        self.assert_(actor_ref_post.normalized_nick)
        self.assert_(api.stream_get_presence(api.ROOT, log))
        self.assert_(api.stream_get_comment(api.ROOT, log))
Beispiel #22
0
def authenticate_user_personal_key(nick, key):
    actor_ref = api.actor_get(api.ROOT, nick)
    check_key = generate_personal_key(actor_ref)

    if check_key != key:
        return None

    actor_ref.access_level = api.WRITE_ACCESS
    return actor_ref
Beispiel #23
0
 def test_xmlrpc_with_legacy_key(self):
     self.overrides = test_util.override(API_ALLOW_LEGACY_AUTH=True)
     popular_ref = api.actor_get(api.ROOT, 'popular')
     personal_key = legacy.generate_personal_key(popular_ref)
     params = {
         'user': '******',
         'personal_key': personal_key,
         'nick': 'popular'
     }
     self.assert_valid_actor_get_response(params)
Beispiel #24
0
 def setUp(self):
     super(NotificationTest, self).setUp()
     self.popular = api.actor_get(api.ROOT, '*****@*****.**')
     self.unpopular = api.actor_get(api.ROOT, '*****@*****.**')
     self.girlfriend = api.actor_get(api.ROOT, '*****@*****.**')
     self.boyfriend = api.actor_get(api.ROOT, '*****@*****.**')
     self.otherboyfriend = api.actor_get(api.ROOT,
                                         '*****@*****.**')
     self.channel = api.channel_get(api.ROOT, '#[email protected]')
     self.popular_entry = api.entry_get(
         api.ROOT, 'stream/[email protected]/presence/12345')
     self.girlfriend_entry = api.entry_get(
         api.ROOT, 'stream/[email protected]/presence/16961')
     self.channel_entry = api.entry_get(
         api.ROOT, 'stream/#[email protected]/presence/13345')
     self.pshb_endpoints = [
         x.target for x in api.pshb_get_firehoses(api.ROOT)
         if x.state == 'subscribed'
     ]
Beispiel #25
0
 def test_xmlrpc_with_disabled_legacy_key(self):
   self.overrides = test_util.override(API_ALLOW_LEGACY_AUTH=False)
   popular_ref = api.actor_get(api.ROOT, 'popular')
   personal_key = legacy.generate_personal_key(popular_ref)
   params = {'user': '******',
             'personal_key': personal_key,
             'nick': 'popular'}
   xml = xmlrpclib.dumps((params,), 'actor_get')
   response = self.client.post('/api/xmlrpc', xml, 'text/xml')
   self.assertContains(response, 'Parameter not found')
Beispiel #26
0
 def process_request(self, request):
   logging.info("VerifyInstallMiddleware")
   logging.info("Path %s" % request.path)
   if not request.path == '/install':
     try:
       root_user = api.actor_get(api.ROOT, settings.ROOT_NICK)
       logging.info("Root Exists")
     except:
       logging.info("Root Does Not Exists")
       return HttpResponseRedirect('/install')
Beispiel #27
0
 def test_xmlrpc_with_disabled_legacy_key(self):
     self.overrides = test_util.override(API_ALLOW_LEGACY_AUTH=False)
     popular_ref = api.actor_get(api.ROOT, 'popular')
     personal_key = legacy.generate_personal_key(popular_ref)
     params = {
         'user': '******',
         'personal_key': personal_key,
         'nick': 'popular'
     }
     xml = xmlrpclib.dumps((params, ), 'actor_get')
     response = self.client.post('/api/xmlrpc', xml, 'text/xml')
     self.assertContains(response, 'Parameter not found')
Beispiel #28
0
 def test_browse_older(self):
     popular_ref = api.actor_get(api.ROOT, 'popular')
     existing_entries_per_page = views.ENTRIES_PER_PAGE
     # change the entries per page setting to make sure that the paging
     # link shows up
     try:
         views.ENTRIES_PER_PAGE = 3
         r = self.client.get('/user/popular')
         self.assertContains(r, '<div class="paging">')
         self.assertContains(r, 'Older')
     finally:
         views.ENTRIES_PER_PAGE = existing_entries_per_page
Beispiel #29
0
 def test_browse_older(self):
   popular_ref = api.actor_get(api.ROOT, 'popular')
   existing_entries_per_page = views.ENTRIES_PER_PAGE
   # change the entries per page setting to make sure that the paging
   # link shows up
   try:
     views.ENTRIES_PER_PAGE = 3
     r = self.client.get('/user/popular')
     self.assertContains(r, '<div class="paging">')
     self.assertContains(r, 'Older')
   finally:
     views.ENTRIES_PER_PAGE = existing_entries_per_page
Beispiel #30
0
def invite_email(request, code):
  """User has received the invite email, and has followed the link to accept or
     or refuse it."""
  
  if request.user:
    handled = common_views.handle_view_action(
        request,
        {'invite_accept': request.user.url('/overview'),
         'invite_reject': request.user.url('/overview')
         }
        )
    if handled:
      return handled

  # Retrieve the invite
  invite = api.invite_get(api.ROOT, code)
  from_actor = invite.from_actor
  
  # Translate the from_actor into a display name
  from_actor_ref = api.actor_get(api.ROOT, from_actor)
  view = from_actor_ref

  if not from_actor_ref:
    # Corner case: from_actor was deleted since the invite was sent.
    # In this case, do we want to consider the invitation invalid?
    # (probably we do, because it's more likely that it was spam)
    return util.RedirectError("That invite is no longer valid")
    
    
  # We use api.ROOT in the next set of functions because the
  # invite is giving possibly private access to the user
  inbox = api.inbox_get_actor_contacts(api.ROOT,
                                       view.nick,
                                       limit=5)
  entries = api.entry_get_entries(api.ROOT, inbox)
  stream_keys = [e.stream for e in entries]
  streams = api.stream_get_streams(api.ROOT, stream_keys)
  actor_nicks = ([view.nick] +
                 [s.owner for s in streams.values() if s] +
                 [e.owner for e in entries] +
                 [e.actor for e in entries])
  actors = api.actor_get_actors(api.ROOT, actor_nicks)

  streams = display.prep_stream_dict(streams, actors)
  entries = display.prep_entry_list(entries, streams, actors)


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

  t = loader.get_template('email.html')
  return http.HttpResponse(t.render(c))
Beispiel #31
0
def login_noreally(request):
    if 'sso_token' in request.GET:
        sso_token = request.GET['sso_token']
        redirect_to = request.GET['redirect_to']
        redirect_to = clean.redirect_to(redirect_to)

        nick, rememberme = cache.get('sso/%s' % sso_token)
        cache.delete('sso/%s' % sso_token)
        actor_ref = api.actor_get(api.ROOT, nick)
        response = http.HttpResponseRedirect(redirect_to)
        response = user.set_user_cookie(response, actor_ref, rememberme)
        return response
    return http.HttpResponseRedirect('/login')
Beispiel #32
0
    def check_inboxes_for_entry(self, entry_ref, expected):
        inboxes = api.inbox_get_all_for_entry(api.ROOT, entry_ref.stream,
                                              entry_ref.uuid, entry_ref.entry)

        #self.assertEqual(len(inboxes), len(set(inboxes)), 'duplicates: %s' % inboxes)
        self.assertSetEqual(set(expected), set(inboxes))
        for inbox in inboxes:
            actor_ref = api.actor_get(api.ROOT,
                                      util.get_user_from_topic(inbox))
            if not api.entry_get_safe(actor_ref, entry_ref.keyname()):
                self.fail(
                    'An entry not visible by a user was added to their inbox')
        return inboxes
Beispiel #33
0
  def check_inboxes_for_entry(self, entry_ref, expected):
    inboxes = api.inbox_get_all_for_entry(api.ROOT,
                                          entry_ref.stream,
                                          entry_ref.uuid,
                                          entry_ref.entry)

    #self.assertEqual(len(inboxes), len(set(inboxes)), 'duplicates: %s' % inboxes)
    self.assertSetEqual(set(expected), set(inboxes))
    for inbox in inboxes:
      actor_ref = api.actor_get(api.ROOT, util.get_user_from_topic(inbox))
      if not api.entry_get_safe(actor_ref, entry_ref.keyname()):
        self.fail('An entry not visible by a user was added to their inbox')
    return inboxes
Beispiel #34
0
    def test_photo_upload(self):
        nick = 'popular'
        nick = clean.nick(nick)
        old_avatar = api.actor_get(api.ROOT,
                                   nick).extra.get('icon', 'avatar_default')

        self.login(nick)
        f = open('testdata/test_avatar.jpg')
        r = self.client.post(
            '/welcome/1', {
                'imgfile': f,
                '_nonce': util.create_nonce('popular', 'change_photo'),
            })
        r = self.assertRedirectsPrefix(r, '/welcome/1?')

        new_avatar = api.actor_get(api.ROOT,
                                   nick).extra.get('icon', 'avatar_default')
        self.assertNotEquals(old_avatar, new_avatar)

        self.assertContains(r, 'Avatar uploaded')
        self.assertTemplateUsed(r, 'join/templates/welcome_photo.html')
        self.assertTemplateUsed(r, 'common/templates/flash.html')
Beispiel #35
0
def login_noreally(request):
  if 'sso_token' in request.GET:
    sso_token = request.GET['sso_token']
    redirect_to = request.GET['redirect_to']
    redirect_to = clean.redirect_to(redirect_to)

    nick, rememberme = cache.get('sso/%s' % sso_token)
    cache.delete('sso/%s' % sso_token)
    actor_ref = api.actor_get(api.ROOT, nick)
    response = http.HttpResponseRedirect(redirect_to)
    response = user.set_user_cookie(response, actor_ref, rememberme)
    return response
  return http.HttpResponseRedirect('/login')
Beispiel #36
0
  def test_settings_upload_avatar(self):
    nick = 'obligated'
    self.login(nick)

    nick = clean.nick(nick)
    old_contact_avatars = api.actor_get_contacts_avatars_since(api.ROOT, nick)
    contacts = api.actor_get_contacts(api.ROOT, nick)
    self.assertEquals(len(old_contact_avatars), len(contacts) + 1)
    old_avatar = api.actor_get(api.ROOT, nick).extra.get('icon',
                                                         'avatar_default')
    start_time = api.utcnow()
    no_contact_avatars = api.actor_get_contacts_avatars_since(api.ROOT, nick,
                                                              since_time=start_time)
    self.assertEquals(len(no_contact_avatars), 0)

    # TODO(teemu): add more tests for different file types (gif and jpg).
    # Alternatively, test those against api.avatar_upload.
    f = open('testdata/test_avatar.jpg')
    r = self.client.post('/user/obligated/settings/photo',
                         {
                           'imgfile': f,
                           '_nonce' :
                              util.create_nonce('obligated', 'change_photo'),
                         })
    r = self.assertRedirectsPrefix(r, '/user/obligated/settings/photo')

    actor_ref = api.actor_get(api.ROOT, nick)
    new_avatar = actor_ref.extra.get('icon', 'avatar_default')
    self.assertNotEquals(old_avatar, new_avatar)
    self.assertTrue(actor_ref.avatar_updated_at >= start_time)
    new_contact_avatars = api.actor_get_contacts_avatars_since(api.ROOT, nick,
                                                               since_time=start_time)
    self.assertEquals(len(new_contact_avatars), 1)
    self.assertEquals(new_contact_avatars.pop().nick, nick)

    self.assertContains(r, 'Avatar uploaded')
    self.assertTemplateUsed(r, 'actor/templates/settings_photo.html')
    self.assertTemplateUsed(r, 'common/templates/flash.html')
Beispiel #37
0
    def test_settings_upload_avatar(self):
        nick = 'obligated'
        self.login(nick)

        nick = clean.nick(nick)
        old_contact_avatars = api.actor_get_contacts_avatars_since(
            api.ROOT, nick)
        contacts = api.actor_get_contacts(api.ROOT, nick)
        self.assertEquals(len(old_contact_avatars), len(contacts) + 1)
        old_avatar = api.actor_get(api.ROOT,
                                   nick).extra.get('icon', 'avatar_default')
        start_time = api.utcnow()
        no_contact_avatars = api.actor_get_contacts_avatars_since(
            api.ROOT, nick, since_time=start_time)
        self.assertEquals(len(no_contact_avatars), 0)

        # TODO(teemu): add more tests for different file types (gif and jpg).
        # Alternatively, test those against api.avatar_upload.
        f = open('testdata/test_avatar.jpg')
        r = self.client.post(
            '/user/obligated/settings/photo', {
                'imgfile': f,
                '_nonce': util.create_nonce('obligated', 'change_photo'),
            })
        r = self.assertRedirectsPrefix(r, '/user/obligated/settings/photo')

        actor_ref = api.actor_get(api.ROOT, nick)
        new_avatar = actor_ref.extra.get('icon', 'avatar_default')
        self.assertNotEquals(old_avatar, new_avatar)
        self.assertTrue(actor_ref.avatar_updated_at >= start_time)
        new_contact_avatars = api.actor_get_contacts_avatars_since(
            api.ROOT, nick, since_time=start_time)
        self.assertEquals(len(new_contact_avatars), 1)
        self.assertEquals(new_contact_avatars.pop().nick, nick)

        self.assertContains(r, 'Avatar uploaded')
        self.assertTemplateUsed(r, 'actor/templates/settings_photo.html')
        self.assertTemplateUsed(r, 'common/templates/flash.html')
Beispiel #38
0
def get_api_user_from_oauth_request(oauth_request):
  oauth_token = oauth_request.get_parameter('oauth_token')
  oauth_consumer = oauth_request.get_parameter('oauth_consumer_key')
  
  if oauth_token == ROOT_TOKEN.key:
    return api.ROOT
  
  token_ref = api.oauth_get_access_token(api.ROOT, oauth_token)
  if not token_ref:
    return None
  
  actor_ref = api.actor_get(api.ROOT, token_ref.actor)
  actor_ref.access_level = token_ref.perms
  return actor_ref
Beispiel #39
0
 def check_pshb_for_entry(self, entry_ref):
   if entry_ref.is_comment():
     self.assertEqual(0, len(pshb.outbox), 'no pshb for comments')
     return
   if entry_ref.is_channel():
     self.assertEqual(0, len(pshb.outbox), 'no pshb for channels (yet)')
     return
   owner_ref = api.actor_get(api.ROOT, entry_ref.owner)
   feed_url = owner_ref.url('/atom')
   check = set([(endpoint, (feed_url,)) for endpoint in self.pshb_endpoints])
   if len(check) > 0:
     self.assertSetEqual(check, set(pshb.outbox))
   else:
     self.fail('Bad test, no pshb to check')
Beispiel #40
0
  def test_photo_upload(self):
    nick = 'popular'
    nick = clean.nick(nick)
    old_avatar = api.actor_get(api.ROOT, nick).extra.get('icon', 
                                                         'avatar_default')

    self.login(nick)
    f = open('testdata/test_avatar.jpg')
    r = self.client.post('/welcome/1',
                         {
                           'imgfile': f,
                           '_nonce' :
                              util.create_nonce('popular', 'change_photo'),
                         })
    r = self.assertRedirectsPrefix(r, '/welcome/1?')

    new_avatar = api.actor_get(api.ROOT, nick).extra.get('icon', 
                                                         'avatar_default')
    self.assertNotEquals(old_avatar, new_avatar)

    self.assertContains(r, 'Avatar uploaded')
    self.assertTemplateUsed(r, 'join/templates/welcome_photo.html')
    self.assertTemplateUsed(r, 'common/templates/flash.html')
Beispiel #41
0
def get_api_user_from_oauth_request(oauth_request):
    oauth_token = oauth_request.get_parameter('oauth_token')
    oauth_consumer = oauth_request.get_parameter('oauth_consumer_key')

    if oauth_token == ROOT_TOKEN.key:
        return api.ROOT

    token_ref = api.oauth_get_access_token(api.ROOT, oauth_token)
    if not token_ref:
        return None

    actor_ref = api.actor_get(api.ROOT, token_ref.actor)
    actor_ref.access_level = token_ref.perms
    return actor_ref
Beispiel #42
0
 def check_pshb_for_entry(self, entry_ref):
     if entry_ref.is_comment():
         self.assertEqual(0, len(pshb.outbox), 'no pshb for comments')
         return
     if entry_ref.is_channel():
         self.assertEqual(0, len(pshb.outbox), 'no pshb for channels (yet)')
         return
     owner_ref = api.actor_get(api.ROOT, entry_ref.owner)
     feed_url = owner_ref.url('/atom')
     check = set([(endpoint, (feed_url, ))
                  for endpoint in self.pshb_endpoints])
     if len(check) > 0:
         self.assertSetEqual(check, set(pshb.outbox))
     else:
         self.fail('Bad test, no pshb to check')
Beispiel #43
0
    def test_settings_change_avatar(self):
        nick = 'obligated'
        self.login(nick)

        nick = clean.nick(nick)
        old_avatar = api.actor_get(api.ROOT,
                                   nick).extra.get('icon', 'avatar_default')

        # TODO(teemu): add more tests for different file types (gif and jpg).
        # Alternatively, test those against api.avatar_upload.
        r = self.client.post(
            '/user/obligated/settings/photo', {
                'avatar': 'default/animal_9',
                '_nonce': util.create_nonce('obligated', 'change_photo'),
            })
        r = self.assertRedirectsPrefix(r, '/user/obligated/settings/photo')

        new_avatar = api.actor_get(api.ROOT,
                                   nick).extra.get('icon', 'avatar_default')
        self.assertNotEquals(old_avatar, new_avatar)

        self.assertContains(r, 'Avatar changed')
        self.assertTemplateUsed(r, 'actor/templates/settings_photo.html')
        self.assertTemplateUsed(r, 'common/templates/flash.html')
Beispiel #44
0
 def assert_valid_actor_get_response(self, params):
   xml = xmlrpclib.dumps((params,), 'actor_get')
   response = self.client.post('/api/xmlrpc', xml, 'text/xml')
   rv = xmlrpclib.loads(response.content)
   actor = api.actor_get(api.ROOT, 'popular')
   expected = {
       'actor': {'avatar_updated_at': '2001-01-01 00:00:00',
                 'extra': {'follower_count': 4,
                           'contact_count': 2,
                           'icon': 'default/animal_3'},
                 'privacy': 3,
                 'nick': '*****@*****.**',
                 'deleted_at': None,
                 'type': 'user' }
       }
   self.assertEquals(expected, rv[0][0])
Beispiel #45
0
def invite_email(request, code):
    """User has received the invite email, and has followed the link to accept or
     or refuse it."""

    if request.user:
        handled = common_views.handle_view_action(
            request, {
                'invite_accept': request.user.url('/overview'),
                'invite_reject': request.user.url('/overview')
            })
        if handled:
            return handled

    # Retrieve the invite
    invite = api.invite_get(api.ROOT, code)
    from_actor = invite.from_actor

    # Translate the from_actor into a display name
    from_actor_ref = api.actor_get(api.ROOT, from_actor)
    view = from_actor_ref

    if not from_actor_ref:
        # Corner case: from_actor was deleted since the invite was sent.
        # In this case, do we want to consider the invitation invalid?
        # (probably we do, because it's more likely that it was spam)
        return util.RedirectError("That invite is no longer valid")

    # We use api.ROOT in the next set of functions because the
    # invite is giving possibly private access to the user
    inbox = api.inbox_get_actor_contacts(api.ROOT, view.nick, limit=5)
    entries = api.entry_get_entries(api.ROOT, inbox)
    stream_keys = [e.stream for e in entries]
    streams = api.stream_get_streams(api.ROOT, stream_keys)
    actor_nicks = ([view.nick] + [s.owner for s in streams.values() if s] +
                   [e.owner for e in entries] + [e.actor for e in entries])
    actors = api.actor_get_actors(api.ROOT, actor_nicks)

    streams = display.prep_stream_dict(streams, actors)
    entries = display.prep_entry_list(entries, streams, actors)

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

    t = loader.get_template('invite/templates/email.html')
    return http.HttpResponse(t.render(c))
Beispiel #46
0
def install(request):
  try:
    root_user = api.actor_get(api.ROOT, settings.ROOT_NICK)
    if root_user:
      return util.RedirectFlash('/', 'Already Installed')
  except:
    root_user = None

  post_name = util.get_metadata('POST_NAME')
  default_channel = util.get_metadata('DEFAULT_CHANNEL')

  if request.POST:
    site_name = request.POST.get('site_name', None)
    tagline = request.POST.get('tagline', None)
    post_name = request.POST.get('post_name', None)

    root_mail = request.POST.get('root_mail', None)
    password = request.POST.get('password', None)
    confirm =  request.POST.get('confirm', None)
    default_channel = request.POST.get('default_channel', None)

    try:
      logging.info('saving values')
      validate.nonce(request, 'install')
      validate.email(root_mail)
      validate.password(password)
      validate.password_and_confirm(password, confirm)
      channel = clean.channel(default_channel)

      admin_helper.validate_and_save_sitesettings(site_name, tagline, post_name)
      root_user = api.user_create_root(api.ROOT, password=password)
      api.email_associate(api.ROOT, root_user.nick, root_mail)
      channel_ref = api.channel_create(api.ROOT, nick=api.ROOT.nick, channel=channel, tags=[],
                                       type='', description='Support Channel')
      util.set_metadata('DEFAULT_CHANNEL', default_channel)

      logging.info('Installed and Redirecting to front')
      return util.RedirectFlash('/', 'Installed Successfully')
    except:
      exception.handle_exception(request)

  redirect_to = '/'

  c = template.RequestContext(request, locals())
  return render_to_response('administration/templates/install.html', c)
Beispiel #47
0
  def test_task_post_process_any(self):
    """ test that api.post creates a task and additional calls resume
    """
    nick = '*****@*****.**'
    uuid = 'HOWNOW'
    message = 'BROWNCOW'

    actor_ref = api.actor_get(api.ROOT, nick)

    # DROP
    old_max = api.MAX_FOLLOWERS_PER_INBOX
    api.MAX_FOLLOWERS_PER_INBOX = 1

    entry_ref = api.post(actor_ref, nick=nick, uuid=uuid, message=message)
    self.assertEqual(entry_ref.extra['title'], message)
    
    # make sure we can repeat
    two_entry_ref = api.post(actor_ref, nick=nick, uuid=uuid, message=message)
    self.assertEqual(entry_ref.uuid, two_entry_ref.uuid)
    
    # and that task_process_actor works
    task_more = api.task_process_any(api.ROOT)
    self.assert_(task_more)

    # and run out the queue
    task_more = api.task_process_any(api.ROOT)
    self.assert_(task_more)
    task_more = api.task_process_any(api.ROOT)
    self.assert_(task_more)
    task_more = api.task_process_any(api.ROOT)
    self.assert_(task_more)
    task_more = api.task_process_any(api.ROOT)
    self.assert_(not task_more)

    def _nope():
      task_more = api.task_process_any(api.ROOT)
    
    self.assertRaises(exception.ApiNoTasks, _nope)

    api.MAX_FOLLOWERS_PER_INBOX = old_max  

    pass
Beispiel #48
0
def badge_badge(request, format, nick):
  view = api.actor_get(request.user, nick)
  
  presence = api.presence_get(request.user, view.nick)
  
  if not presence:
    # look offline please
    line = 'Offline'
    light = 'gray'
    location = ''
  else:
    line = presence.extra.get('status', 'Offline')
    light = presence.extra.get('light', 'gray')
    location = presence.extra.get('location', '')

  if format == 'image':
    # TODO: Create badge images
    return http.HttpResponseRedirect('/images/badge_%s.gif' % light)

  if format == 'js-small':
    multiline = len(line) > 17
    truncated_line = len(line) > 30 and "%s..." % (line[:27]) or line
    content_type = 'text/javascript'
    template_path = 'js_small.js'
  elif format == 'js-medium' or format == 'js-large':
    truncated_line = len(line) > 40 and "%s..." % (line[:27]) or line
    content_type = 'text/javascript'
    template_path = '%s.js' % format.replace('-', '_')
  elif format == 'json':
    # TODO: Create badge.json template
    content_type = 'application/json'
    template_path = 'badge.json'
  elif format == 'xml':
    content_type = 'application/xml'
    # TODO: Create badge.xml template
    template_path = 'badge.xml'

  c = template.RequestContext(request, locals())
  t = loader.get_template('badge/templates/%s' % template_path)
  r = http.HttpResponse(t.render(c))
  r['Content-type'] = content_type
  return r
Beispiel #49
0
 def assert_valid_actor_get_response(self, params):
     xml = xmlrpclib.dumps((params, ), 'actor_get')
     response = self.client.post('/api/xmlrpc', xml, 'text/xml')
     rv = xmlrpclib.loads(response.content)
     actor = api.actor_get(api.ROOT, 'popular')
     expected = {
         'actor': {
             'avatar_updated_at': '2001-01-01 00:00:00',
             'extra': {
                 'follower_count': 4,
                 'contact_count': 2,
                 'icon': 'default/animal_3'
             },
             'privacy': 3,
             'nick': '*****@*****.**',
             'deleted_at': None,
             'type': 'user'
         }
     }
     self.assertEquals(expected, rv[0][0])
Beispiel #50
0
    def test_invite_email_link(self):
        self.login('popular')
        popular_ref = api.actor_get(api.ROOT, '*****@*****.**')
        r = self.client.post(
            '/user/popular/invite', {
                'email': '*****@*****.**',
                'nick': '*****@*****.**',
                '_nonce': util.create_nonce(popular_ref,
                                            'invite_request_email'),
                'invite_request_email': ''
            })
        r = self.assertRedirectsPrefix(r, '/user/popular/invite')
        self.assertContains(r, 'Invitation sent')
        self.assertTemplateUsed(r, 'actor/templates/invite.html')
        self.assertEqual(len(mail.outbox), 1)

        sent_mail = mail.outbox[0]
        url = tests.get_relative_url(sent_mail.body)

        r = self.login_and_get('hermit', url)
        self.assertTemplateUsed(r, 'invite/templates/email.html')
Beispiel #51
0
  def test_invite_email_link(self):
    self.login('popular')
    popular_ref = api.actor_get(api.ROOT, '*****@*****.**')
    r = self.client.post(
        '/user/popular/invite',
        {'email': '*****@*****.**',
         'nick': '*****@*****.**',
         '_nonce': util.create_nonce(popular_ref, 'invite_request_email'),
         'invite_request_email': ''
         }
        )
    r = self.assertRedirectsPrefix(r, '/user/popular/invite')
    self.assertContains(r, 'Invitation sent')
    self.assertTemplateUsed(r, 'invite.html')
    self.assertEqual(len(mail.outbox), 1)

    sent_mail = mail.outbox[0]
    url = tests.get_relative_url(sent_mail.body)
    
    r = self.login_and_get('hermit', url)
    self.assertTemplateUsed(r, 'email.html')
Beispiel #52
0
def badge_badge(request, format, nick):
  view = api.actor_get(request.user, nick)
  
  presence = api.presence_get(request.user, view.nick)
  
  if not presence:
    # look offline please
    line = 'Offline'
    light = 'gray'
    location = ''
  else:
    line = presence.extra.get('status', 'Offline')
    light = presence.extra.get('light', 'gray')
    location = presence.extra.get('location', '')

  if format == 'image':
    return http.HttpResponseRedirect('/images/badge_%s.gif' % light)

  if format == 'js-small':
    multiline = len(line) > 17
    truncated_line = len(line) > 30 and "%s..." % (line[:27]) or line
    content_type = 'text/javascript'
    template_path = 'js_small.js'
  elif format == 'js-medium' or format == 'js-large':
    truncated_line = len(line) > 40 and "%s..." % (line[:27]) or line
    content_type = 'text/javascript'
    template_path = '%s.js' % format.replace('-', '_')
  elif format == 'json':
    content_type = 'text/javascript'
    template_path = 'badge.json'

  elif format == 'xml':
    content_type = 'application/xml'
    template_path = 'badge.xml'

  c = template.RequestContext(request, locals())
  t = loader.get_template('badge/templates/%s' % template_path)
  r = http.HttpResponse(t.render(c))
  r['Content-type'] = content_type
  return r
Beispiel #53
0
    def test_task_post_process_any(self):
        """ test that api.post creates a task and additional calls resume
    """
        nick = '*****@*****.**'
        uuid = 'HOWNOW'
        message = 'BROWNCOW'

        actor_ref = api.actor_get(api.ROOT, nick)

        # DROP
        old_max = api.MAX_FOLLOWERS_PER_INBOX
        api.MAX_FOLLOWERS_PER_INBOX = 1

        try:
            entry_ref = api.post(actor_ref,
                                 nick=nick,
                                 uuid=uuid,
                                 message=message)
            self.assertEqual(entry_ref.extra['title'], message)

            # make sure we can repeat
            two_entry_ref = api.post(actor_ref,
                                     nick=nick,
                                     uuid=uuid,
                                     message=message)
            self.assertEqual(entry_ref.uuid, two_entry_ref.uuid)

            # and that task_process_any works
            # and run out the queue
            for i in range(5):
                api.task_process_any(api.ROOT, nick)

            self.assertRaises(exception.ApiNoTasks,
                              lambda: api.task_process_actor(api.ROOT, nick))
        finally:
            api.MAX_FOLLOWERS_PER_INBOX = old_max
Beispiel #54
0
    def test_task_crud(self):
        # make a fake task for posting a simple message
        nick = '*****@*****.**'
        action = 'post'
        uuid = 'forever'
        message = 'more'

        actor_ref = api.actor_get(api.ROOT, nick)

        # STOP TIME! OMG!
        test_util.utcnow = lambda: self.now

        # makin
        l = profile.label('api_task_create')
        task_ref = api.task_create(actor_ref,
                                   nick,
                                   action,
                                   uuid,
                                   args=[],
                                   kw={
                                       'nick': nick,
                                       'message': message,
                                       'uuid': uuid
                                   })
        l.stop()

        # grabbin
        l = profile.label('api_task_get (unlocked)')
        task_ref = api.task_get(actor_ref, nick, action, uuid)
        l.stop()

        # grab again, LOCK VILLE
        def _again():
            task_ref = api.task_get(actor_ref, nick, action, uuid)

        l = profile.label('api_task_get (locked)')
        self.assertRaises(exception.ApiLocked, _again)
        l.stop()

        # increment time
        new_now = self.now + self.delta
        test_util.utcnow = lambda: new_now

        # grab again, EXPIRED
        task_ref = api.task_get(actor_ref, nick, action, uuid)

        # locked if we try again
        self.assertRaises(exception.ApiLocked, _again)

        # updatin
        l = profile.label('api_task_update')
        task_ref = api.task_update(actor_ref, nick, action, uuid, '1')
        l.stop()
        self.assertEqual(task_ref.progress, '1')

        # grab again, FRESH AND CLEAN
        task_ref = api.task_get(actor_ref, nick, action, uuid)
        self.assertEqual(task_ref.progress, '1')

        # removin
        l = profile.label('api_task_remove')
        api.task_remove(actor_ref, nick, action, uuid)
        l.stop()

        # grab again, NOT FOUND
        def _not_found():
            task_ref = api.task_get(actor_ref, nick, action, uuid)

        self.assertRaises(exception.ApiNotFound, _not_found)
Beispiel #55
0
    progress
    args (picked list)
    kw (pickled dict)
  
  It will map to an api call (action) that will be called with 
  (actor, _task_ref=task_ref, *args, **kw) as arguments.
  """
    try:
        task_ref = api.Task.from_request(request)
    except Exception, e:
        logging.exception('Unhandled exception while building task ref')
        logging.warning('request.post %s', request.POST)
        return http.HttpResponse('')

    try:
        actor_ref = api.actor_get(api.ROOT, task_ref.actor)
        method_ref = api.PublicApi.get_method(task_ref.action)
        method_ref(actor_ref,
                   _task_ref=task_ref,
                   *task_ref.args,
                   **task_ref.kw)
    except exception.Error:
        logging.exception('Unexpected error while processing queue:')
    return http.HttpResponse('')


def _model_to_dict(rv):
    # TODO(mikie): This must be replaced with a to_dict() on the model object so
    # that we can remove/add fields and change representations if needed.
    o = {}
    if not rv:
Beispiel #56
0
 def setUp(self):
     super(ThrottleTest, self).setUp()
     self.popular = api.actor_get(api.ROOT, '*****@*****.**')
Beispiel #57
0
def common_listings(request, nick, listings, template_name):
    view = api.actor_get(api.ROOT, nick)
    if request.POST:
        logging.info("Post Request: %s" % request.POST)
        try:
            # Add Listing Action
            logging.info("Action: %s" % request.POST.get("action"))
            if request.POST.get("action") == "add_listing":
                author = view.nick
                logging.info(
                    "Calling Create Listing - Params: %s, Author: %s" %
                    (request.POST, author))
                address = request.POST.get("address")
                price = request.POST.get("price")
                baths = request.POST.get("baths")
                beds = request.POST.get("beds")
                size = request.POST.get("size")
                description = request.POST.get("description")
                property_type = request.POST.get("property_type")
                amenities = request.POST.get("amenities")
                tag = request.POST.get("tag")
                galleryUrl = request.POST.get("galleryUrl")
                handled = api.add_listing(address, price, baths, beds, size,
                                          description, property_type,
                                          amenities, author, tag, galleryUrl)

        # Edit Listings Page
            if request.POST.get("action") == "edit_listing":
                author = view.nick
                logging.info(
                    "Calling Edit Listing - Params: %s, Author: %s, Key: %s" %
                    (request.POST, author, request.POST.get("id")))
                id = request.POST.get("id")
                address = request.POST.get("address")
                price = request.POST.get("price")
                baths = request.POST.get("baths")
                beds = request.POST.get("beds")
                size = request.POST.get("size")
                description = request.POST.get("description")
                property_type = request.POST.get("property_type")
                amenities = request.POST.get("amenities")
                tag = request.POST.get("tag")
                galleryUrl = request.POST.get("galleryUrl")
                handled = api.edit_listing(id, address, price, baths, beds,
                                           size, description, property_type,
                                           amenities, author, tag, galleryUrl)

            return util.RedirectFlash(view.url() + '/settings/listings',
                                      'listings updated')
        except:
            exception.handle_exception(request)

    if request.GET and 'restore' in request.GET:
        api.background_clear_actor(request.user, nick)
        return util.RedirectFlash(view.url() + '/settings/listings',
                                  'listings updated')

    model = {}

    if request.GET.get("action") == "edit" and request.GET.get("id"):
        editListingId = request.GET.get("id")
        if editListingId:
            key = Key(editListingId)
            logging.info("ID: %s" % key)
            obj = db.get(key)
            model['edit'] = obj

    model['listings'] = listings
    logging.info("Model: %s" % model)
    t = loader.get_template(template_name)
    return http.HttpResponse(t.render(template.RequestContext(request, model)))