david / django-modelviews

Backup of an old repository with useful ideas. Initial goal: integrating REST to django admin (class-based views).

Clone this repository (size: 85.8 KB): HTTPS / SSH
$ hg clone http://code.welldev.org/django-modelviews
commit 47: b04c6c1a9f26
parent 46: ce94cd50e1ba
branch: default
The default responder will no longer be 'html', but will instead be the first responder listed in the list of responders for the ModelView. Some ModelViews may not support html, so this seems like a more sensible default.
Will Larson
2 years ago

Changed (Δ92 bytes):

raw changeset »

generic/rest_views.py (3 lines added, 2 lines removed)

Up to file-list generic/rest_views.py:

@@ -88,6 +88,7 @@ class ModelView(BaseView):
88
88
        self.post_save_redirect = post_save_redirect
89
89
        self.paginate_by = paginate_by
90
90
        self.allow_empty = allow_empty
91
        self.default_responder = responders[0].__name__.split("Responder")[0]
91
92
        self.responders = dict((responder.__name__, responder) for responder in responders)
92
93
        if isinstance(methods, tuple):
93
94
            self.methods = dict(zip(methods, len(methods)*(False,)))
@@ -96,7 +97,7 @@ class ModelView(BaseView):
96
97
        super(ModelView, self).__init__(queryset)
97
98
98
99
99
    def __call__(self, request, object_pk=None, slug=None, format='html', **kwargs):
100
    def __call__(self, request, object_pk=None, slug=None, format=None, **kwargs):
100
101
        """
101
102
        Redirects to one of the CRUD methods depending on the HTTP method of 
102
103
        the request. Checks whether the requested method is allowed for this 
@@ -116,7 +117,7 @@ class ModelView(BaseView):
116
117
        # explicitly check for None and assign the desired
117
118
        # value if we want default values.
118
119
        if format is None:
119
            format = 'html'
120
            format = self.default_responder
120
121
121
122
        # Filter initial queryset given request arguments.
122
123
        subset = self.get_subset(request, object_pk, slug, **kwargs)