Beispiel #1
0
def home():
    params = get_params(request.args)

    query = params.get('q')
    if query == None:
        return render('home.html', sample_queries=get_sample_queries())
    default_command = params.get('default')

    try:
        commands = builtin_commands
        if user_signed_in():
            user = get_current_user()
            commands = user.commands
            default_command = user.getDefaultCommand()

        return redirect(commands.getRedirectUrl(query, default_command))
    except (NotEnoughArgumentsException, UnknownCommandException,
            UnknownDefaultCommandException) as e:
        return render(
            'command_error.html',
            exception_type=e.__class__.__name__,
            exception=e,
        )
    except MalformedQueryException:
        return redirect(HOME)
Beispiel #2
0
    def test_render(self):
        template = 'template'
        arg = 'arg'
        utils.request = mock()
        utils.request.host_url = 'localhost'
        utils.render_template = mock(return_value='OK')
        self.user_key_exists()

        utils.render(template, arg=arg)
        utils.render_template.assert_called_with(
            template,
            signed_in=True,
            routes=routes,
            host='localhost',
            arg=arg,
        )

        self.no_user_key()
        utils.render(template, arg=arg)
        utils.render_template.assert_called_with(
            template,
            signed_in=False,
            routes=routes,
            host='localhost',
            arg=arg,
        )
Beispiel #3
0
def setup(browser=None):
    no_browser_given = False
    if browser == None:
        browser = request.user_agent.browser
    else:
        no_browser_given = True
    if request.user_agent.platform in supported_platforms or no_browser_given:
        if browser == 'chrome':
            return render('setup_chrome.html')
        if browser == 'firefox':
            return render('setup_firefox.html')
    return render('no_setup.html')
Beispiel #4
0
def commands():
    if user_signed_in():
        user = get_current_user()
        return render(
            'commands.html',
            commands=user.commands.asSortedList(),
            default_command=user.getDefaultCommand(),
            command_limit=Commands.limit,
            csrf_token=get_csrf_token(),
        )

    return render(
        'builtin_commands.html',
        builtin_command_groups=builtin_command_groups,
    )
Beispiel #5
0
def server_error(e):
    if isinstance(e, RedirectException):
        return redirect(e.route)

    # Log the error and stacktrace.
    logging.exception('unhandled exception')
    return render('error.html')
Beispiel #6
0
def pick_commands():
    assert_user_signed_in()

    checkbox_prefix = 'checkbox_'
    checked = {}
    error = None
    if request.method == 'POST':
        try:
            params = get_params(request.form)

            user = get_current_user()
            for k in params.iterkeys():
                if k.startswith(checkbox_prefix):
                    command = builtin_commands.get(k[len(checkbox_prefix):])
                    if command != None:
                        checked[command.name] = True
            for k in sorted(checked.keys()):
                user.commands.add(builtin_commands.get(k))
            user.put()
            return redirect(COMMANDS)
        except ParamException as e:
            error = e.message

    return render(
        'pick_commands.html',
        builtin_command_groups=builtin_command_groups,
        checkbox_prefix=checkbox_prefix,
        checked=checked,
        error=error,
        csrf_token=get_csrf_token(),
    )
Beispiel #7
0
def login_form():
    """
    Show login form.

    If user is already logged in, they will be redirected to index page.
    """

    if current_user.is_authenticated:
        return redirect(url_for('index'))

    next_page = request.args.get('next')

    if next_page and url_parse(next_page).netloc == '':
        session['next_page'] = next_page

    if request.method == 'GET':
        return response(render('auth/login.html'))

    loginform = LoginForm()

    if not loginform.validate():
        flash(loginform.errors, category='form_error')
        return failed_login()

    user = User.by_email_address(loginform.email_id.data)

    if user is None:
        flash('Could not locate your email address', 'login_info')
        return failed_login()

    if not user.check_password(loginform.password.data):
        flash('invalid password', 'login_info')
        return failed_login()

    return _login(user, loginform.remember_me.data)
Beispiel #8
0
def sign_in():
    assert_user_signed_out()

    services = [
        'Facebook',
        'GitHub',
        'Google',
        'Twitter',
    ]

    return render('sign_in.html', services=services)
    def edit_item(item_id):
        item = ICT.get(ICT.decode_id(item_id), True)

        if current_user.id != item.user_id:
            flash('No permission grant to modify this item.', 'form_error')
            return redirect(url('catalog.show_item', item_id=item.hash_id))

        if request.method == 'POST':
            return PageController.update_item(item)

        item = ICT.item_to_dict(item)

        categories = CCT.index()

        return response(
            render('catalog/edit_item.html', item=item, categories=categories))
    def index(category_name=None):
        categories = CCT.index()

        page = request.args.get('page', 1)
        per_page = request.args.get('per_page', 15)

        if category_name:
            url_category = " ".join(category_name.split('_'))
            db_category = CCT.get_by_name(url_category)
            db_items = ICT.index(db_category.id, page=page, per_page=per_page)
        else:
            db_items = ICT.index(page=page, per_page=per_page)

        return response(
            render('catalog/items_list.html',
                   current_category=category_name,
                   items=db_items,
                   categories=categories))
Beispiel #11
0
def edit_command(command_name=None):
    assert_user_signed_in()

    if command_name == None:
        return redirect(NEW_COMMAND_ONLY)

    user = get_current_user()
    command = user.commands.get(command_name)
    if command == None:
        return redirect(NEW_COMMAND_ONLY + command_name)

    params = None
    if request.method == 'POST':
        # remove command, it might be renamed
        user.commands.remove(command.name)
        params = get_params(request.form)
        try:
            save_command(**params)
            return redirect(COMMANDS)
        except ParamException as e:
            params['error'] = e.message
            # add the command back, some other code might use it
            # before response is finalized
            user.commands.add(command)
    else:
        params = {
            'name': command.name,
            'description': command.description,
            'url_pattern': command.url_pattern,
            'default_url': command.default_url,
        }

    params['action'] = EDIT_COMMAND_ONLY + command_name
    params['original_command'] = command_name
    params['csrf_token'] = get_csrf_token()
    params['modifiers'] = modifiers

    return render('new_command.html', **params)
Beispiel #12
0
def new_command(command_name=None):
    assert_user_signed_in()

    params = {}
    if command_name != None:
        user = get_current_user()
        if user.commands.get(command_name) != None:
            return redirect(EDIT_COMMAND_ONLY + command_name)
        params['name'] = command_name

    if request.method == 'POST':
        params = get_params(request.form)
        try:
            save_command(**params)
            return redirect(COMMANDS)
        except ParamException as e:
            params['error'] = e.message

    params['action'] = NEW_COMMAND_ONLY
    params['csrf_token'] = get_csrf_token()
    params['modifiers'] = modifiers

    return render('new_command.html', **params)
Beispiel #13
0
def not_found(e):
    return render('404.html')
    def create_item():
        if request.method == 'POST':
            return PageController.store_item()

        categories = CCT.index()
        return response(render('catalog/add_item.html', categories=categories))
 def show_item(item_id):
     item = ICT.get(ICT.decode_id(item_id))
     return response(render('catalog/show_item.html', item=item))
Beispiel #16
0
def run():
    return render('run.html')