Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AE UTBM
Sith
Commits
e9544f25
Commit
e9544f25
authored
Jun 24, 2016
by
Skia
🤘
Browse files
Update CanCreateView and fix accounting views in consequence
parent
1396f2ca
Changes
3
Hide whitespace changes
Inline
Side-by-side
accounting/models.py
View file @
e9544f25
...
...
@@ -88,34 +88,12 @@ class GeneralJournal(models.Model):
amount
=
CurrencyField
(
_
(
'amount'
),
default
=
0
)
effective_amount
=
CurrencyField
(
_
(
'effective_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
):
"""
Method to see if that object can be edited by the given user
"""
if
user
.
is_in_group
(
settings
.
SITH_GROUPS
[
'accounting-admin'
][
'name'
]):
return
True
return
False
def
can_be_edited_by
(
self
,
user
):
"""
Method to see if that object can be edited by the given user
"""
if
self
.
club_account
.
can_be_edited_by
(
user
):
return
True
return
False
...
...
@@ -165,7 +143,7 @@ class Operation(models.Model):
"""
if
user
.
is_in_group
(
settings
.
SITH_GROUPS
[
'accounting-admin'
][
'name'
]):
return
True
m
=
self
.
journal
.
club_account
.
get_membership_for
(
user
)
m
=
self
.
journal
.
club_account
.
club
.
get_membership_for
(
user
)
if
m
is
not
None
and
m
.
role
>=
7
:
return
True
return
False
...
...
@@ -182,8 +160,8 @@ class Operation(models.Model):
return
reverse
(
'accounting:journal_details'
,
kwargs
=
{
'j_id'
:
self
.
journal
.
id
})
def
__str__
(
self
):
return
"%d
| %d
€ | %s | %s | %s"
%
(
self
.
id
,
self
.
amount
,
self
.
date
,
self
.
accounting_type
,
self
.
done
,
return
"%d € | %s | %s | %s"
%
(
self
.
amount
,
self
.
date
,
self
.
accounting_type
,
self
.
done
,
)
class
AccountingType
(
models
.
Model
):
...
...
accounting/views.py
View file @
e9544f25
...
...
@@ -26,7 +26,7 @@ class AccountingTypeEditView(CanViewMixin, UpdateView):
fields
=
[
'code'
,
'label'
,
'movement_type'
]
template_name
=
'core/edit.jinja'
class
AccountingTypeCreateView
(
Can
EditProp
Mixin
,
CreateView
):
# TODO: move to CanCreateMixin
class
AccountingTypeCreateView
(
Can
Create
Mixin
,
CreateView
):
"""
Create an accounting type (for the admins)
"""
...
...
@@ -60,7 +60,7 @@ class BankAccountDetailView(CanViewMixin, DetailView):
pk_url_kwarg
=
"b_account_id"
template_name
=
'accounting/bank_account_details.jinja'
class
BankAccountCreateView
(
Can
EditProp
Mixin
,
CreateView
):
# TODO: move to CanCreateMixin
class
BankAccountCreateView
(
Can
Create
Mixin
,
CreateView
):
"""
Create a bank account (for the admins)
"""
...
...
@@ -96,7 +96,7 @@ class ClubAccountDetailView(CanViewMixin, DetailView):
pk_url_kwarg
=
"c_account_id"
template_name
=
'accounting/club_account_details.jinja'
class
ClubAccountCreateView
(
Can
EditProp
Mixin
,
CreateView
):
# TODO: move to CanCreateMixin
class
ClubAccountCreateView
(
Can
Create
Mixin
,
CreateView
):
"""
Create a club account (for the admins)
"""
...
...
@@ -158,7 +158,7 @@ class JournalEditView(CanEditMixin, UpdateView):
# Operation views
class
OperationCreateView
(
Can
Edit
Mixin
,
CreateView
):
# TODO: move to CanCreateMixin
class
OperationCreateView
(
Can
Create
Mixin
,
CreateView
):
"""
Create an operation
"""
...
...
core/views/__init__.py
View file @
e9544f25
...
...
@@ -12,11 +12,6 @@ def forbidden(request):
def
not_found
(
request
):
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
):
if
obj
is
None
or
user
.
is_owner
(
obj
):
return
True
...
...
@@ -37,12 +32,10 @@ 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
def
form_valid
(
self
,
form
):
obj
=
form
.
instance
if
can_edit_prop
(
obj
,
self
.
request
.
user
):
return
super
(
CanCreateMixin
,
self
).
form_valid
(
form
)
raise
PermissionDenied
class
CanEditPropMixin
(
View
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment