1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00

Merge branch 'master' into api

# Conflicts:
#	apps/note/forms.py
#	apps/note/urls.py
#	apps/note/views.py
This commit is contained in:
Yohann D'ANELLO 2020-02-16 22:25:00 +01:00
commit 00d560c20e
9 changed files with 125 additions and 9 deletions

View File

@ -118,6 +118,9 @@ class Role(models.Model):
verbose_name = _('role') verbose_name = _('role')
verbose_name_plural = _('roles') verbose_name_plural = _('roles')
def __str__(self):
return str(self.name)
class Membership(models.Model): class Membership(models.Model):
""" """

View File

@ -8,7 +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 Transaction, TransactionTemplate from .models.transactions import Transaction, TransactionCategory, TransactionTemplate
class AliasInlines(admin.TabularInline): class AliasInlines(admin.TabularInline):
@ -146,3 +146,12 @@ class TransactionTemplateAdmin(admin.ModelAdmin):
return str(obj.destination) return str(obj.destination)
poly_destination.short_description = _('destination') poly_destination.short_description = _('destination')
@admin.register(TransactionCategory)
class TransactionCategoryAdmin(admin.ModelAdmin):
"""
Admin customisation for TransactionTemplate
"""
list_display = ('name',)
list_filter = ('name',)

View File

@ -46,3 +46,16 @@ class TransactionForm(forms.ModelForm):
'data-minimum-input-length': 1, 'data-minimum-input-length': 1,
},), },),
} }
class ConsoForm(forms.ModelForm):
def save(self, commit=True):
button: TransactionTemplate = TransactionTemplate.objects.filter(name=self.data['button']).get()
self.instance.destination = button.destination
self.instance.amount = button.amount
self.instance.transaction_type = 'bouton'
self.instance.reason = button.name
super().save(commit)
class Meta:
model = Transaction
fields = ('source',)

View File

@ -4,11 +4,11 @@
from .notes import Alias, Note, NoteClub, NoteSpecial, NoteUser from .notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
from .transactions import MembershipTransaction, Transaction, \ from .transactions import MembershipTransaction, Transaction, \
TransactionTemplate TransactionCategory, TransactionTemplate
__all__ = [ __all__ = [
# Notes # Notes
'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser', 'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser',
# Transactions # Transactions
'MembershipTransaction', 'Transaction', 'TransactionTemplate', 'MembershipTransaction', 'Transaction', 'TransactionCategory', 'TransactionTemplate',
] ]

View File

@ -13,10 +13,28 @@ from .notes import Note,NoteClub
Defines transactions Defines transactions
""" """
class TransactionCategory(models.Model):
"""
Defined a recurrent transaction category
Example: food, softs, ...
"""
name = models.CharField(
verbose_name=_("name"),
max_length=31,
unique=True,
)
class Meta:
verbose_name = _("transaction category")
verbose_name_plural = _("transaction categories")
def __str__(self):
return str(self.name)
class TransactionTemplate(models.Model): class TransactionTemplate(models.Model):
""" """
Defined a reccurent transaction Defined a recurrent transaction
associated to selling something (a burger, a beer, ...) associated to selling something (a burger, a beer, ...)
""" """
@ -35,7 +53,9 @@ class TransactionTemplate(models.Model):
verbose_name=_('amount'), verbose_name=_('amount'),
help_text=_('in centimes'), help_text=_('in centimes'),
) )
template_type = models.CharField( template_type = models.ForeignKey(
TransactionCategory,
on_delete=models.PROTECT,
verbose_name=_('type'), verbose_name=_('type'),
max_length=31 max_length=31
) )

View File

@ -13,6 +13,8 @@ urlpatterns = [
path('buttons/create/',views.TransactionTemplateCreateView.as_view(),name='template_create'), path('buttons/create/',views.TransactionTemplateCreateView.as_view(),name='template_create'),
path('buttons/update/<int:pk>/',views.TransactionTemplateUpdateView.as_view(),name='template_update'), path('buttons/update/<int:pk>/',views.TransactionTemplateUpdateView.as_view(),name='template_update'),
path('buttons/',views.TransactionTemplateListView.as_view(),name='template_list'), path('buttons/',views.TransactionTemplateListView.as_view(),name='template_list'),
path('consos/<str:template_type>/',views.ConsoView.as_view(),name='consos'),
path('consos/',views.ConsoView.as_view(),name='consos'),
# API for the note autocompleter # API for the note autocompleter
path('note-autocomplete/', views.NoteAutocomplete.as_view(model=Note),name='note_autocomplete'), path('note-autocomplete/', views.NoteAutocomplete.as_view(model=Note),name='note_autocomplete'),

View File

@ -5,11 +5,12 @@
from dal import autocomplete from dal import autocomplete
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Q from django.db.models import Q
from django.urls import reverse_lazy, reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, ListView, DetailView, UpdateView from django.views.generic import CreateView, ListView, DetailView, UpdateView
from .models import Transaction, TransactionTemplate, Note from .models import Note, Transaction, TransactionCategory, TransactionTemplate
from .forms import TransactionForm, TransactionTemplateForm from .forms import TransactionForm, TransactionTemplateForm, ConsoForm
class TransactionCreate(LoginRequiredMixin, CreateView): class TransactionCreate(LoginRequiredMixin, CreateView):
""" """
@ -105,4 +106,31 @@ class TransactionTemplateUpdateView(LoginRequiredMixin,UpdateView):
""" """
""" """
model = TransactionTemplate model = TransactionTemplate
form_class=TransactionTemplateForm form_class = TransactionTemplateForm
class ConsoView(LoginRequiredMixin,CreateView):
"""
Consume
"""
model = Transaction
template_name = "note/conso_form.html"
form_class = ConsoForm
def get_context_data(self, **kwargs):
"""
Add some context variables in template such as page title
"""
context = super().get_context_data(**kwargs)
context['template_types'] = TransactionCategory.objects.all()
if 'template_type' not in self.kwargs.keys():
return context
template_type = TransactionCategory.objects.filter(name=self.kwargs.get('template_type')).get()
context['buttons'] = TransactionTemplate.objects.filter(template_type=template_type)
context['title'] = template_type
return context
def get_success_url(self):
return reverse('note:consos',args=(self.kwargs.get('template_type'),))

View File

@ -52,7 +52,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<div class="collapse navbar-collapse" id="navbarNavDropdown"> <div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav"> <ul class="navbar-nav">
<li class="nav-item active"> <li class="nav-item active">
<a class="nav-link" href="#"><i class="fa fa-coffee"></i> Consos</a> <a class="nav-link" href="{% url 'note:consos' %}"><i class="fa fa-coffee"></i> Consos</a>
</li> </li>
<li class="nav-item active"> <li class="nav-item active">
<a class="nav-link" href="{% url 'member:club_list' %}"><i class="fa fa-users"></i> Clubs</a> <a class="nav-link" href="{% url 'member:club_list' %}"><i class="fa fa-users"></i> Clubs</a>

View File

@ -0,0 +1,41 @@
{% extends "base.html" %}
{% load i18n static pretty_money %}
{% block content %}
<fieldset class="module aligned">
{% for type in template_types %}
<a href="{% url 'note:consos' template_type=type %}"><button>{{ type }}</button></a>
{% endfor %}
</fieldset>
<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 %}
{% for button in buttons %}
<button name="button" value="{{ button.name }}">{{ button.name }} ({{ button.amount | pretty_money }})</button>
{% endfor %}
</fieldset>
</form>
{% endblock %}