Пример #1
0
  def populate(self, redirect, request, args, kwargs):
    """Populates the fields in the RequestData object.

    Args:
      request: Django HTTPRequest object.
      args & kwargs: The args and kwargs django sends along.
    """
    self.redirect = redirect
    self.request = request
    self.args = args
    self.kwargs = kwargs
    self.GET = request.GET
    self.POST = request.POST
    self.path = request.path.encode('utf-8')
    self.full_path = request.get_full_path().encode('utf-8')
    # XSRF middleware already retrieved it for us
    if not hasattr(request, 'site'):
      request.site = site.singleton()
    self.site = request.site
    self.user = user.current()
    if users.is_current_user_admin():
      self.is_developer = True
    if self.user and self.user.is_developer:
      self.is_developer = True
    self.gae_user = users.get_current_user()
Пример #2
0
  def wrapped(self):
    """Decorator wrapper method.
    """
    link_id = clean_link_id(field_name)(self)

    user_entity = user.current()
    # pylint: disable=E1103
    if not user_entity or user_entity.link_id != link_id:
      # this user is not the current user
      raise forms.ValidationError("This user is not you.")

    return user_entity if as_user else link_id
Пример #3
0
  def wrapped(self):
    """Decorator wrapper method.
    """
    clean_user_field = clean_existing_user(field_name)
    user_entity = clean_user_field(self)

    current_user_entity = user.current()
    # pylint: disable=E1103
    if user_entity.key() == current_user_entity.key():
      # users are equal
      raise forms.ValidationError("You cannot enter yourself here.")

    return user_entity
Пример #4
0
  def user(self):
    """Returns the user field."""
    if not self._isSet(self._user):
      self._user = user_logic.current()

      # developer may view the page as another user
      if self._user and user_logic.isDeveloper(user=self._user):
        settings = settings_logic.getUserSettings(
            ndb.Key.from_old_key(self._user.key()))
        if settings.view_as is not None:
          user = user_model.User.get(settings.view_as.to_old_key())
          if user:
            self._user = user
          else:
            # TODO(daniel): use main LINKER object when merged
            linker = links.Linker()
            user_settings_url = linker.user(
                self._user, urls.UrlNames.USER_SETTINGS)
            raise exception.BadRequest(
                message=VIEW_AS_USER_DOES_NOT_EXIST % user_settings_url)

    return self._user
Пример #5
0
def as_comment(context, comment):
  """Returns a HTML representation of a comment.
  """

  edit_link = ''
  current_user = user.current()
  # pylint: disable=E1103
  if current_user and comment.author.key() == current_user.key():
    params = {'url_name': context['comment_on_url_name']}
    edit_link = redirects.getEditRedirect(comment, params)

  context.update({
      'author': comment.author.name,
      'content': comment.content,
      'created': comment.created,
      'edit_link': edit_link,
      'modified_on': comment.modified,
      'modified_by': comment.modified_by.name if comment.modified_by else '',
      'comment_class': "public" if comment.is_public else "private",
      })

  return context