예제 #1
0
def test_i18n_path(req):
    req.locale = 'en_US'
    s = mod.i18n_path('/foo')
    assert s == '/en_US/foo'
    req.locale = 'es_ES'
    s = mod.i18n_path('/foo')
    assert s == '/es_ES/foo'
예제 #2
0
def update_content_details(id):
    content = get_content_or_404(id)

    if not content.is_editable:
        # Translators, shown when content is not editable (it's on air, etc)
        response.flash(_('This content is not editable'))
        redirect(i18n_path(content.path))

    errors = {}

    title = request.forms.getunicode('title', '').strip()
    license = request.forms.get('license') or None

    if not content.title and not title:
        errors['title'] = _('Title cannot be blank')

    if license and license not in Content.LICENSE_CHOICES:
        errors['license'] = _('Please select a license from provided choices')

    if not errors:
        to_put = []
        if title and content.title != title:
            content.title = title
            to_put.append(Event.create(Event.TITLE, content.key))
        if license and content.license != license:
            content.license = license
            to_put.append(Event.create(Event.LICENSE, content.key))
        if to_put:
            # If we have events in to_put list, we also need to put the content
            to_put.append(content)
        ndb.put_multi(to_put)
        response.flash(_('Content has been updated'))
        redirect(content.path)

    return dict(vals=request.forms, errors=erorrs, content=content)
예제 #3
0
def update_content_details(id):
    to_put = []
    content = get_content_or_404(id)
    ref_path = i18n_path(request.forms.get('back', content.path))

    if not content.is_editable:
        response.flash(
            _('Voting is disabled for content that is being '
              'broadcast'))
        redirect(ref_path)

    vote = request.forms.get('vote')

    if vote not in ['up', 'down']:
        response.flash(
            _('There was a problem with the request. Please try '
              'again later.'))
        redirect(ref_path)

    if vote == 'up':
        content.upvotes += 1
        to_put.append(Event.create(Event.UPVOTE, content.key))
    elif vote == 'down':
        content.downvotes += 1
        to_put.append(Event.create(Event.DOWNVOTE, content.key))
    to_put.append(content)
    ndb.put_multi(to_put)
    redirect(ref_path)
예제 #4
0
def update_content_details(id):
    content = get_content_or_404(id)

    if not content.is_editable:
        # Translators, shown when content is not editable (it's on air, etc)
        response.flash(_('This content is not editable'))
        redirect(i18n_path(content.path))

    errors = {}

    title = request.forms.getunicode('title', '').strip()
    license = request.forms.get('license') or None

    if not content.title and not title:
        errors['title'] = _('Title cannot be blank')

    if license and license not in Content.LICENSE_CHOICES:
        errors['license'] = _('Please select a license from provided choices')

    if not errors:
        to_put = []
        if title and content.title != title:
            content.title = title
            to_put.append(Event.create(Event.TITLE, content.key))
        if license and content.license != license:
            content.license = license
            to_put.append(Event.create(Event.LICENSE, content.key))
        if to_put:
            # If we have events in to_put list, we also need to put the content
            to_put.append(content)
        ndb.put_multi(to_put)
        response.flash(_('Content has been updated'))
        redirect(content.path)

    return dict(vals=request.forms, errors=erorrs, content=content)
예제 #5
0
def update_content_details(id):
    to_put = []
    content = get_content_or_404(id)
    ref_path = i18n_path(request.forms.get('back', content.path))

    if not content.is_editable:
        response.flash(_('Voting is disabled for content that is being '
                         'broadcast'))
        redirect(ref_path)

    vote = request.forms.get('vote')

    if vote not in ['up', 'down']:
        response.flash(_('There was a problem with the request. Please try '
                         'again later.'))
        redirect(ref_path)

    if vote == 'up':
        content.upvotes += 1
        to_put.append(Event.create(Event.UPVOTE, content.key))
    elif vote == 'down':
        content.downvotes += 1
        to_put.append(Event.create(Event.DOWNVOTE, content.key))
    to_put.append(content)
    ndb.put_multi(to_put)
    redirect(ref_path)
예제 #6
0
def update_details(urlid):
    content = get_content_or_404(urlid)
    title = request.forms.getunicode('title', '').strip()
    license = request.forms.get('license')
    partner = request.forms.getunicode('partner', '').strip()
    flags = request.forms.getall('flags')
    replaces = request.forms.get('replaces', '').strip()
    is_partner = 'is_partner' in flags

    errors = {}

    if not title:
        errors['title'] = _('Title cannot be blank')

    if not errors:
        content.populate(title=title,
                         license=license,
                         partner=partner or None,
                         replaces=replaces or None,
                         is_partner=is_partner)
        content.put()
        response.flash(_('Content details have been updated'))
        redirect(i18n_path(content.admin_path))

    return dict(vals=request.forms, errors=errors, content=content)
예제 #7
0
def login():
    next_path = request.params.get('next', '/')

    form = LoginForm(request.params)
    if form.is_valid():
        return http_redirect(i18n_path(next_path))

    return dict(next_path=next_path, form=form)
예제 #8
0
    def apply(self):
        language = request.user.options.get('language')
        i18n_prefix = '/{0}/'.format(request.locale)
        # redirect only requests without a locale prefixed path
        if language and not request.original_path.startswith(i18n_prefix):
            redirect(i18n_path(locale=language))

        request.user.options['language'] = request.locale
예제 #9
0
def login():
    next_path = request.params.get('next', '/')

    form = LoginForm(request.params)
    if form.is_valid():
        request.user.options.process('language')
        return http_redirect(i18n_path(next_path))

    return dict(next_path=next_path, form=form)
예제 #10
0
def login():
    next_path = request.params.get('next', '/')

    form = LoginForm(request.params)
    if form.is_valid():
        request.user.options.process('language')
        return http_redirect(i18n_path(next_path))

    return dict(next_path=next_path, form=form)
예제 #11
0
 def redirect_to_step(self):
     query = '?{0}={1}'.format(self.step_param, self.current_step_index)
     next_path = i18n_path(request.fullpath + query)
     if request.is_xhr:
         return next_path
     # This is a workaround for a not yet clear issue where if the
     # redirection contains an empty response body, it never reaches
     # the client
     next_url = urlparse.urljoin(request.url, next_path)
     response.set_header('Location', next_url)
     response.status = 302
     return 'OK'
예제 #12
0
def handle_manual_add():
    url = request.params.get('url', '').strip()
    title = request.params.getunicode('title', '').strip()
    license = request.params.get('license') or None
    archive = request.params.get('archive') or None

    errors = {}
    if not url:
        # Translators, used as error message on failure to submit content
        errors['url'] = _('Please type in a valid URL')

    if not errors:
        try:
            content = Content.create(url=url,
                                     license=license,
                                     title=title,
                                     archive=archive)
            logging.info("Created content for '%s' (real url: '%s')", url,
                         content.url)
            response.flash(_('Content has been added'))
            redirect(i18n_path(PREFIX + '/'))
        except Content.InvalidURLError as err:
            logging.debug("URL error while parsing '%s': %s", url, err)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('This URL is invalid')
        except Content.FetchError as err:
            logging.debug("Fetch error while parsing '%s': %s (%s)", url, err,
                          err.error)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('The page at specified URL does not exist')
        except Content.NotAllowedError as err:
            logging.debug("Access error while parsing '%s': %s", url, err)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('The page must be accessible to robots')
        except Content.ContentError as err:
            logging.debug("Content error while parsing '%s': %s (%s)", url,
                          err, err.error)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('The content on the page could not be '
                              'understood, please provide and URL to a valid '
                              'web page')
        except Content.BotError as err:
            logging.exception("Error while fetching '%s':  %s", url, err)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('There was an unknown error with the URL')

    return get_common_context(dict(vals=request.forms, errors=errors))
예제 #13
0
파일: auth.py 프로젝트: benrito/librarian
def login():
    errors = {}
    next_path = request.forms.get('next', '/')

    # Translators, error message shown when user does not supply username
    username = nonempty('username', _('Type in your username'), errors, True)

    # Translators, error message shown when user does not supply password
    password = nonempty('password', _('Type in your password'), errors)

    if errors:
        return dict(next_path=next_path, errors=errors, vals=request.forms)

    if not auth.login_user(username, password):
        errors['_'] = _("Please enter the correct username and password.")
        return dict(next_path=next_path, errors=errors, vals=request.forms)

    return http_redirect(i18n_path(next_path))
예제 #14
0
def update_notes(urlid):
    content = get_content_or_404(urlid)
    notes = request.forms.getunicode('notes', '').strip()
    content.notes = notes
    content.put()
    redirect(i18n_path(content.admin_path))
예제 #15
0
def add_content_suggestion():
    """
    Handle a content suggestion request.
    """
    # TODO: Handle Unicode URLs
    url = Content.validate_url(request.forms.get('url', ''))
    license = request.forms.get('license') or None

    errors = {}

    if not url:
        # Translators, used as error message on failure submit suggestion
        errors['url'] = _('This URL is invalid')

    if license:
        license = license.strip().upper()
        if license not in Content.LICENSE_CHOICES:
            # Translators, used as error message on failure to submit
            # suggestion
            errors['license'] = _('Please select a license from provided '
                                  'choices')

    if not url:
        # Translators, used as error message on failure to submit suggestion
        errors['url'] = _('Please type in a valid URL')

    if not errors:
        try:
            content = Content.create(url=url, license=license)
            logging.info("Created content for '%s' (real url: '%s')", url,
                         content.url)
            response.flash(_('Your suggestion has been added'))
            redirect(i18n_path(content.path))
        except Content.InvalidURLError as err:
            logging.debug("URL error while parsing '%s': %s", url, err)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('This URL is invalid')
        except Content.FetchError as err:
            logging.debug("Fetch error while parsing '%s': %s (%s)", url, err,
                          err.error)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('The page at specified URL does not exist or '
                              'the domain cannot be reached.')
        except Content.NotAllowedError as err:
            logging.debug("Access error while parsing '%s': %s", url, err)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('The page must be accessible to robots')
        except Content.ContentError as err:
            logging.debug("Content error while parsing '%s': %s (%s)", url,
                          err, err.error)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('The content on the page could not be '
                              'understood, please provide and URL to a valid '
                              'web page')
        except Exception as err:
            logging.debug("Unknown error fetching '%s': %s", url, err)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('There was an unknown error with the URL')

    return dict(vals=request.forms,
                errors=errors,
                Content=Content,
                content=get_content_list())
예제 #16
0
def test_i18n_current_path(req):
    req.fullpath = '/foo/bar/baz'
    req.query_string = 'foo=bar'
    s = mod.i18n_path(locale='en_US')
    assert s == '/en_US/foo/bar/baz?foo=bar', "Should return localized path"
예제 #17
0
def test_i18n_custom_locale(req):
    req.locale = 'en_US'
    s = mod.i18n_path('/foo', locale='es_ES')
    assert s == '/es_ES/foo', "Should return specified locale instead"
예제 #18
0
def test_i18n_returns_lazy():
    s = mod.i18n_path('/foo', 'en_US')
    assert is_lazy(s), "Should be a lazy object"
예제 #19
0
 def get_next_url(self):
     next_path = i18n_path(self.get_next_path())
     return urlparse.urljoin(self.request.url, next_path)
예제 #20
0
 def get_next_url(self):
     next_path = i18n_path(self.get_next_path())
     return urlparse.urljoin(self.request.url, next_path)
예제 #21
0
def logout():
    next_path = request.params.get('next', '/')
    request.user.logout()
    http_redirect(i18n_path(next_path))
예제 #22
0
def logout():
    next_path = request.params.get('next', '/')
    request.user.logout()
    http_redirect(i18n_path(next_path))
예제 #23
0
def finish_with_message(message):
    response.flash(message)
    redirect(i18n_path(PREFIX + '/'))
예제 #24
0
def redirect_to_correct_url():
    redirect(i18n_path(PREFIX + '/'))
예제 #25
0
파일: dugnad.py 프로젝트: ireneteix/dugnad
def path(raw):
    return i18n_path(raw)
예제 #26
0
def add_content_suggestion():
    """
    Handle a content suggestion request.
    """
    # TODO: Handle Unicode URLs
    url = Content.validate_url(request.forms.get('url', ''))
    license = request.forms.get('license') or None

    errors = {}

    if not url:
        # Translators, used as error message on failure submit suggestion
        errors['url'] = _('This URL is invalid')

    if license:
        license = license.strip().upper()
        if license not in Content.LICENSE_CHOICES:
            # Translators, used as error message on failure to submit
            # suggestion
            errors['license'] = _('Please select a license from provided '
                                  'choices')

    if not url:
        # Translators, used as error message on failure to submit suggestion
        errors['url'] = _('Please type in a valid URL')

    if not errors:
        try:
            content = Content.create(url=url, license=license)
            logging.info("Created content for '%s' (real url: '%s')", url,
                         content.url)
            response.flash(_('Your suggestion has been added'))
            redirect(i18n_path(content.path))
        except Content.InvalidURLError as err:
            logging.debug("URL error while parsing '%s': %s", url, err)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('This URL is invalid')
        except Content.FetchError as err:
            logging.debug("Fetch error while parsing '%s': %s (%s)",
                          url, err, err.error)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('The page at specified URL does not exist or '
                              'the domain cannot be reached.')
        except Content.NotAllowedError as err:
            logging.debug("Access error while parsing '%s': %s", url, err)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('The page must be accessible to robots')
        except Content.ContentError as err:
            logging.debug("Content error while parsing '%s': %s (%s)", url,
                          err, err.error)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('The content on the page could not be '
                              'understood, please provide and URL to a valid '
                              'web page')
        except Exception as err:
            logging.debug("Unknown error fetching '%s': %s", url, err)
            # Translators, used as error message on failure submit suggestion
            errors['url'] = _('There was an unknown error with the URL')

    return dict(vals=request.forms, errors=errors, Content=Content,
                content=get_content_list())