More optimisation

This commit is contained in:
Yohann D'ANELLO 2020-03-20 02:05:41 +01:00
parent 6fc43e651e
commit 0ce6cd88b3
2 changed files with 22 additions and 17 deletions

View File

@ -84,9 +84,6 @@ class AliasSerializer(serializers.ModelSerializer):
read_only_fields = ('note', )
def get_note(self, alias):
if PermissionBackend().has_perm(get_current_authenticated_user(), "note.view_note", alias.note):
return NotePolymorphicSerializer().to_representation(alias.note)
else:
return alias.note.id

View File

@ -61,12 +61,22 @@ function li(id, text) {
* @param profile_pic_field
*/
function displayNote(note, alias, user_note_field=null, profile_pic_field=null) {
let img = note == null ? null : note.display_image;
if (img == null)
img = '/media/pic/default.png';
if (note !== null && alias !== note.name)
if (!note.display_image) {
note.display_image = 'https://nk20.ynerant.fr/media/pic/default.png';
$.getJSON("/api/note/note/" + note.id + "/?format=json", function(new_note) {
note.display_image = new_note.display_image.replace("http:", "https:");
note.name = new_note.name;
note.balance = new_note.balance;
displayNote(note, alias, user_note_field, profile_pic_field);
});
return;
}
let img = note.display_image;
if (alias !== note.name)
alias += " (aka. " + note.name + ")";
if (note !== null && user_note_field !== null)
if (user_note_field !== null)
$("#" + user_note_field).text(alias + (note.balance == null ? "" : (" : " + pretty_money(note.balance))));
if (profile_pic_field != null)
$("#" + profile_pic_field).attr('src', img);
@ -173,15 +183,13 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
aliases.results.forEach(function (alias) {
let note = alias.note;
if (typeof note === "number") {
note = {
id: note,
name: alias.name,
alias: alias,
balance: null
};
}
aliases_matched_html += li(alias_prefix + "_" + alias.id, alias.name);
note.alias = alias;
notes.push(note);
});