Python pyramid.httpexceptions.HTTPFound() Examples

The following are 30 code examples of pyramid.httpexceptions.HTTPFound(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyramid.httpexceptions , or try the search function .
Example #1
Source File: account_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 6 votes vote down vote up
def login_post(request: Request):
    data = request_dict.create(request)
    email = data.email
    password = data.password

    user = user_service.login_user(email, password)

    if not user:
        return {
            'email': email,
            'password': password,
            'error': 'The user could not found or the password is incorrect.',
            'user_id': cookie_auth.get_user_id_via_auth_cookie(request)
        }

    cookie_auth.set_auth(request, user.id)
    return x.HTTPFound('/account')


# ################### LOGOUT ################################# 
Example #2
Source File: account_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 6 votes vote down vote up
def login_post(request: Request):
    data = request_dict.create(request)
    email = data.email
    password = data.password

    user = user_service.login_user(email, password)

    if not user:
        return {
            'email': email,
            'password': password,
            'error': 'The user could not found or the password is incorrect.',
            'user_id': cookie_auth.get_user_id_via_auth_cookie(request)
        }

    cookie_auth.set_auth(request, user.id)
    return x.HTTPFound('/account')


# ################### LOGOUT ################################# 
Example #3
Source File: account_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 6 votes vote down vote up
def register_post(request: Request):
    email = request.POST.get('email')
    name = request.POST.get('name')
    password = request.POST.get('password')

    if not email or not name or not password:
        return {
            'email': email,
            'name': name,
            'password': password,
            'error': 'Some required fields are missing.',
            'user_id': cookie_auth.get_user_id_via_auth_cookie(request)
        }

    # create user
    user = user_service.create_user(email, name, password)
    cookie_auth.set_auth(request, user.id)

    return x.HTTPFound('/account')


# ################### LOGIN ################################# 
Example #4
Source File: account_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 6 votes vote down vote up
def register_post(request: Request):
    email = request.POST.get('email')
    name = request.POST.get('name')
    password = request.POST.get('password')

    if not email or not name or not password:
        return {
            'email': email,
            'name': name,
            'password': password,
            'error': 'Some required fields are missing.',
            'user_id': cookie_auth.get_user_id_via_auth_cookie(request)
        }

    # create user
    user = user_service.create_user(email, name, password)
    cookie_auth.set_auth(request, user.id)

    return x.HTTPFound('/account')


# ################### LOGIN ################################# 
Example #5
Source File: views.py    From learning-python with MIT License 6 votes vote down vote up
def login_view(request):
    deform_static.need()

    search_path = ('myShop/templates/deform/',)
    renderer = deform.ZPTRendererFactory(search_path)
    schema = LoginFormSchema(validator=password_validator)
    form = deform.Form(schema, buttons=('submit',), renderer=renderer)

    if 'submit' in request.POST:
        try:
            appstruct = form.validate(request.POST.items())
        except deform.ValidationFailure, e:
            return {
                'title': 'login',
                'form': e.render()
            }

        user = appstruct['login']

        headers = remember(request, user.id)
        return HTTPFound(location='/', headers=headers) 
Example #6
Source File: views.py    From learning-python with MIT License 6 votes vote down vote up
def item_add(request):
    name = request.params.get('name', None)
    category_id = request.matchdict.get('id', None)
    description = request.params.get('description', None)
    price = request.params.get('price', None)
    category = request.db.query(Category). \
        filter_by(id=category_id).first()
    categories = DBSession.query(Category). \
        filter_by(parent=None).all()

    if 'submit' in request.params:
        item = Item()
        item.name = name
        item.price = float(price)
        item.description = description
        item.category = category
        request.db.add(item)
        return HTTPFound(location=request.route_url('category', \
                                                    id=category_id))

    return {
        'title': 'Item Add',
        'categories': categories,
        'category': category,
    } 
Example #7
Source File: __init__.py    From thinkhazard with GNU General Public License v3.0 6 votes vote down vote up
def __call__(self, context, request):
        lang = context['match']['lang']
        if lang not in self.val:
            # Redirect to default language
            raise HTTPFound(
                request.route_url(
                    context['route'].name,
                    **{
                        **context['match'],
                        "lang": request.registry.settings["default_locale_name"],
                    }
                )
            )

        request.response.set_cookie(
            "_LOCALE_", value=lang, max_age=20 * 7 * 24 * 60 * 60
        )
        request.locale_name = lang
        return True 
Example #8
Source File: views.py    From patzilla with GNU Affero General Public License v3.0 6 votes vote down vote up
def get_redirect_query(request, expression=None, query_args=None):

    query_args = query_args or {}

    # FIXME: does not work due reverse proxy anomalies, tune it to make it work!
    #query = '{field}={value}'.format(**locals())
    #return HTTPFound(location=request.route_url('patentsearch', _query={'query': query}))

    # FIXME: this is a hack
    path = '/'
    host = request.headers.get('Host')

    # TODO: at least look this up in development.ini
    if 'localhost:6543' in host:
        path = ''

    redirect_url = path
    if expression:
        query_args.update({'query': expression})

    if query_args:
        redirect_url += '?' + urlencode(query_args)

    return HTTPFound(redirect_url) 
Example #9
Source File: users.py    From travelcrm with GNU General Public License v3.0 5 votes vote down vote up
def view(self):
        if self.request.params.get('rid'):
            resource_id = self.request.params.get('rid')
            user = User.by_resource_id(resource_id)
            return HTTPFound(
                location=self.request.resource_url(
                    self.context, 'view', query={'id': user.id}
                )
            )
        result = self.edit()
        result.update({
            'title': self._get_title(_(u'View')),
            'readonly': True,
        })
        return result 
Example #10
Source File: __init__.py    From thinkhazard with GNU General Public License v3.0 5 votes vote down vote up
def redirect_to_default_language_factory(route_prefix=None):
    def redirect_to_default_language(request):
        """
        A view that redirects path language-free URLs to the browser prefered
        language or default language URLs.

        E.g. /greeter/foobar -> /en/greeter/foobar
        """
        route = request.matched_route.name.replace("_language_redirect_fallback", "")
        return HTTPFound(request.route_path(route, **request.matchdict))

    return redirect_to_default_language 
Example #11
Source File: server.py    From channelstream with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def admin_sign_out(self):
        headers = forget(self.request)
        url = self.request.route_url("admin_action", action="sign_in")
        return HTTPFound(url, headers=headers) 
Example #12
Source File: admin.py    From thinkhazard with GNU General Public License v3.0 5 votes vote down vote up
def admindiv_hazardsets(request):
    hazardtype = request.dbsession.query(HazardType).first()
    return HTTPFound(
        request.route_url(
            "admin_admindiv_hazardsets_hazardtype", hazardtype=hazardtype.mnemonic
        )
    ) 
Example #13
Source File: admin.py    From thinkhazard with GNU General Public License v3.0 5 votes vote down vote up
def technical_rec_delete(request):
    id = request.matchdict["id"]
    obj = request.dbsession.query(TechnicalRecommendation).get(id)
    request.dbsession.delete(obj)
    return HTTPFound(request.route_url("admin_technical_rec")) 
Example #14
Source File: admin.py    From thinkhazard with GNU General Public License v3.0 5 votes vote down vote up
def add_task(request):
    task = request.params.get("task")
    getattr(celery_tasks, task).delay()
    return HTTPFound(request.route_url("admin_index")) 
Example #15
Source File: views.py    From bouncer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def index(request):
    raise httpexceptions.HTTPFound(location=request.registry.settings["hypothesis_url"]) 
Example #16
Source File: admin.py    From thinkhazard with GNU General Public License v3.0 5 votes vote down vote up
def climate_rec_delete(request):
    id = request.matchdict["id"]
    obj = request.dbsession.query(ClimateChangeRecommendation).get(id)
    request.dbsession.delete(obj)
    return HTTPFound(
        request.route_url(
            "admin_climate_rec_hazardtype", hazard_type=obj.hazardtype.mnemonic
        )
    ) 
Example #17
Source File: base_controller.py    From cookiecutter-pyramid-talk-python-starter with MIT License 5 votes vote down vote up
def redirect(self, to_url, permanent=False):
        if permanent:
            raise exc.HTTPMovedPermanently(to_url)
        raise exc.HTTPFound(to_url) 
Example #18
Source File: image_renderer.py    From restful-services-in-pyramid with MIT License 5 votes vote down vote up
def _render(self, value, _):

        adapter = self.adapters.get(type(value))
        if adapter:
            value = adapter(value, None)

        if not isinstance(value, dict):
            raise Exception("Could not convert type {}".format(type(value)))

        image_url = value.get('image')
        if not image_url:
            raise Exception("Could not find URL")

        raise HTTPFound(image_url) 
Example #19
Source File: image_renderer.py    From restful-services-in-pyramid with MIT License 5 votes vote down vote up
def _render(self, value, _):

        adapter = self.adapters.get(type(value))
        if adapter:
            value = adapter(value, None)

        if not isinstance(value, dict):
            raise Exception("Could not convert type {}".format(type(value)))

        image_url = value.get('image')
        if not image_url:
            raise Exception("Could not find URL")

        raise HTTPFound(image_url) 
Example #20
Source File: resource_error.py    From rest_toolkit with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __init__(self, request):
        raise HTTPFound('http://www.wiggy.net') 
Example #21
Source File: error_handlers.py    From channelstream with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def unauthorized_handler(context, request, renderer="json"):
    if (
        request.matched_route
        and request.matched_route.pattern.startswith("/admin")
        or "api-explorer" in request.url
    ):
        url = request.route_url("admin_action", action="sign_in")
        return HTTPFound(url)
    return HTTPForbidden() 
Example #22
Source File: image_renderer.py    From restful-services-in-pyramid with MIT License 5 votes vote down vote up
def _render(self, value, _):

        adapter = self.adapters.get(type(value))
        if adapter:
            value = adapter(value, None)

        if not isinstance(value, dict):
            raise Exception("Could not convert type {}".format(type(value)))

        image_url = value.get('image')
        if not image_url:
            raise Exception("Could not find URL")

        raise HTTPFound(image_url) 
Example #23
Source File: server.py    From channelstream with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def admin_sign_in(self):
        if self.request.method == "POST":
            admin_user = self.request.registry.settings["admin_user"]
            admin_secret = self.request.registry.settings["admin_secret"]
            username = self.request.POST.get("username", "").strip()
            password = self.request.POST.get("password", "").strip()
            if username == admin_user and password == admin_secret:
                headers = remember(self.request, admin_user)
                url = self.request.route_url("admin")
                return HTTPFound(url, headers=headers)
            else:
                # make potential brute forcing non-feasible
                gevent.sleep(0.5)
        return {} 
Example #24
Source File: navigaiton.py    From build-pypi-mongodb-webcast-series with MIT License 5 votes vote down vote up
def redirect_to(url, permanent=False):
    if not permanent:
        raise x.HTTPFound(location=url)
    else:
        raise x.HTTPMovedPermanently(location=url) 
Example #25
Source File: navigaiton.py    From build-pypi-mongodb-webcast-series with MIT License 5 votes vote down vote up
def redirect_to(url, permanent=False):
    if not permanent:
        raise x.HTTPFound(location=url)
    else:
        raise x.HTTPMovedPermanently(location=url) 
Example #26
Source File: navigaiton.py    From build-pypi-mongodb-webcast-series with MIT License 5 votes vote down vote up
def redirect_to(url, permanent=False):
    if not permanent:
        raise x.HTTPFound(location=url)
    else:
        raise x.HTTPMovedPermanently(location=url) 
Example #27
Source File: views.py    From learning-python with MIT License 5 votes vote down vote up
def logout_view(request):
    headers = forget(request)
    return HTTPFound(location='/', headers=headers) 
Example #28
Source File: account_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def login_post(request: Request):
    vm = LoginViewModel(request)
    vm.validate()

    if vm.error:
        return vm.to_dict()

    cookie_auth.set_auth(request, vm.user.id)
    return x.HTTPFound('/account')


# ################### LOGOUT ################################# 
Example #29
Source File: account_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def register_post(request: Request):
    vm = RegisterViewModel(request)
    vm.validate()

    if vm.error:
        return vm.to_dict()

    # create user
    user = user_service.create_user(vm.email, vm.name, vm.password)
    cookie_auth.set_auth(request, user.id)

    return x.HTTPFound('/account')


# ################### LOGIN ################################# 
Example #30
Source File: account_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def index(request):
    vm = AccountHomeViewModel(request)
    if not vm.user:
        return x.HTTPFound('/account/login')

    return vm.to_dict()


# ################### REGISTER #################################