From e0c650a039aba673840bca938cc899ab611ed7d9 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 12 Mar 2020 11:12:21 +0100 Subject: [PATCH] Add true note name if we use an alias --- apps/note/api/serializers.py | 18 ++++++++++++------ apps/note/api/views.py | 2 +- templates/note/conso_form.html | 9 +++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/apps/note/api/serializers.py b/apps/note/api/serializers.py index 73beead1..b2d0ab66 100644 --- a/apps/note/api/serializers.py +++ b/apps/note/api/serializers.py @@ -18,12 +18,6 @@ class NoteSerializer(serializers.ModelSerializer): class Meta: model = Note fields = '__all__' - extra_kwargs = { - 'url': { - 'view_name': 'project-detail', - 'lookup_field': 'pk' - }, - } class NoteClubSerializer(serializers.ModelSerializer): @@ -31,33 +25,45 @@ class NoteClubSerializer(serializers.ModelSerializer): REST API Serializer for Club's notes. The djangorestframework plugin will analyse the model `NoteClub` and parse all fields in the API. """ + name = serializers.SerializerMethodField() class Meta: model = NoteClub fields = '__all__' + def get_name(self, obj): + return str(obj) + class NoteSpecialSerializer(serializers.ModelSerializer): """ REST API Serializer for special notes. The djangorestframework plugin will analyse the model `NoteSpecial` and parse all fields in the API. """ + name = serializers.SerializerMethodField() class Meta: model = NoteSpecial fields = '__all__' + def get_name(self, obj): + return str(obj) + class NoteUserSerializer(serializers.ModelSerializer): """ REST API Serializer for User's notes. The djangorestframework plugin will analyse the model `NoteUser` and parse all fields in the API. """ + name = serializers.SerializerMethodField() class Meta: model = NoteUser fields = '__all__' + def get_name(self, obj): + return str(obj) + class AliasSerializer(serializers.ModelSerializer): """ diff --git a/apps/note/api/views.py b/apps/note/api/views.py index cace7e40..2745a034 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -86,7 +86,7 @@ class NotePolymorphicViewSet(viewsets.ModelViewSet): else: queryset = queryset.none() - return queryset + return queryset.distinct() class AliasViewSet(viewsets.ModelViewSet): diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index 10b6e25f..64205108 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -187,7 +187,10 @@ notes += note; let alias_obj = $("#alias_" + alias.normalized_name); alias_obj.hover(function() { - $("#user_note").text(alias.name + " : " + pretty_money(note.balance)); + var name = alias.name; + if (name !== note.name) + name += " (aka. " + note.name + ")"; + $("#user_note").text(name + " : " + pretty_money(note.balance)); if (note.display_image == null) $("#profile_pic").attr('src', '/media/pic/default.png'); else @@ -257,8 +260,8 @@ }); }); }); - aliases_matched_obj.html(aliases_matched_html); }); + aliases_matched_obj.html(aliases_matched_html); }); }); @@ -283,6 +286,8 @@ consos = []; $("#note_list").html(""); $("#alias_matched").html(""); + $("#profile_pic").attr("src", "/media/pic/default.png"); + $("#user_note").text(""); refreshHistory(); refreshBalance(); });