Notes of users that don't have validated their email addresses are displayed with a different background

This commit is contained in:
Yohann D'ANELLO 2020-04-10 02:56:56 +02:00
parent 31205b9b5d
commit 658d402242
3 changed files with 137 additions and 126 deletions

View File

@ -106,6 +106,8 @@ class ConsumerSerializer(serializers.ModelSerializer):
""" """
note = serializers.SerializerMethodField() note = serializers.SerializerMethodField()
email_confirmed = serializers.SerializerMethodField()
class Meta: class Meta:
model = Alias model = Alias
fields = '__all__' fields = '__all__'
@ -120,6 +122,11 @@ class ConsumerSerializer(serializers.ModelSerializer):
return NotePolymorphicSerializer().to_representation(obj.note) return NotePolymorphicSerializer().to_representation(obj.note)
return dict(id=obj.id) return dict(id=obj.id)
def get_email_confirmed(self, obj):
if isinstance(obj.note, NoteUser):
return obj.note.user.profile.email_confirmed
return True
class TemplateCategorySerializer(serializers.ModelSerializer): class TemplateCategorySerializer(serializers.ModelSerializer):
""" """

View File

@ -89,21 +89,23 @@ function li(id, text,extra_css) {
return "<li class=\"list-group-item py-1 d-flex justify-content-between align-items-center " + extra_css + "\"" + return "<li class=\"list-group-item py-1 d-flex justify-content-between align-items-center " + extra_css + "\"" +
" id=\"" + id + "\">" + text + "</li>\n"; " id=\"" + id + "\">" + text + "</li>\n";
} }
/** /**
* Return style to apply according to the balance of the note * Return style to apply according to the balance of the note and the validation status of the email address
* @param balance The balance of the note. * @param note The concerned note.
*/ */
function displayStyle(balance){ function displayStyle(note) {
if (balance < -5000){ let balance = note.balance;
return " text-danger bg-dark" var css = "";
} if (balance < -5000)
else if(balance <-1000){ css += " text-danger bg-dark";
return " text-danger" else if (balance < -1000)
} css += " text-danger";
else if(balance < 0){ else if (balance < 0)
return "text-warning" css += " text-warning";
} if (!note.email_confirmed)
return "" css += " text-white bg-primary";
return css;
} }
@ -121,24 +123,23 @@ function displayNote(note, alias, user_note_field=null, profile_pic_field=null)
let img = note.display_image; let img = note.display_image;
if (alias !== note.name && note.name) if (alias !== note.name && note.name)
alias += " (aka. " + note.name + ")"; alias += " (aka. " + note.name + ")";
if (user_note_field !== null) if (user_note_field !== null) {
$("#" + user_note_field).removeAttr('class'); $("#" + user_note_field).removeAttr('class');
$("#" + user_note_field).addClass(displayStyle(note.balance)); $("#" + user_note_field).addClass(displayStyle(note));
$("#" + user_note_field).text(alias + (note.balance == null ? "" : (":\n" + pretty_money(note.balance)))); $("#" + user_note_field).text(alias + (note.balance == null ? "" : (":\n" + pretty_money(note.balance))));
if (profile_pic_field != null) { if (profile_pic_field != null) {
$("#" + profile_pic_field).attr('src', img); $("#" + profile_pic_field).attr('src', img);
$("#" + profile_pic_field).click(function () { $("#" + profile_pic_field).click(function () {
console.log(note); console.log(note);
if(note.resourcetype == "NoteUser"){ if (note.resourcetype === "NoteUser") {
document.location.href = "/accounts/user/" + note.user; document.location.href = "/accounts/user/" + note.user;
} } else if (note.resourcetype === "NoteClub") {
else if(note.resourcetype == "NoteClub"){
document.location.href = "/accounts/club/" + note.club; document.location.href = "/accounts/club/" + note.club;
} }
}); });
} }
} }
}
/** /**
* Remove a note from the emitters. * Remove a note from the emitters.
@ -233,7 +234,7 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
let aliases_matched_obj = $("#" + alias_matched_id); let aliases_matched_obj = $("#" + alias_matched_id);
let aliases_matched_html = ""; let aliases_matched_html = "";
// get matched Alias with note associated // get matched Alias with note associated
if(pattern == ""){ if (pattern === "") {
aliases_matched_obj = $("#" + alias_matched_id); aliases_matched_obj = $("#" + alias_matched_id);
aliases_matched_html = ""; aliases_matched_html = "";
aliases_matched_obj.html("") aliases_matched_obj.html("")
@ -250,7 +251,8 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
return; return;
consumers.results.forEach(function (consumer) { consumers.results.forEach(function (consumer) {
let note = consumer.note; let note = consumer.note;
extra_css = displayStyle(note.balance); note.email_confirmed = consumer.email_confirmed;
let extra_css = displayStyle(note);
aliases_matched_html += li(alias_prefix + '_' + consumer.id, aliases_matched_html += li(alias_prefix + '_' + consumer.id,
consumer.name, consumer.name,
extra_css); extra_css);
@ -264,7 +266,8 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
displayNote(consumer.note, consumer.name, user_note_field, profile_pic_field) displayNote(consumer.note, consumer.name, user_note_field, profile_pic_field)
}); });
consumer_obj.click(function () { consumer_obj.click(function () {
field.val(""); old_pattern = ""; // reset input field field.val("");
old_pattern = ""; // reset input field
var disp = null; var disp = null;
notes_display.forEach(function (d) { notes_display.forEach(function (d) {
// We compare the note ids // We compare the note ids

View File

@ -1,6 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load render_table from django_tables2 %} {% load render_table from django_tables2 %}
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% load i18n %}
{% block content %} {% block content %}
<input id="searchbar" type="text" class="form-control" placeholder="Nom/prénom/note/section ..."> <input id="searchbar" type="text" class="form-control" placeholder="Nom/prénom/note/section ...">