示例#1
0
def add_or_edit_redirect(request: Request):
    vm = EditRedirectViewModel(request)

    vm.process_form()
    if vm.error:
        return vm.to_dict()

    if vm.redirect_id:
        cms_service.update_redirect(vm.redirect_id, vm.name, vm.short_url, vm.url)
    else:
        cms_service.create_redirect(vm.name, vm.short_url, vm.url, vm.user.email)

    return HTTPFound('/admin/redirects')
def add_or_edit_redirect(request: Request):
    vm = EditRedirectViewModel(request)

    log.notice(f'User {vm.user.name} adding/updating redirect.')

    vm.process_form()
    if vm.error:
        return vm.to_dict()

    if vm.redirect_id:
        cms_service.update_redirect(vm.redirect_id, vm.name, vm.short_url,
                                    vm.url)
    else:
        cms_service.create_redirect(vm.name, vm.short_url, vm.url,
                                    vm.user.email)

    log.notice(
        f'User {vm.user.name} added/updated new redirect: {vm.name} @ {vm.short_url}.'
    )

    return HTTPFound('/admin/redirects')