Skip to content

Commit

Permalink
global: removal of deprecated flask.ext
Browse files Browse the repository at this point in the history
* FIX Amends deprecated import of Flask extensions via `flask.ext`.
  (closes #29)

Signed-off-by: Jiri Kuncar <jiri.kuncar@cern.ch>
  • Loading branch information
jirikuncar committed Jul 1, 2016
1 parent b81bfa7 commit 398d0d7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Flask-Breadcrumbs is free software; you can redistribute it and/or
modify it under the terms of the Revised BSD License quoted below.

Copyright (C) 2014 CERN.
Copyright (C) 2014, 2016 CERN.

All rights reserved.

Expand Down
48 changes: 24 additions & 24 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ Here is a simple Flask-Breadcrumbs usage example:
.. code-block:: python
from flask import Flask
from flask.ext import breadcrumbs
from flask_breadcrumbs import Breadcrumbs, register_breadcrumbs
app = Flask(__name__)
# Initialize Flask-Breadcrumbs
breadcrumbs.Breadcrumbs(app=app)
Breadcrumbs(app=app)
@app.route('/')
@breadcrumbs.register_breadcrumb(app, '.', 'Home')
@register_breadcrumb(app, '.', 'Home')
def index():
pass
Expand Down Expand Up @@ -157,12 +157,12 @@ your view function, like this:
.. code-block:: python
from flask import Blueprint
from flask.ext import breadcrumbs
from flask_breadcrumbs import register_breadcrumbs
account = Blueprint('account', __name__, url_prefix='/account')
@account.route('/')
@breadcrumbs.register_breadcrumb(account, '.', 'Your account')
@register_breadcrumb(account, '.', 'Your account')
def index():
pass
Expand All @@ -171,18 +171,18 @@ Combining Multiple Blueprints

Sometimes you want to combine multiple blueprints and organise the
navigation to certain hierarchy. This can be achieved by using the
function :func:`~flask.ext.breadcrumbs.default_breadcrumb_root`.
function :func:`~flask_breadcrumbs.default_breadcrumb_root`.

.. code-block:: python
from flask import Blueprint
from flask.ext import breadcrumbs
from flask_breadcrumbs import default_breadcrumb_root, register_breadcrumbs
social = Blueprint('social', __name__, url_prefix='/social')
breadcrumbs.default_breadcrumb_root(social, '.account')
default_breadcrumb_root(social, '.account')
@social.route('/list')
@breadcrumbs.register_breadcrumb(social, '.list', 'Social networks')
@register_breadcrumb(social, '.list', 'Social networks')
def list():
pass
Expand All @@ -192,15 +192,15 @@ with 3 items during processing request for `/social/list`.
.. code-block:: python
from example import app
from flask.ext import breadcrumbs
from flask_breadcrumbs import current_breadcrumbs
import account
import social
app.register_blueprint(account.bp_account)
app.register_blueprint(social.bp_social)
with app.test_client() as c:
c.get('/social/list')
assert map(lambda x: x.url,
list(breadcrumbs.current_breadcrumbs)) == [
list(current_breadcrumbs)) == [
'/', '/account/', '/social/list']
Advanced Examples
Expand All @@ -214,38 +214,38 @@ calling the decorator.
.. code-block:: python
from flask import Flask, render_template, Blueprint
from flask.ext import breadcrumbs
from flask_breadcrumbs import Breadcrumbs, register_breadcrumb
from flask.views import MethodView
app = Flask(__name__)
breadcrumbs.Breadcrumbs(app=app)
Breadcrumbs(app=app)
bp = Blueprint('bp', __name__,)
class LevelOneView(MethodView):
def get(self):
return render_template("template.html")
return render_template('template.html')
class LevelTwoView(MethodView):
def get(self):
return render_template("template.html")
return render_template('template.html')
# Define the view by calling the decorator on its own,
# followed by the view inside parenthesis
level_one_view = breadcrumbs.register_breadcrumb(bp, 'breadcrumbs.', 'Level One')(LevelOneView.as_view('first'))
bp.add_url_rule("/one", view_func=level_one_view) # Add the rule to the blueprint
level_one_view = register_breadcrumb(bp, 'breadcrumbs.', 'Level One')(
LevelOneView.as_view('first')
)
bp.add_url_rule('/one', view_func=level_one_view) # Add the rule to the blueprint
level_two_view = breadcrumbs.register_breadcrumb(bp, 'breadcrumbs.two', 'Level Two')(LevelOneView.as_view('second'))
bp.add_url_rule("/two", view_func=level_two_view)
level_two_view = breadcrumbs.register_breadcrumb(bp, 'breadcrumbs.two', 'Level Two')(
LevelOneView.as_view('second')
)
bp.add_url_rule('/two', view_func=level_two_view)
app.register_blueprint(bp)
if __name__ == '__main__':
app.run(debug=True)
.. code-block:: jinja
<!DOCTYPE html>
Expand Down Expand Up @@ -275,7 +275,7 @@ method, this part of the documentation is for you.
Flask extension
^^^^^^^^^^^^^^^

.. module:: flask.ext.breadcrumbs
.. module:: flask_breadcrumbs

.. autoclass:: Breadcrumbs
:members:
Expand Down
2 changes: 1 addition & 1 deletion flask_breadcrumbs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from flask import Blueprint, current_app, request
# pylint: disable=F0401,E0611
from flask.ext.menu import Menu, register_menu, current_menu
from flask_menu import Menu, register_menu, current_menu
# pylint: enable=F0401,E0611
from werkzeug.local import LocalProxy

Expand Down
11 changes: 4 additions & 7 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
# -*- coding: utf-8 -*-
#
# This file is part of Flask-Breadcrumbs
# Copyright (C) 2013, 2014, 2015 CERN.
# Copyright (C) 2013, 2014, 2015, 2016 CERN.
#
# Flask-Breadcrumbs is free software; you can redistribute it and/or
# modify it under the terms of the Revised BSD License; see LICENSE
# file for more details.

import sys
from unittest import TestCase
from flask import Blueprint, Flask, render_template_string

from flask.ext.breadcrumbs import (Breadcrumbs,
current_breadcrumbs,
current_path,
default_breadcrumb_root,
register_breadcrumb)
from flask import Blueprint, Flask, render_template_string
from flask_breadcrumbs import (Breadcrumbs, current_breadcrumbs, current_path,
default_breadcrumb_root, register_breadcrumb)


breadcrumbs_tpl = """
Expand Down

0 comments on commit 398d0d7

Please sign in to comment.