Minor fixes on consumptions page, research is now faster

This commit is contained in:
Yohann D'ANELLO 2020-03-13 10:29:27 +01:00
parent a1f8ef721a
commit 8c795c38dc
5 changed files with 14 additions and 9 deletions

View File

@ -70,11 +70,15 @@ class AliasSerializer(serializers.ModelSerializer):
REST API Serializer for Aliases. REST API Serializer for Aliases.
The djangorestframework plugin will analyse the model `Alias` and parse all fields in the API. The djangorestframework plugin will analyse the model `Alias` and parse all fields in the API.
""" """
note = serializers.SerializerMethodField()
class Meta: class Meta:
model = Alias model = Alias
fields = '__all__' fields = '__all__'
def get_note(self, alias):
return NotePolymorphicSerializer().to_representation(alias.note)
class NotePolymorphicSerializer(PolymorphicSerializer): class NotePolymorphicSerializer(PolymorphicSerializer):
model_serializer_mapping = { model_serializer_mapping = {

View File

@ -4,7 +4,7 @@
from django.db.models import Q from django.db.models import Q
from django_filters.rest_framework import DjangoFilterBackend from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.filters import SearchFilter from rest_framework.filters import OrderingFilter, SearchFilter
from .serializers import NoteSerializer, NotePolymorphicSerializer, NoteClubSerializer, NoteSpecialSerializer, \ from .serializers import NoteSerializer, NotePolymorphicSerializer, NoteClubSerializer, NoteSpecialSerializer, \
NoteUserSerializer, AliasSerializer, \ NoteUserSerializer, AliasSerializer, \
@ -61,6 +61,9 @@ class NotePolymorphicViewSet(viewsets.ModelViewSet):
""" """
queryset = Note.objects.all() queryset = Note.objects.all()
serializer_class = NotePolymorphicSerializer serializer_class = NotePolymorphicSerializer
filter_backends = [SearchFilter, OrderingFilter]
search_fields = ['$alias__normalized_name', '$alias__name', '$polymorphic_ctype__model', ]
ordering_fields = ['alias__name', 'alias__normalized_name']
def get_queryset(self): def get_queryset(self):
""" """
@ -97,8 +100,9 @@ class AliasViewSet(viewsets.ModelViewSet):
""" """
queryset = Alias.objects.all() queryset = Alias.objects.all()
serializer_class = AliasSerializer serializer_class = AliasSerializer
filter_backends = [SearchFilter] filter_backends = [SearchFilter, OrderingFilter]
search_fields = ['$normalized_name', '$name', '$note__polymorphic_ctype__model', ] search_fields = ['$normalized_name', '$name', '$note__polymorphic_ctype__model', ]
ordering_fields = ['name', 'normalized_name']
def get_queryset(self): def get_queryset(self):
""" """

View File

@ -18,7 +18,6 @@ class HistoryTable(tables.Table):
} }
model = Transaction model = Transaction
exclude = ("id", "polymorphic_ctype", ) exclude = ("id", "polymorphic_ctype", )
order_by = ('-created_at', )
template_name = 'django_tables2/bootstrap4.html' template_name = 'django_tables2/bootstrap4.html'
sequence = ('...', 'total', 'valid') sequence = ('...', 'total', 'valid')

View File

@ -110,12 +110,12 @@ class ConsoView(LoginRequiredMixin, SingleTableView):
""" """
Consume Consume
""" """
model = Transaction queryset = Transaction.objects.order_by("-id").all()[:50]
template_name = "note/conso_form.html" template_name = "note/conso_form.html"
# Transaction history table # Transaction history table
table_class = HistoryTable table_class = HistoryTable
table_pagination = {"per_page": 20} table_pagination = {"per_page": 50}
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
""" """

View File

@ -44,11 +44,9 @@ function refreshBalance() {
* This function is synchronous. * This function is synchronous.
*/ */
function getMatchedNotes(pattern, fun) { function getMatchedNotes(pattern, fun) {
getJSONSync("/api/note/alias/?format=json&alias=" + pattern + "&search=user|club", function(aliases) { getJSONSync("/api/note/alias/?format=json&alias=" + pattern + "&search=user|club&ordering=normalized_name", function(aliases) {
aliases.results.forEach(function(alias) { aliases.results.forEach(function(alias) {
getJSONSync("/api/note/note/" + alias.note + "/?format=json", function (note) { fun(alias, alias.note);
fun(note, alias);
});
}); });
}); });
} }