2019-07-17 11:34:07 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
|
|
|
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2019-07-17 11:53:58 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2020-02-04 00:18:03 +00:00
|
|
|
from django.urls import reverse_lazy, reverse
|
2019-07-17 11:34:07 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2019-08-11 21:24:54 +00:00
|
|
|
from django.views.generic import CreateView, ListView, DetailView, UpdateView
|
2019-07-17 11:34:07 +00:00
|
|
|
|
2020-02-04 00:18:03 +00:00
|
|
|
from .models import Transaction,TransactionCategory,TransactionTemplate
|
|
|
|
from .forms import TransactionTemplateForm, ConsoForm
|
2019-07-17 11:53:58 +00:00
|
|
|
|
|
|
|
class TransactionCreate(LoginRequiredMixin, CreateView):
|
2019-07-17 11:34:07 +00:00
|
|
|
"""
|
|
|
|
Show transfer page
|
|
|
|
|
|
|
|
TODO: If user have sufficient rights, they can transfer from an other note
|
|
|
|
"""
|
2019-07-17 11:53:58 +00:00
|
|
|
model = Transaction
|
|
|
|
fields = ('destination', 'amount', 'reason')
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
"""
|
|
|
|
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
|
2019-08-11 17:54:18 +00:00
|
|
|
|
|
|
|
class TransactionTemplateCreateView(LoginRequiredMixin,CreateView):
|
|
|
|
"""
|
|
|
|
Create TransactionTemplate
|
|
|
|
"""
|
|
|
|
model = TransactionTemplate
|
|
|
|
form_class = TransactionTemplateForm
|
2019-08-11 21:24:54 +00:00
|
|
|
|
2019-08-11 17:54:18 +00:00
|
|
|
class TransactionTemplateListView(LoginRequiredMixin,ListView):
|
|
|
|
"""
|
|
|
|
List TransactionsTemplates
|
|
|
|
"""
|
|
|
|
model = TransactionTemplate
|
|
|
|
form_class = TransactionTemplateForm
|
2019-08-11 21:24:54 +00:00
|
|
|
|
|
|
|
class TransactionTemplateUpdateView(LoginRequiredMixin,UpdateView):
|
2019-08-11 17:54:18 +00:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
model = TransactionTemplate
|
2020-02-04 00:18:03 +00:00
|
|
|
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'),))
|