Skip to content
Myr

Hyphenate "class-based"

Before adoption: this commit came in with the history the project adopted, so no landing records it.

makes it more readable

authored by FND · committed by FND · parent 5cb50a4 · Browse files · 5 files+11 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+11 added−11 removed

  • other:+11 added−11 removed

5 files+11 added−11 removed

modified:docs/api.rst+1 added-1 removed
474 unmodified lines
475 operations, including connecting.476477.. _blinker: http://pypi.python.org/pypi/blinker478479Class Based Views479Class-Based Views480-----------------481482.. versionadded:: 0.7483
145 unmodified lines
modified:docs/extensiondev.rst+2 added-2 removed
146 unmodified lines
147 some helper functions like `OAuth.remote_app` to create a reference to148 a remote application that uses OAuth.149150What to use depends on what you have in mind. For the SQLite 3 extension151we will use the class based approach because it will provide users with a151we will use the class-based approach because it will provide users with a152manager object that handles opening and closing database connections.153154The Extension Code155------------------
46 unmodified lines
202 `g` object to store things like database connections.2035. Finally, we add a `get_db` function that simplifies access to the context's204 database.205206So why did we decide on a class based approach here? Because using our206So why did we decide on a class-based approach here? Because using our207extension looks something like this::208209 from flask import Flask210 from flask_sqlite3 import SQLite3
177 unmodified lines
modified:docs/views.rst+2 added-2 removed
21 unmodified lines
22 return render_template('users.html', users=users)2324This is simple and flexible, but if you want to provide this view in a25generic fashion that can be adapted to other models and templates as well26you might want more flexibility. This is where pluggable class based26you might want more flexibility. This is where pluggable class-based27views come into place. As the first step to convert this into a class28based view you would do this::2930
38 unmodified lines
69 def get_objects(self):70 return User.query.all()7172This of course is not that helpful for such a small example, but it's good73enough to explain the basic principle. When you have a class based view73enough to explain the basic principle. When you have a class-based view74the question comes up what `self` points to. The way this works is that75whenever the request is dispatched a new instance of the class is created76and the :meth:`~flask.views.View.dispatch_request` method is called with77the parameters from the URL rule. The class itself is instantiated with
160 unmodified lines
modified:flask/views.py+4 added-4 removed
1 unmodified line
2"""3 flask.views4 ~~~~~~~~~~~56 This module provides class based views inspired by the ones in Django.6 This module provides class-based views inspired by the ones in Django.78 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""
38 unmodified lines
4950 #: A for which methods this pluggable view can handle.51 methods = None5253 #: The canonical way to decorate class based views is to decorate the53 #: The canonical way to decorate class-based views is to decorate the54 #: return value of as_view(). However since this moves parts of the55 #: logic from the class declaration to the place where it's hooked56 #: into the routing system.57 #:
30 unmodified lines
88 for decorator in cls.decorators:89 view = decorator(view)9091 # we attach the view class to the view function for two reasons:92 # first of all it allows us to easily figure out what class based92 # first of all it allows us to easily figure out what class-based93 # view this thing came from, secondly it's also used for instantiating94 # the view class so you can actually replace it with something else95 # for testing purposes and debugging.96 view.view_class = cls
22 unmodified lines
119 return rv120121122class MethodView(View):123 """Like a regular class based view but that dispatches requests to123 """Like a regular class-based view but that dispatches requests to124 particular methods. For instance if you implement a method called125 :meth:`get` it means you will response to ``'GET'`` requests and126 the :meth:`dispatch_request` implementation will automatically127 forward your request to that. Also :attr:`options` is set for you
23 unmodified lines
modified:CHANGES+2 added-2 removed
87 unmodified lines
88- Refactored test client internally. The ``APPLICATION_ROOT`` configuration89 variable as well as ``SERVER_NAME`` are now properly used by the test client90 as defaults.91- Added :attr:`flask.views.View.decorators` to support simpler decorating of92 pluggable (class based) views.92 pluggable (class-based) views.93- Fixed an issue where the test client if used with the "with" statement did not94 trigger the execution of the teardown handlers.95- Added finer control over the session cookie parameters.96- HEAD requests to a method view now automatically dispatch to the `get`
79 unmodified lines
176 provide custom error messages from a central hub for certain errors that177 might occur during request processing (for instance database connection178 errors, timeouts from remote resources etc.).179- Blueprints can provide blueprint specific error handlers.180- Implemented generic :ref:`views` (class based views).180- Implemented generic :ref:`views` (class-based views).181182Version 0.6.1183-------------184
159 unmodified lines