diff options
Diffstat (limited to 'rest_framework')
4 files changed, 24 insertions, 9 deletions
| diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 496500ba..80985873 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -259,7 +259,7 @@ class PageNumberPagination(BasePagination):              )              raise NotFound(msg) -        if paginator.count > 1: +        if paginator.count > 1 and self.template is not None:              # The browsable API should display pagination controls.              self.display_page_controls = True @@ -347,7 +347,7 @@ class LimitOffsetPagination(BasePagination):          self.offset = self.get_offset(request)          self.count = _get_count(queryset)          self.request = request -        if self.count > self.limit: +        if self.count > self.limit and self.template is not None:              self.display_page_controls = True          return queryset[self.offset:self.offset + self.limit] @@ -518,7 +518,7 @@ class CursorPagination(BasePagination):          # Display page controls in the browsable API if there is more          # than one page. -        if self.has_previous or self.has_next: +        if (self.has_previous or self.has_next) and self.template is not None:              self.display_page_controls = True          return self.page 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 %} | 
