Code Monkey home page Code Monkey logo

flask-breadcrumbs's People

Contributors

alizeepace avatar fmerges avatar jirikuncar avatar kpsherva avatar snorfalorpagus avatar tianhuil avatar tiborsimko avatar utnapischtim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-breadcrumbs's Issues

More than one variable in route causes problems

I try to get to work routes which have more than one variable part with the dynamic list constructors (I can't find an example for that unfortunately). The application works itself, but the links are set wrong. in this specific case, the link on code1 are completely wrong set.

My code to demonstrate the problem (should be executable with python3 app.py. I tried to strip it down to the bone to show the problem, most of the stuff is lend from the few examples):

from flask import Flask, render_template_string, request

from flask_breadcrumbs import Breadcrumbs, register_breadcrumb

breadcrumbs_tpl = """
<div>
{%- for breadcrumb in breadcrumbs -%}
    <a href="{{ breadcrumb.url }}">{{ breadcrumb.text }}</a>
    {{ '| ' if not loop.last }}
{%- endfor -%}
</div>
"""

app = Flask(__name__)
Breadcrumbs(app=app)


@app.route('/')
@register_breadcrumb(app, '.', 'Home')
def index():
    return render_template_string(breadcrumbs_tpl + '<br><a href="topic1">go down</a>')


@app.route('/topic1')
@register_breadcrumb(app, '.topic1', 'Topic 1')
def topic1():
    return render_template_string(breadcrumbs_tpl + '<br><a href="topic1/5">go down</a>')


def code1_dlc(*args, **kwargs):
    code1 = request.view_args['code1']
    return [{'text': code1, 'url': code1}]


@app.route('/topic1/<code1>/')
@register_breadcrumb(app, '.topic1.code1', 'sub_topic1', '', dynamic_list_constructor=code1_dlc)
def sub_topic1(code1):
    return render_template_string(breadcrumbs_tpl + '<br><a href="sub_topic2">go down</a>')


@app.route('/topic1/<code1>/sub_topic2')
@register_breadcrumb(app, '.topic1.code1.sub_topic2', 'sub_topic2')
def sub_topic2(code1):
    return render_template_string(breadcrumbs_tpl + '<br><a href="sub_topic2/7">go down</a>')


def code2_dlc(*args, **kwargs):
    code2 = request.view_args['code2']
    return [{'text': code2, 'url': code2}]


@app.route('/topic1/<code1>/sub_topic2/<code2>')
@register_breadcrumb(app, '.topic1.code1.sub_topic2.code2', '', dynamic_list_constructor=code2_dlc)
def sub_sub_topic2(code1, code2):
    return render_template_string(breadcrumbs_tpl)

if __name__ == '__main__':
    app.run(debug=True)

Or am I doing it wrong?

breadcrumbs: routes with variables

How does Flask-Breadcrumbs handle routes with a variable? For example:

@app.route('/users/<int:user_id>')

In this instance, I'd want the breadcrumb to include a property of the user, not just the ID, e.g.:

/Users/Snorfalorpagus

AttributeError: 'Breadcrumbs' object has no attribute 'root_node'

Package version (if known): 0.5.1

Describe the bug

I'm wondering if something has changed within Flask-Menu that Flask-Breadcrumbs needs to take into account.

Steps to Reproduce

  1. Install latest releases of Flask-Breadcrumbs and Flask-Menu (0.5.1 and 1.0.0 respectively)
  2. Run the Simple Example
  3. Visit the app
  4. Profit...er, error.

Expected behavior

TypeError: The view function for 'index' did not return a valid response. The function either returned None or ended without a return statement.
Ideally there would be no error, but I think index() not returning anything is a (different) bug in the example code.

Screenshots (if applicable)

Additional context

Downgrading flask-menu from 1.0.0 to 0.7.2 makes the problem go away. This leads me to believe current Flask-Breadcrumbs is incompatible with current Flask-Menu.

Flask-Breadcrumbs Not working

Hello,

I have implement Flask-Breadcrumbs menu in my flask app. but it will give me key error like "KeyError: 'menu'"

I will show you some code:
Py File

from flask_breadcrumbs import Breadcrumbs, register_breadcrumb,default_breadcrumb_root
Breadcrumbs(app=app)
default_breadcrumb_root(user_blueprint,'.')


@user_blueprint.route('/user/register')
@register_breadcrumb(user_blueprint, '.user.register', 'Home')
def register():
     error = None
     return render_template('register.html',error=error)

register.html File

	<div>
		{%- for breadcrumb in breadcrumbs -%}
		    <a href="{{ breadcrumb.url }}">{{ breadcrumb.text }}</a>
		    {{ '/' if not loop.last }}
		{%- endfor -%}
	</div>	

keyerror menu werkzeug debugger

global: fix build failure

https://travis-ci.org/inveniosoftware/flask-breadcrumbs/jobs/656676424

$ ./run-tests.sh
Skipped 1 files
lists of files in version control and sdist match
Warning, treated as error:
WARNING: intersphinx inventory 'http://flask.pocoo.org/docs/objects.inv' not fetchable due to <class 'urllib2.HTTPError'>: HTTP Error 403: Forbidden
The command "./run-tests.sh" exited with 1.

Fix also Travis deprecation:
https://travis-ci.org/inveniosoftware/flask-breadcrumbs/jobs/656676424/config

Error with paths, blueprint and more than one route

Hi,

I currently using Flask-Menu to make the menu of my app, and now i want to use Flask-Breadcrumbs to make it more usable but i have a problem.

I changed all decorators of "register_menu" for "register_breadcrumbs" and the menu breaks.

In a app.py i have the base menu like this:

from flask import Flask, render_template
from flask_breadcrumbs import Breadcrumbs, register_breadcrumb

app = Flask(__name__)
Breadcrumbs(app)

@register_breadcrumb(app, '.', 'Home')
@register_breadcrumb(app, '.first', 'First', order=0)
@register_breadcrumb(app, '.second', 'Second', order=1)
@app.route('/')
def index(): return render_template('index.html')

# Loading views
resources_dir = 'views'
import views
for importer, package_name, _ in pkgutil.iter_modules(views.__path__):
    module = importer.find_module(package_name).load_module('%s.%s' % (resources_dir, package_name))
    if hasattr(module, 'bp'):
        try:
            app.register_blueprint(getattr(module, 'bp'))
        except Exception, e:
            pass

In my template i have this code

                        <ol class="breadcrumb">
                           {% for breadcrumb in breadcrumbs %}
                           <li>{{ breadcrumb.text }}</li>
                           {% endfor %}
                        </ol>

And i see this breadcrumb
image

As you can see, i have two entris with "Menu item not initialised"

In one of these views i have more child entris of ".erp" submenu that cause this missfunction

@register_breadcrumb(bp, '.erp.config', 'Config')
@register_breadcrumb(bp, '.erp.exec', 'Exec')
@register_breadcrumb(bp, '.erp.report', 'Reports')
@bp.route('/' )

Can you help me?

King regards

Example is incorrect

In the "simple example", the following code is shown:

from flask_breadcrumbs import Breadcrumbs, register_breadcrumbs

however, there is no register_breadcrumbs function. Instead, it should be

from flask_breadcrumbs import Breadcrumbs, register_breadcrumb

docs: fix incorrect import example

Fix incorrect import example:

docs/index.rst:    from flask_breadcrumbs import Breadcrumbs, register_breadcrumbs
docs/index.rst:    from flask_breadcrumbs import Breadcrumbs, register_breadcrumb

global: check for extension initialization before registering breadcrumb

There are scenarios where some flask extension might want to provide Flask-Breadcrumbs capabilities for its blueprints, but the user of the extension is not interested in this (e.g. if the application doesn't have any UI views, but only provides a REST API).

It should be possible to conditionally register the breadcrumb, by checking if current_breadcrumbs exists before performing the registration:

# inside "register_breadcrumb"
...
def breadcrumb_decorator(func):
    """Applie standard menu decorator and assign breadcrumb."""
    if current_breadcrumbs:
        func.__breadcrumb__ = func_path
    return menu_decorator(func)
...

(this change depends on inveniosoftware/flask-menu#65)

Support internationalization

If you want to translate your breadcrumbs, you might face the following issue:

@register_breadcrumb(app, ".", _("Translate This"))

will throw Out Of Application Context error.

@register_breadcrumb(app, ".", lambda: _("Translate This"))

will leave you with a string like this: [<function <lambda> at 0x7d8fe8ad0630>]

The only possible way I found wass using dynamic_list_constructor like this:

@register_breadcrumb(app, ".", "", dynamic_list_constructor=lambda: [{"text": _("Translate This"), "url": ""}])

but this way the url needs to be entered manually.

Can we get a better example of a dynamic list constructor?

I just cannot figure out how to use the dynamic list constructor for variable rules from the example in the documentation.
Could we get another example?

My question that I don't see addressed in the examples are,

  • What parameters gets passed view_user_dlc? When I try this out, it appears that no arguments get passed to this function at all.
  • What is the significance of the '.user.id' and '' parameters passed to the register_breadcrumb decorator? Are they just placeholders without any significance at all?
  • In view_user_dlc, what is User, and where did that come from? I assume that is a global that is part of the application, but that is never explained.

I have looked at the test routines in the flask-breadcrumbs repo for a hint but the single test program does not demonstrate breadcrumbs on variable content. Any help would be appreciated.

from flask import request, render_template

def view_user_dlc(*args, **kwargs):
    user_id = request.view_args['user_id']
    user = User.query.get(user_id)
    return [{'text': user.name, 'url': user.url}]

@app.route('/users/<int:user_id>')
@breadcrumbs.register_breadcrumb(app, '.user.id', '',
                                 dynamic_list_constructor=view_user_dlc)
def view_user(user_id):
    user = User.query.get(user_id)
    return render_template('user.html', user=user)

Deprecation warnings with Flask 2.2

Runnning the tests on master (539c2ec) yields deprecation warnings due to Flask 2.2:

============================================================================================================= test session starts =============================================================================================================
platform linux -- Python 3.9.16, pytest-7.2.1, pluggy-1.0.0
cachedir: .tox/py39/.pytest_cache
rootdir: /home/flo/tmp/flask-breadcrumbs
plugins: pep8-1.0.6, cov-4.0.0
collected 9 items                                                                                                                                                                                                                             

tests/test_core.py .........                                                                                                                                                                                                            [100%]

============================================================================================================== warnings summary ===============================================================================================================
tests/test_core.py: 24 warnings
  tmp/flask-breadcrumbs/.tox/py39/lib/python3.9/site-packages/flask/scaffold.py:50: DeprecationWarning: 'before_first_request' is deprecated and will be removed in Flask 2.3. Run setup code while creating the application instead.
    return f(self, *args, **kwargs)

tests/test_core.py: 12 warnings
 tmp/flask-breadcrumbs/.tox/py39/lib/python3.9/site-packages/flask/scaffold.py:50: DeprecationWarning: 'before_app_first_request' is deprecated and will be removed in Flask 2.3. Use 'record_once' instead to run setup code when registering the blueprint.
    return f(self, *args, **kwargs)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================================================================= 9 passed, 36 warnings in 0.19s ========================================================================================================

Can't use flask-breadcrubs with blueprint

Hello !

Here is my couple files of my test project:

from flask import Flask
from flask_menu import Menu, MenuEntryMixin
from account import account
from config import DefaultConfig


from flask_breadcrumbs import Breadcrumbs

app = Flask(__name__)
app.config.from_object(DefaultConfig)
Menu(app)

app.register_blueprint(account)
Breadcrumbs(app=app, init_menu=False)
app.run(host='0.0.0.0',debug=True)

__init__.py

from flask import Blueprint, render_template_string, request
from flask_menu import register_menu

from flask_breadcrumbs import register_breadcrumb, default_breadcrumb_root, Breadcrumbs


account = Blueprint('account', __name__ )


@account.route('/')
#@register_menu(account, '.', 'Home')
@register_breadcrumb(account, '.', 'Home')
def index():
    return render_template_string(
    """
    {%- for breadcrumb in breadcrumbs -%}
        <a href="{{ breadcrumb.url }}">{{ breadcrumb.text }}</a>
        {{ '/' if not loop.last }}
    {%- endfor -%}
    """)

@account.route('/first')
#@register_menu(account, '.first', 'first')
@register_breadcrumb(account, '.first', 'first')
def first():
    return render_template_string(
    """
    {%- for breadcrumb in breadcrumbs -%}
        <a href="{{ breadcrumb.url }}">{{ breadcrumb.text }}</a>
        {{ '/' if not loop.last }}
    {%- endfor -%}
    """)

@account.route('/first/f1')
#@register_menu(account, '.first.f1', 'f1')
@register_breadcrumb(account, '.first.f1', 'f1')
def f1():
    return render_template_string(
    """
    {%- for breadcrumb in breadcrumbs -%}
        <a href="{{ breadcrumb.url }}">{{ breadcrumb.text }}</a>
        {{ '/' if not loop.last }}
    {%- endfor -%}
    """)

I tested it in different cases, but I can't make work it properly :(

In this case output like:

Menu item not initialised /Home /first

Please could you provide checked test example of code.

Best regards,
Vladimir.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.