Controller Class for Views

1
2
3
4
5
6
7
8
def controller_view(controller, view):
    def as_view(request, *args, **kwargs):
        return getattr(controller(request, *args, **kwargs), view)(*args, **kwargs)
    return as_view

class Controller:
    def __init__(self, request, *args, **kwargs):
        self.request = request

More like this

  1. FieldsetForm by Ciantic 7 years ago
  2. Using class methods as views by panyam 4 years, 10 months ago
  3. Declaring django views like web.py views by danigm 4 years, 2 months ago
  4. URL models by diverman 4 years, 6 months ago
  5. View and StatefulView classes by Digitalxero 5 years, 6 months ago

Comments

justhamade (on April 22, 2013):

I think you reimplemented classes based views.

#

justhamade (on April 22, 2013):

Correction. Classed based views.

#

jovialbard (on April 22, 2013):

Hmm, if I did then the documentation for Class-based views is not very good. I don't see how I could get several different views that belong to the same class using that tool. Class-based views seems to be an abstraction that allows quickly building common views, not building several different views that share common behavior based on the request or arg data.

#

jovialbard (on April 22, 2013):

I'm hasty and may have been looking at the wrong section of the docs. I will continue looking into class-based views and see if the functionality I want is buried in here somewhere past all the basic usages that mostly just seem to make it easy to implement common cases with less code.

#

jovialbard (on April 22, 2013):

looking over the docs for that more thoroughly, I see how class-based views would be useful, but they are not what I am trying to accomplish. As far as I can tell they do only give you tools for easily building single veiws, not for collecting a set of views into a single controller class for capturing common functionality.

#

jovialbard (on May 1, 2013):

Thank you for the links, I will look into them.

#

(Forgotten your password?)