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
fbcf5253
Commit
fbcf5253
authored
Jun 13, 2017
by
Skia
🤘
Browse files
Merge branch 'pep8' into 'master'
Pep8 See merge request
!81
parents
753fe0d1
9447de44
Pipeline
#1075
failed with stage
in 3 minutes and 19 seconds
Changes
64
Pipelines
2
Expand all
Hide whitespace changes
Inline
Side-by-side
accounting/admin.py
View file @
fbcf5253
...
...
@@ -35,5 +35,3 @@ admin.site.register(SimplifiedAccountingType)
admin
.
site
.
register
(
Operation
)
admin
.
site
.
register
(
Label
)
admin
.
site
.
register
(
Company
)
accounting/models.py
View file @
fbcf5253
...
...
@@ -25,7 +25,6 @@
from
django.core.urlresolvers
import
reverse
from
django.core.exceptions
import
ValidationError
from
django.core
import
validators
from
django.db.models
import
Count
from
django.db
import
models
from
django.conf
import
settings
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -37,6 +36,7 @@ from decimal import Decimal
from
core.models
import
User
,
SithFile
from
club.models
import
Club
class
CurrencyField
(
models
.
DecimalField
):
"""
This is a custom database field used for currency
...
...
@@ -50,12 +50,13 @@ class CurrencyField(models.DecimalField):
def
to_python
(
self
,
value
):
try
:
return
super
(
CurrencyField
,
self
).
to_python
(
value
).
quantize
(
Decimal
(
"0.01"
))
return
super
(
CurrencyField
,
self
).
to_python
(
value
).
quantize
(
Decimal
(
"0.01"
))
except
AttributeError
:
return
None
return
None
# Accounting classes
class
Company
(
models
.
Model
):
name
=
models
.
CharField
(
_
(
'name'
),
max_length
=
60
)
street
=
models
.
CharField
(
_
(
'street'
),
max_length
=
60
,
blank
=
True
)
...
...
@@ -104,6 +105,7 @@ class Company(models.Model):
def
__str__
(
self
):
return
self
.
name
class
BankAccount
(
models
.
Model
):
name
=
models
.
CharField
(
_
(
'name'
),
max_length
=
30
)
iban
=
models
.
CharField
(
_
(
'iban'
),
max_length
=
255
,
blank
=
True
)
...
...
@@ -131,6 +133,7 @@ class BankAccount(models.Model):
def
__str__
(
self
):
return
self
.
name
class
ClubAccount
(
models
.
Model
):
name
=
models
.
CharField
(
_
(
'name'
),
max_length
=
30
)
club
=
models
.
ForeignKey
(
Club
,
related_name
=
"club_account"
,
verbose_name
=
_
(
"club"
))
...
...
@@ -244,6 +247,7 @@ class GeneralJournal(models.Model):
self
.
amount
-=
o
.
amount
self
.
save
()
class
Operation
(
models
.
Model
):
"""
An operation is a line in the journal, a debit or a credit
...
...
@@ -258,17 +262,17 @@ class Operation(models.Model):
invoice
=
models
.
ForeignKey
(
SithFile
,
related_name
=
'operations'
,
verbose_name
=
_
(
"invoice"
),
null
=
True
,
blank
=
True
)
done
=
models
.
BooleanField
(
_
(
'is done'
),
default
=
False
)
simpleaccounting_type
=
models
.
ForeignKey
(
'SimplifiedAccountingType'
,
related_name
=
"operations"
,
verbose_name
=
_
(
"simple type"
),
null
=
True
,
blank
=
True
)
verbose_name
=
_
(
"simple type"
),
null
=
True
,
blank
=
True
)
accounting_type
=
models
.
ForeignKey
(
'AccountingType'
,
related_name
=
"operations"
,
verbose_name
=
_
(
"accounting type"
),
null
=
True
,
blank
=
True
)
verbose_name
=
_
(
"accounting type"
),
null
=
True
,
blank
=
True
)
label
=
models
.
ForeignKey
(
'Label'
,
related_name
=
"operations"
,
verbose_name
=
_
(
"label"
),
null
=
True
,
blank
=
True
,
on_delete
=
models
.
SET_NULL
)
verbose_name
=
_
(
"label"
),
null
=
True
,
blank
=
True
,
on_delete
=
models
.
SET_NULL
)
target_type
=
models
.
CharField
(
_
(
'target type'
),
max_length
=
10
,
choices
=
[(
'USER'
,
_
(
'User'
)),
(
'CLUB'
,
_
(
'Club'
)),
(
'ACCOUNT'
,
_
(
'Account'
)),
(
'COMPANY'
,
_
(
'Company'
)),
(
'OTHER'
,
_
(
'Other'
))])
choices
=
[(
'USER'
,
_
(
'User'
)),
(
'CLUB'
,
_
(
'Club'
)),
(
'ACCOUNT'
,
_
(
'Account'
)),
(
'COMPANY'
,
_
(
'Company'
)),
(
'OTHER'
,
_
(
'Other'
))])
target_id
=
models
.
IntegerField
(
_
(
'target id'
),
null
=
True
,
blank
=
True
)
target_label
=
models
.
CharField
(
_
(
'target label'
),
max_length
=
32
,
default
=
""
,
blank
=
True
)
linked_operation
=
models
.
OneToOneField
(
'self'
,
related_name
=
'operation_linked_to'
,
verbose_name
=
_
(
"linked operation"
),
null
=
True
,
blank
=
True
,
default
=
None
)
null
=
True
,
blank
=
True
,
default
=
None
)
class
Meta
:
unique_together
=
(
'number'
,
'journal'
)
...
...
@@ -349,8 +353,9 @@ class Operation(models.Model):
def
__str__
(
self
):
return
"%d € | %s | %s | %s"
%
(
self
.
amount
,
self
.
date
,
self
.
accounting_type
,
self
.
done
,
)
self
.
amount
,
self
.
date
,
self
.
accounting_type
,
self
.
done
,
)
class
AccountingType
(
models
.
Model
):
"""
...
...
@@ -359,13 +364,13 @@ class AccountingType(models.Model):
Thoses are numbers used in accounting to classify operations
"""
code
=
models
.
CharField
(
_
(
'code'
),
max_length
=
16
,
validators
=
[
validators
.
RegexValidator
(
r
'^[0-9]*$'
,
_
(
'An accounting type code contains only numbers'
)),
],
)
validators
=
[
validators
.
RegexValidator
(
r
'^[0-9]*$'
,
_
(
'An accounting type code contains only numbers'
)),
],
)
label
=
models
.
CharField
(
_
(
'label'
),
max_length
=
128
)
movement_type
=
models
.
CharField
(
_
(
'movement type'
),
choices
=
[(
'CREDIT'
,
_
(
'Credit'
)),
(
'DEBIT'
,
_
(
'Debit'
)),
(
'NEUTRAL'
,
_
(
'Neutral'
))],
max_length
=
12
)
(
'NEUTRAL'
,
_
(
'Neutral'
))],
max_length
=
12
)
class
Meta
:
verbose_name
=
_
(
"accounting type"
)
...
...
@@ -383,7 +388,8 @@ class AccountingType(models.Model):
return
reverse
(
'accounting:type_list'
)
def
__str__
(
self
):
return
self
.
code
+
" - "
+
self
.
get_movement_type_display
()
+
" - "
+
self
.
label
return
self
.
code
+
" - "
+
self
.
get_movement_type_display
()
+
" - "
+
self
.
label
class
SimplifiedAccountingType
(
models
.
Model
):
"""
...
...
@@ -391,7 +397,7 @@ class SimplifiedAccountingType(models.Model):
"""
label
=
models
.
CharField
(
_
(
'label'
),
max_length
=
128
)
accounting_type
=
models
.
ForeignKey
(
AccountingType
,
related_name
=
"simplified_types"
,
verbose_name
=
_
(
"simplified accounting types"
))
verbose_name
=
_
(
"simplified accounting types"
))
class
Meta
:
verbose_name
=
_
(
"simplified type"
)
...
...
@@ -408,7 +414,8 @@ class SimplifiedAccountingType(models.Model):
return
reverse
(
'accounting:simple_type_list'
)
def
__str__
(
self
):
return
self
.
get_movement_type_display
()
+
" - "
+
self
.
accounting_type
.
code
+
" - "
+
self
.
label
return
self
.
get_movement_type_display
()
+
" - "
+
self
.
accounting_type
.
code
+
" - "
+
self
.
label
class
Label
(
models
.
Model
):
"""Label allow a club to sort its operations"""
...
...
@@ -432,4 +439,3 @@ class Label(models.Model):
def
can_be_viewed_by
(
self
,
user
):
return
self
.
club_account
.
can_be_viewed_by
(
user
)
accounting/tests.py
View file @
fbcf5253
...
...
@@ -22,15 +22,12 @@
#
#
from
django.test
import
Client
,
TestCase
from
django.test
import
TestCase
from
django.core.urlresolvers
import
reverse
from
django.contrib.auth.models
import
Group
from
django.core.management
import
call_command
from
django.conf
import
settings
from
datetime
import
date
,
datetime
from
datetime
import
date
from
core.models
import
User
from
counter.models
import
Counter
from
accounting.models
import
GeneralJournal
,
Operation
,
Label
,
AccountingType
,
SimplifiedAccountingType
...
...
@@ -72,10 +69,11 @@ class RefoundAccountTest(TestCase):
self
.
assertFalse
(
response_post
.
status_code
==
403
)
self
.
assertTrue
(
self
.
skia
.
customer
.
amount
==
0
)
class
JournalTest
(
TestCase
):
def
setUp
(
self
):
call_command
(
"populate"
)
self
.
journal
=
GeneralJournal
.
objects
.
filter
(
id
=
1
).
first
()
self
.
journal
=
GeneralJournal
.
objects
.
filter
(
id
=
1
).
first
()
def
test_permission_granted
(
self
):
self
.
client
.
login
(
username
=
'comptable'
,
password
=
'plop'
)
...
...
@@ -91,115 +89,116 @@ class JournalTest(TestCase):
self
.
assertTrue
(
response_get
.
status_code
==
403
)
self
.
assertFalse
(
'<td>M
\xc3\xa9
thode de paiement</td>'
in
str
(
response_get
.
content
))
class
OperationTest
(
TestCase
):
def
setUp
(
self
):
call_command
(
"populate"
)
self
.
journal
=
GeneralJournal
.
objects
.
filter
(
id
=
1
).
first
()
self
.
journal
=
GeneralJournal
.
objects
.
filter
(
id
=
1
).
first
()
self
.
skia
=
User
.
objects
.
filter
(
username
=
'skia'
).
first
()
at
=
AccountingType
(
code
=
'443'
,
label
=
"Ce code n'existe pas"
,
movement_type
=
'CREDIT'
)
at
.
save
()
l
=
Label
(
club_account
=
self
.
journal
.
club_account
,
name
=
'bob'
)
l
=
Label
(
club_account
=
self
.
journal
.
club_account
,
name
=
'bob'
)
l
.
save
()
self
.
client
.
login
(
username
=
'comptable'
,
password
=
'plop'
)
self
.
op1
=
Operation
(
journal
=
self
.
journal
,
date
=
date
.
today
(),
amount
=
1
,
remark
=
"Test bilan"
,
mode
=
'CASH'
,
done
=
True
,
label
=
l
,
accounting_type
=
at
,
target_type
=
'USER'
,
target_id
=
self
.
skia
.
id
)
self
.
op1
=
Operation
(
journal
=
self
.
journal
,
date
=
date
.
today
(),
amount
=
1
,
remark
=
"Test bilan"
,
mode
=
'CASH'
,
done
=
True
,
label
=
l
,
accounting_type
=
at
,
target_type
=
'USER'
,
target_id
=
self
.
skia
.
id
)
self
.
op1
.
save
()
self
.
op2
=
Operation
(
journal
=
self
.
journal
,
date
=
date
.
today
(),
amount
=
2
,
remark
=
"Test bilan"
,
mode
=
'CASH'
,
done
=
True
,
label
=
l
,
accounting_type
=
at
,
target_type
=
'USER'
,
target_id
=
self
.
skia
.
id
)
self
.
op2
=
Operation
(
journal
=
self
.
journal
,
date
=
date
.
today
(),
amount
=
2
,
remark
=
"Test bilan"
,
mode
=
'CASH'
,
done
=
True
,
label
=
l
,
accounting_type
=
at
,
target_type
=
'USER'
,
target_id
=
self
.
skia
.
id
)
self
.
op2
.
save
()
def
test_new_operation
(
self
):
self
.
client
.
login
(
username
=
'comptable'
,
password
=
'plop'
)
at
=
AccountingType
.
objects
.
filter
(
code
=
'604'
).
first
()
response
=
self
.
client
.
post
(
reverse
(
'accounting:op_new'
,
args
=
[
self
.
journal
.
id
]),
{
'amount'
:
30
,
'remark'
:
"Un gros test"
,
'journal'
:
self
.
journal
.
id
,
'target_type'
:
'OTHER'
,
'target_id'
:
''
,
'target_label'
:
"Le fantome de la nuit"
,
'date'
:
'04/12/2020'
,
'mode'
:
'CASH'
,
'cheque_number'
:
''
,
'invoice'
:
''
,
'simpleaccounting_type'
:
''
,
'accounting_type'
:
at
.
id
,
'label'
:
''
,
'done'
:
False
,
})
self
.
client
.
login
(
username
=
'comptable'
,
password
=
'plop'
)
at
=
AccountingType
.
objects
.
filter
(
code
=
'604'
).
first
()
response
=
self
.
client
.
post
(
reverse
(
'accounting:op_new'
,
args
=
[
self
.
journal
.
id
]),
{
'amount'
:
30
,
'remark'
:
"Un gros test"
,
'journal'
:
self
.
journal
.
id
,
'target_type'
:
'OTHER'
,
'target_id'
:
''
,
'target_label'
:
"Le fantome de la nuit"
,
'date'
:
'04/12/2020'
,
'mode'
:
'CASH'
,
'cheque_number'
:
''
,
'invoice'
:
''
,
'simpleaccounting_type'
:
''
,
'accounting_type'
:
at
.
id
,
'label'
:
''
,
'done'
:
False
,
})
self
.
assertFalse
(
response
.
status_code
==
403
)
self
.
assertTrue
(
self
.
journal
.
operations
.
filter
(
target_label
=
"Le fantome de la nuit"
).
exists
())
self
.
assertTrue
(
self
.
journal
.
operations
.
filter
(
target_label
=
"Le fantome de la nuit"
).
exists
())
response_get
=
self
.
client
.
get
(
reverse
(
"accounting:journal_details"
,
args
=
[
self
.
journal
.
id
]))
self
.
assertTrue
(
'<td>Le fantome de la nuit</td>'
in
str
(
response_get
.
content
))
def
test_bad_new_operation
(
self
):
self
.
client
.
login
(
username
=
'comptable'
,
password
=
'plop'
)
at
=
AccountingType
.
objects
.
filter
(
code
=
'604'
).
first
()
response
=
self
.
client
.
post
(
reverse
(
'accounting:op_new'
,
args
=
[
self
.
journal
.
id
]),
{
'amount'
:
30
,
'remark'
:
"Un gros test"
,
'journal'
:
self
.
journal
.
id
,
'target_type'
:
'OTHER'
,
'target_id'
:
''
,
'target_label'
:
"Le fantome de la nuit"
,
'date'
:
'04/12/2020'
,
'mode'
:
'CASH'
,
'cheque_number'
:
''
,
'invoice'
:
''
,
'simpleaccounting_type'
:
''
,
'accounting_type'
:
''
,
'label'
:
''
,
'done'
:
False
,
})
AccountingType
.
objects
.
filter
(
code
=
'604'
).
first
()
response
=
self
.
client
.
post
(
reverse
(
'accounting:op_new'
,
args
=
[
self
.
journal
.
id
]),
{
'amount'
:
30
,
'remark'
:
"Un gros test"
,
'journal'
:
self
.
journal
.
id
,
'target_type'
:
'OTHER'
,
'target_id'
:
''
,
'target_label'
:
"Le fantome de la nuit"
,
'date'
:
'04/12/2020'
,
'mode'
:
'CASH'
,
'cheque_number'
:
''
,
'invoice'
:
''
,
'simpleaccounting_type'
:
''
,
'accounting_type'
:
''
,
'label'
:
''
,
'done'
:
False
,
})
self
.
assertTrue
(
'Vous devez fournir soit un type comptable simplifi
\\
xc3
\\
xa9 ou un type comptable standard'
in
str
(
response
.
content
))
def
test_new_operation_not_authorized
(
self
):
self
.
client
.
login
(
username
=
'skia'
,
password
=
'plop'
)
at
=
AccountingType
.
objects
.
filter
(
code
=
'604'
).
first
()
response
=
self
.
client
.
post
(
reverse
(
'accounting:op_new'
,
args
=
[
self
.
journal
.
id
]),
{
'amount'
:
30
,
'remark'
:
"Un gros test"
,
'journal'
:
self
.
journal
.
id
,
'target_type'
:
'OTHER'
,
'target_id'
:
''
,
'target_label'
:
"Le fantome du jour"
,
'date'
:
'04/12/2020'
,
'mode'
:
'CASH'
,
'cheque_number'
:
''
,
'invoice'
:
''
,
'simpleaccounting_type'
:
''
,
'accounting_type'
:
at
.
id
,
'label'
:
''
,
'done'
:
False
,
})
at
=
AccountingType
.
objects
.
filter
(
code
=
'604'
).
first
()
response
=
self
.
client
.
post
(
reverse
(
'accounting:op_new'
,
args
=
[
self
.
journal
.
id
]),
{
'amount'
:
30
,
'remark'
:
"Un gros test"
,
'journal'
:
self
.
journal
.
id
,
'target_type'
:
'OTHER'
,
'target_id'
:
''
,
'target_label'
:
"Le fantome du jour"
,
'date'
:
'04/12/2020'
,
'mode'
:
'CASH'
,
'cheque_number'
:
''
,
'invoice'
:
''
,
'simpleaccounting_type'
:
''
,
'accounting_type'
:
at
.
id
,
'label'
:
''
,
'done'
:
False
,
})
self
.
assertTrue
(
response
.
status_code
==
403
)
self
.
assertFalse
(
self
.
journal
.
operations
.
filter
(
target_label
=
"Le fantome du jour"
).
exists
())
self
.
assertFalse
(
self
.
journal
.
operations
.
filter
(
target_label
=
"Le fantome du jour"
).
exists
())
def
test__operation_simple_accounting
(
self
):
self
.
client
.
login
(
username
=
'comptable'
,
password
=
'plop'
)
sat
=
SimplifiedAccountingType
.
objects
.
all
().
first
()
response
=
self
.
client
.
post
(
reverse
(
'accounting:op_new'
,
args
=
[
self
.
journal
.
id
]),
{
'amount'
:
23
,
'remark'
:
"Un gros test"
,
'journal'
:
self
.
journal
.
id
,
'target_type'
:
'OTHER'
,
'target_id'
:
''
,
'target_label'
:
"Le fantome de l'aurore"
,
'date'
:
'04/12/2020'
,
'mode'
:
'CASH'
,
'cheque_number'
:
''
,
'invoice'
:
''
,
'simpleaccounting_type'
:
sat
.
id
,
'accounting_type'
:
''
,
'label'
:
''
,
'done'
:
False
,
})
response
=
self
.
client
.
post
(
reverse
(
'accounting:op_new'
,
args
=
[
self
.
journal
.
id
]),
{
'amount'
:
23
,
'remark'
:
"Un gros test"
,
'journal'
:
self
.
journal
.
id
,
'target_type'
:
'OTHER'
,
'target_id'
:
''
,
'target_label'
:
"Le fantome de l'aurore"
,
'date'
:
'04/12/2020'
,
'mode'
:
'CASH'
,
'cheque_number'
:
''
,
'invoice'
:
''
,
'simpleaccounting_type'
:
sat
.
id
,
'accounting_type'
:
''
,
'label'
:
''
,
'done'
:
False
,
})
self
.
assertFalse
(
response
.
status_code
==
403
)
self
.
assertTrue
(
self
.
journal
.
operations
.
filter
(
amount
=
23
).
exists
())
response_get
=
self
.
client
.
get
(
reverse
(
"accounting:journal_details"
,
args
=
[
self
.
journal
.
id
]))
...
...
@@ -216,8 +215,7 @@ class OperationTest(TestCase):
response_get
=
self
.
client
.
get
(
reverse
(
"accounting:journal_person_statement"
,
args
=
[
self
.
journal
.
id
]))
self
.
assertTrue
(
"S' Kia</a></td>
\\
n
\\
n <td>3.00</td>"
in
str
(
response_get
.
content
))
def
test_accounting_statement
(
self
):
self
.
client
.
login
(
username
=
'comptable'
,
password
=
'plop'
)
response_get
=
self
.
client
.
get
(
reverse
(
"accounting:journal_accounting_statement"
,
args
=
[
self
.
journal
.
id
]))
self
.
assertTrue
(
"<td>443 - Cr
\\
xc3
\\
xa9dit - Ce code n'existe pas</td>
\\
n <td>3.00</td>"
in
str
(
response_get
.
content
))
\ No newline at end of file
self
.
assertTrue
(
"<td>443 - Cr
\\
xc3
\\
xa9dit - Ce code n'existe pas</td>
\\
n <td>3.00</td>"
in
str
(
response_get
.
content
))
accounting/urls.py
View file @
fbcf5253
...
...
@@ -22,7 +22,7 @@
#
#
from
django.conf.urls
import
url
,
include
from
django.conf.urls
import
url
from
accounting.views
import
*
...
...
@@ -71,5 +71,3 @@ urlpatterns = [
# User account
url
(
r
'^refound/account$'
,
RefoundAccountView
.
as_view
(),
name
=
'refound_account'
),
]
accounting/views.py
View file @
fbcf5253
This diff is collapsed.
Click to expand it.
club/admin.py
View file @
fbcf5253
...
...
@@ -29,4 +29,3 @@ from club.models import Club, Membership
admin
.
site
.
register
(
Club
)
admin
.
site
.
register
(
Membership
)
club/models.py
View file @
fbcf5253
...
...
@@ -27,12 +27,13 @@ from django.core import validators
from
django.conf
import
settings
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.core.exceptions
import
ValidationError
from
django.db
import
IntegrityError
,
transaction
from
django.db
import
transaction
from
django.core.urlresolvers
import
reverse
from
django.utils
import
timezone
from
core.models
import
User
,
MetaGroup
,
Group
,
SithFile
# Create your models here.
class
Club
(
models
.
Model
):
...
...
@@ -43,17 +44,17 @@ class Club(models.Model):
name
=
models
.
CharField
(
_
(
'name'
),
max_length
=
64
)
parent
=
models
.
ForeignKey
(
'Club'
,
related_name
=
'children'
,
null
=
True
,
blank
=
True
)
unix_name
=
models
.
CharField
(
_
(
'unix name'
),
max_length
=
30
,
unique
=
True
,
validators
=
[
validators
.
RegexValidator
(
r
'^[a-z0-9][a-z0-9._-]*[a-z0-9]$'
,
_
(
'Enter a valid unix name. This value may contain only '
'letters, numbers ./-/_ characters.'
)
),
],
error_messages
=
{
'unique'
:
_
(
"A club with that unix name already exists."
),
},
)
validators
=
[
validators
.
RegexValidator
(
r
'^[a-z0-9][a-z0-9._-]*[a-z0-9]$'
,
_
(
'Enter a valid unix name. This value may contain only '
'letters, numbers ./-/_ characters.'
)
),
],
error_messages
=
{
'unique'
:
_
(
"A club with that unix name already exists."
),
},
)
address
=
models
.
CharField
(
_
(
'address'
),
max_length
=
254
)
# email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically
owner_group
=
models
.
ForeignKey
(
Group
,
related_name
=
"owned_club"
,
...
...
@@ -61,7 +62,7 @@ class Club(models.Model):
edit_groups
=
models
.
ManyToManyField
(
Group
,
related_name
=
"editable_club"
,
blank
=
True
)
view_groups
=
models
.
ManyToManyField
(
Group
,
related_name
=
"viewable_club"
,
blank
=
True
)
home
=
models
.
OneToOneField
(
SithFile
,
related_name
=
'home_of_club'
,
verbose_name
=
_
(
"home"
),
null
=
True
,
blank
=
True
,
on_delete
=
models
.
SET_NULL
)
on_delete
=
models
.
SET_NULL
)
class
Meta
:
ordering
=
[
'name'
,
'unix_name'
]
...
...
@@ -109,9 +110,9 @@ class Club(models.Model):
self
.
_change_unixname
(
self
.
unix_name
)
super
(
Club
,
self
).
save
(
*
args
,
**
kwargs
)
if
creation
:
board
=
MetaGroup
(
name
=
self
.
unix_name
+
settings
.
SITH_BOARD_SUFFIX
)
board
=
MetaGroup
(
name
=
self
.
unix_name
+
settings
.
SITH_BOARD_SUFFIX
)
board
.
save
()
member
=
MetaGroup
(
name
=
self
.
unix_name
+
settings
.
SITH_MEMBER_SUFFIX
)
member
=
MetaGroup
(
name
=
self
.
unix_name
+
settings
.
SITH_MEMBER_SUFFIX
)
member
.
save
()
subscribers
=
Group
.
objects
.
filter
(
name
=
settings
.
SITH_MAIN_MEMBERS_GROUP
).
first
()
self
.
make_home
()
...
...
@@ -153,6 +154,7 @@ class Club(models.Model):
return
sub
.
is_subscribed
_memberships
=
{}
def
get_membership_for
(
self
,
user
):
"""
Returns the current membership the given user
...
...
@@ -168,6 +170,7 @@ class Club(models.Model):
Club
.
_memberships
[
self
.
id
][
user
.
id
]
=
m
return
m
class
Membership
(
models
.
Model
):
"""
The Membership class makes the connection between User and Clubs
...
...
@@ -184,7 +187,7 @@ class Membership(models.Model):
start_date
=
models
.
DateField
(
_
(
'start date'
),
default
=
timezone
.
now
)
end_date
=
models
.
DateField
(
_
(
'end date'
),
null
=
True
,
blank
=
True
)
role
=
models
.
IntegerField
(
_
(
'role'
),
choices
=
sorted
(
settings
.
SITH_CLUB_ROLES
.
items
()),
default
=
sorted
(
settings
.
SITH_CLUB_ROLES
.
items
())[
0
][
0
])
default
=
sorted
(
settings
.
SITH_CLUB_ROLES
.
items
())[
0
][
0
])
description
=
models
.
CharField
(
_
(
'description'
),
max_length
=
128
,
null
=
False
,
blank
=
True
)
def
clean
(
self
):
...
...
@@ -195,9 +198,9 @@ class Membership(models.Model):
raise
ValidationError
(
_
(
'User is already member of that club'
))
def
__str__
(
self
):
return
self
.
club
.
name
+
' - '
+
self
.
user
.
username
+
' - '
+
str
(
settings
.
SITH_CLUB_ROLES
[
self
.
role
])
+
str
(
" - "
+
str
(
_
(
'past member'
))
if
self
.
end_date
is
not
None
else
""
)
return
self
.
club
.
name
+
' - '
+
self
.
user
.
username
+
' - '
+
str
(
settings
.
SITH_CLUB_ROLES
[
self
.
role
])
+
str
(
" - "
+
str
(
_
(
'past member'
))
if
self
.
end_date
is
not
None
else
""
)
def
is_owned_by
(
self
,
user
):
"""
...
...
@@ -216,4 +219,3 @@ class Membership(models.Model):
def
get_absolute_url
(
self
):
return
reverse
(
'club:club_members'
,
kwargs
=
{
'club_id'
:
self
.
club
.
id
})
club/tests.py
View file @
fbcf5253
...
...
@@ -31,6 +31,7 @@ from club.models import Club
# Create your tests here.
class
ClubTest
(
TestCase
):
def
setUp
(
self
):
call_command
(
"populate"
)
...
...
@@ -41,34 +42,34 @@ class ClubTest(TestCase):
def
test_create_add_user_to_club_from_root_ok
(
self
):
self
.
client
.
login
(
username
=
'root'
,
password
=
'plop'
)
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
"user"
:
self
.
skia
.
id
,
"start_date"
:
"12/06/2016"
,
"role"
:
3
})
response
=
self
.
client
.
get
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}))
response
=
self
.
client
.
get
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}))
self
.
assertTrue
(
response
.
status_code
==
200
)
self
.
assertTrue
(
"S' Kia</a></td>
\\
n <td>Responsable info</td>"
in
str
(
response
.
content
))
def
test_create_add_user_to_club_from_root_fail_not_subscriber
(
self
):
self
.
client
.
login
(
username
=
'root'
,
password
=
'plop'
)
response
=
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
response
=
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
"user"
:
self
.
guy
.
id
,
"start_date"
:
"12/06/2016"
,
"role"
:
3
})
self
.
assertTrue
(
response
.
status_code
==
200
)
self
.
assertTrue
(
'<ul class="errorlist nonfield"><li>'
in
str
(
response
.
content
))
response
=
self
.
client
.
get
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}))
response
=
self
.
client
.
get
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}))
self
.
assertFalse
(
"Guy Carlier</a></td>
\\
n <td>Responsable info</td>"
in
str
(
response
.
content
))
def
test_create_add_user_to_club_from_root_fail_already_in_club
(
self
):
self
.
client
.
login
(
username
=
'root'
,
password
=
'plop'
)
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
"user"
:
self
.
skia
.
id
,
"start_date"
:
"12/06/2016"
,
"role"
:
3
})
response
=
self
.
client
.
get
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}))
response
=
self
.
client
.
get
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}))
self
.
assertTrue
(
"S' Kia</a></td>
\\
n <td>Responsable info</td>"
in
str
(
response
.
content
))
response
=
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
response
=
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
"user"
:
self
.
skia
.
id
,
"start_date"
:
"12/06/2016"
,
"role"
:
4
})
...
...
@@ -77,30 +78,29 @@ class ClubTest(TestCase):
def
test_create_add_user_to_club_from_skia_ok
(
self
):
self
.
client
.
login
(
username
=
'root'
,
password
=
'plop'
)
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
"user"
:
self
.
skia
.
id
,
"start_date"
:
"12/06/2016"
,
"role"
:
10
})
self
.
client
.
login
(
username
=
'skia'
,
password
=
'plop'
)
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
"user"
:
self
.
rbatsbak
.
id
,
"start_date"
:
"12/06/2016"
,
"role"
:
9
})
response
=
self
.
client
.
get
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}))
response
=
self
.
client
.
get
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}))
self
.
assertTrue
(
response
.
status_code
==
200
)
self
.
assertTrue
(
"""Richard Batsbak</a></td>
\\
n <td>Vice-Pr
\\
xc3
\\
xa9sident</td>"""
in
str
(
response
.
content
))
def
test_create_add_user_to_club_from_richard_fail
(
self
):
self
.
client
.
login
(
username
=
'root'
,
password
=
'plop'
)
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
self
.
client
.
post
(
reverse
(
"club:club_members"
,
kwargs
=
{
"club_id"
:
self
.
bdf
.
id
}),
{
"user"
:
self
.
rbatsbak
.
id
,