Commit e0f267ba authored by alexandre's avatar alexandre

django views and proto filter view

parent b343cf69
......@@ -27,6 +27,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'rest_framework',
'django_filters',
'playground',
]
......
......@@ -1336,13 +1336,29 @@ window.W = window.W || {};
'click .search': 'search',
},
onSearch: function (event) {
onSearch: function (view, event) {
this.collection.queryParams.search = this.$el.find('.search-input').val();
this.collection.fetch();
},
});
W.FilterView = Backbone.Marionette.View.extend({
template: '#filters-template',
triggers: {
'click a': 'filter',
},
onFilter: function (view, event) {
console.log(event);
this.collection.queryParams.score_type = $(event.currentTarget).data('value');
// this.collection.queryParams.score_type = e.val();
this.collection.fetch();
},
});
W.CreateView = Backbone.Marionette.View.extend({
template: '#create-template',
......@@ -1377,7 +1393,7 @@ window.W = window.W || {};
search: '#search',
list: '#list',
pagination: '#pagination',
search: '#search',
filters: '#filters',
},
onRender: function () {
......@@ -1400,6 +1416,10 @@ window.W = window.W || {};
collection: scoreCollection
});
var myFilterView = new W.FilterView({
collection: scoreCollection
});
var mySearchView = new W.SearchView({
collection: scoreCollection
});
......@@ -1427,6 +1447,7 @@ window.W = window.W || {};
myListView.collection.fetch({
success: function () {
that.showChildView('search', mySearchView);
that.showChildView('filters', myFilterView);
that.showChildView('list', myListView);
that.showChildView('pagination', myPaginationView);
}
......@@ -1469,7 +1490,8 @@ window.W = window.W || {};
}
});
var myListView = new W.ListView({
var myListView = new Backgrid.Grid({
columns: columns,
collection: scoreCollection
});
......
......@@ -36,6 +36,10 @@
{% include "playground/underscore/search.mtpl" %}
</script>
<script id="filters-template" type="text/template">
{% include "playground/underscore/filters.mtpl" %}
</script>
<script id="create-template" type="text/template">
{% include "playground/underscore/create.mtpl" %}
</script>
......
<ul>
<li><a href="1" data-value="1">transcription</a></li>
<li><a href="2" data-value="2">prescription</a></li>
<li><a href="3" data-value="3">traduction</a></li>
</ul>
<div>
<h1>Partitions existantes</h1>
<div id="search"></div>
<div id="filters"></div>
<div id="list"></div>
<div id="pagination"></div>
</div>
......@@ -3,6 +3,7 @@ from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination
from rest_framework.parsers import FormParser, MultiPartParser
from rest_framework.filters import OrderingFilter, SearchFilter
from django_filters.rest_framework import DjangoFilterBackend
# from django_filters.rest_framework import DjangoFilterBackend
from .models import Attachment, Score
from .serializers import AttachmentSerializer, ScoreSerializer, ScoreLightSerializer
......@@ -30,8 +31,9 @@ class ScoreViewSet(viewsets.ModelViewSet):
"""
queryset = Score.objects.all()
pagination_class = ScoreViewSetPagination
filter_backends = (OrderingFilter, SearchFilter)
filter_backends = (DjangoFilterBackend, OrderingFilter, SearchFilter)
search_fields = ('title',)
filter_fields = ('title', 'score_type')
def get_serializer_class(self, *args, **kwargs):
"""
......
......@@ -3,3 +3,4 @@ django-registration
djangorestframework
djangorestframework-recursive
psycopg2
django-filter
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment