mirror of https://gitlab.crans.org/bde/nk20
Minor fixes on consumptions page, research is now faster
This commit is contained in:
parent
a1f8ef721a
commit
8c795c38dc
|
@ -70,11 +70,15 @@ class AliasSerializer(serializers.ModelSerializer):
|
|||
REST API Serializer for Aliases.
|
||||
The djangorestframework plugin will analyse the model `Alias` and parse all fields in the API.
|
||||
"""
|
||||
note = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Alias
|
||||
fields = '__all__'
|
||||
|
||||
def get_note(self, alias):
|
||||
return NotePolymorphicSerializer().to_representation(alias.note)
|
||||
|
||||
|
||||
class NotePolymorphicSerializer(PolymorphicSerializer):
|
||||
model_serializer_mapping = {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
from django.db.models import Q
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
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, \
|
||||
NoteUserSerializer, AliasSerializer, \
|
||||
|
@ -61,6 +61,9 @@ class NotePolymorphicViewSet(viewsets.ModelViewSet):
|
|||
"""
|
||||
queryset = Note.objects.all()
|
||||
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):
|
||||
"""
|
||||
|
@ -97,8 +100,9 @@ class AliasViewSet(viewsets.ModelViewSet):
|
|||
"""
|
||||
queryset = Alias.objects.all()
|
||||
serializer_class = AliasSerializer
|
||||
filter_backends = [SearchFilter]
|
||||
filter_backends = [SearchFilter, OrderingFilter]
|
||||
search_fields = ['$normalized_name', '$name', '$note__polymorphic_ctype__model', ]
|
||||
ordering_fields = ['name', 'normalized_name']
|
||||
|
||||
def get_queryset(self):
|
||||
"""
|
||||
|
|
|
@ -18,7 +18,6 @@ class HistoryTable(tables.Table):
|
|||
}
|
||||
model = Transaction
|
||||
exclude = ("id", "polymorphic_ctype", )
|
||||
order_by = ('-created_at', )
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
sequence = ('...', 'total', 'valid')
|
||||
|
||||
|
|
|
@ -110,12 +110,12 @@ class ConsoView(LoginRequiredMixin, SingleTableView):
|
|||
"""
|
||||
Consume
|
||||
"""
|
||||
model = Transaction
|
||||
queryset = Transaction.objects.order_by("-id").all()[:50]
|
||||
template_name = "note/conso_form.html"
|
||||
|
||||
# Transaction history table
|
||||
table_class = HistoryTable
|
||||
table_pagination = {"per_page": 20}
|
||||
table_pagination = {"per_page": 50}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""
|
||||
|
|
|
@ -44,11 +44,9 @@ function refreshBalance() {
|
|||
* This function is synchronous.
|
||||
*/
|
||||
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) {
|
||||
getJSONSync("/api/note/note/" + alias.note + "/?format=json", function (note) {
|
||||
fun(note, alias);
|
||||
});
|
||||
fun(alias, alias.note);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue