Exemple #1
0
  def post(self, data, check, mutator):
    """See base.RequestHandler.post for specification."""
    form = UserSettingsForm(data=data.POST)
    if form.is_valid():
      view_as = form.cleaned_data['view_as'] or None

      settings_logic.setUserSettings(data.url_ndb_user.key, view_as=view_as)

      return http.HttpResponseRedirect(data.request.get_full_path())
    else:
      # TODO(nathaniel): problematic self-use.
      return self.get(data, check, mutator)
Exemple #2
0
    def post(self, data, check, mutator):
        """See base.RequestHandler.post for specification."""
        form = UserSettingsForm(data=data.POST)
        if form.is_valid():
            view_as = form.cleaned_data['view_as'] or None

            settings_logic.setUserSettings(data.url_ndb_user.key,
                                           view_as=view_as)

            return http.HttpResponseRedirect(data.request.get_full_path())
        else:
            # TODO(nathaniel): problematic self-use.
            return self.get(data, check, mutator)
Exemple #3
0
  def testForNonExistingSettings(self):
    """Tests that new entity is created if there is not one."""
    test_key = ndb.Key('User', 'test_user')
    user_settings = settings_logic.setUserSettings(
        self.user_key, view_as=test_key)

    # check that settings are returned
    self.assertIsNotNone(user_settings)

    # check that property is set correctly
    self.assertEqual(user_settings.view_as, test_key)
Exemple #4
0
  def testForExistingSettings(self):
    """Tests that existing entity is updated."""
    # seed user settings
    properties = {'view_as': ndb.Key('User', 'test_user')}
    user_settings = settings_model.UserSettings(
        parent=self.user_key, **properties).put()

    other_key = ndb.Key('User', 'other_user')
    updated_settings = settings_logic.setUserSettings(
        self.user_key, view_as=other_key)

    # check that no new entity is created
    self.assertEqual(user_settings, updated_settings.key)

    # check that property is updated correctly
    self.assertEqual(updated_settings.view_as, other_key)