Commit c8b2cf2a authored by alexandre's avatar alexandre

Show shared scores in the user personnal page

parent 6f5e6be1
......@@ -1909,6 +1909,77 @@ window.W = window.W || {};
W.UserDetailView = Backbone.Marionette.View.extend({
template: '#user-detail-template',
regions: {
list: '#list',
pagination: '#pagination',
},
onRender: function () {
var scoreCollection = new W.ScoreCollection([], {
// All the `state` and `queryParams` key value pairs are merged with
// the defaults too.
state: {
pageSize: 25,
firstPage: 1,
currentPage: 1,
sortKey: "title",
order: -1
}
});
scoreCollection.queryParams.shared_with=true;
var myListView = new Backgrid.Grid({
columns: columns,
collection: scoreCollection
});
var myPaginationView = new Backgrid.Extension.Paginator({
controls : {
rewind: {
label: "",
title: "First"
},
back: {
label: "",
title: "Previous"
},
forward: {
label: "",
title: "Next"
},
fastForward: {
label: "",
title: "Last"
}
},
// If you anticipate a large number of pages, you can adjust
// the number of page handles to show. The sliding window
// will automatically show the next set of page handles when
// you click next at the end of a window.
windowSize: 20, // Default is 10
// Used to multiple windowSize to yield a number of pages to slide,
// in the case the number is 5
slideScale: 0.25, // Default is 0.5
// Whether sorting should go back to the first page
goBackFirstOnSort: false, // Default is true
collection: scoreCollection
});
var that = this;
myListView.collection.fetch({
success: function () {
that.showChildView('list', myListView);
that.showChildView('pagination', myPaginationView);
}
});
}
});
......
<p>here comes the user detail</p>
<h2>Partitions partagées avec vous</h2>
<div id="list"></div>
<div id="pagination"></div>
......@@ -9,6 +9,7 @@ from .models import Attachment, Score, FeaturedScore
from .serializers import AttachmentSerializer, ScoreSerializer, ScoreLightSerializer, UserSerializer
from guardian.shortcuts import get_anonymous_user
from django.contrib.auth.models import User
from guardian.shortcuts import get_objects_for_user
......@@ -35,11 +36,12 @@ class ScoreViewSetPagination(PageNumberPagination):
class ScoreFilter(FilterSet):
is_featured = BooleanFilter(method='my_custom_filter')
is_featured = BooleanFilter()
shared_with = BooleanFilter()
class Meta:
model = Score
fields = ('title', 'score_type', 'is_featured')
fields = ('title', 'score_type', 'is_featured', 'shared_with')
class ScoreAuthentication(authentication.SessionAuthentication):
......@@ -102,10 +104,15 @@ class ScoreViewSet(viewsets.ModelViewSet):
"""
queryset = super(ScoreViewSet, self).get_queryset()
shared_with = self.request.query_params.get('shared_with', None)
if shared_with is not None:
queryset = get_objects_for_user(self.request.user, 'playground.view_score')
is_featured = self.request.query_params.get('is_featured', None)
if is_featured is not None:
ids = FeaturedScore.objects.all().values_list("score__id", flat=True)
queryset = queryset.filter(id__in=ids)
return queryset
def get_serializer_class(self, *args, **kwargs):
......
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