diff options
4 files changed, 24 insertions, 7 deletions
| diff --git a/docs/api-guide/exceptions.md b/docs/api-guide/exceptions.md index 56811ec3..3e4b3e8b 100644 --- a/docs/api-guide/exceptions.md +++ b/docs/api-guide/exceptions.md @@ -47,7 +47,7 @@ Any example validation error might look like this:  You can implement custom exception handling by creating a handler function that converts exceptions raised in your API views into response objects.  This allows you to control the style of error responses used by your API. -The function must take a single argument, which is the exception to be handled, and should either return a `Response` object, or return `None` if the exception cannot be handled.  If the handler returns `None` then the exception will be re-raised and Django will return a standard HTTP 500 'server error' response. +The function must take a pair of arguments, this first is the exception to be handled, and the second is a dictionary containing any extra context such as the view currently being handled. The exception handler function should either return a `Response` object, or return `None` if the exception cannot be handled.  If the handler returns `None` then the exception will be re-raised and Django will return a standard HTTP 500 'server error' response.  For example, you might want to ensure that all error responses include the HTTP status code in the body of the response, like so: @@ -72,6 +72,8 @@ In order to alter the style of the response, you could write the following custo          return response +The context argument is not used by the default handler, but can be useful if the exception handler needs further information such as the view currently being handled, which can be accessed as `context['view']`. +  The exception handler must also be configured in your settings, using the `EXCEPTION_HANDLER` setting key. For example:      REST_FRAMEWORK = { diff --git a/rest_framework/templates/rest_framework/horizontal/select_multiple.html b/rest_framework/templates/rest_framework/horizontal/select_multiple.html index 01c251fb..0735f280 100644 --- a/rest_framework/templates/rest_framework/horizontal/select_multiple.html +++ b/rest_framework/templates/rest_framework/horizontal/select_multiple.html @@ -1,11 +1,16 @@ +{% load i18n %} +{% trans "No items to select." as no_items %} +  <div class="form-group">      {% if field.label %}          <label class="col-sm-2 control-label {% if style.hide_label %}sr-only{% endif %}">{{ field.label }}</label>      {% endif %}      <div class="col-sm-10"> -        <select multiple class="form-control" name="{{ field.name }}"> +        <select multiple {{ field.choices|yesno:",disabled" }} class="form-control" name="{{ field.name }}">              {% for key, text in field.choices.items %} -            <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> +                <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> +            {% empty %} +                <option>{{ no_items }}</option>              {% endfor %}          </select>          {% if field.errors %} diff --git a/rest_framework/templates/rest_framework/inline/select_multiple.html b/rest_framework/templates/rest_framework/inline/select_multiple.html index feddf7ab..5a8b2494 100644 --- a/rest_framework/templates/rest_framework/inline/select_multiple.html +++ b/rest_framework/templates/rest_framework/inline/select_multiple.html @@ -1,10 +1,15 @@ +{% load i18n %} +{% trans "No items to select." as no_items %} +  <div class="form-group {% if field.errors %}has-error{% endif %}">      {% if field.label %}          <label class="sr-only">{{ field.label }}</label>      {% endif %} -    <select multiple class="form-control" name="{{ field.name }}"> +    <select multiple {{ field.choices|yesno:",disabled" }} class="form-control" name="{{ field.name }}">          {% for key, text in field.choices.items %} -        <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> +            <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> +        {% empty %} +            <option>{{ no_items }}</option>          {% endfor %}      </select>  </div> diff --git a/rest_framework/templates/rest_framework/vertical/select_multiple.html b/rest_framework/templates/rest_framework/vertical/select_multiple.html index 54839294..81b25c2a 100644 --- a/rest_framework/templates/rest_framework/vertical/select_multiple.html +++ b/rest_framework/templates/rest_framework/vertical/select_multiple.html @@ -1,10 +1,15 @@ +{% load i18n %} +{% trans "No items to select." as no_items %} +  <div class="form-group {% if field.errors %}has-error{% endif %}">      {% if field.label %}          <label {% if style.hide_label %}class="sr-only"{% endif %}>{{ field.label }}</label>      {% endif %} -    <select multiple class="form-control" name="{{ field.name }}"> +    <select multiple {{ field.choices|yesno:",disabled" }} class="form-control" name="{{ field.name }}">          {% for key, text in field.choices.items %} -        <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> +            <option value="{{ key }}" {% if key in field.value %}selected{% endif %}>{{ text }}</option> +        {% empty %} +            <option>{{ no_items }}</option>          {% endfor %}      </select>      {% if field.errors %} | 
