diff --git a/apps/note/forms.py b/apps/note/forms.py index 2e8e4456..933e29f5 100644 --- a/apps/note/forms.py +++ b/apps/note/forms.py @@ -50,52 +50,3 @@ class TransactionTemplateForm(forms.ModelForm): }, ), } - - -class TransactionForm(forms.ModelForm): - def save(self, commit=True): - super().save(commit) - - def clean(self): - """ - If the user has no right to transfer funds, then it will be the source of the transfer by default. - Transactions between a note and the same note are not authorized. - """ - - cleaned_data = super().clean() - if "source" not in cleaned_data: # TODO Replace it with "if %user has no right to transfer funds" - cleaned_data["source"] = self.user.note - - if cleaned_data["source"].pk == cleaned_data["destination"].pk: - self.add_error("destination", _("Source and destination must be different.")) - - return cleaned_data - - class Meta: - model = Transaction - fields = ( - 'source', - 'destination', - 'reason', - 'amount', - ) - - # Voir ci-dessus - widgets = { - 'source': - autocomplete.ModelSelect2( - url='note:note_autocomplete', - attrs={ - 'data-placeholder': 'Note ...', - 'data-minimum-input-length': 1, - }, - ), - 'destination': - autocomplete.ModelSelect2( - url='note:note_autocomplete', - attrs={ - 'data-placeholder': 'Note ...', - 'data-minimum-input-length': 1, - }, - ), - } diff --git a/apps/note/views.py b/apps/note/views.py index f950fd73..e323a4fd 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -5,24 +5,22 @@ from dal import autocomplete from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.contenttypes.models import ContentType from django.db.models import Q -from django.urls import reverse from django.utils.translation import gettext_lazy as _ -from django.views.generic import CreateView, ListView, UpdateView +from django.views.generic import CreateView, ListView, UpdateView, TemplateView from django_tables2 import SingleTableView -from .forms import TransactionForm, TransactionTemplateForm +from .forms import TransactionTemplateForm from .models import Transaction, TransactionTemplate, Alias, TemplateTransaction from .tables import HistoryTable -class TransactionCreate(LoginRequiredMixin, CreateView): +class TransactionCreate(LoginRequiredMixin, TemplateView): """ Show transfer page TODO: If user have sufficient rights, they can transfer from an other note """ - model = Transaction - form_class = TransactionForm + template_name = "note/transaction_form.html" def get_context_data(self, **kwargs): """ @@ -31,26 +29,10 @@ class TransactionCreate(LoginRequiredMixin, CreateView): context = super().get_context_data(**kwargs) context['title'] = _('Transfer money from your account ' 'to one or others') - - context['no_cache'] = True + context['polymorphic_ctype'] = ContentType.objects.get_for_model(Transaction).pk return context - def get_form(self, form_class=None): - """ - If the user has no right to transfer funds, then it won't have the choice of the source of the transfer. - """ - form = super().get_form(form_class) - - if False: # TODO: fix it with "if %user has no right to transfer funds" - del form.fields['source'] - form.user = self.request.user - - return form - - def get_success_url(self): - return reverse('note:transfer') - class NoteAutocomplete(autocomplete.Select2QuerySetView): """ diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 05836a54..6fb317ad 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -408,6 +408,10 @@ msgstr "Un modèle de transaction avec un nom similaire existe déjà." msgid "amount" msgstr "montant" +#: apps/note/models/transactions.py:56 apps/note/models/transactions.py:109 +msgid "Amount" +msgstr "Montant" + #: apps/note/models/transactions.py:57 msgid "in centimes" msgstr "en centimes" @@ -428,6 +432,9 @@ msgstr "quantité" msgid "reason" msgstr "raison" +msgid "Reason" +msgstr "Raison" + #: apps/note/models/transactions.py:115 msgid "valid" msgstr "valide" diff --git a/static/js/base.js b/static/js/base.js index 0c63fb26..cfd8f70e 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -26,7 +26,8 @@ function pretty_money(value) { if (value % 100 === 0) return (value < 0 ? "- " : "") + Math.floor(Math.abs(value) / 100) + " €"; else - return (value < 0 ? "- " : "") + Math.floor(Math.abs(value) / 100) + "." + (Math.abs(value) % 100) + " €"; + return (value < 0 ? "- " : "") + Math.floor(Math.abs(value) / 100) + "." + + (Math.abs(value) % 100 < 10 ? "0" : "") + (Math.abs(value) % 100) + " €"; } /** @@ -47,7 +48,6 @@ function getMatchedNotes(pattern, fun) { aliases.results.forEach(function(alias) { getJSONSync("/api/note/note/" + alias.note + "/?format=json", function (note) { fun(note, alias); - console.log(alias.name); }); }); }); @@ -85,13 +85,14 @@ function displayNote(note, alias, user_note_field=null, profile_pic_field=null) * @param d The note to remove * @param note_prefix The prefix of the identifiers of the
Default content...
{% endblock content %} diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index 5cfccb37..c5dcef00 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -130,7 +130,7 @@ {% block extrajavascript %} {% endblock %}