mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Add CanCreateMixin, and add amount in journals
This commit is contained in:
parent
18db95cfd2
commit
3023d6d744
30
accounting/migrations/0003_auto_20160617_1520.py
Normal file
30
accounting/migrations/0003_auto_20160617_1520.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import accounting.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounting', '0002_auto_20160530_1001'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='bankaccount',
|
||||||
|
name='rib',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='bankaccount',
|
||||||
|
name='iban',
|
||||||
|
field=models.CharField(blank=True, verbose_name='iban', max_length=255),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='generaljournal',
|
||||||
|
name='amount',
|
||||||
|
field=accounting.models.CurrencyField(default=0, max_digits=12, decimal_places=2, verbose_name='amount'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
20
accounting/migrations/0004_auto_20160620_1307.py
Normal file
20
accounting/migrations/0004_auto_20160620_1307.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import accounting.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounting', '0003_auto_20160617_1520'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='generaljournal',
|
||||||
|
name='amount',
|
||||||
|
field=accounting.models.CurrencyField(max_digits=12, verbose_name='amount', default=0, decimal_places=2),
|
||||||
|
),
|
||||||
|
]
|
@ -27,7 +27,7 @@ class CurrencyField(models.DecimalField):
|
|||||||
|
|
||||||
class BankAccount(models.Model):
|
class BankAccount(models.Model):
|
||||||
name = models.CharField(_('name'), max_length=30)
|
name = models.CharField(_('name'), max_length=30)
|
||||||
rib = models.CharField(_('rib'), max_length=255, blank=True)
|
iban = models.CharField(_('iban'), max_length=255, blank=True)
|
||||||
number = models.CharField(_('account number'), max_length=255, blank=True)
|
number = models.CharField(_('account number'), max_length=255, blank=True)
|
||||||
club = models.ForeignKey(Club, related_name="bank_accounts")
|
club = models.ForeignKey(Club, related_name="bank_accounts")
|
||||||
|
|
||||||
@ -85,6 +85,23 @@ class GeneralJournal(models.Model):
|
|||||||
name = models.CharField(_('name'), max_length=30)
|
name = models.CharField(_('name'), max_length=30)
|
||||||
closed = models.BooleanField(_('is closed'), default=False)
|
closed = models.BooleanField(_('is closed'), default=False)
|
||||||
club_account = models.ForeignKey(ClubAccount, related_name="journals", null=False)
|
club_account = models.ForeignKey(ClubAccount, related_name="journals", null=False)
|
||||||
|
amount = CurrencyField(_('amount'), default=0)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(GeneralJournal, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if self.id == None:
|
||||||
|
amount = 0
|
||||||
|
super(GeneralJournal, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
def can_be_created_by(user):
|
||||||
|
"""
|
||||||
|
Method to see if an object can be created by the given user
|
||||||
|
"""
|
||||||
|
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): # TODO: add the treasurer of the club
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def is_owned_by(self, user):
|
def is_owned_by(self, user):
|
||||||
"""
|
"""
|
||||||
|
@ -2,8 +2,10 @@ from django.views.generic import ListView, DetailView, RedirectView
|
|||||||
from django.views.generic.edit import UpdateView, CreateView, DeleteView
|
from django.views.generic.edit import UpdateView, CreateView, DeleteView
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.core.urlresolvers import reverse_lazy
|
from django.core.urlresolvers import reverse_lazy
|
||||||
|
from django.forms.models import modelform_factory
|
||||||
|
from django.forms import HiddenInput
|
||||||
|
|
||||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
|
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
|
||||||
from accounting.models import BankAccount, ClubAccount, GeneralJournal, Operation, AccountingType
|
from accounting.models import BankAccount, ClubAccount, GeneralJournal, Operation, AccountingType
|
||||||
|
|
||||||
# Accounting types
|
# Accounting types
|
||||||
@ -113,13 +115,13 @@ class ClubAccountDeleteView(CanEditPropMixin, DeleteView): # TODO change Delete
|
|||||||
|
|
||||||
# Journal views
|
# Journal views
|
||||||
|
|
||||||
class JournalCreateView(CanEditMixin, CreateView):
|
class JournalCreateView(CanCreateMixin, CreateView): # FIXME: anonymous user has been able to create a journal
|
||||||
"""
|
"""
|
||||||
Create a general journal
|
Create a general journal
|
||||||
"""
|
"""
|
||||||
model = GeneralJournal
|
model = GeneralJournal
|
||||||
fields = ['name', 'start_date', 'club_account']
|
|
||||||
template_name = 'accounting/account_edit.jinja'
|
template_name = 'accounting/account_edit.jinja'
|
||||||
|
fields = ['name', 'start_date', 'club_account']
|
||||||
|
|
||||||
class JournalDetailView(CanViewMixin, DetailView):
|
class JournalDetailView(CanViewMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
@ -145,7 +147,7 @@ class OperationCreateView(CanEditMixin, CreateView):
|
|||||||
Create an operation
|
Create an operation
|
||||||
"""
|
"""
|
||||||
model = Operation
|
model = Operation
|
||||||
fields = ['journal', 'date', 'cheque_number', 'type']
|
fields = ['amount', 'journal', 'date', 'cheque_number', 'type']
|
||||||
template_name = 'accounting/account_edit.jinja'
|
template_name = 'accounting/account_edit.jinja'
|
||||||
|
|
||||||
class OperationEditView(CanViewMixin, UpdateView):
|
class OperationEditView(CanViewMixin, UpdateView):
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
<h3>Club tools</h3>
|
<h3>Club tools</h3>
|
||||||
<p><a href="{{ url('club:club_view', club_id=object.id) }}">Back to club</a></p>
|
<p><a href="{{ url('club:club_view', club_id=object.id) }}">Back to club</a></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object }}</a></li>
|
{% if object.club_account %}
|
||||||
|
<li>Accouting: <a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object }}</a></li>
|
||||||
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
|||||||
return True
|
return True
|
||||||
if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked
|
if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked
|
||||||
if 'subscription' in settings.INSTALLED_APPS:
|
if 'subscription' in settings.INSTALLED_APPS:
|
||||||
from subscription import Subscriber
|
from subscription.models import Subscriber
|
||||||
s = Subscriber.objects.filter(pk=self.pk).first()
|
s = Subscriber.objects.filter(pk=self.pk).first()
|
||||||
if s is not None and s.is_subscribed():
|
if s is not None and s.is_subscribed():
|
||||||
return True
|
return True
|
||||||
@ -256,6 +256,14 @@ class AnonymousUser(AuthAnonymousUser):
|
|||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
super(AnonymousUser, self).__init__()
|
super(AnonymousUser, self).__init__()
|
||||||
|
|
||||||
|
def is_in_group(self, group_name):
|
||||||
|
"""
|
||||||
|
The anonymous user is only the public group
|
||||||
|
"""
|
||||||
|
if group_name == settings.SITH_GROUPS['public']['name']:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def is_owner(self, obj):
|
def is_owner(self, obj):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -12,6 +12,11 @@ def forbidden(request):
|
|||||||
def not_found(request):
|
def not_found(request):
|
||||||
return HttpResponseNotFound(render(request, "core/404.jinja"))
|
return HttpResponseNotFound(render(request, "core/404.jinja"))
|
||||||
|
|
||||||
|
def can_create(mod, user):
|
||||||
|
if mod.can_be_created_by(user):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def can_edit_prop(obj, user):
|
def can_edit_prop(obj, user):
|
||||||
if obj is None or user.is_owner(obj):
|
if obj is None or user.is_owner(obj):
|
||||||
return True
|
return True
|
||||||
@ -27,6 +32,19 @@ def can_view(obj, user):
|
|||||||
return True
|
return True
|
||||||
return can_edit(obj, user)
|
return can_edit(obj, user)
|
||||||
|
|
||||||
|
class CanCreateMixin(View):
|
||||||
|
"""
|
||||||
|
This view is made to protect any child view that would create an object, and thus, that can not be protected by any
|
||||||
|
of the following mixin
|
||||||
|
"""
|
||||||
|
def dispatch(self, request, *arg, **kwargs):
|
||||||
|
res = super(CanCreateMixin, self).dispatch(request, *arg, **kwargs)
|
||||||
|
if hasattr(self, 'model'):
|
||||||
|
mod = self.model
|
||||||
|
if can_create(mod, self.request.user):
|
||||||
|
return res
|
||||||
|
raise PermissionDenied
|
||||||
|
|
||||||
class CanEditPropMixin(View):
|
class CanEditPropMixin(View):
|
||||||
"""
|
"""
|
||||||
This view is made to protect any child view that would be showing some properties of an object that are restricted
|
This view is made to protect any child view that would be showing some properties of an object that are restricted
|
||||||
|
Loading…
Reference in New Issue
Block a user