Add setting key to allow more HTTP status codes than 200
This commit is contained in:
parent
d1ddf7b5d6
commit
3245869817
8
README
8
README
|
@ -108,7 +108,9 @@ The config dictonnary can contain the following keys:
|
|||
content of the dictionnary is described later,
|
||||
- `template`, the template in which to render the data sources, it
|
||||
will receive a variable named `data_sources` in its context
|
||||
containing property named after the `slug` field of each source.
|
||||
containing property named after the `slug` field of each source,
|
||||
- `accepted_http_status`, a list of integers giving the accepted HTTP status,
|
||||
default is `[200]`.
|
||||
|
||||
A source definition is a dictionnary containing the following keys:
|
||||
- `slug`, the field name to hold this source parsed value in the
|
||||
|
@ -164,7 +166,9 @@ A source definition is a dictionnary containing the following keys:
|
|||
present,
|
||||
- `user_context`, whether the user must be part of the cache key. For retro
|
||||
compatibility If authentication mechanism is OAuth2, it defaults to True
|
||||
otherwise to False.
|
||||
otherwise to False,
|
||||
- `accepted_http_status`, a list of integers giving the accepted HTTP status,
|
||||
default is taken from the renderer level.
|
||||
|
||||
Exemple with the JSON parser
|
||||
----------------------------
|
||||
|
|
|
@ -37,6 +37,7 @@ class Renderer(template.TemplateRenderer):
|
|||
'timeout': 10, # optional default is 1, it cannot be less than 1
|
||||
'refresh': 3600, # optional, default is taken from the renderer level
|
||||
'limit': 0, # optional, default is taken from the renderer level
|
||||
'accepted_http_status': [200,400], # optional, default it taken from the renderer level
|
||||
},
|
||||
]
|
||||
'template_name': 'data_from_xyz.html'
|
||||
|
@ -51,6 +52,7 @@ class Renderer(template.TemplateRenderer):
|
|||
# not limited if it is 0
|
||||
# you can also override it in each source
|
||||
'limit': 0, # optional default is 0
|
||||
'accepted_http_status': [200,400], # optional, default is [200]
|
||||
}
|
||||
|
||||
'''
|
||||
|
@ -141,6 +143,8 @@ class Data(object):
|
|||
self.signature_key = source.get('signature_key')
|
||||
self.parser_type = source.get('parser_type', 'raw')
|
||||
self.content_type = source.get('content_type', self.MAPPING[self.parser_type])
|
||||
self.accepted_http_status = source.get('accepted_http_status',
|
||||
config.get('accepted_http_status', [200]))
|
||||
self.user_context = source.get('user_context',
|
||||
config.get('user_context', self.auth_mech == 'oauth2'))
|
||||
pre_hash = 'datasource-{self.slug}-{self.url}-{self.limit}-' \
|
||||
|
@ -195,7 +199,8 @@ class Data(object):
|
|||
allow_redirects=self.redirects,
|
||||
timeout=self.timeout,
|
||||
stream=True)
|
||||
request.raise_for_status()
|
||||
if request.status_code not in self.accepted_http_status:
|
||||
request.raise_for_status()
|
||||
return request.raw, None
|
||||
except HTTPError:
|
||||
error = 'HTTP Error %s when loading URL %s for renderer %r' % (
|
||||
|
|
Reference in New Issue