def test_set_qparam_multiple():
    qs = 'a=1&b=3&c=4'
    ret = mod.set_qparam(mod.set_qparam(qs, a=2), b=4)
    assert 'a=2' in str(ret)
    assert 'a=1' not in str(ret)
    assert 'b=4' in str(ret)
    assert 'b=3' not in str(ret)
Beispiel #2
0
def reset():
    next_path = request.params.get('next', '/')
    form = PasswordResetForm(request.params)
    if request.user.is_authenticated:
        # Set arbitrary non-empty value to prevent form error. We don't really
        # care about this field otherwise.
        form.reset_token.bind_value('not needed')
    if not form.is_valid():
        return dict(next_path=next_path, form=form)
    if request.user.is_authenticated:
        username = request.user.username
    else:
        user = get_user_by_reset_token(form.processed_data['reset_token'])
        if not user:
            form._error = ValidationError('invalid_token', {'value': ''})
            return dict(next_path=next_path, form=form)
        username = user.username
    set_password(username, form.processed_data['password1'])
    if request.user.is_authenticated:
        request.user.logout()
    login_url = i18n_url('auth:login_form') + set_qparam(
        next=next_path).to_qs()
    return template('feedback.tpl',
                    # Translators, used as page title on feedback page
                    page_title=_('New password was set'),
                    # Translators, used as link label on feedback page in "You
                    # will be taken to log-in page..."
                    redirect_target=_('log-in page'),
                    # Translators, shown after password has been changed
                    message=_("Password for username '%(username)s' has been "
                              "set.") % {'username': username},
                    status='success',
                    redirect_url=login_url)
def reset():
    next_path = request.params.get('next', '/')
    form = PasswordResetForm(request.params)
    if request.user.is_authenticated:
        # Set arbitrary non-empty value to prevent form error. We don't really
        # care about this field otherwise.
        form.reset_token.bind_value('not needed')
    if not form.is_valid():
        return dict(next_path=next_path, form=form)
    if request.user.is_authenticated:
        username = request.user.username
    else:
        user = User.from_reset_token(form.processed_data['reset_token'])
        if not user:
            form._error = ValidationError('invalid_token', {'value': ''})
            return dict(next_path=next_path, form=form)
        username = user.username
    User.set_password(username, form.processed_data['password1'])
    if request.user.is_authenticated:
        request.user.logout()
    login_url = i18n_url('auth:login_form') + set_qparam(
        next=next_path).to_qs()
    return template(
        'ui/feedback.tpl',
        # Translators, used as page title on feedback page
        page_title=_('New password was set'),
        # Translators, used as link label on feedback page in "You
        # will be taken to log-in page..."
        redirect_target=_('log-in page'),
        # Translators, shown after password has been changed
        message=_("Password for username '{username}' has been "
                  "set.").format(username=username),
        status='success',
        redirect_url=login_url)
def content_detail(path, meta):
    """Update view statistics and redirect to an opener."""
    archive = open_archive()
    archive.add_view(meta.path)
    # as mixed content is possible in zipballs, it is allowed to specify which
    # content type is being viewed now explicitly, falling back to the first
    # one found in the content object
    content_type = request.params.get('content_type')
    if content_type is None:
        # pick first available content type present in content object as it was
        # not specified
        content_type = meta.content_type_names[0]

    url = i18n_url('files:path', path=meta.path)
    openers = request.app.supervisor.exts.openers
    opener_id = openers.first(content_type=content_type)
    # if there is no opener registered for this content_type, it will just
    # redirect to the file manager
    if opener_id:
        # found registered opener for content_type, so use it for displaying
        # the content item
        url += set_qparam(action='open', opener_id=opener_id).to_qs()

    if request.is_xhr:
        return str(url)

    return redirect(url)
def content_detail(path, meta):
    """Update view statistics and redirect to an opener."""
    archive = open_archive()
    archive.add_view(meta.path)
    # as mixed content is possible in zipballs, it is allowed to specify which
    # content type is being viewed now explicitly, falling back to the first
    # one found in the content object
    content_type = request.params.get('content_type')
    if content_type is None:
        # pick first available content type present in content object as it was
        # not specified
        content_type = meta.content_type_names[0]

    url = i18n_url('files:path', path=meta.path)
    openers = request.app.supervisor.exts.openers
    opener_id = openers.first(content_type=content_type)
    # if there is no opener registered for this content_type, it will just
    # redirect to the file manager
    if opener_id:
        # found registered opener for content_type, so use it for displaying
        # the content item
        url += set_qparam(action='open', opener_id=opener_id).to_qs()

    if request.is_xhr:
        return str(url)

    return redirect(url)
Beispiel #6
0
 def add_next_parameter(self, base_url):
     next_params = {self.next_url_parameter_name: self.get_next_path()}
     return base_url + set_qparam(**next_params).to_qs()
 def add_next_parameter(self, base_url):
     next_params = {self.next_url_parameter_name: self.get_next_path()}
     return base_url + set_qparam(**next_params).to_qs()
def test_set_qparam_default(request):
    request.query_string = 'a=1&b=2'
    ret = mod.set_qparam(a=2)
    assert 'a=2' in str(ret)
    assert 'b=2' in str(ret)
    assert 'a=1' not in str(ret)
def test_set_qparam_unicode_coercion():
    qs = 'a=1&b=3&c=4'
    ret = mod.set_qparam(qs, a=0)
    assert 'a=0' in str(ret)
    assert 'a=1' not in str(ret)
def test_set_qparam():
    qs = 'a=1&b=3&c=4'
    ret = mod.set_qparam(qs, a='0')
    assert 'a=0' in str(ret)
    assert 'a=1' not in str(ret)