Create view for transaction

This commit is contained in:
Alexandre Iooss 2019-07-17 13:53:58 +02:00
parent 7bafbeb93a
commit 51ad354e0b
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
9 changed files with 105 additions and 38 deletions

View File

@ -8,8 +8,7 @@ from polymorphic.admin import PolymorphicChildModelAdmin, \
PolymorphicChildModelFilter, PolymorphicParentModelAdmin PolymorphicChildModelFilter, PolymorphicParentModelAdmin
from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
from .models.transactions import MembershipTransaction, Transaction, \ from .models.transactions import Transaction, TransactionTemplate
TransactionTemplate
class AliasInlines(admin.TabularInline): class AliasInlines(admin.TabularInline):

View File

@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-07-17 13:32+0200\n" "POT-Creation-Date: 2019-07-17 13:48+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -13,11 +13,11 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: admin.py:113 models/transactions.py:46 #: admin.py:112 models/transactions.py:46
msgid "source" msgid "source"
msgstr "source" msgstr "source"
#: admin.py:121 admin.py:139 models/transactions.py:25 #: admin.py:120 admin.py:138 models/transactions.py:25
#: models/transactions.py:52 #: models/transactions.py:52
msgid "destination" msgid "destination"
msgstr "destination" msgstr "destination"
@ -136,33 +136,37 @@ msgid "quantity"
msgstr "quantité" msgstr "quantité"
#: models/transactions.py:69 #: models/transactions.py:69
msgid "description" msgid "reason"
msgstr "description" msgstr "raison"
#: models/transactions.py:72 #: models/transactions.py:73
msgid "valid" msgid "valid"
msgstr "valide" msgstr "valide"
#: models/transactions.py:76 #: models/transactions.py:77
msgid "transaction" msgid "transaction"
msgstr "transaction" msgstr "transaction"
#: models/transactions.py:77 #: models/transactions.py:78
msgid "transactions" msgid "transactions"
msgstr "transactions" msgstr "transactions"
#: models/transactions.py:88 #: models/transactions.py:89
msgid "membership transaction" msgid "membership transaction"
msgstr "transaction d'adhésion" msgstr "transaction d'adhésion"
#: models/transactions.py:89 #: models/transactions.py:90
msgid "membership transactions" msgid "membership transactions"
msgstr "transactions d'adhésion" msgstr "transactions d'adhésion"
#: templates/note/transfer.html:7 #: templates/note/transaction_form.html:10
msgid "Home" msgid "Home"
msgstr "Accueil" msgstr "Accueil"
#: views.py:21 #: templates/note/transaction_form.html:53
msgid "Transfer"
msgstr "Virement"
#: views.py:26
msgid "Transfer money from your account to one or others" msgid "Transfer money from your account to one or others"
msgstr "Transfert d'argent de ton compte vers un ou plusieurs autres" msgstr "Transfert d'argent de ton compte vers un ou plusieurs autres"

View File

@ -65,8 +65,9 @@ class Transaction(models.Model):
verbose_name=_('type'), verbose_name=_('type'),
max_length=31, max_length=31,
) )
description = models.TextField( reason = models.CharField(
verbose_name=_('description'), verbose_name=_('reason'),
max_length=255,
) )
valid = models.NullBooleanField( valid = models.NullBooleanField(
verbose_name=_('valid'), verbose_name=_('valid'),

View File

@ -0,0 +1,55 @@
{% extends "admin/base_site.html" %}
{% comment %}
SPDX-License-Identifier: GPL-2.0-or-later
{% endcomment %}
{% load i18n static %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'index' %}">{% trans 'Home' %}</a>
{% if title %} &rsaquo; {{ title }}{% endif %}
</div>
{% endblock %}
{% block extrahead %}{{ block.super }}
{# Load Django Admin datetime widget #}
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/core.js' %}"></script>
{{ form.media }}
{% endblock %}
{% block extrastyle %}{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">
{% endblock %}
{% block content %}
<form method="post" onsubmit="window.onbeforeunload=null">{% csrf_token %}
{% if form.non_field_errors %}
<p class="errornote">
{% for error in form.non_field_errors %}
{{ error }}
{% endfor %}
</p>
{% endif %}
<fieldset class="module aligned">
{% for field in form %}
<div class="form-row{% if field.errors %} errors{% endif %}">
{{ field.errors }}
<div>
{{ field.label_tag }}
{% if field.is_readonly %}
<div class="readonly">{{ field.contents }}</div>
{% else %}
{{ field }}
{% endif %}
{% if field.field.help_text %}
<div class="help">{{ field.field.help_text|safe }}</div>
{% endif %}
</div>
</div>
{% endfor %}
</fieldset>
<input type="submit" value="{% trans 'Transfer' %}">
</form>
{% endblock %}

View File

@ -1,10 +0,0 @@
{% extends "admin/base_site.html" %}
{% load i18n %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'index' %}">{% trans 'Home' %}</a>
{% if title %} &rsaquo; {{ title }}{% endif %}
</div>
{% endblock %}

View File

@ -8,5 +8,5 @@ from . import views
app_name = 'note' app_name = 'note'
urlpatterns = [ urlpatterns = [
path('transfer/', views.transfer, name='transfer'), path('transfer/', views.TransactionCreate.as_view(), name='transfer'),
] ]

View File

@ -2,22 +2,27 @@
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay # Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic.edit import CreateView
from .models import Transaction
@login_required class TransactionCreate(LoginRequiredMixin, CreateView):
def transfer(request):
""" """
Show transfer page Show transfer page
TODO: If user have sufficient rights, they can transfer from an other note TODO: If user have sufficient rights, they can transfer from an other note
""" """
return render( model = Transaction
request, fields = ('destination', 'amount', 'reason')
'note/transfer.html',
{ def get_context_data(self, **kwargs):
'title': _('Transfer money from your account to one or others') """
} Add some context variables in template such as page title
) """
context = super().get_context_data(**kwargs)
context['title'] = _('Transfer money from your account '
'to one or others')
return context

View File

@ -9,3 +9,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
<a href="{% url 'index' %}">{% trans 'Home' %}</a> <a href="{% url 'index' %}">{% trans 'Home' %}</a>
</div> </div>
{% endblock %} {% endblock %}
{% block content %}
<p>{% trans "Thanks for spending some quality time with the Web site today." %}</p>
<p><a href="{% url 'index' %}">{% trans 'Log in again' %}</a></p>
{% endblock %}

View File

@ -0,0 +1,8 @@
{% extends "admin/login.html" %}
{% comment %}
SPDX-License-Identifier: GPL-2.0-or-later
{% endcomment %}
{% load i18n %}
{% block title %}{% trans "Log in" %}{% endblock %}