mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-12 12:59:24 +00:00
Compare commits
1207 Commits
feature/im
...
master
Author | SHA1 | Date | |
---|---|---|---|
f6683068ff | |||
3e3c6631ff | |||
a3ac04fc9e | |||
6e724a9c74 | |||
c177ef2a3a | |||
6cf8910626 | |||
eb4fbcbda4 | |||
570510f18d | |||
7f371984d8 | |||
abf7bf6bfa | |||
02ef8fdb88 | |||
a7f4630d13 | |||
c7087c6e7e | |||
f38926c4a3 | |||
9a19f34ea2 | |||
67884017f8 | |||
f474edc84f
|
|||
f5a8228358 | |||
59a714af9f | |||
9049d8779c | |||
d111023363
|
|||
cdfa76ad57 | |||
88b70bf51f | |||
ca593c7d81
|
|||
94bdc5e615
|
|||
7d454749e0
|
|||
06090e0cd9 | |||
a1ae67da7d | |||
10d5b9d63f
|
|||
cc96c93d23
|
|||
8cc0b01e9c | |||
88755358a6 | |||
0e850e5486 | |||
af67c5fc27 | |||
30809a69c9
|
|||
0c442a8f03 | |||
f1b69dd47d | |||
b5ebf09fcb
|
|||
9d9ce5b30a | |||
a87460fa3e | |||
81d1d1caca | |||
48fae33651 | |||
6fec250658 | |||
75b37cd6e3 | |||
9c3820f986 | |||
28b60c7bae | |||
efbbfcda76 | |||
9e1fe7a296 | |||
50d7b7e731 | |||
ae7784a973 | |||
a23604383b | |||
80866086a8 | |||
2c7eb99f31 | |||
189081f5a8 | |||
52e53da9ef | |||
b5d65133f3 | |||
44e1902693 | |||
1d55a5c2da | |||
853aa34c18 | |||
dc72789c14 | |||
2f0454355f | |||
1c14bb22a0 | |||
d1f11216c7 | |||
2299e3f966
|
|||
0f55bcc513
|
|||
b19973ec9c
|
|||
17129af1bb
|
|||
42434d10ca
|
|||
c904e41ea3
|
|||
2dd4fd5c71
|
|||
dad09deab7 | |||
6782638a5d | |||
c7e4de7df2 | |||
dcc84894e5 | |||
9d841cd606 | |||
9f54e8362d | |||
c62c09f603 | |||
9c8e3b7cac | |||
c07f0c33cb | |||
7b778d3e6b | |||
4c67bb1e2a
|
|||
96f91138dd
|
|||
7b8102c242
|
|||
36d4a02a45
|
|||
4774a7b741
|
|||
d58c713fc5 | |||
6f48a9a151
|
|||
1cc2378476 | |||
99be8a56f3 | |||
e04a99cabd | |||
bfea0989fb
|
|||
be32486115 | |||
861447ae36 | |||
5f701d1a17
|
|||
64fd123a85
|
|||
7090254658
|
|||
d80f2e73e8 | |||
ee3646594b | |||
b0d9063153 | |||
0980fccf93
|
|||
fb3fd9536e
|
|||
3892e1cee2
|
|||
c10b488080
|
|||
ad91c8ed4f | |||
3b90bd54fc | |||
61e370cf73 | |||
350a92bc44 | |||
95b4b0ba03 | |||
bab44b31b1 | |||
f0fa27a8b5 | |||
6d16e35624 | |||
13b892cd01 | |||
54be8addeb | |||
9256aff944 | |||
7c989cd749 | |||
2fc51e9901 | |||
943fb5979d | |||
ff1f1040b6 | |||
fa90477de5 | |||
af613c4cca | |||
13f8b5db61
|
|||
e63a09ee7e
|
|||
6bb6be011c
|
|||
3a5bff8810
|
|||
d1e5c93a08
|
|||
19aac8f302
|
|||
9bd3c618a4
|
|||
68b1a96270
|
|||
48bf72f623
|
|||
1872e4abe5
|
|||
35e96fb875
|
|||
5e953d04fe | |||
cab2adb45d | |||
2ed0fad51a | |||
39422a0cb8 | |||
33ba1e8bbb | |||
5ca1f03d9d | |||
ac0c2c9880 | |||
1a81911cd6 | |||
934d17d9d2 | |||
f647feb8c8 | |||
73e9c3132b | |||
5da417c1a0 | |||
df26ab4d50 | |||
5dc9e24cd0 | |||
7c9a966e54 | |||
a31dc8254a | |||
2a7c1a6438 | |||
8af6af1303 | |||
4f5a69c353 | |||
7296640a8d | |||
e556305062 | |||
e9c956e08c | |||
da56a7f651 | |||
0654dfb05d | |||
2a381101ac | |||
ccd4275b02 | |||
f64409c612 | |||
f352b89fc0 | |||
2ae9baa82f | |||
bc99390b25 | |||
262ed7eb4c | |||
6377acfffa | |||
4fa83d0667 | |||
6b55b981ca | |||
e6668728f2 | |||
3431fbf2d1 | |||
77853b808a | |||
05756520a3 | |||
b3eb6a945f | |||
169faec479 | |||
42317bfecc | |||
d6e858e0e3 | |||
d8be9a62b5 | |||
2658244671 | |||
31575d0b64 | |||
4ce885ac6b | |||
5c2f324e13 | |||
ed52a4f828 | |||
ff220e67c1 | |||
805ffc498f | |||
ad4afce67f | |||
f4276d6be5 | |||
64085ac2a4 | |||
f301365ebb | |||
3c8933461a | |||
53038a365f | |||
d2fe0f1fab | |||
e96d224a8d | |||
6128b6564c | |||
0f961c71e0 | |||
59b275ef43 | |||
6362fcdf2d | |||
3e61560875 | |||
744223b76f | |||
6e39b59dd5 | |||
67bc49fb21 | |||
91b30e7550 | |||
c236092c4f | |||
7b23196071 | |||
10367d21ab | |||
60fd72917d | |||
2c7b94547c | |||
376af35bfb | |||
13f417ba30 | |||
b83fbf91e1 | |||
156305a16a | |||
11efa4fca2 | |||
26456e3a7f | |||
fab0d19eeb | |||
8a381aed38 | |||
5de05c0360 | |||
2e1a849aff | |||
b09d5e5ffd | |||
811c83552f | |||
b6511d5b84 | |||
e52b2eadbe | |||
86b8745665 | |||
597339749a | |||
d94d90357e | |||
59e8272c7f | |||
d98718f7ba | |||
d03c425a17 | |||
e35c1d1928 | |||
3b9c8d7b03 | |||
322cb74635 | |||
62c394eec4 | |||
f254490790 | |||
a78ccbd2cc | |||
77537a84c2 | |||
65c06dda8b | |||
7623474124 | |||
6a5da0302d | |||
9e0cb7647b | |||
fe5c685204 | |||
b0e24350e2 | |||
98e470fa2a | |||
49cca67eba | |||
a6e23b0b4c | |||
5c48924387 | |||
e4264d400a | |||
b541e7c1fc | |||
89efda6e26 | |||
056b3a1702 | |||
df5838034e | |||
29c1142537 | |||
3d40e92958 | |||
b8a40027b8 | |||
c527e87fd1 | |||
8699750c72 | |||
24f6a2b1cc | |||
cdd32c9a82 | |||
a6ac10e60c | |||
26d4c4b811 | |||
002554b802 | |||
6dfd4e16e2 | |||
635bc79dd6 | |||
eee78008b1 | |||
e7bb08448c | |||
7515e739b6 | |||
c7d02d4c77 | |||
9a691b5b0a | |||
6e0e633660 | |||
b9a8b46049 | |||
812e0f5f4c | |||
3d3c6adfa5 | |||
b14b498eb1 | |||
fb4909fc36 | |||
805b146f17 | |||
f764ce1585 | |||
15d541b596 | |||
df2d0d4d4c | |||
ac1e40038e | |||
146c14fc86 | |||
e1eb634c62 | |||
bb3dfb7e8a | |||
93d11bb439 | |||
99e1318071 | |||
d16237d015 | |||
8a38ebb09d | |||
7f2ee24cb9 | |||
9ac8728d30 | |||
4b0cd04355 | |||
5c5755d4a6 | |||
aaa8c4ba67 | |||
04c7df8ac8 | |||
0f6cda377c | |||
60db7e2516 | |||
218aab1af3 | |||
650227b6e2 | |||
598ff3ffdf | |||
76fc55b125 | |||
7c3186da79 | |||
106dc32a3d | |||
05edf33062 | |||
bba5339407 | |||
d10393ea37 | |||
98175e397c | |||
62246f342d | |||
bff6513192 | |||
bf0779a096 | |||
9991507297 | |||
222ff762da | |||
6b27a97e7b | |||
87f790a044 | |||
75c4c55a32 | |||
728ad157e9 | |||
e542fe11b9 | |||
aa66fc61ab | |||
7f8304e407 | |||
3b80b36ed6 | |||
ba6e2a6402 | |||
6841d96455 | |||
8528820d89 | |||
2c9b72fe1d | |||
fe417b0c29 | |||
b3f67657d7 | |||
602c57c001 | |||
6a17e4480e | |||
2b99da5a37 | |||
1f1cd2ce0f | |||
a653f98fc1 | |||
a01ea13f5b | |||
10701ccdfa | |||
07028c8dd8 | |||
4890fcf0e1 | |||
2e71275f5b | |||
be87af5e06 | |||
f9c36c8f99 | |||
92d282f4ba | |||
a1bf86dabf | |||
21284546c4 | |||
e936f0d285 | |||
6af03240a1 | |||
01c92feb40 | |||
94d2c5660a | |||
71b3588577 | |||
2def57d82c | |||
0e88260c31 | |||
86c2ea7fd9 | |||
fc3b82c35c | |||
1d177412c3 | |||
c272cad2ea | |||
e757fb43a1 | |||
8705fbe4b2 | |||
aa60462653 | |||
9c0d89de83 | |||
809febc353 | |||
f4ff247862 | |||
1978658b9c | |||
219700f0bc | |||
2918048b16 | |||
a87016a23f | |||
f7ff77b88f | |||
e8db68b960 | |||
93a5c3a02a | |||
e46cba7a06 | |||
ba21738bd9 | |||
b1db52d2b6 | |||
2bed89aaba | |||
86c68eeb32 | |||
8cb53ceba2 | |||
a96b374ad7 | |||
9945993f0b | |||
59e90ec754 | |||
41bff53853 | |||
88b3f7c322 | |||
b31445fefb | |||
2dc32f8b20 | |||
b43b531c3b | |||
bf388e68f0 | |||
5252d450a9 | |||
8f17c3d830 | |||
6627ea417c | |||
92b2befd55 | |||
43207455b8 | |||
5fa431e29b | |||
78f3caa455 | |||
6d519e3a07 | |||
85c8b7d11c | |||
fa02f4b5f0 | |||
3df33261ce | |||
ee1bcf2011 | |||
571b3a4e02 | |||
6bf02cecd9 | |||
05d4a09f8c | |||
169e9ea55a | |||
9b916f6204 | |||
2123e83010 | |||
294b59b4d6 | |||
820ceb48dd | |||
73ce681307 | |||
faa757b54f | |||
36076aefcc | |||
b9482a6f08 | |||
d573182f4b | |||
75be6454eb | |||
428fe68cdb | |||
18967cf3d6 | |||
14ed43aaa5 | |||
c555d5c78c | |||
5db9819560 | |||
dd2cd0a18d | |||
c7ae70972f | |||
17cf0c67b3 | |||
7d40387f43 | |||
20a535429c | |||
5ff7bb3259 | |||
0d95c3b9c9 | |||
170f9dde61 | |||
61170c0918 | |||
80940765fe | |||
9d98a20e40 | |||
6f9f1ac1e7 | |||
71b096f9ef | |||
9272f53bea | |||
9b5f08e13c | |||
d0b1a49300 | |||
e500cf92ee | |||
551091f650 | |||
0c01ad1770 | |||
cba915c34d | |||
7ac41ac5cb | |||
c6bb509fc3 | |||
4d0d7adce1 | |||
6bcc420af1 | |||
9f35f5356b | |||
8d73ec797b | |||
c3fc8538cc | |||
600657b1a8 | |||
d3f21c8f16 | |||
895d51586e | |||
e200f28267 | |||
a4c6439981 | |||
6ee2e8c5da | |||
f4af29acb4 | |||
a8810816f0 | |||
b7bf3fd375 | |||
b26e85ebb2 | |||
8b8a295e16 | |||
894690a97f | |||
843ce2e3a7 | |||
9f33ddd883 | |||
a2dc4f1964 | |||
cca486f2b9 | |||
b9e27ef191 | |||
29e875bcde | |||
686d67410a | |||
4226ba88ae | |||
672bc91e36 | |||
bc9cb9b36c | |||
edafc06c3f | |||
134f8a7989 | |||
771cbdbd77 | |||
a491baddb9 | |||
8d10a5e0ab | |||
cbe42d3a60 | |||
0c4d72e17a | |||
2db3290bed | |||
429df81ec9 | |||
bb24516474 | |||
16de128fdb | |||
8e339c3d4b | |||
25298518bc | |||
2e26ff2cde | |||
a8702d4f5e | |||
7f4cc5fb0f | |||
e7215be00e | |||
4f35cc00bc | |||
af47587116 | |||
3c4daeadb0 | |||
348ab19ac6 | |||
ada74a3e42 | |||
785ac9bdab | |||
d1e604e7a5 | |||
2749a88704 | |||
eb3db134f8 | |||
fa7f5d24b0 | |||
ba76015c71 | |||
1887a2790f | |||
5d0fc38107 | |||
65df55a635 | |||
a60e1f1fdc | |||
0a0f44607e | |||
007080ee48 | |||
a13e3e95b7 | |||
169938e1da | |||
e5fb875968 | |||
9bd14f1b4e | |||
fd2295119d | |||
eac2709e86 | |||
48f6d134bf | |||
6d7467e746 | |||
0d1629495b | |||
63839dc22b | |||
c627944bd1 | |||
f0be4b270b | |||
728065e771 | |||
849fac490d | |||
5752229312 | |||
6eb860579a | |||
d08d54b4c9 | |||
bb210f8d47 | |||
efca10e252 | |||
b8f851b009 | |||
1e29ae4171 | |||
0ae1e850f4 | |||
d380668c0f | |||
9a72c5eb72 | |||
407cfbe02b | |||
6400b2c2c2 | |||
0d3fd954a3 | |||
cce7ecbe73 | |||
d200c1e381 | |||
673c427485 | |||
2f9e5bfee1 | |||
11702d3d7c | |||
43f47e2087 | |||
4b881903f0 | |||
761e37ade6 | |||
10ed2f7404 | |||
43768f1691 | |||
280d27343d | |||
138e1662c7 | |||
c80fe094a2 | |||
139221dd22 | |||
72c2981d66 | |||
6f003ffa53 | |||
7f6fd7dc47 | |||
ccf5118c9d | |||
022c19c020 | |||
2e5e217842 | |||
9c93c004ec | |||
472800eff6 | |||
b8d43a629b | |||
f6693e12cf | |||
38f491cf57 | |||
3464d5d860 | |||
81773dc800 | |||
da400155eb | |||
5079938a5b | |||
b8430adc50 | |||
eed434aeb2 | |||
372470b44b | |||
7071553c3b | |||
eea237b813 | |||
c37288c285 | |||
ccf5767a01 | |||
ffe6fc8c2a | |||
5f0b4d2050 | |||
f9d7dc7d3a | |||
8ebea00896 | |||
a548f4744e | |||
a383f3e717 | |||
60f18669c8 | |||
a36946529b | |||
eaac0c728f | |||
9ca95774a3 | |||
fa66851889 | |||
ab81f11199 | |||
bea7741d35 | |||
81e163812e | |||
4f233538e0 | |||
4ac09ac08b | |||
6d02970676 | |||
b773a05bb5 | |||
accf1befce | |||
6953eaa9d0 | |||
180bae59c8 | |||
9cafc163e8 | |||
8f8eef4107 | |||
7af745087e | |||
aab093200b | |||
1a9556f811 | |||
39b36aa509 | |||
3fc260a12c | |||
1696a2f579 | |||
baebc0b690 | |||
9f3a10ca71 | |||
38ceaf3106 | |||
87b619794d | |||
29c4a36479 | |||
ddeb12f08c | |||
a7b1406e06 | |||
871ef60cf6 | |||
7e9071a533 | |||
8c660e9856 | |||
6ca641ab7f | |||
8d6609566f | |||
17e4c63737 | |||
fad470b670 | |||
c5646b1e59 | |||
5da27bb266 | |||
be6a077c8e | |||
8d643fc6b4 | |||
47876e3971 | |||
c79c251ba7 | |||
483670e798 | |||
6c8a6008d5 | |||
e680124d7b | |||
b06a06f50c | |||
c1be55a719 | |||
6416de237f | |||
ad44fd52a4 | |||
03c27b10e5 | |||
fc0ef29738 | |||
a0eb53a607 | |||
66e5ef64fd | |||
f5d5cc18a8 | |||
4c65939bbe | |||
379527cd58 | |||
f63fb59cbf | |||
cde864fdc7 | |||
e9361697f7 | |||
830c752971 | |||
6bdc1b73ae | |||
0f003870bb | |||
0631c77a1c | |||
2cc4308a58 | |||
4975475e85 | |||
466fe58763 | |||
3b7e338808 | |||
53b13e7aef | |||
fa60ecb25a | |||
a975824481 | |||
c51e5eb6cb | |||
f0bc502ec9 | |||
902cafc5e4 | |||
b2f54aa23e | |||
29a5425259 | |||
e2a34c75ea | |||
de7aa6f6a6 | |||
9acb421b2e | |||
66d2dc74e7 | |||
2f613607af | |||
d4b9c3afb1 | |||
b81cf49d0a | |||
1da45fdffc | |||
10dde3f002 | |||
c2d6af12ab | |||
6e48f88c06 | |||
7a91a71565 | |||
c4764110d8 | |||
ff68e65250 | |||
c9d83e5916 | |||
5dc99dbfcb | |||
8dbec85c8e | |||
84d7e40e66 | |||
0b509f2200 | |||
9591162cc9 | |||
007e17fd8b | |||
35c5f96672 | |||
95f8e7517c | |||
9667c79162 | |||
1c79c25262 | |||
04b4b34bfe | |||
fc0e689d4e | |||
83bb4b3b12 | |||
8dcfc604a0 | |||
d2d639e5f6 | |||
b3eb7693e3 | |||
10f42b1522 | |||
76e9f3b1dc | |||
d0ff9bc16c | |||
5e4ebd16f9 | |||
d2b19424ff | |||
08286254cd | |||
4805c39b45 | |||
f845bbf20a | |||
71c7158124 | |||
c4643ee52c | |||
b46b0882f3 | |||
1c4efc9431 | |||
4133e0ccdd | |||
de415e7e75 | |||
9d17524f45 | |||
68ad9650af | |||
8d4d8a3abc | |||
9617e29ed5 | |||
75406f7b58 | |||
70f5ae4f9c | |||
ff307f1d65 | |||
d7ae601c52 | |||
33b9ff78bb | |||
0739ce2fb4 | |||
8fc1a754de | |||
ca8c1c9d92 | |||
0485ab1120 | |||
8a8851847c | |||
7b41051d0d | |||
3db1f592e2 | |||
6853ec0b69 | |||
3b39049c20 | |||
37d1669a72 | |||
ee9f36d883 | |||
e712f9fdb8 | |||
9991f5dc64 | |||
fce6c3d29c | |||
346439076e | |||
5e8d8b8d5d | |||
db9f86c41e | |||
c7adde62eb | |||
34559dda08 | |||
37c4621e9e | |||
dd7ed290f5 | |||
dc1e1fc897 | |||
0a5ddcea68 | |||
37abde04d7 | |||
40f2f7033e | |||
aebf909dc6 | |||
ec7d45fd91 | |||
3af5d96bf5 | |||
c7a8a1a91c | |||
2dd434d987 | |||
5e954bae6a | |||
a97dba18c2 | |||
26770de40e | |||
583d4ddfb8 | |||
486047b929 | |||
b65ec6463b | |||
7cc13ea669 | |||
c2efc969d0 | |||
b091fee035 | |||
2a0f2454f4 | |||
97ea1763f1 | |||
b9f51596e9 | |||
0610794dbe | |||
a6b32fcad1 | |||
e583e78a4e | |||
3eb3feea49 | |||
935914428b | |||
ab63ba1c54 | |||
afdc6b69df | |||
8b419dcee6 | |||
e7181257e3 | |||
8e7c09332f | |||
d9ea5e5538 | |||
a21460a1b8 | |||
b6a480ff61 | |||
84ee6dd2f5 | |||
a950585a02 | |||
7f8a2c1eaf | |||
125157fdf4 | |||
517263dd58 | |||
301fc73687 | |||
45441c351d | |||
be5ce414ba | |||
bb3f277ba5 | |||
23049a8ae2 | |||
8bbebfdb13 | |||
662b4b5c53 | |||
9675b6372c | |||
03afd49115 | |||
0af3505c2a | |||
f78b968075 | |||
7d40316044 | |||
e3dcad62cc | |||
db6a871854 | |||
ce4f57bd8f | |||
8be8328830 | |||
0a0092e189 | |||
c50f0a2ac5 | |||
6b3012d21c | |||
729f848c14 | |||
56cc4776a6 | |||
e6f25fb707 | |||
b9cbba2309 | |||
4165f8d4af | |||
cac185634d | |||
66dceefcf0 | |||
677ff51ea5 | |||
645b8a543e | |||
74a506c48b | |||
deda2b4055 | |||
67ebb90ffa | |||
5d16ba135a | |||
150d08dc45 | |||
c1a85486cc | |||
d16a207a83 | |||
d114b01bcc | |||
dee54c3b41 | |||
670d2fa12e | |||
a68e47ce8c | |||
0314aa6733 | |||
496ad7ce9b | |||
efdd4a6b16 | |||
0b31b215f6 | |||
7e1734aed5 | |||
19cd51043a | |||
5348a451e9 | |||
83ae21140d | |||
cdf9519a9f | |||
d77358eaac | |||
9609a7615b | |||
361a06e5b3 | |||
1720307c21 | |||
15ae24f0bd | |||
143713fac1 | |||
e4845b580b | |||
40c623b202 | |||
092ace8432 | |||
00cf619c68 | |||
b6e1c3bc88 | |||
3b1d06a71d | |||
a5d8c96bab | |||
564d95f701 | |||
19e21c80df | |||
768e2867b5 | |||
f07a855e7e | |||
2fa9daf627 | |||
a1bae7ced3 | |||
7312580a8d | |||
1c774aa4a0 | |||
cbcdc6171f | |||
444a2936e2 | |||
6a31f38ceb | |||
29b32f6cbf | |||
465e0f31d9 | |||
5a8052ae47 | |||
6a64e05247 | |||
81a64eed08 | |||
29b27dc626 | |||
ca25a12be0 | |||
c0a6f5eb30 | |||
4bc4d266c2 | |||
8f0ee4df6d | |||
579d077b35 | |||
32444fac90 | |||
849177562d | |||
86bbc4cf6e | |||
46e58bb49e | |||
9199f91151 | |||
9247696c1c | |||
37f62e15cf | |||
a98c924b24 | |||
a71ca60270 | |||
76cc730d8f | |||
12bb7e9294 | |||
1dca0ea003 | |||
b340a6568f | |||
6f4e93bb76 | |||
93eb09887e | |||
09081b03b6 | |||
ceee393bd8 | |||
b969513d94 | |||
2111a2c67e | |||
7405241b82 | |||
b0884c6b04 | |||
20bea62542 | |||
24925f7726 | |||
d0c18d4538 | |||
37eaa4b912 | |||
a3cca056ae | |||
ee965008d1 | |||
c57d2ece9c | |||
e5aa7aa866 | |||
cacdf600f4 | |||
5ee0ee8efb | |||
08f20796a7 | |||
58d3a7ee2c | |||
f6be360eab | |||
543a48b4ab | |||
0f657b934d | |||
c4e42212aa | |||
a4fe4996aa | |||
fbcacb24f8 | |||
0eaa20e09d | |||
271d57051e | |||
3d6c260e53 | |||
d0f17bd41a | |||
819cd257a8 | |||
655d72a2b1 | |||
71c96fdf62 | |||
3f2327dee4 | |||
06eecfce40 | |||
67af1485b3 | |||
a00a85a56a | |||
bb953a6139 | |||
140dc26dc6 | |||
3548deebf6 | |||
c67155f02c | |||
c10e1e8cbf | |||
c5f5ad3f75 | |||
8ec3074488 | |||
1b1284d3d0 | |||
f71518ed6f | |||
1800785b80 | |||
6449724ed5 | |||
6179c3e7d4 | |||
3e5d4c5fbb | |||
3f2b63aaa5 | |||
d29a5cdb44 | |||
bbcc7ffeaa | |||
93f4dede3e | |||
683f8235b1 | |||
43917317b4 | |||
f182de5929 | |||
c6657bffd2 | |||
3d138d404f | |||
9c93162741 | |||
6068c6048a | |||
d47461ba40 | |||
66e88ac6fb | |||
d3cada4c95 | |||
27443bcd21 | |||
b246e171b7 | |||
ec434bec56 | |||
7458f622f5 | |||
ab72e01707 | |||
acad74528d | |||
813bbbb94a | |||
a2a858262a | |||
727e5cb199 | |||
71602b43bd | |||
bc40b92744 | |||
d545becf24 | |||
48f605dbe0 | |||
b0d7bbbb79 | |||
f624b7c66d | |||
bf96d8a10c | |||
e8b496cfdc | |||
79ef151ad3 | |||
8e48103fd2 | |||
ed4c65600c | |||
ae16a1bd89 | |||
e2b42145e1 | |||
55ad1f99fd | |||
5b427bee35 | |||
d1c88a5cef | |||
99a25d5e9b | |||
d148d6b3a5 | |||
66189d3ab2 | |||
f1afa3b436 | |||
6380fb193c | |||
341ffc9a55 | |||
6962b39fc9 | |||
d04b4c77c6 | |||
453b7df0be | |||
878ee99fe4 | |||
6918e3044f | |||
cf46c3800f | |||
7c0c132f40 | |||
e0bf797876 | |||
dd07c374d7 | |||
b3e59b3829 | |||
352b09d9cd | |||
93cc6d99f8 | |||
85a99fc8fa | |||
a4d801bed4 | |||
fbff38c5c3 | |||
14402f7537 | |||
88d24f8067 | |||
cc1d700f7d | |||
e82acdabb0 | |||
ea42c98571 | |||
cc5df9b171 | |||
b4749f297b | |||
e564c6604c | |||
712615a312 | |||
d95d4901d2 | |||
9373654306 | |||
4a9d9f03a8 | |||
b7261ec629 | |||
2e1f16fa04 | |||
d295cc5223 | |||
ff088009d9 | |||
52c19e9962 | |||
68d0a16d1c | |||
a422e8d39a | |||
ef80c1be61 | |||
85d9816aaa | |||
93b66d980d | |||
07d617da91 | |||
34aac40e65 | |||
f54bf2b8af | |||
e7d04d9817 | |||
ef1537ac2c | |||
d1f86fe3d9 | |||
d13b79552b | |||
4036bfd703 | |||
759e360a1d | |||
8865529b39 | |||
cdb73ee49c | |||
9188c28ee7 | |||
2a6c1f050d | |||
2ec1f8cdc0 | |||
121b388d85 | |||
589119c9ee | |||
b35e1a476e | |||
8174bce720 | |||
d8a7d62b23 | |||
a75730d91f | |||
a2b5f929dd | |||
7a0fa9f1a0 | |||
28ff7f24c5 | |||
e6db25357b | |||
72ea6b6fdd | |||
bf5f72fd9d | |||
af724a1e0e | |||
0eeaf1ce21 | |||
57a8215c6b | |||
9163e4dee6 | |||
c56d6e3f6b | |||
20e8854467 | |||
3ef38fabdb | |||
f5cee10761 | |||
d1cbb765c0 | |||
7ea9a5ca2d | |||
20c015c312 | |||
ecb48ce663 | |||
00dc03a235 | |||
d3b203a4a1 | |||
4506440a62 | |||
da6bd84cdf | |||
0b9ccf6a57 | |||
a056bd177f | |||
d2ea8f2898 | |||
5cce4269bb | |||
0a2ed6dd94 | |||
417f328206 | |||
cca9732925 | |||
f02864b752 | |||
62bb15317c | |||
b35751126f | |||
28d6d8ba96 | |||
6bdb16e293 | |||
eb45cf6175 | |||
d6d8f56570 | |||
5322dc1de8 | |||
51bb1a5c9d | |||
996dadf6f5 | |||
29bb0f6712 | |||
f6fbad8403 | |||
e37ce4172e | |||
1dfd871169 | |||
a637742bb0 | |||
a5e4db99fb | |||
a9f66e2cd9 | |||
7bc7af8245 | |||
e5dfe1e638 | |||
284f064cbf | |||
e5c6f00283 | |||
12d316ebe4 | |||
cbd8932075 | |||
feb6dcbc94 | |||
181e74b1d1 | |||
eb04e26b22 | |||
7b97f0bf47 | |||
19fdaf4c89 | |||
7ca9c8dc42 | |||
946f35c601 | |||
c7b47bdd02 | |||
eef15e05f4 | |||
f265346a10 | |||
a321bd79ed | |||
819e2b5f9f | |||
91344741a5 | |||
4d2b82235c | |||
ffa3936878 | |||
26c70aa071 | |||
1bd887567e | |||
3304f32ef0 | |||
0790ae2298 | |||
39151b61e7 | |||
3f49d70745 | |||
e5434961de | |||
aab2d3a03f | |||
b022ebb80e | |||
2737cae4ab | |||
c4e6272535 | |||
aa0c98bf34 | |||
63b6b262c6 | |||
424639ea80 | |||
594776f3a6 | |||
918e93d211 | |||
b82f98c87f | |||
6c4251a91f | |||
2261782920 | |||
043dcfb283 | |||
3c76c5e0f1 | |||
d348e6314a | |||
b3fa6f352b | |||
191b05c305 | |||
215fdce411 | |||
b25805e0a1 | |||
13d0d2a300 | |||
15f51fb03f | |||
a24b1f5c2a | |||
04e7f65e8e | |||
41b9318028 | |||
378e8b53f2 | |||
c832e8b1a7 | |||
fee7ade1a5 | |||
d51dbf8a53 | |||
c03a1b57c5 | |||
0c566cfbde | |||
9295325d21 | |||
cb1aa8bef0 | |||
b9d19be183 | |||
293369f165 | |||
3046438cb1 | |||
811e5a5ad1 | |||
2c8f18d7fc | |||
c7f8cdd098 | |||
58ff5b934a | |||
03d15ddded | |||
002d8f80a6 | |||
82d3791859 | |||
d9531838f2 | |||
c7b5c77395 | |||
223aa37161 | |||
c1acadbf3d | |||
54af894b82 | |||
e1ac75f394 | |||
8c69a94488 | |||
07b625d4aa | |||
a1296dc7af | |||
e5a2236d72 | |||
588a82426e | |||
8245ddf2a6 | |||
775a0c6478 | |||
bad67a8b65 | |||
7e98e184a0 | |||
6240eff160 | |||
a8918ebe86 | |||
b852176958 | |||
c9e398b7ec | |||
e84d5626df | |||
0fb61938ce | |||
d6b27f2f21 | |||
e15bcfae07 | |||
72cf5a3d5e | |||
7de2e00c94 | |||
efe5d75798 | |||
9f1eedbe1b | |||
7fe495179f | |||
7f6c4f6236 | |||
30948f1701 | |||
02ec3607b2 | |||
3c2dcfbfa2 | |||
8bcf59aaf0 | |||
c6d2ac9100 | |||
2ac578c3ad | |||
f941435232 | |||
171a1cb876 | |||
cfc19434d0 | |||
688871a680 | |||
44c8558aa3 | |||
6b923d2310 | |||
09e0b31bc9 | |||
eb2454eded | |||
3014d8cead | |||
70fdc2edf2 | |||
e47f29aa38 | |||
d811896e21 | |||
5c999b6ef1 | |||
79a6d9e771 | |||
e1cf1c786d | |||
71fe9559b1 | |||
f1fa8d34bf | |||
aa07fa9207 | |||
47fec973bc | |||
ea8247aa16 | |||
bf18284450 | |||
cd58d5a357 | |||
75bb3f992c | |||
ae1fcdb8c0 | |||
507080f75e | |||
5bcf043d97 | |||
99605b98d4 | |||
6dfd43a8da | |||
c7135875b8 | |||
e29e1101cd | |||
d97602e60b | |||
a5cbac1f97 | |||
3143d3d91a | |||
9bdf3fc4ac | |||
e06bc7dba3 | |||
a8b9f38000 | |||
ca27b89a8b | |||
e1bf7caa9a | |||
e681c17a0f | |||
5416d88c97 | |||
0dca152436 | |||
9ce7abd31d | |||
f41ff281fb | |||
ee437649f0 | |||
321cb72ca8 | |||
4303d51c0a | |||
d16bf12611 | |||
4231a7972d | |||
c436d39014 | |||
51a12814f9 | |||
00ae6e4623 | |||
4b587e8711 | |||
d2f377b54f | |||
193c820757 | |||
b9298792ae | |||
aaf30ab965 | |||
2db66e6154 | |||
38295e591d | |||
544b0248b2 | |||
2bccf633d5 | |||
4f9d5ae7b1 | |||
259337dff1 | |||
84768eb74e | |||
288764b551 |
18
.env.example
Normal file
18
.env.example
Normal file
@ -0,0 +1,18 @@
|
||||
HTTPS=off
|
||||
SITH_DEBUG=true
|
||||
|
||||
# This is not the real key used in prod
|
||||
SECRET_KEY=(4sjxvhz@m5$0a$j0_pqicnc$s!vbve)z+&++m%g%bjhlz4+g2
|
||||
|
||||
# comment the sqlite line and uncomment the postgres one to switch the dbms
|
||||
DATABASE_URL=sqlite:///db.sqlite3
|
||||
#DATABASE_URL=postgres://user:password@127.0.0.1:5432/sith
|
||||
|
||||
REDIS_PORT=7963
|
||||
CACHE_URL=redis://127.0.0.1:${REDIS_PORT}/0
|
||||
TASK_BROKER_URL=redis://127.0.0.1:${REDIS_PORT}/1
|
||||
|
||||
# Used to select which other services to run alongside
|
||||
# manage.py, pytest and runserver
|
||||
PROCFILE_STATIC=Procfile.static
|
||||
PROCFILE_SERVICE=Procfile.service
|
14
.envrc
14
.envrc
@ -1,14 +1,6 @@
|
||||
if [[ ! -f pyproject.toml ]]; then
|
||||
log_error 'No pyproject.toml found. Use `poetry new` or `poetry init` to create one first.'
|
||||
if [[ ! -d .venv ]]; then
|
||||
log_error 'No .venv folder found. Use `uv sync` to create one first.'
|
||||
exit 2
|
||||
fi
|
||||
|
||||
local VENV=$(poetry env list --full-path | cut -d' ' -f1)
|
||||
if [[ -z $VENV || ! -d $VENV/bin ]]; then
|
||||
log_error 'No poetry virtual environment found. Use `poetry install` to create one first.'
|
||||
exit 2
|
||||
fi
|
||||
|
||||
export VIRTUAL_ENV=$VENV
|
||||
export POETRY_ACTIVE=1
|
||||
PATH_add "$VENV/bin"
|
||||
. .venv/bin/activate
|
8
.github/actions/compile_messages/action.yml
vendored
8
.github/actions/compile_messages/action.yml
vendored
@ -1,8 +0,0 @@
|
||||
name: "Compile messages"
|
||||
description: "Compile the gettext translation messages"
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Setup project
|
||||
run: poetry run ./manage.py compilemessages
|
||||
shell: bash
|
78
.github/actions/setup_project/action.yml
vendored
78
.github/actions/setup_project/action.yml
vendored
@ -1,53 +1,65 @@
|
||||
name: "Setup project"
|
||||
description: "Setup Python and Poetry"
|
||||
inputs:
|
||||
full:
|
||||
description: >
|
||||
If true, do a full setup, else install
|
||||
only python, uv and non-xapian python deps
|
||||
required: false
|
||||
default: "false"
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Install apt packages
|
||||
uses: awalsh128/cache-apt-pkgs-action@latest
|
||||
if: ${{ inputs.full == 'true' }}
|
||||
uses: awalsh128/cache-apt-pkgs-action@v1.4.3
|
||||
with:
|
||||
packages: gettext libxapian-dev libgraphviz-dev
|
||||
packages: gettext
|
||||
version: 1.0 # increment to reset cache
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install gettext libxapian-dev libgraphviz-dev
|
||||
shell: bash
|
||||
|
||||
- name: Set up python
|
||||
uses: actions/setup-python@v4
|
||||
- name: Install Redis
|
||||
if: ${{ inputs.full == 'true' }}
|
||||
uses: shogo82148/actions-setup-redis@v1
|
||||
with:
|
||||
python-version: "3.10"
|
||||
redis-version: "7.x"
|
||||
|
||||
- name: Load cached Poetry installation
|
||||
id: cached-poetry
|
||||
uses: actions/cache@v3
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
path: ~/.local
|
||||
key: poetry-0 # increment to reset cache
|
||||
version: "0.5.14"
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "uv.lock"
|
||||
|
||||
- name: Install Poetry
|
||||
if: steps.cached-poetry.outputs.cache-hit != 'true'
|
||||
shell: bash
|
||||
run: curl -sSL https://install.python-poetry.org | python3 -
|
||||
|
||||
- name: Check pyproject.toml syntax
|
||||
shell: bash
|
||||
run: poetry check
|
||||
|
||||
- name: Load cached dependencies
|
||||
uses: actions/cache@v3
|
||||
- name: "Set up Python"
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
path: ~/.cache/pypoetry
|
||||
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-poetry-
|
||||
python-version-file: ".python-version"
|
||||
|
||||
- name: Restore cached virtualenv
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
key: venv-${{ runner.os }}-${{ hashFiles('.python-version') }}-${{ hashFiles('pyproject.toml') }}-${{ env.CACHE_SUFFIX }}
|
||||
path: .venv
|
||||
|
||||
- name: Install dependencies
|
||||
run: poetry install -E testing -E docs
|
||||
run: uv sync
|
||||
shell: bash
|
||||
|
||||
- name: Install Xapian
|
||||
if: ${{ inputs.full == 'true' }}
|
||||
run: uv run ./manage.py install_xapian
|
||||
shell: bash
|
||||
|
||||
# compiling xapian accounts for almost the entirety of the virtualenv setup,
|
||||
# so we save the virtual environment only on workflows where it has been installed
|
||||
- name: Save cached virtualenv
|
||||
if: ${{ inputs.full == 'true' }}
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
key: venv-${{ runner.os }}-${{ hashFiles('.python-version') }}-${{ hashFiles('pyproject.toml') }}-${{ env.CACHE_SUFFIX }}
|
||||
path: .venv
|
||||
|
||||
- name: Compile gettext messages
|
||||
run: poetry run ./manage.py compilemessages
|
||||
if: ${{ inputs.full == 'true' }}
|
||||
run: uv run ./manage.py compilemessages
|
||||
shell: bash
|
||||
|
10
.github/actions/setup_xapian/action.yml
vendored
10
.github/actions/setup_xapian/action.yml
vendored
@ -1,10 +0,0 @@
|
||||
name: "Setup xapian"
|
||||
description: "Setup the xapian indexes"
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Setup xapian index
|
||||
run: |
|
||||
mkdir -p /dev/shm/search_indexes
|
||||
ln -s /dev/shm/search_indexes sith/search_indexes
|
||||
shell: bash
|
6
.github/dependabot.yml
vendored
6
.github/dependabot.yml
vendored
@ -8,11 +8,7 @@ updates:
|
||||
- package-ecosystem: "pip" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
||||
# Raise pull requests for version updates
|
||||
# to pip against the `develop` branch
|
||||
interval: "weekly"
|
||||
target-branch: "taiste"
|
||||
reviewers:
|
||||
- "ae-utbm/developpers-v3"
|
||||
commit-message:
|
||||
prefix: "[UPDATE] "
|
56
.github/workflows/ci.yml
vendored
56
.github/workflows/ci.yml
vendored
@ -1,43 +1,55 @@
|
||||
name: Sith 3 CI
|
||||
name: Sith CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- taiste
|
||||
branches: [master, taiste]
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- taiste
|
||||
branches: [master, taiste]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
SECRET_KEY: notTheRealOne
|
||||
DATABASE_URL: sqlite:///db.sqlite3
|
||||
CACHE_URL: redis://127.0.0.1:6379/0
|
||||
TASK_BROKER_URL: redis://127.0.0.1:6379/1
|
||||
|
||||
jobs:
|
||||
black:
|
||||
name: Black format
|
||||
pre-commit:
|
||||
name: Launch pre-commits checks (ruff)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Setup Project
|
||||
uses: ./.github/actions/setup_project
|
||||
- run: poetry run black --check .
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
- uses: pre-commit/action@v3.0.1
|
||||
with:
|
||||
extra_args: --all-files
|
||||
|
||||
tests:
|
||||
name: Run tests and generate coverage report
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false # don't interrupt the other test processes
|
||||
matrix:
|
||||
pytest-mark: [not slow]
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
- uses: ./.github/actions/setup_project
|
||||
- uses: ./.github/actions/setup_xapian
|
||||
- uses: ./.github/actions/compile_messages
|
||||
with:
|
||||
full: true
|
||||
env:
|
||||
# To avoid race conditions on environment cache
|
||||
CACHE_SUFFIX: ${{ matrix.pytest-mark }}
|
||||
- name: Run tests
|
||||
run: poetry run coverage run ./manage.py test
|
||||
run: uv run coverage run -m pytest -m "${{ matrix.pytest-mark }}"
|
||||
- name: Generate coverage report
|
||||
run: |
|
||||
poetry run coverage report
|
||||
poetry run coverage html
|
||||
uv run coverage report
|
||||
uv run coverage html
|
||||
- name: Archive code coverage results
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: coverage-report
|
||||
name: coverage-report-${{ matrix.pytest-mark }}
|
||||
path: coverage_report
|
||||
|
27
.github/workflows/deploy.yml
vendored
27
.github/workflows/deploy.yml
vendored
@ -14,7 +14,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: SSH Remote Commands
|
||||
uses: appleboy/ssh-action@dce9d565de8d876c11d93fa4fe677c0285a66d78
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
with:
|
||||
# Proxy
|
||||
proxy_host : ${{secrets.PROXY_HOST}}
|
||||
@ -31,17 +31,18 @@ jobs:
|
||||
|
||||
script_stop: true
|
||||
|
||||
# See https://github.com/ae-utbm/sith3/wiki/GitHub-Actions#deployment-action
|
||||
# See https://github.com/ae-utbm/sith/wiki/GitHub-Actions#deployment-action
|
||||
script: |
|
||||
export PATH="/home/sith/.local/bin:$PATH"
|
||||
pushd ${{secrets.SITH_PATH}}
|
||||
cd ${{secrets.SITH_PATH}}
|
||||
|
||||
git pull
|
||||
poetry install
|
||||
poetry run ./manage.py migrate
|
||||
echo "yes" | poetry run ./manage.py collectstatic
|
||||
poetry run ./manage.py compilestatic
|
||||
poetry run ./manage.py compilemessages
|
||||
git fetch
|
||||
git reset --hard origin/master
|
||||
uv sync --group prod
|
||||
npm install
|
||||
uv run ./manage.py install_xapian
|
||||
uv run ./manage.py migrate
|
||||
uv run ./manage.py collectstatic --clear --noinput
|
||||
uv run ./manage.py compilemessages
|
||||
|
||||
sudo systemctl restart uwsgi
|
||||
|
||||
@ -51,14 +52,14 @@ jobs:
|
||||
timeout-minutes: 30
|
||||
needs: deployment
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Sentry Release
|
||||
uses: getsentry/action-release@v1.2.0
|
||||
uses: getsentry/action-release@v1.7.0
|
||||
env:
|
||||
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
||||
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
|
||||
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
|
||||
SENTRY_URL: ${{ secrets.SENTRY_URL }}
|
||||
with:
|
||||
environment: production
|
||||
environment: production
|
21
.github/workflows/deploy_docs.yml
vendored
Normal file
21
.github/workflows/deploy_docs.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: deploy_docs
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- taiste
|
||||
permissions:
|
||||
contents: write
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ./.github/actions/setup_project
|
||||
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
key: mkdocs-material-${{ env.cache_id }}
|
||||
path: .cache
|
||||
restore-keys: |
|
||||
mkdocs-material-
|
||||
- run: uv run mkdocs gh-deploy --force
|
44
.github/workflows/taiste.yml
vendored
44
.github/workflows/taiste.yml
vendored
@ -1,8 +1,9 @@
|
||||
name: Sith3 taiste
|
||||
name: Sith taiste
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ taiste ]
|
||||
branches: [taiste]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
deployment:
|
||||
@ -12,7 +13,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: SSH Remote Commands
|
||||
uses: appleboy/ssh-action@dce9d565de8d876c11d93fa4fe677c0285a66d78
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
with:
|
||||
# Proxy
|
||||
proxy_host : ${{secrets.PROXY_HOST}}
|
||||
@ -29,34 +30,17 @@ jobs:
|
||||
|
||||
script_stop: true
|
||||
|
||||
# See https://github.com/ae-utbm/sith3/wiki/GitHub-Actions#deployment-action
|
||||
# See https://github.com/ae-utbm/sith/wiki/GitHub-Actions#deployment-action
|
||||
script: |
|
||||
export PATH="$HOME/.poetry/bin:$PATH"
|
||||
pushd ${{secrets.SITH_PATH}}
|
||||
cd ${{secrets.SITH_PATH}}
|
||||
|
||||
git pull
|
||||
poetry install
|
||||
poetry run ./manage.py migrate
|
||||
echo "yes" | poetry run ./manage.py collectstatic
|
||||
poetry run ./manage.py compilestatic
|
||||
poetry run ./manage.py compilemessages
|
||||
git fetch
|
||||
git reset --hard origin/taiste
|
||||
uv sync --group prod
|
||||
npm install
|
||||
uv run ./manage.py install_xapian
|
||||
uv run ./manage.py migrate
|
||||
uv run ./manage.py collectstatic --clear --noinput
|
||||
uv run ./manage.py compilemessages
|
||||
|
||||
sudo systemctl restart uwsgi
|
||||
|
||||
sentry:
|
||||
runs-on: ubuntu-latest
|
||||
environment: taiste
|
||||
timeout-minutes: 30
|
||||
needs: deployment
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Sentry Release
|
||||
uses: getsentry/action-release@v1.2.0
|
||||
env:
|
||||
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
||||
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
|
||||
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
|
||||
SENTRY_URL: ${{ secrets.SENTRY_URL }}
|
||||
with:
|
||||
environment: taiste
|
||||
|
17
.gitignore
vendored
17
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
db.sqlite3
|
||||
*.sqlite3
|
||||
*.log
|
||||
*.pyc
|
||||
*.mo
|
||||
@ -8,7 +8,7 @@ pyrightconfig.json
|
||||
dist/
|
||||
.vscode/
|
||||
.idea/
|
||||
env/
|
||||
.venv/
|
||||
doc/html
|
||||
data/
|
||||
galaxy/test_galaxy_state.json
|
||||
@ -17,4 +17,15 @@ sith/settings_custom.py
|
||||
sith/search_indexes/
|
||||
.coverage
|
||||
coverage_report/
|
||||
doc/_build
|
||||
node_modules/
|
||||
.env
|
||||
*.pid
|
||||
|
||||
# compiled documentation
|
||||
site/
|
||||
|
||||
### Redis ###
|
||||
|
||||
# Ignore redis binary dump (dump.rdb) files
|
||||
|
||||
*.rdb
|
||||
|
26
.pre-commit-config.yaml
Normal file
26
.pre-commit-config.yaml
Normal file
@ -0,0 +1,26 @@
|
||||
repos:
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: v0.11.13
|
||||
hooks:
|
||||
- id: ruff-check # just check the code, and print the errors
|
||||
- id: ruff-check # actually fix the fixable errors, but print nothing
|
||||
args: ["--fix", "--silent"]
|
||||
# Run the formatter.
|
||||
- id: ruff-format
|
||||
- repo: https://github.com/biomejs/pre-commit
|
||||
rev: v0.6.1
|
||||
hooks:
|
||||
- id: biome-check
|
||||
additional_dependencies: ["@biomejs/biome@1.9.4"]
|
||||
- repo: https://github.com/rtts/djhtml
|
||||
rev: 3.0.7
|
||||
hooks:
|
||||
- id: djhtml
|
||||
name: format templates
|
||||
entry: djhtml --tabwidth 2
|
||||
types: ["jinja"]
|
||||
- id: djcss
|
||||
name: format scss files
|
||||
entry: djcss --tabwidth 2
|
||||
types: ["scss"]
|
1
.python-version
Normal file
1
.python-version
Normal file
@ -0,0 +1 @@
|
||||
3.12
|
@ -1,26 +0,0 @@
|
||||
# Read the Docs configuration file
|
||||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||
|
||||
# Required
|
||||
version: 2
|
||||
|
||||
# Allow installing xapian-bindings in pip
|
||||
build:
|
||||
apt_packages:
|
||||
- libxapian-dev
|
||||
|
||||
# Build documentation in the doc/ directory with Sphinx
|
||||
sphinx:
|
||||
configuration: doc/conf.py
|
||||
|
||||
# Optionally build your docs in additional formats such as PDF and ePub
|
||||
formats: all
|
||||
|
||||
# Optionally set the version of Python and requirements required to build your docs
|
||||
python:
|
||||
version: "3.8"
|
||||
install:
|
||||
- method: pip
|
||||
path: .
|
||||
extra_requirements:
|
||||
- docs
|
2
Procfile.service
Normal file
2
Procfile.service
Normal file
@ -0,0 +1,2 @@
|
||||
redis: redis-server --port $REDIS_PORT
|
||||
celery: uv run celery -A sith worker --beat -l INFO
|
1
Procfile.static
Normal file
1
Procfile.static
Normal file
@ -0,0 +1 @@
|
||||
bundler: npm run serve
|
49
README.md
49
README.md
@ -1,40 +1,21 @@
|
||||
<p align="center">
|
||||
<a href="#">
|
||||
<img src="https://img.shields.io/badge/Code%20Style-Black-000000?style=for-the-badge">
|
||||
</a>
|
||||
<a href="#">
|
||||
<img src="https://img.shields.io/github/checks-status/ae-utbm/sith3/master?logo=github&style=for-the-badge&label=BUILD">
|
||||
</a>
|
||||
<a href="https://sith-ae.readthedocs.io/">
|
||||
<img src="https://img.shields.io/readthedocs/sith-ae?logo=readthedocs&style=for-the-badge">
|
||||
</a>
|
||||
<a href="https://discord.gg/XK9WfPsUFm">
|
||||
<img src="https://img.shields.io/discord/971448179075731476?label=Discord&logo=discord&style=for-the-badge">
|
||||
</a>
|
||||
</p>
|
||||
# Sith
|
||||
|
||||
<h3 align="center">This is the source code of the UTBM's student association available at https://ae.utbm.fr/.</h3>
|
||||
[](#)
|
||||
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||
[](#)
|
||||
[](https://ae-utbm.github.io/sith)
|
||||
[](https://squidfunk.github.io/mkdocs-material/)
|
||||
[](https://biomejs.dev)
|
||||
[](https://discord.gg/xk9wfpsufm)
|
||||
|
||||
<p align="justify">All documentation is in the <code>docs</code> directory and online at https://sith-ae.readthedocs.io/. This documentation is written in French because it targets a French audience and it's too much work to maintain two versions. The code and code comments are strictly written in English.</p>
|
||||
### This is the source code of the UTBM's student association available at [https://ae.utbm.fr/](https://ae.utbm.fr/).
|
||||
|
||||
<h4>If you want to contribute, here's how we recommend to read the docs:</h4>
|
||||
All documentation is in the `docs` directory and online at [https://ae-utbm.github.io/sith](https://ae-utbm.github.io/sith). This documentation is written in French because it targets a French audience and it's too much work to maintain two versions. The code and code comments are strictly written in English.
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<p align="justify">
|
||||
First, it's advised to read the about part of the project to understand the goals and the mindset of the current and previous maintainers and know what to expect to learn.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p align="justify">
|
||||
If in the first part you realize that you need more background about what we use, we provide some links to tutorials and documentation at the end of our documentation. Feel free to use it and complete it with what you found helpful.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p align="justify">
|
||||
Keep in mind that this documentation is thought to be read in order.
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
#### If you want to contribute, here's how we recommend to read the docs:
|
||||
|
||||
* First, it's advised to read the about part of the project to understand the goals and the mindset of the current and previous maintainers and know what to expect to learn.
|
||||
* If in the first part you realize that you need more background about what we use, we provide some links to tutorials and documentation at the end of our documentation. Feel free to use it and complete it with what you found helpful.
|
||||
* Keep in mind that this documentation is thought to be read in order.
|
||||
|
||||
> This project is licensed under GNU GPL, see the LICENSE file at the top of the repository for more details.
|
||||
|
@ -1,15 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
@ -1,29 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
from accounting.models import *
|
||||
|
||||
|
||||
admin.site.register(BankAccount)
|
||||
admin.site.register(ClubAccount)
|
||||
admin.site.register(GeneralJournal)
|
||||
admin.site.register(AccountingType)
|
||||
admin.site.register(SimplifiedAccountingType)
|
||||
admin.site.register(Operation)
|
||||
admin.site.register(Label)
|
||||
admin.site.register(Company)
|
@ -1,280 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.core.validators
|
||||
import accounting.models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="AccountingType",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
auto_created=True,
|
||||
),
|
||||
),
|
||||
(
|
||||
"code",
|
||||
models.CharField(
|
||||
max_length=16,
|
||||
verbose_name="code",
|
||||
validators=[
|
||||
django.core.validators.RegexValidator(
|
||||
"^[0-9]*$",
|
||||
"An accounting type code contains only numbers",
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
("label", models.CharField(max_length=128, verbose_name="label")),
|
||||
(
|
||||
"movement_type",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("CREDIT", "Credit"),
|
||||
("DEBIT", "Debit"),
|
||||
("NEUTRAL", "Neutral"),
|
||||
],
|
||||
max_length=12,
|
||||
verbose_name="movement type",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "accounting type",
|
||||
"ordering": ["movement_type", "code"],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="BankAccount",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
auto_created=True,
|
||||
),
|
||||
),
|
||||
("name", models.CharField(max_length=30, verbose_name="name")),
|
||||
(
|
||||
"iban",
|
||||
models.CharField(max_length=255, blank=True, verbose_name="iban"),
|
||||
),
|
||||
(
|
||||
"number",
|
||||
models.CharField(
|
||||
max_length=255, blank=True, verbose_name="account number"
|
||||
),
|
||||
),
|
||||
],
|
||||
options={"verbose_name": "Bank account", "ordering": ["club", "name"]},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="ClubAccount",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
auto_created=True,
|
||||
),
|
||||
),
|
||||
("name", models.CharField(max_length=30, verbose_name="name")),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "Club account",
|
||||
"ordering": ["bank_account", "name"],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="Company",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
auto_created=True,
|
||||
),
|
||||
),
|
||||
("name", models.CharField(max_length=60, verbose_name="name")),
|
||||
],
|
||||
options={"verbose_name": "company"},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="GeneralJournal",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
auto_created=True,
|
||||
),
|
||||
),
|
||||
("start_date", models.DateField(verbose_name="start date")),
|
||||
(
|
||||
"end_date",
|
||||
models.DateField(
|
||||
null=True, verbose_name="end date", default=None, blank=True
|
||||
),
|
||||
),
|
||||
("name", models.CharField(max_length=40, verbose_name="name")),
|
||||
(
|
||||
"closed",
|
||||
models.BooleanField(verbose_name="is closed", default=False),
|
||||
),
|
||||
(
|
||||
"amount",
|
||||
accounting.models.CurrencyField(
|
||||
decimal_places=2,
|
||||
default=0,
|
||||
verbose_name="amount",
|
||||
max_digits=12,
|
||||
),
|
||||
),
|
||||
(
|
||||
"effective_amount",
|
||||
accounting.models.CurrencyField(
|
||||
decimal_places=2,
|
||||
default=0,
|
||||
verbose_name="effective_amount",
|
||||
max_digits=12,
|
||||
),
|
||||
),
|
||||
],
|
||||
options={"verbose_name": "General journal", "ordering": ["-start_date"]},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="Operation",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
auto_created=True,
|
||||
),
|
||||
),
|
||||
("number", models.IntegerField(verbose_name="number")),
|
||||
(
|
||||
"amount",
|
||||
accounting.models.CurrencyField(
|
||||
decimal_places=2, max_digits=12, verbose_name="amount"
|
||||
),
|
||||
),
|
||||
("date", models.DateField(verbose_name="date")),
|
||||
("remark", models.CharField(max_length=128, verbose_name="comment")),
|
||||
(
|
||||
"mode",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("CHECK", "Check"),
|
||||
("CASH", "Cash"),
|
||||
("TRANSFERT", "Transfert"),
|
||||
("CARD", "Credit card"),
|
||||
],
|
||||
max_length=255,
|
||||
verbose_name="payment method",
|
||||
),
|
||||
),
|
||||
(
|
||||
"cheque_number",
|
||||
models.CharField(
|
||||
max_length=32,
|
||||
null=True,
|
||||
verbose_name="cheque number",
|
||||
default="",
|
||||
blank=True,
|
||||
),
|
||||
),
|
||||
("done", models.BooleanField(verbose_name="is done", default=False)),
|
||||
(
|
||||
"target_type",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("USER", "User"),
|
||||
("CLUB", "Club"),
|
||||
("ACCOUNT", "Account"),
|
||||
("COMPANY", "Company"),
|
||||
("OTHER", "Other"),
|
||||
],
|
||||
max_length=10,
|
||||
verbose_name="target type",
|
||||
),
|
||||
),
|
||||
(
|
||||
"target_id",
|
||||
models.IntegerField(
|
||||
null=True, verbose_name="target id", blank=True
|
||||
),
|
||||
),
|
||||
(
|
||||
"target_label",
|
||||
models.CharField(
|
||||
max_length=32,
|
||||
blank=True,
|
||||
verbose_name="target label",
|
||||
default="",
|
||||
),
|
||||
),
|
||||
(
|
||||
"accounting_type",
|
||||
models.ForeignKey(
|
||||
null=True,
|
||||
related_name="operations",
|
||||
verbose_name="accounting type",
|
||||
to="accounting.AccountingType",
|
||||
blank=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
),
|
||||
),
|
||||
],
|
||||
options={"ordering": ["-number"]},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="SimplifiedAccountingType",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
auto_created=True,
|
||||
),
|
||||
),
|
||||
("label", models.CharField(max_length=128, verbose_name="label")),
|
||||
(
|
||||
"accounting_type",
|
||||
models.ForeignKey(
|
||||
verbose_name="simplified accounting types",
|
||||
to="accounting.AccountingType",
|
||||
related_name="simplified_types",
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "simplified type",
|
||||
"ordering": ["accounting_type__movement_type", "accounting_type__code"],
|
||||
},
|
||||
),
|
||||
]
|
@ -1,106 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("club", "0001_initial"),
|
||||
("accounting", "0001_initial"),
|
||||
("core", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="operation",
|
||||
name="invoice",
|
||||
field=models.ForeignKey(
|
||||
null=True,
|
||||
related_name="operations",
|
||||
verbose_name="invoice",
|
||||
to="core.SithFile",
|
||||
blank=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="operation",
|
||||
name="journal",
|
||||
field=models.ForeignKey(
|
||||
verbose_name="journal",
|
||||
to="accounting.GeneralJournal",
|
||||
related_name="operations",
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="operation",
|
||||
name="linked_operation",
|
||||
field=models.OneToOneField(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
blank=True,
|
||||
to="accounting.Operation",
|
||||
null=True,
|
||||
related_name="operation_linked_to",
|
||||
verbose_name="linked operation",
|
||||
default=None,
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="operation",
|
||||
name="simpleaccounting_type",
|
||||
field=models.ForeignKey(
|
||||
null=True,
|
||||
related_name="operations",
|
||||
verbose_name="simple type",
|
||||
to="accounting.SimplifiedAccountingType",
|
||||
blank=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="generaljournal",
|
||||
name="club_account",
|
||||
field=models.ForeignKey(
|
||||
verbose_name="club account",
|
||||
to="accounting.ClubAccount",
|
||||
related_name="journals",
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="clubaccount",
|
||||
name="bank_account",
|
||||
field=models.ForeignKey(
|
||||
verbose_name="bank account",
|
||||
to="accounting.BankAccount",
|
||||
related_name="club_accounts",
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="clubaccount",
|
||||
name="club",
|
||||
field=models.ForeignKey(
|
||||
verbose_name="club",
|
||||
to="club.Club",
|
||||
related_name="club_account",
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="bankaccount",
|
||||
name="club",
|
||||
field=models.ForeignKey(
|
||||
verbose_name="club",
|
||||
to="club.Club",
|
||||
related_name="bank_accounts",
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="operation", unique_together=set([("number", "journal")])
|
||||
),
|
||||
]
|
@ -1,49 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import phonenumber_field.modelfields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("accounting", "0002_auto_20160824_2152")]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="company",
|
||||
name="city",
|
||||
field=models.CharField(blank=True, verbose_name="city", max_length=60),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="company",
|
||||
name="country",
|
||||
field=models.CharField(blank=True, verbose_name="country", max_length=32),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="company",
|
||||
name="email",
|
||||
field=models.EmailField(blank=True, verbose_name="email", max_length=254),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="company",
|
||||
name="phone",
|
||||
field=phonenumber_field.modelfields.PhoneNumberField(
|
||||
blank=True, verbose_name="phone", max_length=128
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="company",
|
||||
name="postcode",
|
||||
field=models.CharField(blank=True, verbose_name="postcode", max_length=10),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="company",
|
||||
name="street",
|
||||
field=models.CharField(blank=True, verbose_name="street", max_length=60),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="company",
|
||||
name="website",
|
||||
field=models.CharField(blank=True, verbose_name="website", max_length=64),
|
||||
),
|
||||
]
|
@ -1,51 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("accounting", "0003_auto_20160824_2203")]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Label",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
verbose_name="ID",
|
||||
primary_key=True,
|
||||
auto_created=True,
|
||||
serialize=False,
|
||||
),
|
||||
),
|
||||
("name", models.CharField(max_length=64, verbose_name="label")),
|
||||
(
|
||||
"club_account",
|
||||
models.ForeignKey(
|
||||
related_name="labels",
|
||||
verbose_name="club account",
|
||||
to="accounting.ClubAccount",
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="operation",
|
||||
name="label",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name="operations",
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name="label",
|
||||
to="accounting.Label",
|
||||
),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="label", unique_together=set([("name", "club_account")])
|
||||
),
|
||||
]
|
@ -1,18 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("accounting", "0004_auto_20161005_1505")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="operation",
|
||||
name="remark",
|
||||
field=models.CharField(
|
||||
null=True, max_length=128, blank=True, verbose_name="comment"
|
||||
),
|
||||
)
|
||||
]
|
@ -1,575 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from django.urls import reverse
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core import validators
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.template import defaultfilters
|
||||
|
||||
from phonenumber_field.modelfields import PhoneNumberField
|
||||
|
||||
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
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs["max_digits"] = 12
|
||||
kwargs["decimal_places"] = 2
|
||||
super(CurrencyField, self).__init__(*args, **kwargs)
|
||||
|
||||
def to_python(self, value):
|
||||
try:
|
||||
return super(CurrencyField, self).to_python(value).quantize(Decimal("0.01"))
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
|
||||
# Accounting classes
|
||||
|
||||
|
||||
class Company(models.Model):
|
||||
name = models.CharField(_("name"), max_length=60)
|
||||
street = models.CharField(_("street"), max_length=60, blank=True)
|
||||
city = models.CharField(_("city"), max_length=60, blank=True)
|
||||
postcode = models.CharField(_("postcode"), max_length=10, blank=True)
|
||||
country = models.CharField(_("country"), max_length=32, blank=True)
|
||||
phone = PhoneNumberField(_("phone"), blank=True)
|
||||
email = models.EmailField(_("email"), blank=True)
|
||||
website = models.CharField(_("website"), max_length=64, blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("company")
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
|
||||
return True
|
||||
return False
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
for club in user.memberships.filter(end_date=None).all():
|
||||
if club and club.role == settings.SITH_CLUB_ROLES_ID["Treasurer"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def can_be_viewed_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be viewed by the given user
|
||||
"""
|
||||
for club in user.memberships.filter(end_date=None).all():
|
||||
if club and club.role >= settings.SITH_CLUB_ROLES_ID["Treasurer"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("accounting:co_edit", kwargs={"co_id": self.id})
|
||||
|
||||
def get_display_name(self):
|
||||
return self.name
|
||||
|
||||
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)
|
||||
number = models.CharField(_("account number"), max_length=255, blank=True)
|
||||
club = models.ForeignKey(
|
||||
Club,
|
||||
related_name="bank_accounts",
|
||||
verbose_name=_("club"),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Bank account")
|
||||
ordering = ["club", "name"]
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
|
||||
return True
|
||||
m = self.club.get_membership_for(user)
|
||||
if m is not None and m.role >= settings.SITH_CLUB_ROLES_ID["Treasurer"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("accounting:bank_details", kwargs={"b_account_id": self.id})
|
||||
|
||||
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"),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
bank_account = models.ForeignKey(
|
||||
BankAccount,
|
||||
related_name="club_accounts",
|
||||
verbose_name=_("bank account"),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Club account")
|
||||
ordering = ["bank_account", "name"]
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
|
||||
return True
|
||||
return False
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
m = self.club.get_membership_for(user)
|
||||
if m and m.role == settings.SITH_CLUB_ROLES_ID["Treasurer"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def can_be_viewed_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be viewed by the given user
|
||||
"""
|
||||
m = self.club.get_membership_for(user)
|
||||
if m and m.role >= settings.SITH_CLUB_ROLES_ID["Treasurer"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def has_open_journal(self):
|
||||
for j in self.journals.all():
|
||||
if not j.closed:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_open_journal(self):
|
||||
return self.journals.filter(closed=False).first()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("accounting:club_details", kwargs={"c_account_id": self.id})
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_display_name(self):
|
||||
return _("%(club_account)s on %(bank_account)s") % {
|
||||
"club_account": self.name,
|
||||
"bank_account": self.bank_account,
|
||||
}
|
||||
|
||||
|
||||
class GeneralJournal(models.Model):
|
||||
"""
|
||||
Class storing all the operations for a period of time
|
||||
"""
|
||||
|
||||
start_date = models.DateField(_("start date"))
|
||||
end_date = models.DateField(_("end date"), null=True, blank=True, default=None)
|
||||
name = models.CharField(_("name"), max_length=40)
|
||||
closed = models.BooleanField(_("is closed"), default=False)
|
||||
club_account = models.ForeignKey(
|
||||
ClubAccount,
|
||||
related_name="journals",
|
||||
null=False,
|
||||
verbose_name=_("club account"),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
amount = CurrencyField(_("amount"), default=0)
|
||||
effective_amount = CurrencyField(_("effective_amount"), default=0)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("General journal")
|
||||
ordering = ["-start_date"]
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
|
||||
return True
|
||||
if self.club_account.can_be_edited_by(user):
|
||||
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 user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
|
||||
return True
|
||||
if self.club_account.can_be_edited_by(user):
|
||||
return True
|
||||
return False
|
||||
|
||||
def can_be_viewed_by(self, user):
|
||||
return self.club_account.can_be_viewed_by(user)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("accounting:journal_details", kwargs={"j_id": self.id})
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def update_amounts(self):
|
||||
self.amount = 0
|
||||
self.effective_amount = 0
|
||||
for o in self.operations.all():
|
||||
if o.accounting_type.movement_type == "CREDIT":
|
||||
if o.done:
|
||||
self.effective_amount += o.amount
|
||||
self.amount += o.amount
|
||||
else:
|
||||
if o.done:
|
||||
self.effective_amount -= o.amount
|
||||
self.amount -= o.amount
|
||||
self.save()
|
||||
|
||||
|
||||
class Operation(models.Model):
|
||||
"""
|
||||
An operation is a line in the journal, a debit or a credit
|
||||
"""
|
||||
|
||||
number = models.IntegerField(_("number"))
|
||||
journal = models.ForeignKey(
|
||||
GeneralJournal,
|
||||
related_name="operations",
|
||||
null=False,
|
||||
verbose_name=_("journal"),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
amount = CurrencyField(_("amount"))
|
||||
date = models.DateField(_("date"))
|
||||
remark = models.CharField(_("comment"), max_length=128, null=True, blank=True)
|
||||
mode = models.CharField(
|
||||
_("payment method"),
|
||||
max_length=255,
|
||||
choices=settings.SITH_ACCOUNTING_PAYMENT_METHOD,
|
||||
)
|
||||
cheque_number = models.CharField(
|
||||
_("cheque number"), max_length=32, default="", null=True, blank=True
|
||||
)
|
||||
invoice = models.ForeignKey(
|
||||
SithFile,
|
||||
related_name="operations",
|
||||
verbose_name=_("invoice"),
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
done = models.BooleanField(_("is done"), default=False)
|
||||
simpleaccounting_type = models.ForeignKey(
|
||||
"SimplifiedAccountingType",
|
||||
related_name="operations",
|
||||
verbose_name=_("simple type"),
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
accounting_type = models.ForeignKey(
|
||||
"AccountingType",
|
||||
related_name="operations",
|
||||
verbose_name=_("accounting type"),
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
label = models.ForeignKey(
|
||||
"Label",
|
||||
related_name="operations",
|
||||
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")),
|
||||
],
|
||||
)
|
||||
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,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("number", "journal")
|
||||
ordering = ["-number"]
|
||||
|
||||
def __getattribute__(self, attr):
|
||||
if attr == "target":
|
||||
return self.get_target()
|
||||
else:
|
||||
return object.__getattribute__(self, attr)
|
||||
|
||||
def clean(self):
|
||||
super(Operation, self).clean()
|
||||
if self.date is None:
|
||||
raise ValidationError(_("The date must be set."))
|
||||
elif self.date < self.journal.start_date:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"""The date can not be before the start date of the journal, which is
|
||||
%(start_date)s."""
|
||||
)
|
||||
% {
|
||||
"start_date": defaultfilters.date(
|
||||
self.journal.start_date, settings.DATE_FORMAT
|
||||
)
|
||||
}
|
||||
)
|
||||
if self.target_type != "OTHER" and self.get_target() is None:
|
||||
raise ValidationError(_("Target does not exists"))
|
||||
if self.target_type == "OTHER" and self.target_label == "":
|
||||
raise ValidationError(
|
||||
_("Please add a target label if you set no existing target")
|
||||
)
|
||||
if not self.accounting_type and not self.simpleaccounting_type:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"You need to provide ether a simplified accounting type or a standard accounting type"
|
||||
)
|
||||
)
|
||||
if self.simpleaccounting_type:
|
||||
self.accounting_type = self.simpleaccounting_type.accounting_type
|
||||
|
||||
@property
|
||||
def target(self):
|
||||
return self.get_target()
|
||||
|
||||
def get_target(self):
|
||||
tar = None
|
||||
if self.target_type == "USER":
|
||||
tar = User.objects.filter(id=self.target_id).first()
|
||||
elif self.target_type == "CLUB":
|
||||
tar = Club.objects.filter(id=self.target_id).first()
|
||||
elif self.target_type == "ACCOUNT":
|
||||
tar = ClubAccount.objects.filter(id=self.target_id).first()
|
||||
elif self.target_type == "COMPANY":
|
||||
tar = Company.objects.filter(id=self.target_id).first()
|
||||
return tar
|
||||
|
||||
def save(self):
|
||||
if self.number is None:
|
||||
self.number = self.journal.operations.count() + 1
|
||||
super(Operation, self).save()
|
||||
self.journal.update_amounts()
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
|
||||
return True
|
||||
if self.journal.closed:
|
||||
return False
|
||||
m = self.journal.club_account.club.get_membership_for(user)
|
||||
if m is not None and m.role >= settings.SITH_CLUB_ROLES_ID["Treasurer"]:
|
||||
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 user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
|
||||
return True
|
||||
if self.journal.closed:
|
||||
return False
|
||||
m = self.journal.club_account.club.get_membership_for(user)
|
||||
if m is not None and m.role == settings.SITH_CLUB_ROLES_ID["Treasurer"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("accounting:journal_details", kwargs={"j_id": self.journal.id})
|
||||
|
||||
def __str__(self):
|
||||
return "%d € | %s | %s | %s" % (
|
||||
self.amount,
|
||||
self.date,
|
||||
self.accounting_type,
|
||||
self.done,
|
||||
)
|
||||
|
||||
|
||||
class AccountingType(models.Model):
|
||||
"""
|
||||
Class describing the accounting types.
|
||||
|
||||
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")
|
||||
)
|
||||
],
|
||||
)
|
||||
label = models.CharField(_("label"), max_length=128)
|
||||
movement_type = models.CharField(
|
||||
_("movement type"),
|
||||
choices=[
|
||||
("CREDIT", _("Credit")),
|
||||
("DEBIT", _("Debit")),
|
||||
("NEUTRAL", _("Neutral")),
|
||||
],
|
||||
max_length=12,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("accounting type")
|
||||
ordering = ["movement_type", "code"]
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("accounting:type_list")
|
||||
|
||||
def __str__(self):
|
||||
return self.code + " - " + self.get_movement_type_display() + " - " + self.label
|
||||
|
||||
|
||||
class SimplifiedAccountingType(models.Model):
|
||||
"""
|
||||
Class describing the simplified accounting types.
|
||||
"""
|
||||
|
||||
label = models.CharField(_("label"), max_length=128)
|
||||
accounting_type = models.ForeignKey(
|
||||
AccountingType,
|
||||
related_name="simplified_types",
|
||||
verbose_name=_("simplified accounting types"),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("simplified type")
|
||||
ordering = ["accounting_type__movement_type", "accounting_type__code"]
|
||||
|
||||
@property
|
||||
def movement_type(self):
|
||||
return self.accounting_type.movement_type
|
||||
|
||||
def get_movement_type_display(self):
|
||||
return self.accounting_type.get_movement_type_display()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("accounting:simple_type_list")
|
||||
|
||||
def __str__(self):
|
||||
return (
|
||||
self.get_movement_type_display()
|
||||
+ " - "
|
||||
+ self.accounting_type.code
|
||||
+ " - "
|
||||
+ self.label
|
||||
)
|
||||
|
||||
|
||||
class Label(models.Model):
|
||||
"""Label allow a club to sort its operations"""
|
||||
|
||||
name = models.CharField(_("label"), max_length=64)
|
||||
club_account = models.ForeignKey(
|
||||
ClubAccount,
|
||||
related_name="labels",
|
||||
verbose_name=_("club account"),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("name", "club_account")
|
||||
|
||||
def __str__(self):
|
||||
return "%s (%s)" % (self.name, self.club_account.name)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse(
|
||||
"accounting:label_list", kwargs={"clubaccount_id": self.club_account.id}
|
||||
)
|
||||
|
||||
def is_owned_by(self, user):
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return self.club_account.is_owned_by(user)
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
return self.club_account.can_be_edited_by(user)
|
||||
|
||||
def can_be_viewed_by(self, user):
|
||||
return self.club_account.can_be_viewed_by(user)
|
@ -1,27 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Accounting type list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
<p>
|
||||
<a href="{{ url('accounting:bank_list') }}">{% trans %}Accounting{% endtrans %}</a> >
|
||||
{% trans %}Accounting types{% endtrans %}
|
||||
</p>
|
||||
<hr>
|
||||
<p><a href="{{ url('accounting:type_new') }}">{% trans %}New accounting type{% endtrans %}</a></p>
|
||||
{% if accountingtype_list %}
|
||||
<h3>{% trans %}Accounting type list{% endtrans %}</h3>
|
||||
<ul>
|
||||
{% for a in accountingtype_list %}
|
||||
<li><a href="{{ url('accounting:type_edit', type_id=a.id) }}">{{ a }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% trans %}There is no types in this website.{% endtrans %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -1,38 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Bank account: {% endtrans %}{{ object.name }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
<p>
|
||||
<a href="{{ url('accounting:bank_list') }}">{% trans %}Accounting{% endtrans %}</a> >
|
||||
{{ object.name }}
|
||||
</p>
|
||||
<hr>
|
||||
<h2>{% trans %}Bank account: {% endtrans %}{{ object.name }}</h2>
|
||||
{% if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) and not object.club_accounts.exists() %}
|
||||
<a href="{{ url('accounting:bank_delete', b_account_id=object.id) }}">{% trans %}Delete{% endtrans %}</a>
|
||||
{% endif %}
|
||||
<h4>{% trans %}Infos{% endtrans %}</h4>
|
||||
<ul>
|
||||
<li><strong>{% trans %}IBAN: {% endtrans %}</strong>{{ object.iban }}</li>
|
||||
<li><strong>{% trans %}Number: {% endtrans %}</strong>{{ object.number }}</li>
|
||||
</ul>
|
||||
<p><a href="{{ url('accounting:club_new') }}?parent={{ object.id }}">{% trans %}New club account{% endtrans %}</a></p>
|
||||
<ul>
|
||||
{% for c in object.club_accounts.all() %}
|
||||
<li><a href="{{ url('accounting:club_details', c_account_id=c.id) }}">{{ c }}</a>
|
||||
- <a href="{{ url('accounting:club_edit', c_account_id=c.id) }}">{% trans %}Edit{% endtrans %}</a>
|
||||
{% if c.journals.count() == 0 %}
|
||||
- <a href="{{ url('accounting:club_delete', c_account_id=c.id) }}">{% trans %}Delete{% endtrans %}</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -1,33 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Bank account list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
<h4>
|
||||
{% trans %}Accounting{% endtrans %}
|
||||
</h4>
|
||||
{% if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
|
||||
<p><a href="{{ url('accounting:simple_type_list') }}">{% trans %}Manage simplified types{% endtrans %}</a></p>
|
||||
<p><a href="{{ url('accounting:type_list') }}">{% trans %}Manage accounting types{% endtrans %}</a></p>
|
||||
<p><a href="{{ url('accounting:bank_new') }}">{% trans %}New bank account{% endtrans %}</a></p>
|
||||
{% endif %}
|
||||
{% if bankaccount_list %}
|
||||
<h3>{% trans %}Bank account list{% endtrans %}</h3>
|
||||
<ul>
|
||||
{% for a in object_list %}
|
||||
<li><a href="{{ url('accounting:bank_details', b_account_id=a.id) }}">{{ a }}</a>
|
||||
- <a href="{{ url('accounting:bank_edit', b_account_id=a.id) }}">{% trans %}Edit{% endtrans %}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% trans %}There is no accounts in this website.{% endtrans %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -1,68 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Club account:{% endtrans %} {{ object.name }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
<p>
|
||||
<a href="{{ url('accounting:bank_list') }}">{% trans %}Accounting{% endtrans %}</a> >
|
||||
<a href="{{ url('accounting:bank_details', b_account_id=object.bank_account.id) }}">{{object.bank_account }}</a> >
|
||||
{{ object }}
|
||||
</p>
|
||||
<hr>
|
||||
<h2>{% trans %}Club account:{% endtrans %} {{ object.name }}</h2>
|
||||
{% if user.is_root and not object.journals.exists() %}
|
||||
<a href="{{ url('accounting:club_delete', c_account_id=object.id) }}">{% trans %}Delete{% endtrans %}</a>
|
||||
{% endif %}
|
||||
{% if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
|
||||
<p><a href="{{ url('accounting:label_new') }}?parent={{ object.id }}">{% trans %}New label{% endtrans %}</a></p>
|
||||
{% endif %}
|
||||
<p><a href="{{ url('accounting:label_list', clubaccount_id=object.id) }}">{% trans %}Label list{% endtrans %}</a></p>
|
||||
{% if not object.has_open_journal() %}
|
||||
<p><a href="{{ url('accounting:journal_new') }}?parent={{ object.id }}">{% trans %}New journal{% endtrans %}</a></p>
|
||||
{% else %}
|
||||
<p>{% trans %}You can not create new journal while you still have one opened{% endtrans %}</p>
|
||||
{% endif %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Name{% endtrans %}</td>
|
||||
<td>{% trans %}Start{% endtrans %}</td>
|
||||
<td>{% trans %}End{% endtrans %}</td>
|
||||
<td>{% trans %}Amount{% endtrans %}</td>
|
||||
<td>{% trans %}Effective amount{% endtrans %}</td>
|
||||
<td>{% trans %}Closed{% endtrans %}</td>
|
||||
<td>{% trans %}Actions{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for j in object.journals.all() %}
|
||||
<tr>
|
||||
<td>{{ j.name }}</td>
|
||||
<td>{{ j.start_date }}</td>
|
||||
{% if j.end_date %}
|
||||
<td>{{ j.end_date }}</td>
|
||||
{% else %}
|
||||
<td> - </td>
|
||||
{% endif %}
|
||||
<td>{{ j.amount }} €</td>
|
||||
<td>{{ j.effective_amount }} €</td>
|
||||
{% if j.closed %}
|
||||
<td>{% trans %}Yes{% endtrans %}</td>
|
||||
{% else %}
|
||||
<td>{% trans %}No{% endtrans %}</td>
|
||||
{% endif %}
|
||||
<td> <a href="{{ url('accounting:journal_details', j_id=j.id) }}">{% trans %}View{% endtrans %}</a>
|
||||
<a href="{{ url('accounting:journal_edit', j_id=j.id) }}">{% trans %}Edit{% endtrans %}</a>
|
||||
{% if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) and j.operations.count() == 0 %}
|
||||
<a href="{{ url('accounting:journal_delete', j_id=j.id) }}">{% trans %}Delete{% endtrans %}</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,30 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Company list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
{% if user.is_root
|
||||
or user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID)
|
||||
%}
|
||||
<p><a href="{{ url('accounting:co_new') }}">{% trans %}Create new company{% endtrans %}</a></p>
|
||||
{% endif %}
|
||||
<br/>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Companies{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for o in object_list %}
|
||||
<tr>
|
||||
<td><a href="{{ url('accounting:co_edit', co_id=o.id) }}">{{ o.get_display_name() }}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,103 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}General journal:{% endtrans %} {{ object.name }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
<p>
|
||||
<a href="{{ url('accounting:bank_list') }}">{% trans %}Accounting{% endtrans %}</a> >
|
||||
<a href="{{ url('accounting:bank_details', b_account_id=object.club_account.bank_account.id) }}">{{object.club_account.bank_account }}</a> >
|
||||
<a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object.club_account }}</a> >
|
||||
{{ object.name }}
|
||||
</p>
|
||||
<hr>
|
||||
<h2>{% trans %}General journal:{% endtrans %} {{ object.name }}</h2>
|
||||
<p><a href="{{ url('accounting:label_new') }}?parent={{ object.club_account.id }}">{% trans %}New label{% endtrans %}</a></p>
|
||||
<p><a href="{{ url('accounting:label_list', clubaccount_id=object.club_account.id) }}">{% trans %}Label list{% endtrans %}</a></p>
|
||||
<p><a href="{{ url('accounting:co_list') }}">{% trans %}Company list{% endtrans %}</a></p>
|
||||
<p><strong>{% trans %}Amount: {% endtrans %}</strong>{{ object.amount }} € -
|
||||
<strong>{% trans %}Effective amount: {% endtrans %}</strong>{{ object.effective_amount }} €</p>
|
||||
{% if object.closed %}
|
||||
<p>{% trans %}Journal is closed, you can not create operation{% endtrans %}</p>
|
||||
{% else %}
|
||||
<p><a href="{{ url('accounting:op_new', j_id=object.id) }}">{% trans %}New operation{% endtrans %}</a></p>
|
||||
</br>
|
||||
{% endif %}
|
||||
<div class="journal-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Nb{% endtrans %}</td>
|
||||
<td>{% trans %}Date{% endtrans %}</td>
|
||||
<td>{% trans %}Label{% endtrans %}</td>
|
||||
<td>{% trans %}Amount{% endtrans %}</td>
|
||||
<td>{% trans %}Payment mode{% endtrans %}</td>
|
||||
<td>{% trans %}Target{% endtrans %}</td>
|
||||
<td>{% trans %}Code{% endtrans %}</td>
|
||||
<td>{% trans %}Nature{% endtrans %}</td>
|
||||
<td>{% trans %}Done{% endtrans %}</td>
|
||||
<td>{% trans %}Comment{% endtrans %}</td>
|
||||
<td>{% trans %}File{% endtrans %}</td>
|
||||
<td>{% trans %}Actions{% endtrans %}</td>
|
||||
<td>{% trans %}PDF{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for o in object.operations.all() %}
|
||||
<tr>
|
||||
<td>{{ o.number }}</td>
|
||||
<td>{{ o.date }}</td>
|
||||
<td>{{ o.label or "" }}</td>
|
||||
{% if o.accounting_type.movement_type == "DEBIT" %}
|
||||
<td class="neg-amount"> {{ o.amount }} €</td>
|
||||
{% else %}
|
||||
<td class="pos-amount"> {{ o.amount }} €</td>
|
||||
{% endif %}
|
||||
<td>{{ o.get_mode_display() }}</td>
|
||||
{% if o.target_type == "OTHER" %}
|
||||
<td>{{ o.target_label }}</td>
|
||||
{% else %}
|
||||
<td><a href="{{ o.target.get_absolute_url() }}">{{ o.target.get_display_name() }}</a></td>
|
||||
{% endif %}
|
||||
<td>{{ o.accounting_type.code }}</td>
|
||||
<td>{{ o.accounting_type.label }}</td>
|
||||
{% if o.done %}
|
||||
<td>{% trans %}Yes{% endtrans %}</td>
|
||||
{% else %}
|
||||
<td>{% trans %}No{% endtrans %}</td>
|
||||
{% endif %}
|
||||
<td>{{ o.remark }}
|
||||
{% if not o.linked_operation and o.target_type == "ACCOUNT" and not o.target.has_open_journal() %}
|
||||
<p><strong>
|
||||
{% trans %}Warning: this operation has no linked operation because the targeted club account has no opened journal.{% endtrans %}
|
||||
</strong></p>
|
||||
<p><strong>
|
||||
{% trans url=o.target.get_absolute_url() %}Open a journal in <a href="{{ url }}">this club account</a>, then save this operation again to make the linked operation.{% endtrans %}
|
||||
</strong></p>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% if o.invoice %}
|
||||
<td><a href="{{ url('core:download', file_id=o.invoice.id) }}">{{ o.invoice.name }}</a></td>
|
||||
{% else %}
|
||||
<td>-</td>
|
||||
{% endif %}
|
||||
<td>
|
||||
{%
|
||||
if o.journal.club_account.bank_account.name not in ["AE TI", "TI"]
|
||||
or user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID)
|
||||
%}
|
||||
{% if not o.journal.closed %}
|
||||
<a href="{{ url('accounting:op_edit', op_id=o.id) }}">{% trans %}Edit{% endtrans %}</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td><a href="{{ url('accounting:op_pdf', op_id=o.id) }}">{% trans %}Generate{% endtrans %}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,33 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}General journal:{% endtrans %} {{ object.name }}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
<h3>{% trans %}Accounting statement: {% endtrans %} {{ object.name }}</h3>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Operation type{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for k,v in statement.items() %}
|
||||
<tr>
|
||||
<td>{{ k }}</td>
|
||||
<td>{{ "%.2f" % v }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<p><strong>{% trans %}Amount: {% endtrans %}</strong>{{ "%.2f" % object.amount }} €</p>
|
||||
<p><strong>{% trans %}Effective amount: {% endtrans %}</strong>{{ "%.2f" %object.effective_amount }} €</p>
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,57 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}General journal:{% endtrans %} {{ object.name }}
|
||||
{% endblock %}
|
||||
|
||||
{% macro display_tables(dict) %}
|
||||
<div id="accounting">
|
||||
<h6>{% trans %}Credit{% endtrans %}</h6>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Nature of operation{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for k,v in dict['CREDIT'].items() %}
|
||||
<tr>
|
||||
<td>{{ k }}</td>
|
||||
<td>{{ "%.2f" % v }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% trans %}Total: {% endtrans %}{{ "%.2f" % dict['CREDIT_sum'] }}
|
||||
|
||||
<h6>{% trans %}Debit{% endtrans %}</h6>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Nature of operation{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for k,v in dict['DEBIT'].items() %}
|
||||
<tr>
|
||||
<td>{{ k }}</td>
|
||||
<td>{{ "%.2f" % v }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% trans %}Total: {% endtrans %}{{ "%.2f" % dict['DEBIT_sum'] }}
|
||||
{% endmacro %}
|
||||
|
||||
{% block content %}
|
||||
<h3>{% trans %}Statement by nature: {% endtrans %} {{ object.name }}</h3>
|
||||
|
||||
{% for k,v in statement.items() %}
|
||||
<h4 style="background: lightblue; padding: 4px;">{{ k }} : {{ "%.2f" % (v['CREDIT_sum'] - v['DEBIT_sum']) }}</h4>
|
||||
{{ display_tables(v) }}
|
||||
<hr>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,68 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}General journal:{% endtrans %} {{ object.name }}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
<h3>{% trans %}Statement by person: {% endtrans %} {{ object.name }}</h3>
|
||||
|
||||
<h4>{% trans %}Credit{% endtrans %}</h4>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Target of the operation{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key in credit_statement.keys() %}
|
||||
<tr>
|
||||
{% if key.target_type == "OTHER" %}
|
||||
<td>{{ o.target_label }}</td>
|
||||
{% elif key %}
|
||||
<td><a href="{{ key.get_absolute_url() }}">{{ key.get_display_name() }}</a></td>
|
||||
{% else %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
<td>{{ "%.2f" % credit_statement[key] }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<p>Total : {{ "%.2f" % total_credit }}</p>
|
||||
|
||||
<h4>{% trans %}Debit{% endtrans %}</h4>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Target of the operation{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key in debit_statement.keys() %}
|
||||
<tr>
|
||||
{% if key.target_type == "OTHER" %}
|
||||
<td>{{ o.target_label }}</td>
|
||||
{% elif key %}
|
||||
<td><a href="{{ key.get_absolute_url() }}">{{ key.get_display_name() }}</a></td>
|
||||
{% else %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
<td>{{ "%.2f" % debit_statement[key] }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<p>Total : {{ "%.2f" % total_debit }}</p>
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,36 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Label list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
<p>
|
||||
<a href="{{ url('accounting:bank_list') }}">{% trans %}Accounting{% endtrans %}</a> >
|
||||
<a href="{{ url('accounting:bank_details', b_account_id=object.bank_account.id) }}">{{object.bank_account }}</a> >
|
||||
<a href="{{ url('accounting:club_details', c_account_id=object.id) }}">{{ object }}</a>
|
||||
</p>
|
||||
<hr>
|
||||
<p><a href="{{ url('accounting:club_details', c_account_id=object.id) }}">{% trans %}Back to club account{% endtrans %}</a></p>
|
||||
{% if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
|
||||
<p><a href="{{ url('accounting:label_new') }}?parent={{ object.id }}">{% trans %}New label{% endtrans %}</a></p>
|
||||
{% endif %}
|
||||
{% if object.labels.all() %}
|
||||
<h3>{% trans %}Label list{% endtrans %}</h3>
|
||||
<ul>
|
||||
{% for l in object.labels.all() %}
|
||||
<li><a href="{{ url('accounting:label_edit', label_id=l.id) }}">{{ l }}</a>
|
||||
{% if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
|
||||
-
|
||||
<a href="{{ url('accounting:label_delete', label_id=l.id) }}">{% trans %}Delete{% endtrans %}</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% trans %}There is no label in this club account.{% endtrans %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -1,123 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Edit operation{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
<p>
|
||||
<a href="{{ url('accounting:bank_list') }}">{% trans %}Accounting{% endtrans %}</a> >
|
||||
<a href="{{ url('accounting:bank_details', b_account_id=object.club_account.bank_account.id) }}">{{object.club_account.bank_account }}</a> >
|
||||
<a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object.club_account }}</a> >
|
||||
<a href="{{ url('accounting:journal_details', j_id=object.id) }}">{{ object.name }}</a> >
|
||||
{% trans %}Edit operation{% endtrans %}
|
||||
</p>
|
||||
<hr>
|
||||
<h2>{% trans %}Edit operation{% endtrans %}</h2>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.non_field_errors() }}
|
||||
{{ form.journal }}
|
||||
{{ form.target_id }}
|
||||
<p>{{ form.amount.errors }}<label for="{{ form.amount.name }}">{{ form.amount.label }}</label> {{ form.amount }}</p>
|
||||
<p>{{ form.remark.errors }}<label for="{{ form.remark.name }}">{{ form.remark.label }}</label> {{ form.remark }}</p>
|
||||
<br />
|
||||
<strong>{% trans %}Warning: if you select <em>Account</em>, the opposite operation will be created in the target account. If you don't want that, select <em>Club</em> instead of <em>Account</em>.{% endtrans %}</strong>
|
||||
<p>{{ form.target_type.errors }}<label for="{{ form.target_type.name }}">{{ form.target_type.label }}</label> {{ form.target_type }}</p>
|
||||
{{ form.user }}
|
||||
{{ form.club }}
|
||||
{{ form.club_account }}
|
||||
{{ form.company }}
|
||||
{{ form.target_label }}
|
||||
<span id="id_need_link_full"><label>{{ form.need_link.label }}</label> {{ form.need_link }}</span>
|
||||
<p>{{ form.date.errors }}<label for="{{ form.date.name }}">{{ form.date.label }}</label> {{ form.date }}</p>
|
||||
<p>{{ form.mode.errors }}<label for="{{ form.mode.name }}">{{ form.mode.label }}</label> {{ form.mode }}</p>
|
||||
<p>{{ form.cheque_number.errors }}<label for="{{ form.cheque_number.name }}">{{ form.cheque_number.label }}</label> {{
|
||||
form.cheque_number }}</p>
|
||||
<p>{{ form.invoice.errors }}<label for="{{ form.invoice.name }}">{{ form.invoice.label }}</label> {{ form.invoice }}</p>
|
||||
<p>{{ form.simpleaccounting_type.errors }}<label for="{{ form.simpleaccounting_type.name }}">{{
|
||||
form.simpleaccounting_type.label }}</label> {{ form.simpleaccounting_type }}</p>
|
||||
<p>{{ form.accounting_type.errors }}<label for="{{ form.accounting_type.name }}">{{ form.accounting_type.label }}</label> {{
|
||||
form.accounting_type }}</p>
|
||||
<p>{{ form.label.errors }}<label for="{{ form.label.name }}">{{ form.label.label }}</label> {{ form.label }}</p>
|
||||
<p>{{ form.done.errors }}<label for="{{ form.done.name }}">{{ form.done.label }}</label> {{ form.done }}</p>
|
||||
{% if form.instance.linked_operation %}
|
||||
{% set obj = form.instance.linked_operation %}
|
||||
<p><strong>{% trans %}Linked operation:{% endtrans %}</strong><br>
|
||||
<a href="{{ url('accounting:bank_details', b_account_id=obj.journal.club_account.bank_account.id) }}">
|
||||
{{obj.journal.club_account.bank_account }}</a> >
|
||||
<a href="{{ url('accounting:club_details', c_account_id=obj.journal.club_account.id) }}">{{ obj.journal.club_account }}</a> >
|
||||
<a href="{{ url('accounting:journal_details', j_id=obj.journal.id) }}">{{ obj.journal }}</a> >
|
||||
n°{{ obj.number }}
|
||||
</p>
|
||||
{% endif %}
|
||||
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
{{ super() }}
|
||||
<script>
|
||||
$( function() {
|
||||
var target_type = $('#id_target_type');
|
||||
var user = $('#id_user_wrapper');
|
||||
var club = $('#id_club_wrapper');
|
||||
var club_account = $('#id_club_account_wrapper');
|
||||
var company = $('#id_company_wrapper');
|
||||
var other = $('#id_target_label');
|
||||
var need_link = $('#id_need_link_full');
|
||||
function update_targets () {
|
||||
if (target_type.val() == "USER") {
|
||||
console.log(user);
|
||||
user.show();
|
||||
club.hide();
|
||||
club_account.hide();
|
||||
company.hide();
|
||||
other.hide();
|
||||
need_link.hide();
|
||||
} else if (target_type.val() == "ACCOUNT") {
|
||||
club_account.show();
|
||||
need_link.show();
|
||||
user.hide();
|
||||
club.hide();
|
||||
company.hide();
|
||||
other.hide();
|
||||
} else if (target_type.val() == "CLUB") {
|
||||
club.show();
|
||||
user.hide();
|
||||
club_account.hide();
|
||||
company.hide();
|
||||
other.hide();
|
||||
need_link.hide();
|
||||
} else if (target_type.val() == "COMPANY") {
|
||||
company.show();
|
||||
user.hide();
|
||||
club_account.hide();
|
||||
club.hide();
|
||||
other.hide();
|
||||
need_link.hide();
|
||||
} else if (target_type.val() == "OTHER") {
|
||||
other.show();
|
||||
user.hide();
|
||||
club.hide();
|
||||
club_account.hide();
|
||||
company.hide();
|
||||
need_link.hide();
|
||||
} else {
|
||||
company.hide();
|
||||
user.hide();
|
||||
club_account.hide();
|
||||
club.hide();
|
||||
other.hide();
|
||||
need_link.hide();
|
||||
}
|
||||
}
|
||||
update_targets();
|
||||
target_type.change(update_targets);
|
||||
} );
|
||||
</script>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Refound account{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
<h3>{% trans %}Refound account{% endtrans %}</h3>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p() }}
|
||||
<p><input type="submit" value="{% trans %}Refound{% endtrans %}" /></p>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,27 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Simplified type list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="accounting">
|
||||
<p>
|
||||
<a href="{{ url('accounting:bank_list') }}">{% trans %}Accounting{% endtrans %}</a> >
|
||||
{% trans %}Simplified types{% endtrans %}
|
||||
</p>
|
||||
<hr>
|
||||
<p><a href="{{ url('accounting:simple_type_new') }}">{% trans %}New simplified type{% endtrans %}</a></p>
|
||||
{% if simplifiedaccountingtype_list %}
|
||||
<h3>{% trans %}Simplified type list{% endtrans %}</h3>
|
||||
<ul>
|
||||
{% for a in simplifiedaccountingtype_list %}
|
||||
<li><a href="{{ url('accounting:simple_type_edit', type_id=a.id) }}">{{ a }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% trans %}There is no types in this website.{% endtrans %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -1,313 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from django.core.management import call_command
|
||||
from datetime import date, timedelta
|
||||
|
||||
from core.models import User
|
||||
from accounting.models import (
|
||||
GeneralJournal,
|
||||
Operation,
|
||||
Label,
|
||||
AccountingType,
|
||||
SimplifiedAccountingType,
|
||||
)
|
||||
|
||||
|
||||
class RefoundAccountTest(TestCase):
|
||||
def setUp(self):
|
||||
self.skia = User.objects.filter(username="skia").first()
|
||||
# reffil skia's account
|
||||
self.skia.customer.amount = 800
|
||||
self.skia.customer.save()
|
||||
|
||||
def test_permission_denied(self):
|
||||
self.client.login(username="guy", password="plop")
|
||||
response_post = self.client.post(
|
||||
reverse("accounting:refound_account"), {"user": self.skia.id}
|
||||
)
|
||||
response_get = self.client.get(reverse("accounting:refound_account"))
|
||||
self.assertTrue(response_get.status_code == 403)
|
||||
self.assertTrue(response_post.status_code == 403)
|
||||
|
||||
def test_root_granteed(self):
|
||||
self.client.login(username="root", password="plop")
|
||||
response_post = self.client.post(
|
||||
reverse("accounting:refound_account"), {"user": self.skia.id}
|
||||
)
|
||||
self.skia = User.objects.filter(username="skia").first()
|
||||
response_get = self.client.get(reverse("accounting:refound_account"))
|
||||
self.assertFalse(response_get.status_code == 403)
|
||||
self.assertTrue('<form action="" method="post">' in str(response_get.content))
|
||||
self.assertFalse(response_post.status_code == 403)
|
||||
self.assertTrue(self.skia.customer.amount == 0)
|
||||
|
||||
def test_comptable_granteed(self):
|
||||
self.client.login(username="comptable", password="plop")
|
||||
response_post = self.client.post(
|
||||
reverse("accounting:refound_account"), {"user": self.skia.id}
|
||||
)
|
||||
self.skia = User.objects.filter(username="skia").first()
|
||||
response_get = self.client.get(reverse("accounting:refound_account"))
|
||||
self.assertFalse(response_get.status_code == 403)
|
||||
self.assertTrue('<form action="" method="post">' in str(response_get.content))
|
||||
self.assertFalse(response_post.status_code == 403)
|
||||
self.assertTrue(self.skia.customer.amount == 0)
|
||||
|
||||
|
||||
class JournalTest(TestCase):
|
||||
def setUp(self):
|
||||
self.journal = GeneralJournal.objects.filter(id=1).first()
|
||||
|
||||
def test_permission_granted(self):
|
||||
self.client.login(username="comptable", password="plop")
|
||||
response_get = self.client.get(
|
||||
reverse("accounting:journal_details", args=[self.journal.id])
|
||||
)
|
||||
|
||||
self.assertTrue(response_get.status_code == 200)
|
||||
self.assertTrue(
|
||||
"<td>M\\xc3\\xa9thode de paiement</td>" in str(response_get.content)
|
||||
)
|
||||
|
||||
def test_permission_not_granted(self):
|
||||
self.client.login(username="skia", password="plop")
|
||||
response_get = self.client.get(
|
||||
reverse("accounting:journal_details", args=[self.journal.id])
|
||||
)
|
||||
|
||||
self.assertTrue(response_get.status_code == 403)
|
||||
self.assertFalse(
|
||||
"<td>M\xc3\xa9thode de paiement</td>" in str(response_get.content)
|
||||
)
|
||||
|
||||
|
||||
class OperationTest(TestCase):
|
||||
def setUp(self):
|
||||
self.tomorrow_formatted = (date.today() + timedelta(days=1)).strftime(
|
||||
"%d/%m/%Y"
|
||||
)
|
||||
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.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.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.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": self.tomorrow_formatted,
|
||||
"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()
|
||||
)
|
||||
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")
|
||||
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": self.tomorrow_formatted,
|
||||
"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": self.tomorrow_formatted,
|
||||
"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()
|
||||
)
|
||||
|
||||
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": self.tomorrow_formatted,
|
||||
"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])
|
||||
)
|
||||
self.assertTrue(
|
||||
"<td>Le fantome de l'aurore</td>" in str(response_get.content)
|
||||
)
|
||||
self.assertTrue(
|
||||
self.journal.operations.filter(amount=23)
|
||||
.values("accounting_type")
|
||||
.first()["accounting_type"]
|
||||
== AccountingType.objects.filter(code=6).values("id").first()["id"]
|
||||
)
|
||||
|
||||
def test_nature_statement(self):
|
||||
self.client.login(username="comptable", password="plop")
|
||||
response = self.client.get(
|
||||
reverse("accounting:journal_nature_statement", args=[self.journal.id])
|
||||
)
|
||||
self.assertContains(response, "bob (Troll Penché) : 3.00", status_code=200)
|
||||
|
||||
def test_person_statement(self):
|
||||
self.client.login(username="comptable", password="plop")
|
||||
response = self.client.get(
|
||||
reverse("accounting:journal_person_statement", args=[self.journal.id])
|
||||
)
|
||||
self.assertContains(response, "Total : 5575.72", status_code=200)
|
||||
self.assertContains(response, "Total : 71.42")
|
||||
self.assertContains(
|
||||
response,
|
||||
"""
|
||||
<td><a href="/user/1/">S' Kia</a></td>
|
||||
|
||||
<td>3.00</td>""",
|
||||
)
|
||||
self.assertContains(
|
||||
response,
|
||||
"""
|
||||
<td><a href="/user/1/">S' Kia</a></td>
|
||||
|
||||
<td>823.00</td>""",
|
||||
)
|
||||
|
||||
def test_accounting_statement(self):
|
||||
self.client.login(username="comptable", password="plop")
|
||||
response = self.client.get(
|
||||
reverse("accounting:journal_accounting_statement", args=[self.journal.id])
|
||||
)
|
||||
self.assertContains(
|
||||
response,
|
||||
"""
|
||||
<tr>
|
||||
<td>443 - Crédit - Ce code n'existe pas</td>
|
||||
<td>3.00</td>
|
||||
</tr>""",
|
||||
status_code=200,
|
||||
)
|
||||
self.assertContains(
|
||||
response,
|
||||
"""
|
||||
<p><strong>Montant : </strong>-5504.30 €</p>
|
||||
<p><strong>Montant effectif: </strong>-5504.30 €</p>""",
|
||||
)
|
@ -1,140 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from django.urls import path
|
||||
|
||||
from accounting.views import *
|
||||
|
||||
urlpatterns = [
|
||||
# Accounting types
|
||||
path(
|
||||
"simple_type/",
|
||||
SimplifiedAccountingTypeListView.as_view(),
|
||||
name="simple_type_list",
|
||||
),
|
||||
path(
|
||||
"simple_type/create/",
|
||||
SimplifiedAccountingTypeCreateView.as_view(),
|
||||
name="simple_type_new",
|
||||
),
|
||||
path(
|
||||
"simple_type/<int:type_id>/edit/",
|
||||
SimplifiedAccountingTypeEditView.as_view(),
|
||||
name="simple_type_edit",
|
||||
),
|
||||
# Accounting types
|
||||
path("type/", AccountingTypeListView.as_view(), name="type_list"),
|
||||
path("type/create/", AccountingTypeCreateView.as_view(), name="type_new"),
|
||||
path(
|
||||
"type/<int:type_id>/edit/",
|
||||
AccountingTypeEditView.as_view(),
|
||||
name="type_edit",
|
||||
),
|
||||
# Bank accounts
|
||||
path("", BankAccountListView.as_view(), name="bank_list"),
|
||||
path("bank/create", BankAccountCreateView.as_view(), name="bank_new"),
|
||||
path(
|
||||
"bank/<int:b_account_id>/",
|
||||
BankAccountDetailView.as_view(),
|
||||
name="bank_details",
|
||||
),
|
||||
path(
|
||||
"bank/<int:b_account_id>/edit/",
|
||||
BankAccountEditView.as_view(),
|
||||
name="bank_edit",
|
||||
),
|
||||
path(
|
||||
"bank/<int:b_account_id>/delete/",
|
||||
BankAccountDeleteView.as_view(),
|
||||
name="bank_delete",
|
||||
),
|
||||
# Club accounts
|
||||
path("club/create/", ClubAccountCreateView.as_view(), name="club_new"),
|
||||
path(
|
||||
"club/<int:c_account_id>/",
|
||||
ClubAccountDetailView.as_view(),
|
||||
name="club_details",
|
||||
),
|
||||
path(
|
||||
"club/<int:c_account_id>/edit/",
|
||||
ClubAccountEditView.as_view(),
|
||||
name="club_edit",
|
||||
),
|
||||
path(
|
||||
"club/<int:c_account_id>/delete/",
|
||||
ClubAccountDeleteView.as_view(),
|
||||
name="club_delete",
|
||||
),
|
||||
# Journals
|
||||
path("journal/create/", JournalCreateView.as_view(), name="journal_new"),
|
||||
path(
|
||||
"journal/<int:j_id>/",
|
||||
JournalDetailView.as_view(),
|
||||
name="journal_details",
|
||||
),
|
||||
path(
|
||||
"journal/<int:j_id>/edit/",
|
||||
JournalEditView.as_view(),
|
||||
name="journal_edit",
|
||||
),
|
||||
path(
|
||||
"journal/<int:j_id>/delete/",
|
||||
JournalDeleteView.as_view(),
|
||||
name="journal_delete",
|
||||
),
|
||||
path(
|
||||
"journal/<int:j_id>/statement/nature/",
|
||||
JournalNatureStatementView.as_view(),
|
||||
name="journal_nature_statement",
|
||||
),
|
||||
path(
|
||||
"journal/<int:j_id>/statement/person/",
|
||||
JournalPersonStatementView.as_view(),
|
||||
name="journal_person_statement",
|
||||
),
|
||||
path(
|
||||
"journal/<int:j_id>/statement/accounting/",
|
||||
JournalAccountingStatementView.as_view(),
|
||||
name="journal_accounting_statement",
|
||||
),
|
||||
# Operations
|
||||
path(
|
||||
"operation/create/<int:j_id>/",
|
||||
OperationCreateView.as_view(),
|
||||
name="op_new",
|
||||
),
|
||||
path("operation/<int:op_id>/", OperationEditView.as_view(), name="op_edit"),
|
||||
path("operation/<int:op_id>/pdf/", OperationPDFView.as_view(), name="op_pdf"),
|
||||
# Companies
|
||||
path("company/list/", CompanyListView.as_view(), name="co_list"),
|
||||
path("company/create/", CompanyCreateView.as_view(), name="co_new"),
|
||||
path("company/<int:co_id>/", CompanyEditView.as_view(), name="co_edit"),
|
||||
# Labels
|
||||
path("label/new/", LabelCreateView.as_view(), name="label_new"),
|
||||
path(
|
||||
"label/<int:clubaccount_id>/",
|
||||
LabelListView.as_view(),
|
||||
name="label_list",
|
||||
),
|
||||
path("label/<int:label_id>/edit/", LabelEditView.as_view(), name="label_edit"),
|
||||
path(
|
||||
"label/<int:label_id>/delete/",
|
||||
LabelDeleteView.as_view(),
|
||||
name="label_delete",
|
||||
),
|
||||
# User account
|
||||
path("refound/account/", RefoundAccountView.as_view(), name="refound_account"),
|
||||
]
|
@ -1,934 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from django.views.generic import ListView, DetailView
|
||||
from django.views.generic.edit import UpdateView, CreateView, DeleteView, FormView
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.forms.models import modelform_factory
|
||||
from django.core.exceptions import PermissionDenied, ValidationError
|
||||
from django.forms import HiddenInput
|
||||
from django.db import transaction
|
||||
from django.db.models import Sum
|
||||
from django.conf import settings
|
||||
from django import forms
|
||||
from django.http import HttpResponse
|
||||
import collections
|
||||
|
||||
from ajax_select.fields import AutoCompleteSelectField
|
||||
|
||||
from core.views import (
|
||||
CanViewMixin,
|
||||
CanEditMixin,
|
||||
CanEditPropMixin,
|
||||
CanCreateMixin,
|
||||
TabedViewMixin,
|
||||
)
|
||||
from core.views.forms import SelectFile, SelectDate
|
||||
from accounting.models import (
|
||||
BankAccount,
|
||||
ClubAccount,
|
||||
GeneralJournal,
|
||||
Operation,
|
||||
AccountingType,
|
||||
Company,
|
||||
SimplifiedAccountingType,
|
||||
Label,
|
||||
)
|
||||
from counter.models import Counter, Selling, Product
|
||||
|
||||
# Main accounting view
|
||||
|
||||
|
||||
class BankAccountListView(CanViewMixin, ListView):
|
||||
"""
|
||||
A list view for the admins
|
||||
"""
|
||||
|
||||
model = BankAccount
|
||||
template_name = "accounting/bank_account_list.jinja"
|
||||
ordering = ["name"]
|
||||
|
||||
|
||||
# Simplified accounting types
|
||||
|
||||
|
||||
class SimplifiedAccountingTypeListView(CanViewMixin, ListView):
|
||||
"""
|
||||
A list view for the admins
|
||||
"""
|
||||
|
||||
model = SimplifiedAccountingType
|
||||
template_name = "accounting/simplifiedaccountingtype_list.jinja"
|
||||
|
||||
|
||||
class SimplifiedAccountingTypeEditView(CanViewMixin, UpdateView):
|
||||
"""
|
||||
An edit view for the admins
|
||||
"""
|
||||
|
||||
model = SimplifiedAccountingType
|
||||
pk_url_kwarg = "type_id"
|
||||
fields = ["label", "accounting_type"]
|
||||
template_name = "core/edit.jinja"
|
||||
|
||||
|
||||
class SimplifiedAccountingTypeCreateView(CanCreateMixin, CreateView):
|
||||
"""
|
||||
Create an accounting type (for the admins)
|
||||
"""
|
||||
|
||||
model = SimplifiedAccountingType
|
||||
fields = ["label", "accounting_type"]
|
||||
template_name = "core/create.jinja"
|
||||
|
||||
|
||||
# Accounting types
|
||||
|
||||
|
||||
class AccountingTypeListView(CanViewMixin, ListView):
|
||||
"""
|
||||
A list view for the admins
|
||||
"""
|
||||
|
||||
model = AccountingType
|
||||
template_name = "accounting/accountingtype_list.jinja"
|
||||
|
||||
|
||||
class AccountingTypeEditView(CanViewMixin, UpdateView):
|
||||
"""
|
||||
An edit view for the admins
|
||||
"""
|
||||
|
||||
model = AccountingType
|
||||
pk_url_kwarg = "type_id"
|
||||
fields = ["code", "label", "movement_type"]
|
||||
template_name = "core/edit.jinja"
|
||||
|
||||
|
||||
class AccountingTypeCreateView(CanCreateMixin, CreateView):
|
||||
"""
|
||||
Create an accounting type (for the admins)
|
||||
"""
|
||||
|
||||
model = AccountingType
|
||||
fields = ["code", "label", "movement_type"]
|
||||
template_name = "core/create.jinja"
|
||||
|
||||
|
||||
# BankAccount views
|
||||
|
||||
|
||||
class BankAccountEditView(CanViewMixin, UpdateView):
|
||||
"""
|
||||
An edit view for the admins
|
||||
"""
|
||||
|
||||
model = BankAccount
|
||||
pk_url_kwarg = "b_account_id"
|
||||
fields = ["name", "iban", "number", "club"]
|
||||
template_name = "core/edit.jinja"
|
||||
|
||||
|
||||
class BankAccountDetailView(CanViewMixin, DetailView):
|
||||
"""
|
||||
A detail view, listing every club account
|
||||
"""
|
||||
|
||||
model = BankAccount
|
||||
pk_url_kwarg = "b_account_id"
|
||||
template_name = "accounting/bank_account_details.jinja"
|
||||
|
||||
|
||||
class BankAccountCreateView(CanCreateMixin, CreateView):
|
||||
"""
|
||||
Create a bank account (for the admins)
|
||||
"""
|
||||
|
||||
model = BankAccount
|
||||
fields = ["name", "club", "iban", "number"]
|
||||
template_name = "core/create.jinja"
|
||||
|
||||
|
||||
class BankAccountDeleteView(
|
||||
CanEditPropMixin, DeleteView
|
||||
): # TODO change Delete to Close
|
||||
"""
|
||||
Delete a bank account (for the admins)
|
||||
"""
|
||||
|
||||
model = BankAccount
|
||||
pk_url_kwarg = "b_account_id"
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
success_url = reverse_lazy("accounting:bank_list")
|
||||
|
||||
|
||||
# ClubAccount views
|
||||
|
||||
|
||||
class ClubAccountEditView(CanViewMixin, UpdateView):
|
||||
"""
|
||||
An edit view for the admins
|
||||
"""
|
||||
|
||||
model = ClubAccount
|
||||
pk_url_kwarg = "c_account_id"
|
||||
fields = ["name", "club", "bank_account"]
|
||||
template_name = "core/edit.jinja"
|
||||
|
||||
|
||||
class ClubAccountDetailView(CanViewMixin, DetailView):
|
||||
"""
|
||||
A detail view, listing every journal
|
||||
"""
|
||||
|
||||
model = ClubAccount
|
||||
pk_url_kwarg = "c_account_id"
|
||||
template_name = "accounting/club_account_details.jinja"
|
||||
|
||||
|
||||
class ClubAccountCreateView(CanCreateMixin, CreateView):
|
||||
"""
|
||||
Create a club account (for the admins)
|
||||
"""
|
||||
|
||||
model = ClubAccount
|
||||
fields = ["name", "club", "bank_account"]
|
||||
template_name = "core/create.jinja"
|
||||
|
||||
def get_initial(self):
|
||||
ret = super(ClubAccountCreateView, self).get_initial()
|
||||
if "parent" in self.request.GET.keys():
|
||||
obj = BankAccount.objects.filter(id=int(self.request.GET["parent"])).first()
|
||||
if obj is not None:
|
||||
ret["bank_account"] = obj.id
|
||||
return ret
|
||||
|
||||
|
||||
class ClubAccountDeleteView(
|
||||
CanEditPropMixin, DeleteView
|
||||
): # TODO change Delete to Close
|
||||
"""
|
||||
Delete a club account (for the admins)
|
||||
"""
|
||||
|
||||
model = ClubAccount
|
||||
pk_url_kwarg = "c_account_id"
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
success_url = reverse_lazy("accounting:bank_list")
|
||||
|
||||
|
||||
# Journal views
|
||||
|
||||
|
||||
class JournalTabsMixin(TabedViewMixin):
|
||||
def get_tabs_title(self):
|
||||
return _("Journal")
|
||||
|
||||
def get_list_of_tabs(self):
|
||||
tab_list = []
|
||||
tab_list.append(
|
||||
{
|
||||
"url": reverse(
|
||||
"accounting:journal_details", kwargs={"j_id": self.object.id}
|
||||
),
|
||||
"slug": "journal",
|
||||
"name": _("Journal"),
|
||||
}
|
||||
)
|
||||
tab_list.append(
|
||||
{
|
||||
"url": reverse(
|
||||
"accounting:journal_nature_statement",
|
||||
kwargs={"j_id": self.object.id},
|
||||
),
|
||||
"slug": "nature_statement",
|
||||
"name": _("Statement by nature"),
|
||||
}
|
||||
)
|
||||
tab_list.append(
|
||||
{
|
||||
"url": reverse(
|
||||
"accounting:journal_person_statement",
|
||||
kwargs={"j_id": self.object.id},
|
||||
),
|
||||
"slug": "person_statement",
|
||||
"name": _("Statement by person"),
|
||||
}
|
||||
)
|
||||
tab_list.append(
|
||||
{
|
||||
"url": reverse(
|
||||
"accounting:journal_accounting_statement",
|
||||
kwargs={"j_id": self.object.id},
|
||||
),
|
||||
"slug": "accounting_statement",
|
||||
"name": _("Accounting statement"),
|
||||
}
|
||||
)
|
||||
return tab_list
|
||||
|
||||
|
||||
class JournalCreateView(CanCreateMixin, CreateView):
|
||||
"""
|
||||
Create a general journal
|
||||
"""
|
||||
|
||||
model = GeneralJournal
|
||||
form_class = modelform_factory(
|
||||
GeneralJournal,
|
||||
fields=["name", "start_date", "club_account"],
|
||||
widgets={"start_date": SelectDate},
|
||||
)
|
||||
template_name = "core/create.jinja"
|
||||
|
||||
def get_initial(self):
|
||||
ret = super(JournalCreateView, self).get_initial()
|
||||
if "parent" in self.request.GET.keys():
|
||||
obj = ClubAccount.objects.filter(id=int(self.request.GET["parent"])).first()
|
||||
if obj is not None:
|
||||
ret["club_account"] = obj.id
|
||||
return ret
|
||||
|
||||
|
||||
class JournalDetailView(JournalTabsMixin, CanViewMixin, DetailView):
|
||||
"""
|
||||
A detail view, listing every operation
|
||||
"""
|
||||
|
||||
model = GeneralJournal
|
||||
pk_url_kwarg = "j_id"
|
||||
template_name = "accounting/journal_details.jinja"
|
||||
current_tab = "journal"
|
||||
|
||||
|
||||
class JournalEditView(CanEditMixin, UpdateView):
|
||||
"""
|
||||
Update a general journal
|
||||
"""
|
||||
|
||||
model = GeneralJournal
|
||||
pk_url_kwarg = "j_id"
|
||||
fields = ["name", "start_date", "end_date", "club_account", "closed"]
|
||||
template_name = "core/edit.jinja"
|
||||
|
||||
|
||||
class JournalDeleteView(CanEditPropMixin, DeleteView):
|
||||
"""
|
||||
Delete a club account (for the admins)
|
||||
"""
|
||||
|
||||
model = GeneralJournal
|
||||
pk_url_kwarg = "j_id"
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
success_url = reverse_lazy("accounting:club_details")
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
if self.object.operations.count() == 0:
|
||||
return super(JournalDeleteView, self).dispatch(request, *args, **kwargs)
|
||||
else:
|
||||
raise PermissionDenied
|
||||
|
||||
|
||||
# Operation views
|
||||
|
||||
|
||||
class OperationForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Operation
|
||||
fields = [
|
||||
"amount",
|
||||
"remark",
|
||||
"journal",
|
||||
"target_type",
|
||||
"target_id",
|
||||
"target_label",
|
||||
"date",
|
||||
"mode",
|
||||
"cheque_number",
|
||||
"invoice",
|
||||
"simpleaccounting_type",
|
||||
"accounting_type",
|
||||
"label",
|
||||
"done",
|
||||
]
|
||||
widgets = {
|
||||
"journal": HiddenInput,
|
||||
"target_id": HiddenInput,
|
||||
"date": SelectDate,
|
||||
"invoice": SelectFile,
|
||||
}
|
||||
|
||||
user = AutoCompleteSelectField("users", help_text=None, required=False)
|
||||
club_account = AutoCompleteSelectField(
|
||||
"club_accounts", help_text=None, required=False
|
||||
)
|
||||
club = AutoCompleteSelectField("clubs", help_text=None, required=False)
|
||||
company = AutoCompleteSelectField("companies", help_text=None, required=False)
|
||||
need_link = forms.BooleanField(
|
||||
label=_("Link this operation to the target account"),
|
||||
required=False,
|
||||
initial=False,
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
club_account = kwargs.pop("club_account", None)
|
||||
super(OperationForm, self).__init__(*args, **kwargs)
|
||||
if club_account:
|
||||
self.fields["label"].queryset = club_account.labels.order_by("name").all()
|
||||
if self.instance.target_type == "USER":
|
||||
self.fields["user"].initial = self.instance.target_id
|
||||
elif self.instance.target_type == "ACCOUNT":
|
||||
self.fields["club_account"].initial = self.instance.target_id
|
||||
elif self.instance.target_type == "CLUB":
|
||||
self.fields["club"].initial = self.instance.target_id
|
||||
elif self.instance.target_type == "COMPANY":
|
||||
self.fields["company"].initial = self.instance.target_id
|
||||
|
||||
def clean(self):
|
||||
self.cleaned_data = super(OperationForm, self).clean()
|
||||
if "target_type" in self.cleaned_data.keys():
|
||||
if (
|
||||
self.cleaned_data.get("user") is None
|
||||
and self.cleaned_data.get("club") is None
|
||||
and self.cleaned_data.get("club_account") is None
|
||||
and self.cleaned_data.get("company") is None
|
||||
and self.cleaned_data.get("target_label") == ""
|
||||
):
|
||||
self.add_error(
|
||||
"target_type", ValidationError(_("The target must be set."))
|
||||
)
|
||||
else:
|
||||
if self.cleaned_data["target_type"] == "USER":
|
||||
self.cleaned_data["target_id"] = self.cleaned_data["user"].id
|
||||
elif self.cleaned_data["target_type"] == "ACCOUNT":
|
||||
self.cleaned_data["target_id"] = self.cleaned_data[
|
||||
"club_account"
|
||||
].id
|
||||
elif self.cleaned_data["target_type"] == "CLUB":
|
||||
self.cleaned_data["target_id"] = self.cleaned_data["club"].id
|
||||
elif self.cleaned_data["target_type"] == "COMPANY":
|
||||
self.cleaned_data["target_id"] = self.cleaned_data["company"].id
|
||||
|
||||
if self.cleaned_data.get("amount") is None:
|
||||
self.add_error("amount", ValidationError(_("The amount must be set.")))
|
||||
|
||||
return self.cleaned_data
|
||||
|
||||
def save(self):
|
||||
ret = super(OperationForm, self).save()
|
||||
if (
|
||||
self.instance.target_type == "ACCOUNT"
|
||||
and not self.instance.linked_operation
|
||||
and self.instance.target.has_open_journal()
|
||||
and self.cleaned_data["need_link"]
|
||||
):
|
||||
inst = self.instance
|
||||
club_account = inst.target
|
||||
acc_type = (
|
||||
AccountingType.objects.exclude(movement_type="NEUTRAL")
|
||||
.exclude(movement_type=inst.accounting_type.movement_type)
|
||||
.order_by("code")
|
||||
.first()
|
||||
) # Select a random opposite accounting type
|
||||
op = Operation(
|
||||
journal=club_account.get_open_journal(),
|
||||
amount=inst.amount,
|
||||
date=inst.date,
|
||||
remark=inst.remark,
|
||||
mode=inst.mode,
|
||||
cheque_number=inst.cheque_number,
|
||||
invoice=inst.invoice,
|
||||
done=False, # Has to be checked by hand
|
||||
simpleaccounting_type=None,
|
||||
accounting_type=acc_type,
|
||||
target_type="ACCOUNT",
|
||||
target_id=inst.journal.club_account.id,
|
||||
target_label="",
|
||||
linked_operation=inst,
|
||||
)
|
||||
op.save()
|
||||
self.instance.linked_operation = op
|
||||
self.save()
|
||||
return ret
|
||||
|
||||
|
||||
class OperationCreateView(CanCreateMixin, CreateView):
|
||||
"""
|
||||
Create an operation
|
||||
"""
|
||||
|
||||
model = Operation
|
||||
form_class = OperationForm
|
||||
template_name = "accounting/operation_edit.jinja"
|
||||
|
||||
def get_form(self, form_class=None):
|
||||
self.journal = GeneralJournal.objects.filter(id=self.kwargs["j_id"]).first()
|
||||
ca = self.journal.club_account if self.journal else None
|
||||
return self.form_class(club_account=ca, **self.get_form_kwargs())
|
||||
|
||||
def get_initial(self):
|
||||
ret = super(OperationCreateView, self).get_initial()
|
||||
if self.journal is not None:
|
||||
ret["journal"] = self.journal.id
|
||||
return ret
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Add journal to the context"""
|
||||
kwargs = super(OperationCreateView, self).get_context_data(**kwargs)
|
||||
if self.journal:
|
||||
kwargs["object"] = self.journal
|
||||
return kwargs
|
||||
|
||||
|
||||
class OperationEditView(CanEditMixin, UpdateView):
|
||||
"""
|
||||
An edit view, working as detail for the moment
|
||||
"""
|
||||
|
||||
model = Operation
|
||||
pk_url_kwarg = "op_id"
|
||||
form_class = OperationForm
|
||||
template_name = "accounting/operation_edit.jinja"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Add journal to the context"""
|
||||
kwargs = super(OperationEditView, self).get_context_data(**kwargs)
|
||||
kwargs["object"] = self.object.journal
|
||||
return kwargs
|
||||
|
||||
|
||||
class OperationPDFView(CanViewMixin, DetailView):
|
||||
"""
|
||||
Display the PDF of a given operation
|
||||
"""
|
||||
|
||||
model = Operation
|
||||
pk_url_kwarg = "op_id"
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
from reportlab.pdfgen import canvas
|
||||
from reportlab.lib.units import cm
|
||||
from reportlab.platypus import Table, TableStyle
|
||||
from reportlab.lib import colors
|
||||
from reportlab.lib.pagesizes import letter
|
||||
from reportlab.lib.utils import ImageReader
|
||||
from reportlab.pdfbase.ttfonts import TTFont
|
||||
from reportlab.pdfbase import pdfmetrics
|
||||
|
||||
pdfmetrics.registerFont(TTFont("DejaVu", "DejaVuSerif.ttf"))
|
||||
|
||||
self.object = self.get_object()
|
||||
amount = self.object.amount
|
||||
remark = self.object.remark
|
||||
nature = self.object.accounting_type.movement_type
|
||||
num = self.object.number
|
||||
date = self.object.date
|
||||
mode = self.object.mode
|
||||
club_name = self.object.journal.club_account.name
|
||||
ti = self.object.journal.name
|
||||
op_label = self.object.label
|
||||
club_address = self.object.journal.club_account.club.address
|
||||
id_op = self.object.id
|
||||
|
||||
if self.object.target_type == "OTHER":
|
||||
target = self.object.target_label
|
||||
else:
|
||||
target = self.object.target.get_display_name()
|
||||
|
||||
response = HttpResponse(content_type="application/pdf")
|
||||
response["Content-Disposition"] = 'filename="op-%d(%s_on_%s).pdf"' % (
|
||||
num,
|
||||
ti,
|
||||
club_name,
|
||||
)
|
||||
p = canvas.Canvas(response)
|
||||
|
||||
p.setFont("DejaVu", 12)
|
||||
|
||||
p.setTitle("%s %d" % (_("Operation"), num))
|
||||
width, height = letter
|
||||
im = ImageReader("core/static/core/img/logo.jpg")
|
||||
iw, ih = im.getSize()
|
||||
p.drawImage(im, 40, height - 50, width=iw / 2, height=ih / 2)
|
||||
|
||||
labelStr = [["%s %s - %s %s" % (_("Journal"), ti, _("Operation"), num)]]
|
||||
|
||||
label = Table(labelStr, colWidths=[150], rowHeights=[20])
|
||||
|
||||
label.setStyle(TableStyle([("ALIGN", (0, 0), (-1, -1), "RIGHT")]))
|
||||
w, h = label.wrapOn(label, 0, 0)
|
||||
label.drawOn(p, width - 180, height)
|
||||
|
||||
p.drawString(
|
||||
90, height - 100, _("Financial proof: ") + "OP%010d" % (id_op)
|
||||
) # Justificatif du libellé
|
||||
p.drawString(
|
||||
90, height - 130, _("Club: %(club_name)s") % ({"club_name": club_name})
|
||||
)
|
||||
p.drawString(
|
||||
90,
|
||||
height - 160,
|
||||
_("Label: %(op_label)s")
|
||||
% {"op_label": op_label if op_label is not None else ""},
|
||||
)
|
||||
p.drawString(90, height - 190, _("Date: %(date)s") % {"date": date})
|
||||
|
||||
data = []
|
||||
|
||||
data += [
|
||||
["%s" % (_("Credit").upper() if nature == "CREDIT" else _("Debit").upper())]
|
||||
]
|
||||
|
||||
data += [[_("Amount: %(amount).2f €") % {"amount": amount}]]
|
||||
|
||||
payment_mode = ""
|
||||
for m in settings.SITH_ACCOUNTING_PAYMENT_METHOD:
|
||||
if m[0] == mode:
|
||||
payment_mode += "[\u00D7]"
|
||||
else:
|
||||
payment_mode += "[ ]"
|
||||
payment_mode += " %s\n" % (m[1])
|
||||
|
||||
data += [[payment_mode]]
|
||||
|
||||
data += [
|
||||
[
|
||||
"%s : %s"
|
||||
% (_("Debtor") if nature == "CREDIT" else _("Creditor"), target),
|
||||
"",
|
||||
]
|
||||
]
|
||||
|
||||
data += [["%s \n%s" % (_("Comment:"), remark)]]
|
||||
|
||||
t = Table(
|
||||
data, colWidths=[(width - 90 * 2) / 2] * 2, rowHeights=[20, 20, 70, 20, 80]
|
||||
)
|
||||
t.setStyle(
|
||||
TableStyle(
|
||||
[
|
||||
("ALIGN", (0, 0), (-1, -1), "CENTER"),
|
||||
("VALIGN", (-2, -1), (-1, -1), "TOP"),
|
||||
("VALIGN", (0, 0), (-1, -2), "MIDDLE"),
|
||||
("INNERGRID", (0, 0), (-1, -1), 0.25, colors.black),
|
||||
("SPAN", (0, 0), (1, 0)), # line DEBIT/CREDIT
|
||||
("SPAN", (0, 1), (1, 1)), # line amount
|
||||
("SPAN", (-2, -1), (-1, -1)), # line comment
|
||||
("SPAN", (0, -2), (-1, -2)), # line creditor/debtor
|
||||
("SPAN", (0, 2), (1, 2)), # line payment_mode
|
||||
("ALIGN", (0, 2), (1, 2), "LEFT"), # line payment_mode
|
||||
("ALIGN", (-2, -1), (-1, -1), "LEFT"),
|
||||
("BOX", (0, 0), (-1, -1), 0.25, colors.black),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
signature = []
|
||||
signature += [[_("Signature:")]]
|
||||
|
||||
tSig = Table(signature, colWidths=[(width - 90 * 2)], rowHeights=[80])
|
||||
tSig.setStyle(
|
||||
TableStyle(
|
||||
[
|
||||
("VALIGN", (0, 0), (-1, -1), "TOP"),
|
||||
("BOX", (0, 0), (-1, -1), 0.25, colors.black),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
w, h = tSig.wrapOn(p, 0, 0)
|
||||
tSig.drawOn(p, 90, 200)
|
||||
|
||||
w, h = t.wrapOn(p, 0, 0)
|
||||
|
||||
t.drawOn(p, 90, 350)
|
||||
|
||||
p.drawCentredString(10.5 * cm, 2 * cm, club_name)
|
||||
p.drawCentredString(10.5 * cm, 1 * cm, club_address)
|
||||
|
||||
p.showPage()
|
||||
p.save()
|
||||
return response
|
||||
|
||||
|
||||
class JournalNatureStatementView(JournalTabsMixin, CanViewMixin, DetailView):
|
||||
"""
|
||||
Display a statement sorted by labels
|
||||
"""
|
||||
|
||||
model = GeneralJournal
|
||||
pk_url_kwarg = "j_id"
|
||||
template_name = "accounting/journal_statement_nature.jinja"
|
||||
current_tab = "nature_statement"
|
||||
|
||||
def statement(self, queryset, movement_type):
|
||||
ret = collections.OrderedDict()
|
||||
statement = collections.OrderedDict()
|
||||
total_sum = 0
|
||||
for sat in [None] + list(
|
||||
SimplifiedAccountingType.objects.order_by("label").all()
|
||||
):
|
||||
sum = queryset.filter(
|
||||
accounting_type__movement_type=movement_type, simpleaccounting_type=sat
|
||||
).aggregate(amount_sum=Sum("amount"))["amount_sum"]
|
||||
if sat:
|
||||
sat = sat.label
|
||||
else:
|
||||
sat = ""
|
||||
if sum:
|
||||
total_sum += sum
|
||||
statement[sat] = sum
|
||||
ret[movement_type] = statement
|
||||
ret[movement_type + "_sum"] = total_sum
|
||||
return ret
|
||||
|
||||
def big_statement(self):
|
||||
label_list = (
|
||||
self.object.operations.order_by("label").values_list("label").distinct()
|
||||
)
|
||||
labels = Label.objects.filter(id__in=label_list).all()
|
||||
statement = collections.OrderedDict()
|
||||
gen_statement = collections.OrderedDict()
|
||||
no_label_statement = collections.OrderedDict()
|
||||
gen_statement.update(self.statement(self.object.operations.all(), "CREDIT"))
|
||||
gen_statement.update(self.statement(self.object.operations.all(), "DEBIT"))
|
||||
statement[_("General statement")] = gen_statement
|
||||
no_label_statement.update(
|
||||
self.statement(self.object.operations.filter(label=None).all(), "CREDIT")
|
||||
)
|
||||
no_label_statement.update(
|
||||
self.statement(self.object.operations.filter(label=None).all(), "DEBIT")
|
||||
)
|
||||
statement[_("No label operations")] = no_label_statement
|
||||
for l in labels:
|
||||
l_stmt = collections.OrderedDict()
|
||||
l_stmt.update(
|
||||
self.statement(self.object.operations.filter(label=l).all(), "CREDIT")
|
||||
)
|
||||
l_stmt.update(
|
||||
self.statement(self.object.operations.filter(label=l).all(), "DEBIT")
|
||||
)
|
||||
statement[l] = l_stmt
|
||||
return statement
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Add infos to the context"""
|
||||
kwargs = super(JournalNatureStatementView, self).get_context_data(**kwargs)
|
||||
kwargs["statement"] = self.big_statement()
|
||||
return kwargs
|
||||
|
||||
|
||||
class JournalPersonStatementView(JournalTabsMixin, CanViewMixin, DetailView):
|
||||
"""
|
||||
Calculate a dictionary with operation target and sum of operations
|
||||
"""
|
||||
|
||||
model = GeneralJournal
|
||||
pk_url_kwarg = "j_id"
|
||||
template_name = "accounting/journal_statement_person.jinja"
|
||||
current_tab = "person_statement"
|
||||
|
||||
def sum_by_target(self, target_id, target_type, movement_type):
|
||||
return self.object.operations.filter(
|
||||
accounting_type__movement_type=movement_type,
|
||||
target_id=target_id,
|
||||
target_type=target_type,
|
||||
).aggregate(amount_sum=Sum("amount"))["amount_sum"]
|
||||
|
||||
def statement(self, movement_type):
|
||||
statement = collections.OrderedDict()
|
||||
for op in (
|
||||
self.object.operations.filter(accounting_type__movement_type=movement_type)
|
||||
.order_by("target_type", "target_id")
|
||||
.distinct()
|
||||
):
|
||||
statement[op.target] = self.sum_by_target(
|
||||
op.target_id, op.target_type, movement_type
|
||||
)
|
||||
return statement
|
||||
|
||||
def total(self, movement_type):
|
||||
return sum(self.statement(movement_type).values())
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Add journal to the context"""
|
||||
kwargs = super(JournalPersonStatementView, self).get_context_data(**kwargs)
|
||||
kwargs["credit_statement"] = self.statement("CREDIT")
|
||||
kwargs["debit_statement"] = self.statement("DEBIT")
|
||||
kwargs["total_credit"] = self.total("CREDIT")
|
||||
kwargs["total_debit"] = self.total("DEBIT")
|
||||
return kwargs
|
||||
|
||||
|
||||
class JournalAccountingStatementView(JournalTabsMixin, CanViewMixin, DetailView):
|
||||
"""
|
||||
Calculate a dictionary with operation type and sum of operations
|
||||
"""
|
||||
|
||||
model = GeneralJournal
|
||||
pk_url_kwarg = "j_id"
|
||||
template_name = "accounting/journal_statement_accounting.jinja"
|
||||
current_tab = "accounting_statement"
|
||||
|
||||
def statement(self):
|
||||
statement = collections.OrderedDict()
|
||||
for at in AccountingType.objects.order_by("code").all():
|
||||
sum_by_type = self.object.operations.filter(
|
||||
accounting_type__code__startswith=at.code
|
||||
).aggregate(amount_sum=Sum("amount"))["amount_sum"]
|
||||
if sum_by_type:
|
||||
statement[at] = sum_by_type
|
||||
return statement
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Add journal to the context"""
|
||||
kwargs = super(JournalAccountingStatementView, self).get_context_data(**kwargs)
|
||||
kwargs["statement"] = self.statement()
|
||||
return kwargs
|
||||
|
||||
|
||||
# Company views
|
||||
|
||||
|
||||
class CompanyListView(CanViewMixin, ListView):
|
||||
model = Company
|
||||
template_name = "accounting/co_list.jinja"
|
||||
|
||||
|
||||
class CompanyCreateView(CanCreateMixin, CreateView):
|
||||
"""
|
||||
Create a company
|
||||
"""
|
||||
|
||||
model = Company
|
||||
fields = ["name"]
|
||||
template_name = "core/create.jinja"
|
||||
success_url = reverse_lazy("accounting:co_list")
|
||||
|
||||
|
||||
class CompanyEditView(CanCreateMixin, UpdateView):
|
||||
"""
|
||||
Edit a company
|
||||
"""
|
||||
|
||||
model = Company
|
||||
pk_url_kwarg = "co_id"
|
||||
fields = ["name"]
|
||||
template_name = "core/edit.jinja"
|
||||
success_url = reverse_lazy("accounting:co_list")
|
||||
|
||||
|
||||
# Label views
|
||||
|
||||
|
||||
class LabelListView(CanViewMixin, DetailView):
|
||||
model = ClubAccount
|
||||
pk_url_kwarg = "clubaccount_id"
|
||||
template_name = "accounting/label_list.jinja"
|
||||
|
||||
|
||||
class LabelCreateView(
|
||||
CanCreateMixin, CreateView
|
||||
): # FIXME we need to check the rights before creating the object
|
||||
model = Label
|
||||
form_class = modelform_factory(
|
||||
Label, fields=["name", "club_account"], widgets={"club_account": HiddenInput}
|
||||
)
|
||||
template_name = "core/create.jinja"
|
||||
|
||||
def get_initial(self):
|
||||
ret = super(LabelCreateView, self).get_initial()
|
||||
if "parent" in self.request.GET.keys():
|
||||
obj = ClubAccount.objects.filter(id=int(self.request.GET["parent"])).first()
|
||||
if obj is not None:
|
||||
ret["club_account"] = obj.id
|
||||
return ret
|
||||
|
||||
|
||||
class LabelEditView(CanEditMixin, UpdateView):
|
||||
model = Label
|
||||
pk_url_kwarg = "label_id"
|
||||
fields = ["name"]
|
||||
template_name = "core/edit.jinja"
|
||||
|
||||
|
||||
class LabelDeleteView(CanEditMixin, DeleteView):
|
||||
model = Label
|
||||
pk_url_kwarg = "label_id"
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
|
||||
def get_success_url(self):
|
||||
return self.object.get_absolute_url()
|
||||
|
||||
|
||||
class CloseCustomerAccountForm(forms.Form):
|
||||
user = AutoCompleteSelectField(
|
||||
"users", label=_("Refound this account"), help_text=None, required=True
|
||||
)
|
||||
|
||||
|
||||
class RefoundAccountView(FormView):
|
||||
"""
|
||||
Create a selling with the same amount than the current user money
|
||||
"""
|
||||
|
||||
template_name = "accounting/refound_account.jinja"
|
||||
form_class = CloseCustomerAccountForm
|
||||
|
||||
def permission(self, user):
|
||||
if user.is_root or user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
|
||||
return True
|
||||
else:
|
||||
raise PermissionDenied
|
||||
|
||||
def dispatch(self, request, *arg, **kwargs):
|
||||
res = super(RefoundAccountView, self).dispatch(request, *arg, **kwargs)
|
||||
if self.permission(request.user):
|
||||
return res
|
||||
|
||||
def post(self, request, *arg, **kwargs):
|
||||
self.operator = request.user
|
||||
if self.permission(request.user):
|
||||
return super(RefoundAccountView, self).post(self, request, *arg, **kwargs)
|
||||
|
||||
def form_valid(self, form):
|
||||
self.customer = form.cleaned_data["user"]
|
||||
self.create_selling()
|
||||
return super(RefoundAccountView, self).form_valid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("accounting:refound_account")
|
||||
|
||||
def create_selling(self):
|
||||
with transaction.atomic():
|
||||
uprice = self.customer.customer.amount
|
||||
refound_club_counter = Counter.objects.get(
|
||||
id=settings.SITH_COUNTER_REFOUND_ID
|
||||
)
|
||||
refound_club = refound_club_counter.club
|
||||
s = Selling(
|
||||
label=_("Refound account"),
|
||||
unit_price=uprice,
|
||||
quantity=1,
|
||||
seller=self.operator,
|
||||
customer=self.customer.customer,
|
||||
club=refound_club,
|
||||
counter=refound_club_counter,
|
||||
product=Product.objects.get(id=settings.SITH_PRODUCT_REFOUND_ID),
|
||||
)
|
||||
s.save()
|
10
antispam/admin.py
Normal file
10
antispam/admin.py
Normal file
@ -0,0 +1,10 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from antispam.models import ToxicDomain
|
||||
|
||||
|
||||
@admin.register(ToxicDomain)
|
||||
class ToxicDomainAdmin(admin.ModelAdmin):
|
||||
list_display = ("domain", "is_externally_managed", "created")
|
||||
search_fields = ("domain", "is_externally_managed", "created")
|
||||
list_filter = ("is_externally_managed",)
|
7
antispam/apps.py
Normal file
7
antispam/apps.py
Normal file
@ -0,0 +1,7 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AntispamConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
verbose_name = "antispam"
|
||||
name = "antispam"
|
22
antispam/forms.py
Normal file
22
antispam/forms.py
Normal file
@ -0,0 +1,22 @@
|
||||
from django import forms
|
||||
from django.core.validators import EmailValidator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from antispam.models import ToxicDomain
|
||||
|
||||
|
||||
class AntiSpamEmailValidator(EmailValidator):
|
||||
def __call__(self, value: str):
|
||||
super().__call__(value)
|
||||
domain_part = value.rsplit("@", 1)[1]
|
||||
if ToxicDomain.objects.filter(domain=domain_part).exists():
|
||||
raise forms.ValidationError(_("Email domain is not allowed."))
|
||||
|
||||
|
||||
validate_antispam_email = AntiSpamEmailValidator()
|
||||
|
||||
|
||||
class AntiSpamEmailField(forms.EmailField):
|
||||
"""An email field that email addresses with a known toxic domain."""
|
||||
|
||||
default_validators = [validate_antispam_email]
|
69
antispam/management/commands/update_spam_database.py
Normal file
69
antispam/management/commands/update_spam_database.py
Normal file
@ -0,0 +1,69 @@
|
||||
import requests
|
||||
from django.conf import settings
|
||||
from django.core.management import BaseCommand
|
||||
from django.db.models import Max
|
||||
from django.utils import timezone
|
||||
|
||||
from antispam.models import ToxicDomain
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""Update blocked ips/mails database"""
|
||||
|
||||
help = "Update blocked ips/mails database"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
"--force", action="store_true", help="Force re-creation even if up to date"
|
||||
)
|
||||
|
||||
def _should_update(self, *, force: bool = False) -> bool:
|
||||
if force:
|
||||
return True
|
||||
oldest = ToxicDomain.objects.filter(is_externally_managed=True).aggregate(
|
||||
res=Max("created")
|
||||
)["res"]
|
||||
return not (oldest and timezone.now() < (oldest + timezone.timedelta(days=1)))
|
||||
|
||||
def _download_domains(self, providers: list[str]) -> set[str]:
|
||||
domains = set()
|
||||
for provider in providers:
|
||||
res = requests.get(provider)
|
||||
if not res.ok:
|
||||
self.stderr.write(
|
||||
f"Source {provider} responded with code {res.status_code}"
|
||||
)
|
||||
continue
|
||||
domains |= set(res.text.splitlines())
|
||||
return domains
|
||||
|
||||
def _update_domains(self, domains: set[str]):
|
||||
# Cleanup database
|
||||
ToxicDomain.objects.filter(is_externally_managed=True).delete()
|
||||
|
||||
# Create database
|
||||
ToxicDomain.objects.bulk_create(
|
||||
[
|
||||
ToxicDomain(domain=domain, is_externally_managed=True)
|
||||
for domain in domains
|
||||
],
|
||||
ignore_conflicts=True,
|
||||
)
|
||||
self.stdout.write("Domain database updated")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if not self._should_update(force=options["force"]):
|
||||
self.stdout.write("Domain database is up to date")
|
||||
return
|
||||
self.stdout.write("Updating domain database")
|
||||
|
||||
domains = self._download_domains(settings.TOXIC_DOMAINS_PROVIDERS)
|
||||
|
||||
if not domains:
|
||||
self.stderr.write(
|
||||
"No domains could be fetched from settings.TOXIC_DOMAINS_PROVIDERS. "
|
||||
"Please, have a look at your settings."
|
||||
)
|
||||
return
|
||||
|
||||
self._update_domains(domains)
|
35
antispam/migrations/0001_initial.py
Normal file
35
antispam/migrations/0001_initial.py
Normal file
@ -0,0 +1,35 @@
|
||||
# Generated by Django 4.2.14 on 2024-08-03 23:05
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="ToxicDomain",
|
||||
fields=[
|
||||
(
|
||||
"domain",
|
||||
models.URLField(
|
||||
max_length=253,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="domain",
|
||||
),
|
||||
),
|
||||
("created", models.DateTimeField(auto_now_add=True)),
|
||||
(
|
||||
"is_externally_managed",
|
||||
models.BooleanField(
|
||||
default=False,
|
||||
help_text="True if kept up-to-date using external toxic domain providers, else False",
|
||||
verbose_name="is externally managed",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
19
antispam/models.py
Normal file
19
antispam/models.py
Normal file
@ -0,0 +1,19 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class ToxicDomain(models.Model):
|
||||
"""Domain marked as spam in public databases"""
|
||||
|
||||
domain = models.URLField(_("domain"), max_length=253, primary_key=True)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
is_externally_managed = models.BooleanField(
|
||||
_("is externally managed"),
|
||||
default=False,
|
||||
help_text=_(
|
||||
"True if kept up-to-date using external toxic domain providers, else False"
|
||||
),
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.domain
|
@ -1,15 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
70
api/admin.py
70
api/admin.py
@ -1,19 +1,55 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
from django.contrib import admin, messages
|
||||
from django.db.models import QuerySet
|
||||
from django.http import HttpRequest
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from django.contrib import admin
|
||||
from api.hashers import generate_key
|
||||
from api.models import ApiClient, ApiKey
|
||||
|
||||
# Register your models here.
|
||||
|
||||
@admin.register(ApiClient)
|
||||
class ApiClientAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "owner", "created_at", "updated_at")
|
||||
search_fields = (
|
||||
"name",
|
||||
"owner__first_name",
|
||||
"owner__last_name",
|
||||
"owner__nick_name",
|
||||
)
|
||||
autocomplete_fields = ("owner", "groups", "client_permissions")
|
||||
|
||||
|
||||
@admin.register(ApiKey)
|
||||
class ApiKeyAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "client", "created_at", "revoked")
|
||||
list_filter = ("revoked",)
|
||||
date_hierarchy = "created_at"
|
||||
|
||||
readonly_fields = ("prefix", "hashed_key")
|
||||
actions = ("revoke_keys",)
|
||||
|
||||
def save_model(self, request: HttpRequest, obj: ApiKey, form, change):
|
||||
if not change:
|
||||
key, hashed = generate_key()
|
||||
obj.prefix = key[: ApiKey.PREFIX_LENGTH]
|
||||
obj.hashed_key = hashed
|
||||
self.message_user(
|
||||
request,
|
||||
_(
|
||||
"The API key for %(name)s is: %(key)s. "
|
||||
"Please store it somewhere safe: "
|
||||
"you will not be able to see it again."
|
||||
)
|
||||
% {"name": obj.name, "key": key},
|
||||
level=messages.WARNING,
|
||||
)
|
||||
return super().save_model(request, obj, form, change)
|
||||
|
||||
def get_readonly_fields(self, request, obj: ApiKey | None = None):
|
||||
if obj is None or obj.revoked:
|
||||
return ["revoked", *self.readonly_fields]
|
||||
return self.readonly_fields
|
||||
|
||||
@admin.action(description=_("Revoke selected API keys"))
|
||||
def revoke_keys(self, _request: HttpRequest, queryset: QuerySet[ApiKey]):
|
||||
queryset.update(revoked=True)
|
||||
|
6
api/apps.py
Normal file
6
api/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "api"
|
20
api/auth.py
Normal file
20
api/auth.py
Normal file
@ -0,0 +1,20 @@
|
||||
from django.http import HttpRequest
|
||||
from ninja.security import APIKeyHeader
|
||||
|
||||
from api.hashers import get_hasher
|
||||
from api.models import ApiClient, ApiKey
|
||||
|
||||
|
||||
class ApiKeyAuth(APIKeyHeader):
|
||||
param_name = "X-APIKey"
|
||||
|
||||
def authenticate(self, request: HttpRequest, key: str | None) -> ApiClient | None:
|
||||
if not key or len(key) != ApiKey.KEY_LENGTH:
|
||||
return None
|
||||
hasher = get_hasher()
|
||||
hashed_key = hasher.encode(key)
|
||||
try:
|
||||
key_obj = ApiKey.objects.get(revoked=False, hashed_key=hashed_key)
|
||||
except ApiKey.DoesNotExist:
|
||||
return None
|
||||
return key_obj.client
|
43
api/hashers.py
Normal file
43
api/hashers.py
Normal file
@ -0,0 +1,43 @@
|
||||
import functools
|
||||
import hashlib
|
||||
import secrets
|
||||
|
||||
from django.contrib.auth.hashers import BasePasswordHasher
|
||||
from django.utils.crypto import constant_time_compare
|
||||
|
||||
|
||||
class Sha512ApiKeyHasher(BasePasswordHasher):
|
||||
"""
|
||||
An API key hasher using the sha256 algorithm.
|
||||
|
||||
This hasher shouldn't be used in Django's `PASSWORD_HASHERS` setting.
|
||||
It is insecure for use in hashing passwords, but is safe for hashing
|
||||
high entropy, randomly generated API keys.
|
||||
"""
|
||||
|
||||
algorithm = "sha512"
|
||||
|
||||
def salt(self) -> str:
|
||||
# No need for a salt on a high entropy key.
|
||||
return ""
|
||||
|
||||
def encode(self, password: str, salt: str = "") -> str:
|
||||
hashed = hashlib.sha512(password.encode()).hexdigest()
|
||||
return f"{self.algorithm}$${hashed}"
|
||||
|
||||
def verify(self, password: str, encoded: str) -> bool:
|
||||
encoded_2 = self.encode(password, "")
|
||||
return constant_time_compare(encoded, encoded_2)
|
||||
|
||||
|
||||
@functools.cache
|
||||
def get_hasher():
|
||||
return Sha512ApiKeyHasher()
|
||||
|
||||
|
||||
def generate_key() -> tuple[str, str]:
|
||||
"""Generate a [key, hash] couple."""
|
||||
# this will result in key with a length of 72
|
||||
key = str(secrets.token_urlsafe(54))
|
||||
hasher = get_hasher()
|
||||
return key, hasher.encode(key)
|
113
api/migrations/0001_initial.py
Normal file
113
api/migrations/0001_initial.py
Normal file
@ -0,0 +1,113 @@
|
||||
# Generated by Django 5.2 on 2025-06-01 08:53
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("auth", "0012_alter_user_first_name_max_length"),
|
||||
("core", "0046_permissionrights"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="ApiClient",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("name", models.CharField(max_length=64, verbose_name="name")),
|
||||
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"client_permissions",
|
||||
models.ManyToManyField(
|
||||
blank=True,
|
||||
help_text="Specific permissions for this api client.",
|
||||
related_name="clients",
|
||||
to="auth.permission",
|
||||
verbose_name="client permissions",
|
||||
),
|
||||
),
|
||||
(
|
||||
"groups",
|
||||
models.ManyToManyField(
|
||||
blank=True,
|
||||
related_name="api_clients",
|
||||
to="core.group",
|
||||
verbose_name="groups",
|
||||
),
|
||||
),
|
||||
(
|
||||
"owner",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="api_clients",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
verbose_name="owner",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "api client",
|
||||
"verbose_name_plural": "api clients",
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="ApiKey",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("name", models.CharField(blank=True, default="", verbose_name="name")),
|
||||
(
|
||||
"prefix",
|
||||
models.CharField(
|
||||
editable=False, max_length=5, verbose_name="prefix"
|
||||
),
|
||||
),
|
||||
(
|
||||
"hashed_key",
|
||||
models.CharField(
|
||||
db_index=True,
|
||||
editable=False,
|
||||
max_length=136,
|
||||
verbose_name="hashed key",
|
||||
),
|
||||
),
|
||||
("revoked", models.BooleanField(default=False, verbose_name="revoked")),
|
||||
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||
(
|
||||
"client",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="api_keys",
|
||||
to="api.apiclient",
|
||||
verbose_name="api client",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "api key",
|
||||
"verbose_name_plural": "api keys",
|
||||
"permissions": [("revoke_apikey", "Revoke API keys")],
|
||||
},
|
||||
),
|
||||
]
|
0
api/migrations/__init__.py
Normal file
0
api/migrations/__init__.py
Normal file
107
api/models.py
107
api/models.py
@ -1,19 +1,94 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
from typing import Iterable
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import pgettext_lazy
|
||||
|
||||
# Create your models here.
|
||||
from core.models import Group, User
|
||||
|
||||
|
||||
class ApiClient(models.Model):
|
||||
name = models.CharField(_("name"), max_length=64)
|
||||
owner = models.ForeignKey(
|
||||
User,
|
||||
verbose_name=_("owner"),
|
||||
related_name="api_clients",
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
groups = models.ManyToManyField(
|
||||
Group, verbose_name=_("groups"), related_name="api_clients", blank=True
|
||||
)
|
||||
client_permissions = models.ManyToManyField(
|
||||
Permission,
|
||||
verbose_name=_("client permissions"),
|
||||
blank=True,
|
||||
help_text=_("Specific permissions for this api client."),
|
||||
related_name="clients",
|
||||
)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
_perm_cache: set[str] | None = None
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("api client")
|
||||
verbose_name_plural = _("api clients")
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def has_perm(self, perm: str):
|
||||
"""Return True if the client has the specified permission."""
|
||||
|
||||
if self._perm_cache is None:
|
||||
group_permissions = (
|
||||
Permission.objects.filter(group__group__in=self.groups.all())
|
||||
.values_list("content_type__app_label", "codename")
|
||||
.order_by()
|
||||
)
|
||||
client_permissions = self.client_permissions.values_list(
|
||||
"content_type__app_label", "codename"
|
||||
).order_by()
|
||||
self._perm_cache = {
|
||||
f"{content_type}.{name}"
|
||||
for content_type, name in (*group_permissions, *client_permissions)
|
||||
}
|
||||
return perm in self._perm_cache
|
||||
|
||||
def has_perms(self, perm_list):
|
||||
"""
|
||||
Return True if the client has each of the specified permissions. If
|
||||
object is passed, check if the client has all required perms for it.
|
||||
"""
|
||||
if not isinstance(perm_list, Iterable) or isinstance(perm_list, str):
|
||||
raise ValueError("perm_list must be an iterable of permissions.")
|
||||
return all(self.has_perm(perm) for perm in perm_list)
|
||||
|
||||
|
||||
class ApiKey(models.Model):
|
||||
PREFIX_LENGTH = 5
|
||||
KEY_LENGTH = 72
|
||||
HASHED_KEY_LENGTH = 136
|
||||
|
||||
name = models.CharField(_("name"), blank=True, default="")
|
||||
prefix = models.CharField(_("prefix"), max_length=PREFIX_LENGTH, editable=False)
|
||||
hashed_key = models.CharField(
|
||||
_("hashed key"), max_length=HASHED_KEY_LENGTH, db_index=True, editable=False
|
||||
)
|
||||
client = models.ForeignKey(
|
||||
ApiClient,
|
||||
verbose_name=_("api client"),
|
||||
related_name="api_keys",
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
revoked = models.BooleanField(pgettext_lazy("api key", "revoked"), default=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("api key")
|
||||
verbose_name_plural = _("api keys")
|
||||
permissions = [("revoke_apikey", "Revoke API keys")]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} ({self.prefix}***)"
|
||||
|
197
api/permissions.py
Normal file
197
api/permissions.py
Normal file
@ -0,0 +1,197 @@
|
||||
"""Permission classes to be used within ninja-extra controllers.
|
||||
|
||||
Some permissions are global (like `IsInGroup` or `IsRoot`),
|
||||
and some others are per-object (like `CanView` or `CanEdit`).
|
||||
|
||||
Example:
|
||||
```python
|
||||
# restrict all the routes of this controller
|
||||
# to subscribed users
|
||||
@api_controller("/foo", permissions=[IsSubscriber])
|
||||
class FooController(ControllerBase):
|
||||
@route.get("/bar")
|
||||
def bar_get(self):
|
||||
# This route inherits the permissions of the controller
|
||||
# ...
|
||||
|
||||
@route.bar("/bar/{bar_id}", permissions=[CanView])
|
||||
def bar_get_one(self, bar_id: int):
|
||||
# per-object permission resolution happens
|
||||
# when calling either the `get_object_or_exception`
|
||||
# or `get_object_or_none` method.
|
||||
bar = self.get_object_or_exception(Counter, pk=bar_id)
|
||||
|
||||
# you can also call the `check_object_permission` manually
|
||||
other_bar = Counter.objects.first()
|
||||
self.check_object_permissions(other_bar)
|
||||
|
||||
# ...
|
||||
|
||||
# This route is restricted to counter admins and root users
|
||||
@route.delete(
|
||||
"/bar/{bar_id}",
|
||||
permissions=[IsRoot | IsInGroup(settings.SITH_GROUP_COUNTER_ADMIN_ID)
|
||||
]
|
||||
def bar_delete(self, bar_id: int):
|
||||
# ...
|
||||
```
|
||||
"""
|
||||
|
||||
import operator
|
||||
from functools import reduce
|
||||
from typing import Any, Callable
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.http import HttpRequest
|
||||
from ninja_extra import ControllerBase
|
||||
from ninja_extra.permissions import BasePermission
|
||||
|
||||
from counter.models import Counter
|
||||
|
||||
|
||||
class IsInGroup(BasePermission):
|
||||
"""Check that the user is in the group whose primary key is given."""
|
||||
|
||||
def __init__(self, group_pk: int):
|
||||
self._group_pk = group_pk
|
||||
|
||||
def has_permission(self, request: HttpRequest, controller: ControllerBase) -> bool:
|
||||
return request.user.is_in_group(pk=self._group_pk)
|
||||
|
||||
|
||||
class HasPerm(BasePermission):
|
||||
"""Check that the user has the required perm.
|
||||
|
||||
If multiple perms are given, a comparer function can also be passed,
|
||||
in order to change the way perms are checked.
|
||||
|
||||
Example:
|
||||
```python
|
||||
@api_controller("/foo")
|
||||
class FooController(ControllerBase):
|
||||
# this route will require both permissions
|
||||
@route.put("/foo", permissions=[HasPerm(["foo.change_foo", "foo.add_foo"])]
|
||||
def foo(self): ...
|
||||
|
||||
# This route will require at least one of the perm,
|
||||
# but it's not mandatory to have all of them
|
||||
@route.put(
|
||||
"/bar",
|
||||
permissions=[HasPerm(["foo.change_bar", "foo.add_bar"], op=operator.or_)],
|
||||
)
|
||||
def bar(self): ...
|
||||
```
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
perms: str | Permission | list[str | Permission],
|
||||
op: Callable[[bool, bool], bool] = operator.and_,
|
||||
):
|
||||
"""
|
||||
Args:
|
||||
perms: a permission or a list of permissions the user must have
|
||||
op: An operator to combine multiple permissions (in most cases,
|
||||
it will be either `operator.and_` or `operator.or_`)
|
||||
"""
|
||||
super().__init__()
|
||||
if not isinstance(perms, (list, tuple, set)):
|
||||
perms = [perms]
|
||||
self._operator = op
|
||||
self._perms = perms
|
||||
|
||||
def has_permission(self, request: HttpRequest, controller: ControllerBase) -> bool:
|
||||
# if the request has the `auth` property,
|
||||
# it means that the user has been explicitly authenticated
|
||||
# using a django-ninja authentication backend
|
||||
# (whether it is SessionAuth or ApiKeyAuth).
|
||||
# If not, this authentication has not been done, but the user may
|
||||
# still be implicitly authenticated through AuthenticationMiddleware
|
||||
user = request.auth if hasattr(request, "auth") else request.user
|
||||
# `user` may either be a `core.User` or an `api.ApiClient` ;
|
||||
# they are not the same model, but they both implement the `has_perm` method
|
||||
return reduce(self._operator, (user.has_perm(p) for p in self._perms))
|
||||
|
||||
|
||||
class IsRoot(BasePermission):
|
||||
"""Check that the user is root."""
|
||||
|
||||
def has_permission(self, request: HttpRequest, controller: ControllerBase) -> bool:
|
||||
return request.user.is_root
|
||||
|
||||
|
||||
class IsSubscriber(BasePermission):
|
||||
"""Check that the user is currently subscribed."""
|
||||
|
||||
def has_permission(self, request: HttpRequest, controller: ControllerBase) -> bool:
|
||||
return request.user.is_subscribed
|
||||
|
||||
|
||||
class IsOldSubscriber(BasePermission):
|
||||
"""Check that the user has at least one subscription in its history."""
|
||||
|
||||
def has_permission(self, request: HttpRequest, controller: ControllerBase) -> bool:
|
||||
return request.user.was_subscribed
|
||||
|
||||
|
||||
class CanView(BasePermission):
|
||||
"""Check that this user has the permission to view the object of this route.
|
||||
|
||||
Wrap the `user.can_view(obj)` method.
|
||||
To see an example, look at the example in the module docstring.
|
||||
"""
|
||||
|
||||
def has_permission(self, request: HttpRequest, controller: ControllerBase) -> bool:
|
||||
return True
|
||||
|
||||
def has_object_permission(
|
||||
self, request: HttpRequest, controller: ControllerBase, obj: Any
|
||||
) -> bool:
|
||||
return request.user.can_view(obj)
|
||||
|
||||
|
||||
class CanEdit(BasePermission):
|
||||
"""Check that this user has the permission to edit the object of this route.
|
||||
|
||||
Wrap the `user.can_edit(obj)` method.
|
||||
To see an example, look at the example in the module docstring.
|
||||
"""
|
||||
|
||||
def has_permission(self, request: HttpRequest, controller: ControllerBase) -> bool:
|
||||
return True
|
||||
|
||||
def has_object_permission(
|
||||
self, request: HttpRequest, controller: ControllerBase, obj: Any
|
||||
) -> bool:
|
||||
return request.user.can_edit(obj)
|
||||
|
||||
|
||||
class IsOwner(BasePermission):
|
||||
"""Check that this user owns the object of this route.
|
||||
|
||||
Wrap the `user.is_owner(obj)` method.
|
||||
To see an example, look at the example in the module docstring.
|
||||
"""
|
||||
|
||||
def has_permission(self, request: HttpRequest, controller: ControllerBase) -> bool:
|
||||
return True
|
||||
|
||||
def has_object_permission(
|
||||
self, request: HttpRequest, controller: ControllerBase, obj: Any
|
||||
) -> bool:
|
||||
return request.user.is_owner(obj)
|
||||
|
||||
|
||||
class IsLoggedInCounter(BasePermission):
|
||||
"""Check that a user is logged in a counter."""
|
||||
|
||||
def has_permission(self, request: HttpRequest, controller: ControllerBase) -> bool:
|
||||
if "/counter/" not in request.META.get("HTTP_REFERER", ""):
|
||||
return False
|
||||
token = request.session.get("counter_token")
|
||||
if not token:
|
||||
return False
|
||||
return Counter.objects.filter(token=token).exists()
|
||||
|
||||
|
||||
CanAccessLookup = IsLoggedInCounter | HasPerm("core.access_lookup")
|
19
api/tests.py
19
api/tests.py
@ -1,19 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
0
api/tests/__init__.py
Normal file
0
api/tests/__init__.py
Normal file
29
api/tests/test_api_key.py
Normal file
29
api/tests/test_api_key.py
Normal file
@ -0,0 +1,29 @@
|
||||
import pytest
|
||||
from django.test import RequestFactory
|
||||
from model_bakery import baker
|
||||
|
||||
from api.auth import ApiKeyAuth
|
||||
from api.hashers import generate_key
|
||||
from api.models import ApiClient, ApiKey
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_api_key_auth():
|
||||
key, hashed = generate_key()
|
||||
client = baker.make(ApiClient)
|
||||
baker.make(ApiKey, client=client, hashed_key=hashed)
|
||||
auth = ApiKeyAuth()
|
||||
|
||||
assert auth.authenticate(RequestFactory().get(""), key) == client
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize(
|
||||
("key", "hashed"), [(generate_key()[0], generate_key()[1]), (generate_key()[0], "")]
|
||||
)
|
||||
def test_api_key_auth_invalid(key, hashed):
|
||||
client = baker.make(ApiClient)
|
||||
baker.make(ApiKey, client=client, hashed_key=hashed)
|
||||
auth = ApiKeyAuth()
|
||||
|
||||
assert auth.authenticate(RequestFactory().get(""), key) is None
|
56
api/urls.py
56
api/urls.py
@ -1,50 +1,10 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
from ninja_extra import NinjaExtraAPI
|
||||
|
||||
from django.urls import re_path, path, include
|
||||
|
||||
from api.views import *
|
||||
from rest_framework import routers
|
||||
|
||||
# Router config
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r"counter", CounterViewSet, basename="api_counter")
|
||||
router.register(r"user", UserViewSet, basename="api_user")
|
||||
router.register(r"club", ClubViewSet, basename="api_club")
|
||||
router.register(r"group", GroupViewSet, basename="api_group")
|
||||
|
||||
# Launderette
|
||||
router.register(
|
||||
r"launderette/place", LaunderettePlaceViewSet, basename="api_launderette_place"
|
||||
api = NinjaExtraAPI(
|
||||
title="PICON",
|
||||
description="Portail Interactif de Communication avec les Outils Numériques",
|
||||
version="0.2.0",
|
||||
urls_namespace="api",
|
||||
csrf=True,
|
||||
)
|
||||
router.register(
|
||||
r"launderette/machine",
|
||||
LaunderetteMachineViewSet,
|
||||
basename="api_launderette_machine",
|
||||
)
|
||||
router.register(
|
||||
r"launderette/token", LaunderetteTokenViewSet, basename="api_launderette_token"
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
# API
|
||||
re_path(r"^", include(router.urls)),
|
||||
re_path(r"^login/", include("rest_framework.urls", namespace="rest_framework")),
|
||||
re_path(r"^markdown$", RenderMarkdown, name="api_markdown"),
|
||||
re_path(r"^mailings$", FetchMailingLists, name="mailings_fetch"),
|
||||
re_path(r"^uv$", uv_endpoint, name="uv_endpoint"),
|
||||
path("sas/<int:user>", all_pictures_of_user_endpoint, name="all_pictures_of_user"),
|
||||
]
|
||||
api.auto_discover_controllers()
|
||||
|
@ -1,73 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import viewsets
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from rest_framework.decorators import action
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
from core.views import can_view, can_edit
|
||||
|
||||
|
||||
def check_if(obj, user, test):
|
||||
"""
|
||||
Detect if it's a single object or a queryset
|
||||
aply a given test on individual object and return global permission
|
||||
"""
|
||||
if isinstance(obj, QuerySet):
|
||||
for o in obj:
|
||||
if test(o, user) is False:
|
||||
return False
|
||||
return True
|
||||
else:
|
||||
return test(obj, user)
|
||||
|
||||
|
||||
class ManageModelMixin:
|
||||
@action(detail=True)
|
||||
def id(self, request, pk=None):
|
||||
"""
|
||||
Get by id (api/v1/router/{pk}/id/)
|
||||
"""
|
||||
self.queryset = get_object_or_404(self.queryset.filter(id=pk))
|
||||
serializer = self.get_serializer(self.queryset)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
class RightModelViewSet(ManageModelMixin, viewsets.ModelViewSet):
|
||||
def dispatch(self, request, *arg, **kwargs):
|
||||
res = super(RightModelViewSet, self).dispatch(request, *arg, **kwargs)
|
||||
obj = self.queryset
|
||||
user = self.request.user
|
||||
try:
|
||||
if request.method == "GET" and check_if(obj, user, can_view):
|
||||
return res
|
||||
if request.method != "GET" and check_if(obj, user, can_edit):
|
||||
return res
|
||||
except:
|
||||
pass # To prevent bug with Anonymous user
|
||||
raise PermissionDenied
|
||||
|
||||
|
||||
from .api import *
|
||||
from .counter import *
|
||||
from .user import *
|
||||
from .club import *
|
||||
from .group import *
|
||||
from .launderette import *
|
||||
from .uv import *
|
||||
from .sas import *
|
@ -1,34 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import api_view, renderer_classes
|
||||
from rest_framework.renderers import StaticHTMLRenderer
|
||||
|
||||
from core.templatetags.renderer import markdown
|
||||
|
||||
|
||||
@api_view(["POST"])
|
||||
@renderer_classes((StaticHTMLRenderer,))
|
||||
def RenderMarkdown(request):
|
||||
"""
|
||||
Render Markdown
|
||||
"""
|
||||
try:
|
||||
data = markdown(request.POST["text"])
|
||||
except:
|
||||
data = "Error"
|
||||
return Response(data)
|
@ -1,56 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import serializers
|
||||
from rest_framework.decorators import api_view, renderer_classes
|
||||
from rest_framework.renderers import StaticHTMLRenderer
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
from club.models import Club, Mailing
|
||||
|
||||
from api.views import RightModelViewSet
|
||||
|
||||
|
||||
class ClubSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Club
|
||||
fields = ("id", "name", "unix_name", "address", "members")
|
||||
|
||||
|
||||
class ClubViewSet(RightModelViewSet):
|
||||
"""
|
||||
Manage Clubs (api/v1/club/)
|
||||
"""
|
||||
|
||||
serializer_class = ClubSerializer
|
||||
queryset = Club.objects.all()
|
||||
|
||||
|
||||
@api_view(["GET"])
|
||||
@renderer_classes((StaticHTMLRenderer,))
|
||||
def FetchMailingLists(request):
|
||||
key = request.GET.get("key", "")
|
||||
if key != settings.SITH_MAILING_FETCH_KEY:
|
||||
raise PermissionDenied
|
||||
data = ""
|
||||
for mailing in Mailing.objects.filter(
|
||||
is_moderated=True, club__is_active=True
|
||||
).all():
|
||||
data += mailing.fetch_format() + "\n"
|
||||
return Response(data)
|
@ -1,52 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import action
|
||||
|
||||
from counter.models import Counter
|
||||
|
||||
from api.views import RightModelViewSet
|
||||
|
||||
|
||||
class CounterSerializer(serializers.ModelSerializer):
|
||||
is_open = serializers.BooleanField(read_only=True)
|
||||
barman_list = serializers.ListField(
|
||||
child=serializers.IntegerField(), read_only=True
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Counter
|
||||
fields = ("id", "name", "type", "club", "products", "is_open", "barman_list")
|
||||
|
||||
|
||||
class CounterViewSet(RightModelViewSet):
|
||||
"""
|
||||
Manage Counters (api/v1/counter/)
|
||||
"""
|
||||
|
||||
serializer_class = CounterSerializer
|
||||
queryset = Counter.objects.all()
|
||||
|
||||
@action(detail=False)
|
||||
def bar(self, request):
|
||||
"""
|
||||
Return all bars (api/v1/counter/bar/)
|
||||
"""
|
||||
self.queryset = self.queryset.filter(type="BAR")
|
||||
serializer = self.get_serializer(self.queryset, many=True)
|
||||
return Response(serializer.data)
|
@ -1,35 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.models import RealGroup
|
||||
|
||||
from api.views import RightModelViewSet
|
||||
|
||||
|
||||
class GroupSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = RealGroup
|
||||
|
||||
|
||||
class GroupViewSet(RightModelViewSet):
|
||||
"""
|
||||
Manage Groups (api/v1/group/)
|
||||
"""
|
||||
|
||||
serializer_class = GroupSerializer
|
||||
queryset = RealGroup.objects.all()
|
@ -1,128 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import action
|
||||
|
||||
from launderette.models import Launderette, Machine, Token
|
||||
|
||||
from api.views import RightModelViewSet
|
||||
|
||||
|
||||
class LaunderettePlaceSerializer(serializers.ModelSerializer):
|
||||
machine_list = serializers.ListField(
|
||||
child=serializers.IntegerField(), read_only=True
|
||||
)
|
||||
token_list = serializers.ListField(child=serializers.IntegerField(), read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Launderette
|
||||
fields = (
|
||||
"id",
|
||||
"name",
|
||||
"counter",
|
||||
"machine_list",
|
||||
"token_list",
|
||||
"get_absolute_url",
|
||||
)
|
||||
|
||||
|
||||
class LaunderetteMachineSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Machine
|
||||
fields = ("id", "name", "type", "is_working", "launderette")
|
||||
|
||||
|
||||
class LaunderetteTokenSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Token
|
||||
fields = (
|
||||
"id",
|
||||
"name",
|
||||
"type",
|
||||
"launderette",
|
||||
"borrow_date",
|
||||
"user",
|
||||
"is_avaliable",
|
||||
)
|
||||
|
||||
|
||||
class LaunderettePlaceViewSet(RightModelViewSet):
|
||||
"""
|
||||
Manage Launderette (api/v1/launderette/place/)
|
||||
"""
|
||||
|
||||
serializer_class = LaunderettePlaceSerializer
|
||||
queryset = Launderette.objects.all()
|
||||
|
||||
|
||||
class LaunderetteMachineViewSet(RightModelViewSet):
|
||||
"""
|
||||
Manage Washing Machines (api/v1/launderette/machine/)
|
||||
"""
|
||||
|
||||
serializer_class = LaunderetteMachineSerializer
|
||||
queryset = Machine.objects.all()
|
||||
|
||||
|
||||
class LaunderetteTokenViewSet(RightModelViewSet):
|
||||
"""
|
||||
Manage Launderette's tokens (api/v1/launderette/token/)
|
||||
"""
|
||||
|
||||
serializer_class = LaunderetteTokenSerializer
|
||||
queryset = Token.objects.all()
|
||||
|
||||
@action(detail=False)
|
||||
def washing(self, request):
|
||||
"""
|
||||
Return all washing tokens (api/v1/launderette/token/washing)
|
||||
"""
|
||||
self.queryset = self.queryset.filter(type="WASHING")
|
||||
serializer = self.get_serializer(self.queryset, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
@action(detail=False)
|
||||
def drying(self, request):
|
||||
"""
|
||||
Return all drying tokens (api/v1/launderette/token/drying)
|
||||
"""
|
||||
self.queryset = self.queryset.filter(type="DRYING")
|
||||
serializer = self.get_serializer(self.queryset, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
@action(detail=False)
|
||||
def avaliable(self, request):
|
||||
"""
|
||||
Return all avaliable tokens (api/v1/launderette/token/avaliable)
|
||||
"""
|
||||
self.queryset = self.queryset.filter(
|
||||
borrow_date__isnull=True, user__isnull=True
|
||||
)
|
||||
serializer = self.get_serializer(self.queryset, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
@action(detail=False)
|
||||
def unavaliable(self, request):
|
||||
"""
|
||||
Return all unavaliable tokens (api/v1/launderette/token/unavaliable)
|
||||
"""
|
||||
self.queryset = self.queryset.filter(
|
||||
borrow_date__isnull=False, user__isnull=False
|
||||
)
|
||||
serializer = self.get_serializer(self.queryset, many=True)
|
||||
return Response(serializer.data)
|
@ -1,42 +0,0 @@
|
||||
from typing import List
|
||||
from rest_framework.decorators import api_view, renderer_classes
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
from rest_framework.generics import get_object_or_404
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.response import Response
|
||||
|
||||
from core.views import can_edit
|
||||
from core.models import User
|
||||
from sas.models import Picture
|
||||
|
||||
|
||||
def all_pictures_of_user(user: User) -> List[Picture]:
|
||||
return [
|
||||
relation.picture
|
||||
for relation in user.pictures.exclude(picture=None)
|
||||
.order_by("-picture__parent__date", "id")
|
||||
.select_related("picture__parent")
|
||||
]
|
||||
|
||||
|
||||
@api_view(["GET"])
|
||||
@renderer_classes((JSONRenderer,))
|
||||
def all_pictures_of_user_endpoint(request: Request, user: int):
|
||||
requested_user: User = get_object_or_404(User, pk=user)
|
||||
if not can_edit(requested_user, request.user):
|
||||
raise PermissionDenied
|
||||
|
||||
return Response(
|
||||
[
|
||||
{
|
||||
"name": f"{picture.parent.name} - {picture.name}",
|
||||
"date": picture.date,
|
||||
"author": str(picture.owner),
|
||||
"full_size_url": picture.get_download_url(),
|
||||
"compressed_url": picture.get_download_compressed_url(),
|
||||
"thumb_url": picture.get_download_thumb_url(),
|
||||
}
|
||||
for picture in all_pictures_of_user(requested_user)
|
||||
]
|
||||
)
|
@ -1,60 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
#
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
||||
import datetime
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import action
|
||||
|
||||
from core.models import User
|
||||
|
||||
from api.views import RightModelViewSet
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = (
|
||||
"id",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"email",
|
||||
"date_of_birth",
|
||||
"nick_name",
|
||||
"is_active",
|
||||
"date_joined",
|
||||
)
|
||||
|
||||
|
||||
class UserViewSet(RightModelViewSet):
|
||||
"""
|
||||
Manage Users (api/v1/user/)
|
||||
Only show active users
|
||||
"""
|
||||
|
||||
serializer_class = UserSerializer
|
||||
queryset = User.objects.filter(is_active=True)
|
||||
|
||||
@action(detail=False)
|
||||
def birthday(self, request):
|
||||
"""
|
||||
Return all users born today (api/v1/user/birstdays)
|
||||
"""
|
||||
date = datetime.datetime.today()
|
||||
self.queryset = self.queryset.filter(date_of_birth=date)
|
||||
serializer = self.get_serializer(self.queryset, many=True)
|
||||
return Response(serializer.data)
|
127
api/views/uv.py
127
api/views/uv.py
@ -1,127 +0,0 @@
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import api_view, renderer_classes
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.conf import settings
|
||||
from rest_framework import serializers
|
||||
import urllib.request
|
||||
import json
|
||||
|
||||
from pedagogy.views import CanCreateUVFunctionMixin
|
||||
|
||||
|
||||
@api_view(["GET"])
|
||||
@renderer_classes((JSONRenderer,))
|
||||
def uv_endpoint(request):
|
||||
if not CanCreateUVFunctionMixin.can_create_uv(request.user):
|
||||
raise PermissionDenied
|
||||
|
||||
params = request.query_params
|
||||
if "year" not in params or "code" not in params:
|
||||
raise serializers.ValidationError("Missing query parameter")
|
||||
|
||||
short_uv, full_uv = find_uv("fr", params["year"], params["code"])
|
||||
if short_uv is None or full_uv is None:
|
||||
return Response(status=204)
|
||||
|
||||
return Response(make_clean_uv(short_uv, full_uv))
|
||||
|
||||
|
||||
def find_uv(lang, year, code):
|
||||
"""
|
||||
Uses the UTBM API to find an UV.
|
||||
short_uv is the UV entry in the UV list. It is returned as it contains
|
||||
information which are not in full_uv.
|
||||
full_uv is the detailed representation of an UV.
|
||||
"""
|
||||
# query the UV list
|
||||
uvs_url = settings.SITH_PEDAGOGY_UTBM_API + "/uvs/{}/{}".format(lang, year)
|
||||
response = urllib.request.urlopen(uvs_url)
|
||||
uvs = json.loads(response.read().decode("utf-8"))
|
||||
|
||||
try:
|
||||
# find the first UV which matches the code
|
||||
short_uv = next(uv for uv in uvs if uv["code"] == code)
|
||||
except StopIteration:
|
||||
return (None, None)
|
||||
|
||||
# get detailed information about the UV
|
||||
uv_url = settings.SITH_PEDAGOGY_UTBM_API + "/uv/{}/{}/{}/{}".format(
|
||||
lang, year, code, short_uv["codeFormation"]
|
||||
)
|
||||
response = urllib.request.urlopen(uv_url)
|
||||
full_uv = json.loads(response.read().decode("utf-8"))
|
||||
|
||||
return (short_uv, full_uv)
|
||||
|
||||
|
||||
def make_clean_uv(short_uv, full_uv):
|
||||
"""
|
||||
Cleans the data up so that it corresponds to our data representation.
|
||||
"""
|
||||
res = {}
|
||||
|
||||
res["credit_type"] = short_uv["codeCategorie"]
|
||||
|
||||
# probably wrong on a few UVs as we pick the first UV we find but
|
||||
# availability depends on the formation
|
||||
semesters = {
|
||||
(True, True): "AUTUMN_AND_SPRING",
|
||||
(True, False): "AUTUMN",
|
||||
(False, True): "SPRING",
|
||||
}
|
||||
res["semester"] = semesters.get(
|
||||
(short_uv["ouvertAutomne"], short_uv["ouvertPrintemps"]), "CLOSED"
|
||||
)
|
||||
|
||||
langs = {"es": "SP", "en": "EN", "de": "DE"}
|
||||
res["language"] = langs.get(full_uv["codeLangue"], "FR")
|
||||
|
||||
if full_uv["departement"] == "Pôle Humanités":
|
||||
res["department"] = "HUMA"
|
||||
else:
|
||||
departments = {
|
||||
"AL": "IMSI",
|
||||
"AE": "EE",
|
||||
"GI": "GI",
|
||||
"GC": "EE",
|
||||
"GM": "MC",
|
||||
"TC": "TC",
|
||||
"GP": "IMSI",
|
||||
"ED": "EDIM",
|
||||
"AI": "GI",
|
||||
"AM": "MC",
|
||||
}
|
||||
res["department"] = departments.get(full_uv["codeFormation"], "NA")
|
||||
|
||||
res["credits"] = full_uv["creditsEcts"]
|
||||
|
||||
activities = ("CM", "TD", "TP", "THE", "TE")
|
||||
for activity in activities:
|
||||
res["hours_{}".format(activity)] = 0
|
||||
for activity in full_uv["activites"]:
|
||||
if activity["code"] in activities:
|
||||
res["hours_{}".format(activity["code"])] += activity["nbh"] // 60
|
||||
|
||||
# wrong if the manager changes depending on the semester
|
||||
semester = full_uv.get("automne", None)
|
||||
if not semester:
|
||||
semester = full_uv.get("printemps", {})
|
||||
res["manager"] = semester.get("responsable", "")
|
||||
|
||||
res["title"] = full_uv["libelle"]
|
||||
|
||||
descriptions = {
|
||||
"objectives": "objectifs",
|
||||
"program": "programme",
|
||||
"skills": "acquisitionCompetences",
|
||||
"key_concepts": "acquisitionNotions",
|
||||
}
|
||||
|
||||
for res_key, full_uv_key in descriptions.items():
|
||||
res[res_key] = full_uv[full_uv_key]
|
||||
# if not found or the API did not return a string
|
||||
if type(res[res_key]) != str:
|
||||
res[res_key] = ""
|
||||
|
||||
return res
|
29
biome.json
Normal file
29
biome.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
|
||||
"vcs": {
|
||||
"enabled": true,
|
||||
"clientKind": "git",
|
||||
"useIgnoreFile": true
|
||||
},
|
||||
"files": {
|
||||
"ignoreUnknown": false,
|
||||
"ignore": ["*.min.*", "staticfiles/generated"]
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": true,
|
||||
"indentStyle": "space",
|
||||
"lineWidth": 88
|
||||
},
|
||||
"organizeImports": {
|
||||
"enabled": true
|
||||
},
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"all": true
|
||||
}
|
||||
},
|
||||
"javascript": {
|
||||
"globals": ["Alpine", "$", "jQuery", "gettext", "interpolate"]
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
@ -6,10 +5,10 @@
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
|
@ -1,4 +1,3 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2023 © AE UTBM
|
||||
# ae@utbm.fr / ae.info@utbm.fr
|
||||
@ -6,14 +5,13 @@
|
||||
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
||||
# https://ae.utbm.fr.
|
||||
#
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith3
|
||||
# You can find the source code of the website at https://github.com/ae-utbm/sith
|
||||
#
|
||||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
||||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith/master/LICENSE
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
from ajax_select import make_ajax_form
|
||||
from django.contrib import admin
|
||||
|
||||
from club.models import Club, Membership
|
||||
@ -21,7 +19,15 @@ from club.models import Club, Membership
|
||||
|
||||
@admin.register(Club)
|
||||
class ClubAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "unix_name", "parent", "is_active")
|
||||
list_display = ("name", "slug_name", "parent", "is_active")
|
||||
search_fields = ("name", "slug_name")
|
||||
autocomplete_fields = (
|
||||
"parent",
|
||||
"board_group",
|
||||
"members_group",
|
||||
"home",
|
||||
"page",
|
||||
)
|
||||
|
||||
|
||||
@admin.register(Membership)
|
||||
@ -33,4 +39,4 @@ class MembershipAdmin(admin.ModelAdmin):
|
||||
"user__last_name",
|
||||
"club__name",
|
||||
)
|
||||
form = make_ajax_form(Membership, {"user": "users"})
|
||||
autocomplete_fields = ("user",)
|
||||
|
42
club/api.py
Normal file
42
club/api.py
Normal file
@ -0,0 +1,42 @@
|
||||
from typing import Annotated
|
||||
|
||||
from annotated_types import MinLen
|
||||
from django.db.models import Prefetch
|
||||
from ninja.security import SessionAuth
|
||||
from ninja_extra import ControllerBase, api_controller, paginate, route
|
||||
from ninja_extra.pagination import PageNumberPaginationExtra
|
||||
from ninja_extra.schemas import PaginatedResponseSchema
|
||||
|
||||
from api.auth import ApiKeyAuth
|
||||
from api.permissions import CanAccessLookup, HasPerm
|
||||
from club.models import Club, Membership
|
||||
from club.schemas import ClubSchema, SimpleClubSchema
|
||||
|
||||
|
||||
@api_controller("/club")
|
||||
class ClubController(ControllerBase):
|
||||
@route.get(
|
||||
"/search",
|
||||
response=PaginatedResponseSchema[SimpleClubSchema],
|
||||
auth=[SessionAuth(), ApiKeyAuth()],
|
||||
permissions=[CanAccessLookup],
|
||||
url_name="search_club",
|
||||
)
|
||||
@paginate(PageNumberPaginationExtra, page_size=50)
|
||||
def search_club(self, search: Annotated[str, MinLen(1)]):
|
||||
return Club.objects.filter(name__icontains=search).values()
|
||||
|
||||
@route.get(
|
||||
"/{int:club_id}",
|
||||
response=ClubSchema,
|
||||
auth=[SessionAuth(), ApiKeyAuth()],
|
||||
permissions=[HasPerm("club.view_club")],
|
||||
url_name="fetch_club",
|
||||
)
|
||||
def fetch_club(self, club_id: int):
|
||||
prefetch = Prefetch(
|
||||
"members", queryset=Membership.objects.ongoing().select_related("user")
|
||||
)
|
||||
return self.get_object_or_exception(
|
||||
Club.objects.prefetch_related(prefetch), id=club_id
|
||||
)
|
118
club/forms.py
118
club/forms.py
@ -1,4 +1,3 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2016,2017
|
||||
# - Skia <skia@libskia.so>
|
||||
@ -23,48 +22,53 @@
|
||||
#
|
||||
#
|
||||
|
||||
from django.conf import settings
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.db.models import Exists, OuterRef, Q
|
||||
from django.db.models.functions import Lower
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField
|
||||
|
||||
from club.models import Mailing, MailingSubscription, Club, Membership
|
||||
|
||||
from club.models import Club, Mailing, MailingSubscription, Membership
|
||||
from core.models import User
|
||||
from core.views.forms import SelectDate, SelectDateTime
|
||||
from counter.models import Counter
|
||||
from core.views.forms import TzAwareDateTimeField
|
||||
from core.views.widgets.ajax_select import AutoCompleteSelectMultipleUser
|
||||
from counter.models import Counter, Selling
|
||||
|
||||
|
||||
class ClubEditForm(forms.ModelForm):
|
||||
error_css_class = "error"
|
||||
required_css_class = "required"
|
||||
|
||||
class Meta:
|
||||
model = Club
|
||||
fields = ["address", "logo", "short_description"]
|
||||
widgets = {"short_description": forms.Textarea()}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ClubEditForm, self).__init__(*args, **kwargs)
|
||||
self.fields["short_description"].widget = forms.Textarea()
|
||||
|
||||
class ClubAdminEditForm(ClubEditForm):
|
||||
admin_fields = ["name", "parent", "is_active"]
|
||||
|
||||
class Meta(ClubEditForm.Meta):
|
||||
fields = ["name", "parent", "is_active", *ClubEditForm.Meta.fields]
|
||||
|
||||
|
||||
class MailingForm(forms.Form):
|
||||
"""
|
||||
Form handling mailing lists right
|
||||
"""
|
||||
"""Form handling mailing lists right."""
|
||||
|
||||
ACTION_NEW_MAILING = 1
|
||||
ACTION_NEW_SUBSCRIPTION = 2
|
||||
ACTION_REMOVE_SUBSCRIPTION = 3
|
||||
|
||||
subscription_users = AutoCompleteSelectMultipleField(
|
||||
"users",
|
||||
subscription_users = forms.ModelMultipleChoiceField(
|
||||
label=_("Users to add"),
|
||||
help_text=_("Search users to add (one or more)."),
|
||||
required=False,
|
||||
widget=AutoCompleteSelectMultipleUser,
|
||||
queryset=User.objects.all(),
|
||||
)
|
||||
|
||||
def __init__(self, club_id, user_id, mailings, *args, **kwargs):
|
||||
super(MailingForm, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.fields["action"] = forms.TypedChoiceField(
|
||||
choices=(
|
||||
@ -109,24 +113,15 @@ class MailingForm(forms.Form):
|
||||
)
|
||||
|
||||
def check_required(self, cleaned_data, field):
|
||||
"""
|
||||
If the given field doesn't exist or has no value, add a required error on it
|
||||
"""
|
||||
"""If the given field doesn't exist or has no value, add a required error on it."""
|
||||
if not cleaned_data.get(field, None):
|
||||
self.add_error(field, _("This field is required"))
|
||||
|
||||
def clean_subscription_users(self):
|
||||
"""
|
||||
Convert given users into real users and check their validity
|
||||
"""
|
||||
cleaned_data = super(MailingForm, self).clean()
|
||||
"""Convert given users into real users and check their validity."""
|
||||
cleaned_data = super().clean()
|
||||
users = []
|
||||
for user in cleaned_data["subscription_users"]:
|
||||
user = User.objects.filter(id=user).first()
|
||||
if not user:
|
||||
raise forms.ValidationError(
|
||||
_("One of the selected users doesn't exist"), code="invalid"
|
||||
)
|
||||
if not user.email:
|
||||
raise forms.ValidationError(
|
||||
_("One of the selected users doesn't have an email address"),
|
||||
@ -136,9 +131,9 @@ class MailingForm(forms.Form):
|
||||
return users
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(MailingForm, self).clean()
|
||||
cleaned_data = super().clean()
|
||||
|
||||
if not "action" in cleaned_data:
|
||||
if "action" not in cleaned_data:
|
||||
# If there is no action provided, we can stop here
|
||||
raise forms.ValidationError(_("An action is required"), code="invalid")
|
||||
|
||||
@ -159,15 +154,28 @@ class MailingForm(forms.Form):
|
||||
|
||||
|
||||
class SellingsForm(forms.Form):
|
||||
begin_date = TzAwareDateTimeField(label=_("Begin date"), required=False)
|
||||
end_date = TzAwareDateTimeField(label=_("End date"), required=False)
|
||||
|
||||
counters = forms.ModelMultipleChoiceField(
|
||||
Counter.objects.order_by("name").all(), label=_("Counter"), required=False
|
||||
begin_date = forms.DateTimeField(
|
||||
label=_("Begin date"), widget=SelectDateTime, required=False
|
||||
)
|
||||
end_date = forms.DateTimeField(
|
||||
label=_("End date"), widget=SelectDateTime, required=False
|
||||
)
|
||||
|
||||
def __init__(self, club, *args, **kwargs):
|
||||
super(SellingsForm, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
# postgres struggles really hard with a single query having three WHERE conditions,
|
||||
# but deals perfectly fine with UNION of multiple queryset with their own WHERE clause,
|
||||
# so we do this to get the ids, which we use to build another queryset that can be used by django.
|
||||
club_sales_subquery = Selling.objects.filter(counter=OuterRef("pk"), club=club)
|
||||
ids = (
|
||||
Counter.objects.filter(Q(club=club) | Q(products__club=club))
|
||||
.union(Counter.objects.filter(Exists(club_sales_subquery)))
|
||||
.values_list("id", flat=True)
|
||||
)
|
||||
counters_qs = Counter.objects.filter(id__in=ids).order_by(Lower("name"))
|
||||
self.fields["counters"] = forms.ModelMultipleChoiceField(
|
||||
counters_qs, label=_("Counter"), required=False
|
||||
)
|
||||
self.fields["products"] = forms.ModelMultipleChoiceField(
|
||||
club.products.order_by("name").filter(archived=False).all(),
|
||||
label=_("Products"),
|
||||
@ -181,18 +189,17 @@ class SellingsForm(forms.Form):
|
||||
|
||||
|
||||
class ClubMemberForm(forms.Form):
|
||||
"""
|
||||
Form handling the members of a club
|
||||
"""
|
||||
"""Form handling the members of a club."""
|
||||
|
||||
error_css_class = "error"
|
||||
required_css_class = "required"
|
||||
|
||||
users = AutoCompleteSelectMultipleField(
|
||||
"users",
|
||||
users = forms.ModelMultipleChoiceField(
|
||||
label=_("Users to add"),
|
||||
help_text=_("Search users to add (one or more)."),
|
||||
required=False,
|
||||
widget=AutoCompleteSelectMultipleUser,
|
||||
queryset=User.objects.all(),
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -200,11 +207,9 @@ class ClubMemberForm(forms.Form):
|
||||
self.request_user = kwargs.pop("request_user")
|
||||
self.club_members = kwargs.pop("club_members", None)
|
||||
if not self.club_members:
|
||||
self.club_members = (
|
||||
self.club.members.filter(end_date=None).order_by("-role").all()
|
||||
)
|
||||
self.club_members = self.club.members.ongoing().order_by("-role").all()
|
||||
self.request_user_membership = self.club.get_membership_for(self.request_user)
|
||||
super(ClubMemberForm, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Using a ModelForm binds too much the form with the model and we don't want that
|
||||
# We want the view to process the model creation since they are multiple users
|
||||
@ -240,18 +245,13 @@ class ClubMemberForm(forms.Form):
|
||||
self.fields.pop("start_date")
|
||||
|
||||
def clean_users(self):
|
||||
"""Check that the user is not trying to add an user already in the club.
|
||||
|
||||
Also check that the user is valid and has a valid subscription.
|
||||
"""
|
||||
Check that the user is not trying to add an user already in the club
|
||||
Also check that the user is valid and has a valid subscription
|
||||
"""
|
||||
cleaned_data = super(ClubMemberForm, self).clean()
|
||||
cleaned_data = super().clean()
|
||||
users = []
|
||||
for user_id in cleaned_data["users"]:
|
||||
user = User.objects.filter(id=user_id).first()
|
||||
if not user:
|
||||
raise forms.ValidationError(
|
||||
_("One of the selected users doesn't exist"), code="invalid"
|
||||
)
|
||||
for user in cleaned_data["users"]:
|
||||
if not user.is_subscribed:
|
||||
raise forms.ValidationError(
|
||||
_("User must be subscriber to take part to a club"), code="invalid"
|
||||
@ -264,10 +264,8 @@ class ClubMemberForm(forms.Form):
|
||||
return users
|
||||
|
||||
def clean(self):
|
||||
"""
|
||||
Check user rights for adding an user
|
||||
"""
|
||||
cleaned_data = super(ClubMemberForm, self).clean()
|
||||
"""Check user rights for adding an user."""
|
||||
cleaned_data = super().clean()
|
||||
|
||||
if "start_date" in cleaned_data and not cleaned_data["start_date"]:
|
||||
# Drop start_date if allowed to edition but not specified
|
||||
|
@ -1,9 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.core.validators
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -1,9 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
@ -1,9 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -1,8 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -1,8 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -1,7 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
@ -1,11 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
import re
|
||||
|
||||
import django.core.validators
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@ -109,6 +109,6 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="mailingsubscription",
|
||||
unique_together=set([("user", "email", "mailing")]),
|
||||
unique_together={("user", "email", "mailing")},
|
||||
),
|
||||
]
|
||||
|
@ -1,21 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
from club.models import Club
|
||||
from core.operations import PsqlRunOnly
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
def generate_club_pages(apps, schema_editor):
|
||||
def recursive_generate_club_page(club):
|
||||
club.make_page()
|
||||
for child in Club.objects.filter(parent=club).all():
|
||||
recursive_generate_club_page(child)
|
||||
|
||||
for club in Club.objects.filter(parent=None).all():
|
||||
recursive_generate_club_page(club)
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@ -49,11 +35,4 @@ class Migration(migrations.Migration):
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
PsqlRunOnly(
|
||||
"SET CONSTRAINTS ALL IMMEDIATE", reverse_sql=migrations.RunSQL.noop
|
||||
),
|
||||
migrations.RunPython(generate_club_pages),
|
||||
PsqlRunOnly(
|
||||
migrations.RunSQL.noop, reverse_sql="SET CONSTRAINTS ALL IMMEDIATE"
|
||||
),
|
||||
]
|
||||
|
@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
@ -1,9 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import club.models
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@ -15,7 +14,7 @@ class Migration(migrations.Migration):
|
||||
name="owner_group",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
default=club.models.Club.get_default_owner_group,
|
||||
default=lambda: settings.SITH_ROOT_USER_ID,
|
||||
related_name="owned_club",
|
||||
to="core.Group",
|
||||
),
|
||||
|
106
club/migrations/0012_club_board_group_club_members_group.py
Normal file
106
club/migrations/0012_club_board_group_club_members_group.py
Normal file
@ -0,0 +1,106 @@
|
||||
# Generated by Django 4.2.16 on 2024-11-20 17:08
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.db.models.functions.datetime
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
from django.db.migrations.state import StateApps
|
||||
from django.db.models import Q
|
||||
from django.utils.timezone import localdate
|
||||
|
||||
|
||||
def migrate_meta_groups(apps: StateApps, schema_editor):
|
||||
"""Attach the existing meta groups to the clubs.
|
||||
|
||||
Until now, the meta groups were not attached to the clubs,
|
||||
nor to the users.
|
||||
This creates actual foreign relationships between the clubs
|
||||
and theirs groups and the users and theirs groups.
|
||||
|
||||
Warnings:
|
||||
When the meta groups associated with the clubs aren't found,
|
||||
they are created.
|
||||
Thus the migration shouldn't fail, and all the clubs will
|
||||
have their groups.
|
||||
However, there will probably be some groups that have
|
||||
not been found but exist nonetheless,
|
||||
so there will be duplicates and dangling groups.
|
||||
There must be a manual cleanup after this migration.
|
||||
"""
|
||||
Group = apps.get_model("core", "Group")
|
||||
Club = apps.get_model("club", "Club")
|
||||
|
||||
meta_groups = Group.objects.filter(is_meta=True)
|
||||
clubs = list(Club.objects.all())
|
||||
for club in clubs:
|
||||
club.board_group = meta_groups.get_or_create(
|
||||
name=club.unix_name + settings.SITH_BOARD_SUFFIX,
|
||||
defaults={"is_meta": True},
|
||||
)[0]
|
||||
club.members_group = meta_groups.get_or_create(
|
||||
name=club.unix_name + settings.SITH_MEMBER_SUFFIX,
|
||||
defaults={"is_meta": True},
|
||||
)[0]
|
||||
club.save()
|
||||
club.refresh_from_db()
|
||||
memberships = club.members.filter(
|
||||
Q(end_date=None) | Q(end_date__gt=localdate())
|
||||
).select_related("user")
|
||||
club.members_group.users.set([m.user for m in memberships])
|
||||
club.board_group.users.set(
|
||||
[
|
||||
m.user
|
||||
for m in memberships.filter(role__gt=settings.SITH_MAXIMUM_FREE_ROLE)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
# steps of the migration :
|
||||
# - Create a nullable field for the board group and the member group
|
||||
# - Edit those new fields to make them point to currently existing meta groups
|
||||
# - When this data migration is done, make the fields non-nullable
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("core", "0040_alter_user_options_user_user_permissions_and_more"),
|
||||
("club", "0011_auto_20180426_2013"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name="club",
|
||||
name="edit_groups",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="club",
|
||||
name="owner_group",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="club",
|
||||
name="view_groups",
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="club",
|
||||
name="board_group",
|
||||
field=models.OneToOneField(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
related_name="club_board",
|
||||
to="core.group",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="club",
|
||||
name="members_group",
|
||||
field=models.OneToOneField(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
related_name="club",
|
||||
to="core.group",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(
|
||||
migrate_meta_groups, reverse_code=migrations.RunPython.noop, elidable=True
|
||||
),
|
||||
]
|
@ -0,0 +1,36 @@
|
||||
# Generated by Django 4.2.17 on 2025-01-04 16:46
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("club", "0012_club_board_group_club_members_group")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="club",
|
||||
name="board_group",
|
||||
field=models.OneToOneField(
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
related_name="club_board",
|
||||
to="core.group",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="club",
|
||||
name="members_group",
|
||||
field=models.OneToOneField(
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
related_name="club",
|
||||
to="core.group",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="membership",
|
||||
constraint=models.CheckConstraint(
|
||||
check=models.Q(("end_date__gte", models.F("start_date"))),
|
||||
name="end_after_start",
|
||||
),
|
||||
),
|
||||
]
|
@ -0,0 +1,75 @@
|
||||
# Generated by Django 4.2.17 on 2025-02-28 20:34
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
import core.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("core", "0044_alter_userban_options"),
|
||||
("club", "0013_alter_club_board_group_alter_club_members_group_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(name="club", options={"ordering": ["name"]}),
|
||||
migrations.RenameField(
|
||||
model_name="club",
|
||||
old_name="unix_name",
|
||||
new_name="slug_name",
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="club",
|
||||
name="name",
|
||||
field=models.CharField(unique=True, max_length=64, verbose_name="name"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="club",
|
||||
name="slug_name",
|
||||
field=models.SlugField(
|
||||
editable=False, max_length=30, unique=True, verbose_name="slug name"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="club",
|
||||
name="id",
|
||||
field=models.AutoField(
|
||||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="club",
|
||||
name="logo",
|
||||
field=core.fields.ResizedImageField(
|
||||
blank=True,
|
||||
force_format="WEBP",
|
||||
height=200,
|
||||
null=True,
|
||||
upload_to="club_logos",
|
||||
verbose_name="logo",
|
||||
width=200,
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="club",
|
||||
name="page",
|
||||
field=models.OneToOneField(
|
||||
blank=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="club",
|
||||
to="core.page",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="club",
|
||||
name="short_description",
|
||||
field=models.CharField(
|
||||
blank=True,
|
||||
default="",
|
||||
help_text="A summary of what your club does. This will be displayed on the club list page.",
|
||||
max_length=1000,
|
||||
verbose_name="short description",
|
||||
),
|
||||
),
|
||||
]
|
605
club/models.py
605
club/models.py
@ -1,4 +1,3 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2016,2017
|
||||
# - Skia <skia@libskia.so>
|
||||
@ -22,77 +21,58 @@
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
from typing import Optional
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterable, Self
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
from django.core import validators
|
||||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.core.exceptions import ValidationError, ObjectDoesNotExist
|
||||
from django.db import transaction
|
||||
from django.core.cache import cache
|
||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||
from django.core.validators import RegexValidator, validate_email
|
||||
from django.db import models, transaction
|
||||
from django.db.models import Exists, F, OuterRef, Q
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.core.validators import RegexValidator, validate_email
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.text import slugify
|
||||
from django.utils.timezone import localdate
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.models import User, MetaGroup, Group, SithFile, RealGroup, Notification, Page
|
||||
|
||||
# Create your models here.
|
||||
from core.fields import ResizedImageField
|
||||
from core.models import Group, Notification, Page, SithFile, User
|
||||
|
||||
|
||||
class Club(models.Model):
|
||||
"""
|
||||
The Club class, made as a tree to allow nice tidy organization
|
||||
"""
|
||||
"""The Club class, made as a tree to allow nice tidy organization."""
|
||||
|
||||
id = models.AutoField(primary_key=True, db_index=True)
|
||||
name = models.CharField(_("name"), max_length=64)
|
||||
name = models.CharField(_("name"), unique=True, max_length=64)
|
||||
parent = models.ForeignKey(
|
||||
"Club", related_name="children", null=True, blank=True, on_delete=models.CASCADE
|
||||
)
|
||||
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.")},
|
||||
slug_name = models.SlugField(
|
||||
_("slug name"), max_length=30, unique=True, editable=False
|
||||
)
|
||||
logo = models.ImageField(
|
||||
upload_to="club_logos", verbose_name=_("logo"), null=True, blank=True
|
||||
logo = ResizedImageField(
|
||||
upload_to="club_logos",
|
||||
verbose_name=_("logo"),
|
||||
null=True,
|
||||
blank=True,
|
||||
force_format="WEBP",
|
||||
height=200,
|
||||
width=200,
|
||||
)
|
||||
is_active = models.BooleanField(_("is active"), default=True)
|
||||
short_description = models.CharField(
|
||||
_("short description"), max_length=1000, default="", blank=True, null=True
|
||||
_("short description"),
|
||||
max_length=1000,
|
||||
default="",
|
||||
blank=True,
|
||||
help_text=_(
|
||||
"A summary of what your club does. "
|
||||
"This will be displayed on the club list page."
|
||||
),
|
||||
)
|
||||
address = models.CharField(_("address"), max_length=254)
|
||||
|
||||
# This function prevents generating migration upon settings change
|
||||
def get_default_owner_group():
|
||||
return settings.SITH_GROUP_ROOT_ID
|
||||
|
||||
owner_group = models.ForeignKey(
|
||||
Group,
|
||||
related_name="owned_club",
|
||||
default=get_default_owner_group,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
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",
|
||||
@ -102,20 +82,59 @@ class Club(models.Model):
|
||||
on_delete=models.SET_NULL,
|
||||
)
|
||||
page = models.OneToOneField(
|
||||
Page, related_name="club", blank=True, null=True, on_delete=models.CASCADE
|
||||
Page, related_name="club", blank=True, on_delete=models.CASCADE
|
||||
)
|
||||
members_group = models.OneToOneField(
|
||||
Group, related_name="club", on_delete=models.PROTECT
|
||||
)
|
||||
board_group = models.OneToOneField(
|
||||
Group, related_name="club_board", on_delete=models.PROTECT
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ["name", "unix_name"]
|
||||
ordering = ["name"]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@transaction.atomic()
|
||||
def save(self, *args, **kwargs):
|
||||
creation = self._state.adding
|
||||
if (slug := slugify(self.name)[:30]) != self.slug_name:
|
||||
self.slug_name = slug
|
||||
if not creation:
|
||||
db_club = Club.objects.get(id=self.id)
|
||||
if self.name != db_club.name:
|
||||
self.home.name = self.slug_name
|
||||
self.home.save()
|
||||
if self.name != db_club.name:
|
||||
self.board_group.name = f"{self.name} - Bureau"
|
||||
self.board_group.save()
|
||||
self.members_group.name = f"{self.name} - Membres"
|
||||
self.members_group.save()
|
||||
if creation:
|
||||
self.board_group = Group.objects.create(
|
||||
name=f"{self.name} - Bureau", is_manually_manageable=False
|
||||
)
|
||||
self.members_group = Group.objects.create(
|
||||
name=f"{self.name} - Membres", is_manually_manageable=False
|
||||
)
|
||||
self.make_home()
|
||||
self.make_page()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("club:club_view", kwargs={"club_id": self.id})
|
||||
|
||||
@cached_property
|
||||
def president(self):
|
||||
def president(self) -> Membership | None:
|
||||
"""Fetch the membership of the current president of this club."""
|
||||
return self.members.filter(
|
||||
role=settings.SITH_CLUB_ROLES_ID["President"], end_date=None
|
||||
).first()
|
||||
|
||||
def check_loop(self):
|
||||
"""Raise a validation error when a loop is found within the parent list"""
|
||||
"""Raise a validation error when a loop is found within the parent list."""
|
||||
objs = []
|
||||
cur = self
|
||||
while cur.parent is not None:
|
||||
@ -127,133 +146,69 @@ class Club(models.Model):
|
||||
def clean(self):
|
||||
self.check_loop()
|
||||
|
||||
def _change_unixname(self, old_name, new_name):
|
||||
c = Club.objects.filter(unix_name=new_name).first()
|
||||
if c is None:
|
||||
# Update all the groups names
|
||||
Group.objects.filter(name=old_name).update(name=new_name)
|
||||
Group.objects.filter(name=old_name + settings.SITH_BOARD_SUFFIX).update(
|
||||
name=new_name + settings.SITH_BOARD_SUFFIX
|
||||
)
|
||||
Group.objects.filter(name=old_name + settings.SITH_MEMBER_SUFFIX).update(
|
||||
name=new_name + settings.SITH_MEMBER_SUFFIX
|
||||
)
|
||||
def make_home(self) -> None:
|
||||
if self.home:
|
||||
return
|
||||
home_root = SithFile.objects.get(parent=None, name="clubs")
|
||||
root = User.objects.get(id=settings.SITH_ROOT_USER_ID)
|
||||
self.home = SithFile.objects.create(
|
||||
parent=home_root, name=self.slug_name, owner=root
|
||||
)
|
||||
|
||||
if self.home:
|
||||
self.home.name = new_name
|
||||
self.home.save()
|
||||
|
||||
else:
|
||||
raise ValidationError(_("A club with that unix_name already exists"))
|
||||
|
||||
def make_home(self):
|
||||
if not self.home:
|
||||
home_root = SithFile.objects.filter(parent=None, name="clubs").first()
|
||||
root = User.objects.filter(username="root").first()
|
||||
if home_root and root:
|
||||
home = SithFile(parent=home_root, name=self.unix_name, owner=root)
|
||||
home.save()
|
||||
self.home = home
|
||||
self.save()
|
||||
|
||||
def make_page(self):
|
||||
root = User.objects.filter(username="root").first()
|
||||
if not self.page:
|
||||
club_root = Page.objects.filter(name=settings.SITH_CLUB_ROOT_PAGE).first()
|
||||
if root and club_root:
|
||||
public = Group.objects.filter(id=settings.SITH_GROUP_PUBLIC_ID).first()
|
||||
p = Page(name=self.unix_name)
|
||||
p.parent = club_root
|
||||
p.save(force_lock=True)
|
||||
if public:
|
||||
p.view_groups.add(public)
|
||||
p.save(force_lock=True)
|
||||
if self.parent and self.parent.page:
|
||||
p.parent = self.parent.page
|
||||
self.page = p
|
||||
self.save()
|
||||
elif self.page and self.page.name != self.unix_name:
|
||||
self.page.unset_lock()
|
||||
self.page.name = self.unix_name
|
||||
self.page.save(force_lock=True)
|
||||
elif (
|
||||
self.page
|
||||
and self.parent
|
||||
and self.parent.page
|
||||
and self.page.parent != self.parent.page
|
||||
):
|
||||
self.page.unset_lock()
|
||||
def make_page(self) -> None:
|
||||
page_name = self.slug_name
|
||||
if not self.page_id:
|
||||
# Club.page is a OneToOneField, so if we are inside this condition
|
||||
# then self._meta.state.adding is True.
|
||||
club_root = Page.objects.get(name=settings.SITH_CLUB_ROOT_PAGE)
|
||||
public = Group.objects.get(id=settings.SITH_GROUP_PUBLIC_ID)
|
||||
p = Page(name=page_name, parent=club_root)
|
||||
p.save(force_lock=True)
|
||||
p.view_groups.add(public)
|
||||
if self.parent and self.parent.page_id:
|
||||
p.parent_id = self.parent.page_id
|
||||
self.page = p
|
||||
return
|
||||
self.page.unset_lock()
|
||||
if self.page.name != page_name:
|
||||
self.page.name = page_name
|
||||
elif self.parent and self.parent.page and self.page.parent != self.parent.page:
|
||||
self.page.parent = self.parent.page
|
||||
self.page.save(force_lock=True)
|
||||
self.page.save(force_lock=True)
|
||||
|
||||
@transaction.atomic()
|
||||
def save(self, *args, **kwargs):
|
||||
old = Club.objects.filter(id=self.id).first()
|
||||
creation = old is None
|
||||
if not creation and old.unix_name != self.unix_name:
|
||||
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.save()
|
||||
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()
|
||||
self.home.edit_groups.set([board])
|
||||
self.home.view_groups.set([member, subscribers])
|
||||
self.home.save()
|
||||
self.make_page()
|
||||
cache.set(f"sith_club_{self.unix_name}", self)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
super().delete(*args, **kwargs)
|
||||
def delete(self, *args, **kwargs) -> tuple[int, dict[str, int]]:
|
||||
# Invalidate the cache of this club and of its memberships
|
||||
for membership in self.members.ongoing().select_related("user"):
|
||||
cache.delete(f"membership_{self.id}_{membership.user.id}")
|
||||
cache.delete(f"sith_club_{self.unix_name}")
|
||||
self.board_group.delete()
|
||||
self.members_group.delete()
|
||||
return super().delete(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
def get_display_name(self) -> str:
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("club:club_view", kwargs={"club_id": self.id})
|
||||
|
||||
def get_display_name(self):
|
||||
return self.name
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be super edited by the given user
|
||||
"""
|
||||
def is_owned_by(self, user: User) -> bool:
|
||||
"""Method to see if that object can be super edited by the given user."""
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return user.is_board_member
|
||||
return user.is_root or user.is_board_member
|
||||
|
||||
def get_full_logo_url(self):
|
||||
return "https://%s%s" % (settings.SITH_URL, self.logo.url)
|
||||
def get_full_logo_url(self) -> str:
|
||||
return f"https://{settings.SITH_URL}{self.logo.url}"
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
def can_be_edited_by(self, user: User) -> bool:
|
||||
"""Method to see if that object can be edited by the given user."""
|
||||
return self.has_rights_in_club(user)
|
||||
|
||||
def can_be_viewed_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be seen by the given user
|
||||
"""
|
||||
sub = User.objects.filter(pk=user.pk).first()
|
||||
if sub is None:
|
||||
return False
|
||||
return sub.was_subscribed
|
||||
def can_be_viewed_by(self, user: User) -> bool:
|
||||
"""Method to see if that object can be seen by the given user."""
|
||||
return user.was_subscribed
|
||||
|
||||
def get_membership_for(self, user: User) -> Optional["Membership"]:
|
||||
"""
|
||||
Return the current membership the given user.
|
||||
The result is cached.
|
||||
def get_membership_for(self, user: User) -> Membership | None:
|
||||
"""Return the current membership the given user.
|
||||
|
||||
Note:
|
||||
The result is cached.
|
||||
"""
|
||||
if user.is_anonymous:
|
||||
return None
|
||||
@ -268,22 +223,17 @@ class Club(models.Model):
|
||||
cache.set(f"membership_{self.id}_{user.id}", membership)
|
||||
return membership
|
||||
|
||||
def has_rights_in_club(self, user):
|
||||
m = self.get_membership_for(user)
|
||||
return m is not None and m.role > settings.SITH_MAXIMUM_FREE_ROLE
|
||||
def has_rights_in_club(self, user: User) -> bool:
|
||||
return user.is_in_group(pk=self.board_group_id)
|
||||
|
||||
|
||||
class MembershipQuerySet(models.QuerySet):
|
||||
def ongoing(self) -> "MembershipQuerySet":
|
||||
"""
|
||||
Filter all memberships which are not finished yet
|
||||
"""
|
||||
# noinspection PyTypeChecker
|
||||
return self.filter(Q(end_date=None) | Q(end_date__gte=timezone.now()))
|
||||
def ongoing(self) -> Self:
|
||||
"""Filter all memberships which are not finished yet."""
|
||||
return self.filter(Q(end_date=None) | Q(end_date__gt=localdate()))
|
||||
|
||||
def board(self) -> "MembershipQuerySet":
|
||||
"""
|
||||
Filter all memberships where the user is/was in the board.
|
||||
def board(self) -> Self:
|
||||
"""Filter all memberships where the user is/was in the board.
|
||||
|
||||
Be aware that users who were in the board in the past
|
||||
are included, even if there are no more members.
|
||||
@ -291,51 +241,71 @@ class MembershipQuerySet(models.QuerySet):
|
||||
If you want to get the users who are currently in the board,
|
||||
mind combining this with the :meth:`ongoing` queryset method
|
||||
"""
|
||||
# noinspection PyTypeChecker
|
||||
return self.filter(role__gt=settings.SITH_MAXIMUM_FREE_ROLE)
|
||||
|
||||
def update(self, **kwargs):
|
||||
"""
|
||||
Work just like the default Django's update() method,
|
||||
but add a cache refresh for the elements of the queryset.
|
||||
def update(self, **kwargs) -> int:
|
||||
"""Refresh the cache and edit group ownership.
|
||||
|
||||
Be aware that this adds a db query to retrieve the updated objects
|
||||
Update the cache, when necessary, remove
|
||||
users from club groups they are no more in
|
||||
and add them in the club groups they should be in.
|
||||
|
||||
Be aware that this adds three db queries :
|
||||
one to retrieve the updated memberships,
|
||||
one to perform group removal and one to perform
|
||||
group attribution.
|
||||
"""
|
||||
nb_rows = super().update(**kwargs)
|
||||
if nb_rows > 0:
|
||||
# if at least a row was affected, refresh the cache
|
||||
for membership in self.all():
|
||||
if membership.end_date is not None:
|
||||
cache.set(
|
||||
f"membership_{membership.club_id}_{membership.user_id}",
|
||||
"not_member",
|
||||
)
|
||||
else:
|
||||
cache.set(
|
||||
f"membership_{membership.club_id}_{membership.user_id}",
|
||||
membership,
|
||||
)
|
||||
if nb_rows == 0:
|
||||
# if no row was affected, no need to refresh the cache
|
||||
return 0
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Work just like the default Django's delete() method,
|
||||
cache_memberships = {}
|
||||
memberships = set(self.select_related("club"))
|
||||
# delete all User-Group relations and recreate the necessary ones
|
||||
# It's more concise to write and more reliable
|
||||
Membership._remove_club_groups(memberships)
|
||||
Membership._add_club_groups(memberships)
|
||||
for member in memberships:
|
||||
cache_key = f"membership_{member.club_id}_{member.user_id}"
|
||||
if member.end_date is None:
|
||||
cache_memberships[cache_key] = member
|
||||
else:
|
||||
cache_memberships[cache_key] = "not_member"
|
||||
cache.set_many(cache_memberships)
|
||||
return nb_rows
|
||||
|
||||
def delete(self) -> tuple[int, dict[str, int]]:
|
||||
"""Work just like the default Django's delete() method,
|
||||
but add a cache invalidation for the elements of the queryset
|
||||
before the deletion.
|
||||
before the deletion,
|
||||
and a removal of the user from the club groups.
|
||||
|
||||
Be aware that this adds a db query to retrieve the deleted element.
|
||||
As this first query take place before the deletion operation,
|
||||
it will be performed even if the deletion fails.
|
||||
Be aware that this adds some db queries :
|
||||
|
||||
- 1 to retrieve the deleted elements in order to perform
|
||||
post-delete operations.
|
||||
As we can't know if a delete will affect rows or not,
|
||||
this query will always happen
|
||||
- 1 query to remove the users from the club groups.
|
||||
If the delete operation affected no row,
|
||||
this query won't happen.
|
||||
"""
|
||||
ids = list(self.values_list("club_id", "user_id"))
|
||||
nb_rows, _ = super().delete()
|
||||
memberships = set(self.all())
|
||||
nb_rows, rows_counts = super().delete()
|
||||
if nb_rows > 0:
|
||||
for club_id, user_id in ids:
|
||||
cache.set(f"membership_{club_id}_{user_id}", "not_member")
|
||||
Membership._remove_club_groups(memberships)
|
||||
cache.set_many(
|
||||
{
|
||||
f"membership_{m.club_id}_{m.user_id}": "not_member"
|
||||
for m in memberships
|
||||
}
|
||||
)
|
||||
return nb_rows, rows_counts
|
||||
|
||||
|
||||
class Membership(models.Model):
|
||||
"""
|
||||
The Membership class makes the connection between User and Clubs
|
||||
"""The Membership class makes the connection between User and Clubs.
|
||||
|
||||
Both Users and Clubs can have many Membership objects:
|
||||
- a user can be a member of many clubs at a time
|
||||
@ -374,54 +344,142 @@ class Membership(models.Model):
|
||||
|
||||
objects = MembershipQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.CheckConstraint(
|
||||
check=Q(end_date__gte=F("start_date")), name="end_after_start"
|
||||
),
|
||||
]
|
||||
|
||||
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 "")
|
||||
f"{self.club.name} - {self.user.username} "
|
||||
f"- {settings.SITH_CLUB_ROLES[self.role]} "
|
||||
f"- {str(_('past member')) if self.end_date is not None else ''}"
|
||||
)
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be super edited by the given user
|
||||
"""
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return user.is_board_member
|
||||
|
||||
def can_be_edited_by(self, user: User) -> bool:
|
||||
"""
|
||||
Check if that object can be edited by the given user
|
||||
"""
|
||||
if user.is_root or user.is_board_member:
|
||||
return True
|
||||
membership = self.club.get_membership_for(user)
|
||||
if membership is not None and membership.role >= self.role:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("club:club_members", kwargs={"club_id": self.club_id})
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super().save(*args, **kwargs)
|
||||
# a save may either be an update or a creation
|
||||
# and may result in either an ongoing or an ended membership.
|
||||
# It could also be a retrogradation from the board to being a simple member.
|
||||
# To avoid problems, the user is removed from the club groups beforehand ;
|
||||
# he will be added back if necessary
|
||||
self._remove_club_groups([self])
|
||||
if self.end_date is None:
|
||||
self._add_club_groups([self])
|
||||
cache.set(f"membership_{self.club_id}_{self.user_id}", self)
|
||||
else:
|
||||
cache.set(f"membership_{self.club_id}_{self.user_id}", "not_member")
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("club:club_members", kwargs={"club_id": self.club_id})
|
||||
|
||||
def is_owned_by(self, user: User) -> bool:
|
||||
"""Method to see if that object can be super edited by the given user."""
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return user.is_root or user.is_board_member
|
||||
|
||||
def can_be_edited_by(self, user: User) -> bool:
|
||||
"""Check if that object can be edited by the given user."""
|
||||
if user.is_root or user.is_board_member:
|
||||
return True
|
||||
membership = self.club.get_membership_for(user)
|
||||
return membership is not None and membership.role >= self.role
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self._remove_club_groups([self])
|
||||
super().delete(*args, **kwargs)
|
||||
cache.delete(f"membership_{self.club_id}_{self.user_id}")
|
||||
|
||||
@staticmethod
|
||||
def _remove_club_groups(
|
||||
memberships: Iterable[Membership],
|
||||
) -> tuple[int, dict[str, int]]:
|
||||
"""Remove users of those memberships from the club groups.
|
||||
|
||||
For example, if a user is in the Troll club board,
|
||||
he is in the board group and the members group of the Troll.
|
||||
After calling this function, he will be in neither.
|
||||
|
||||
Returns:
|
||||
The result of the deletion queryset.
|
||||
|
||||
Warnings:
|
||||
If this function isn't used in combination
|
||||
with an actual deletion of the memberships,
|
||||
it will result in an inconsistent state,
|
||||
where users will be in the clubs, without
|
||||
having the associated rights.
|
||||
"""
|
||||
clubs = {m.club_id for m in memberships}
|
||||
users = {m.user_id for m in memberships}
|
||||
groups = Group.objects.filter(Q(club__in=clubs) | Q(club_board__in=clubs))
|
||||
return User.groups.through.objects.filter(
|
||||
Q(group__in=groups) & Q(user__in=users)
|
||||
).delete()
|
||||
|
||||
@staticmethod
|
||||
def _add_club_groups(
|
||||
memberships: Iterable[Membership],
|
||||
) -> list[User.groups.through]:
|
||||
"""Add users of those memberships to the club groups.
|
||||
|
||||
For example, if a user just joined the Troll club board,
|
||||
he will be added in both the members group and the board group
|
||||
of the club.
|
||||
|
||||
Returns:
|
||||
The created User-Group relations.
|
||||
|
||||
Warnings:
|
||||
If this function isn't used in combination
|
||||
with an actual update/creation of the memberships,
|
||||
it will result in an inconsistent state,
|
||||
where users will have the rights associated to the
|
||||
club, without actually being part of it.
|
||||
"""
|
||||
# only active membership (i.e. `end_date=None`)
|
||||
# grant the attribution of club groups.
|
||||
memberships = [m for m in memberships if m.end_date is None]
|
||||
if not memberships:
|
||||
return []
|
||||
|
||||
if sum(1 for m in memberships if not hasattr(m, "club")) > 1:
|
||||
# if more than one membership hasn't its `club` attribute set
|
||||
# it's less expensive to reload the whole query with
|
||||
# a select_related than perform a distinct query
|
||||
# to fetch each club.
|
||||
ids = {m.id for m in memberships}
|
||||
memberships = list(
|
||||
Membership.objects.filter(id__in=ids).select_related("club")
|
||||
)
|
||||
club_groups = []
|
||||
for membership in memberships:
|
||||
club_groups.append(
|
||||
User.groups.through(
|
||||
user_id=membership.user_id,
|
||||
group_id=membership.club.members_group_id,
|
||||
)
|
||||
)
|
||||
if membership.role > settings.SITH_MAXIMUM_FREE_ROLE:
|
||||
club_groups.append(
|
||||
User.groups.through(
|
||||
user_id=membership.user_id,
|
||||
group_id=membership.club.board_group_id,
|
||||
)
|
||||
)
|
||||
return User.groups.through.objects.bulk_create(
|
||||
club_groups, ignore_conflicts=True
|
||||
)
|
||||
|
||||
|
||||
class Mailing(models.Model):
|
||||
"""
|
||||
This class correspond to a mailing list
|
||||
Remember that mailing lists should be validated by UTBM
|
||||
"""A Mailing list for a club.
|
||||
|
||||
Warning:
|
||||
Remember that mailing lists should be validated by UTBM.
|
||||
"""
|
||||
|
||||
club = models.ForeignKey(
|
||||
@ -454,6 +512,25 @@ class Mailing(models.Model):
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return "%s - %s" % (self.club, self.email_full)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.is_moderated:
|
||||
unread_notif_subquery = Notification.objects.filter(
|
||||
user=OuterRef("pk"), type="MAILING_MODERATION", viewed=False
|
||||
)
|
||||
for user in User.objects.filter(
|
||||
~Exists(unread_notif_subquery),
|
||||
groups__id__in=[settings.SITH_GROUP_COM_ADMIN_ID],
|
||||
):
|
||||
Notification(
|
||||
user=user,
|
||||
url=reverse("com:mailing_admin"),
|
||||
type="MAILING_MODERATION",
|
||||
).save(*args, **kwargs)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def clean(self):
|
||||
if Mailing.objects.filter(email=self.email).exists():
|
||||
raise ValidationError(_("This mailing list already exists."))
|
||||
@ -461,7 +538,7 @@ class Mailing(models.Model):
|
||||
self.is_moderated = True
|
||||
else:
|
||||
self.moderator = None
|
||||
super(Mailing, self).clean()
|
||||
super().clean()
|
||||
|
||||
@property
|
||||
def email_full(self):
|
||||
@ -483,39 +560,15 @@ class Mailing(models.Model):
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.subscriptions.all().delete()
|
||||
super(Mailing, self).delete()
|
||||
super().delete()
|
||||
|
||||
def fetch_format(self):
|
||||
resp = self.email + ": "
|
||||
for sub in self.subscriptions.all():
|
||||
resp += sub.fetch_format()
|
||||
return resp
|
||||
|
||||
def save(self):
|
||||
if not self.is_moderated:
|
||||
for user in (
|
||||
RealGroup.objects.filter(id=settings.SITH_GROUP_COM_ADMIN_ID)
|
||||
.first()
|
||||
.users.all()
|
||||
):
|
||||
if not user.notifications.filter(
|
||||
type="MAILING_MODERATION", viewed=False
|
||||
).exists():
|
||||
Notification(
|
||||
user=user,
|
||||
url=reverse("com:mailing_admin"),
|
||||
type="MAILING_MODERATION",
|
||||
).save()
|
||||
super(Mailing, self).save()
|
||||
|
||||
def __str__(self):
|
||||
return "%s - %s" % (self.club, self.email_full)
|
||||
destination = "".join(s.fetch_format() for s in self.subscriptions.all())
|
||||
return f"{self.email}: {destination}"
|
||||
|
||||
|
||||
class MailingSubscription(models.Model):
|
||||
"""
|
||||
This class makes the link between user and mailing list
|
||||
"""
|
||||
"""Link between user and mailing list."""
|
||||
|
||||
mailing = models.ForeignKey(
|
||||
Mailing,
|
||||
@ -538,6 +591,9 @@ class MailingSubscription(models.Model):
|
||||
class Meta:
|
||||
unique_together = (("user", "email", "mailing"),)
|
||||
|
||||
def __str__(self):
|
||||
return "(%s) - %s : %s" % (self.mailing, self.get_username, self.email)
|
||||
|
||||
def clean(self):
|
||||
if not self.user and not self.email:
|
||||
raise ValidationError(_("At least user or email is required"))
|
||||
@ -552,7 +608,7 @@ class MailingSubscription(models.Model):
|
||||
)
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
super(MailingSubscription, self).clean()
|
||||
super().clean()
|
||||
|
||||
def is_owned_by(self, user):
|
||||
if user.is_anonymous:
|
||||
@ -580,6 +636,3 @@ class MailingSubscription(models.Model):
|
||||
|
||||
def fetch_format(self):
|
||||
return self.get_email + " "
|
||||
|
||||
def __str__(self):
|
||||
return "(%s) - %s : %s" % (self.mailing, self.get_username, self.email)
|
||||
|
40
club/schemas.py
Normal file
40
club/schemas.py
Normal file
@ -0,0 +1,40 @@
|
||||
from ninja import ModelSchema
|
||||
|
||||
from club.models import Club, Membership
|
||||
from core.schemas import SimpleUserSchema
|
||||
|
||||
|
||||
class SimpleClubSchema(ModelSchema):
|
||||
class Meta:
|
||||
model = Club
|
||||
fields = ["id", "name"]
|
||||
|
||||
|
||||
class ClubProfileSchema(ModelSchema):
|
||||
"""The infos needed to display a simple club profile."""
|
||||
|
||||
class Meta:
|
||||
model = Club
|
||||
fields = ["id", "name", "logo"]
|
||||
|
||||
url: str
|
||||
|
||||
@staticmethod
|
||||
def resolve_url(obj: Club) -> str:
|
||||
return obj.get_absolute_url()
|
||||
|
||||
|
||||
class ClubMemberSchema(ModelSchema):
|
||||
class Meta:
|
||||
model = Membership
|
||||
fields = ["start_date", "end_date", "role", "description"]
|
||||
|
||||
user: SimpleUserSchema
|
||||
|
||||
|
||||
class ClubSchema(ModelSchema):
|
||||
class Meta:
|
||||
model = Club
|
||||
fields = ["id", "name", "logo", "is_active", "short_description", "address"]
|
||||
|
||||
members: list[ClubMemberSchema]
|
30
club/static/bundled/club/components/ajax-select-index.ts
Normal file
30
club/static/bundled/club/components/ajax-select-index.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { AjaxSelect } from "#core:core/components/ajax-select-base";
|
||||
import { registerComponent } from "#core:utils/web-components";
|
||||
import type { TomOption } from "tom-select/dist/types/types";
|
||||
import type { escape_html } from "tom-select/dist/types/utils";
|
||||
import { type ClubSchema, clubSearchClub } from "#openapi";
|
||||
|
||||
@registerComponent("club-ajax-select")
|
||||
export class ClubAjaxSelect extends AjaxSelect {
|
||||
protected valueField = "id";
|
||||
protected labelField = "name";
|
||||
protected searchField = ["code", "name"];
|
||||
|
||||
protected async search(query: string): Promise<TomOption[]> {
|
||||
const resp = await clubSearchClub({ query: { search: query } });
|
||||
if (resp.data) {
|
||||
return resp.data.results;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
protected renderOption(item: ClubSchema, sanitize: typeof escape_html) {
|
||||
return `<div class="select-item">
|
||||
<span class="select-item-text">${sanitize(item.name)}</span>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
protected renderItem(item: ClubSchema, sanitize: typeof escape_html) {
|
||||
return `<span>${sanitize(item.name)}</span>`;
|
||||
}
|
||||
}
|
@ -2,16 +2,16 @@
|
||||
{% from 'core/macros.jinja' import user_profile_link %}
|
||||
|
||||
{% block content %}
|
||||
<div id="club_detail">
|
||||
{% if club.logo %}
|
||||
<div class="club_logo"><img src="{{ club.logo.url }}" alt="{{ club.unix_name }}"></div>
|
||||
{% endif %}
|
||||
{% if page_revision %}
|
||||
{{ page_revision|markdown }}
|
||||
{% else %}
|
||||
<h3>{% trans %}Club{% endtrans %}</h3>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div id="club_detail">
|
||||
{% if club.logo %}
|
||||
<div class="club_logo"><img src="{{ club.logo.url }}" alt="{{ club.name }}"></div>
|
||||
{% endif %}
|
||||
{% if page_revision %}
|
||||
{{ page_revision|markdown }}
|
||||
{% else %}
|
||||
<h3>{% trans %}Club{% endtrans %}</h3>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -1,48 +1,48 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Club list{% endtrans %}
|
||||
{% trans %}Club list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% macro display_club(club) -%}
|
||||
|
||||
{% if club.is_active or user.is_root %}
|
||||
|
||||
<li><a href="{{ url('club:club_view', club_id=club.id) }}">{{ club.name }}</a>
|
||||
|
||||
{% if not club.is_active %}
|
||||
({% trans %}inactive{% endtrans %})
|
||||
{% endif %}
|
||||
{% if club.is_active or user.is_root %}
|
||||
|
||||
{% if club.president %} - <a href="{{ url('core:user_profile', user_id=club.president.user.id) }}">{{ club.president.user }}</a>{% endif %}
|
||||
{% if club.short_description %}<p>{{ club.short_description|markdown }}</p>{% endif %}
|
||||
|
||||
{% endif %}
|
||||
<li><a href="{{ url('club:club_view', club_id=club.id) }}">{{ club.name }}</a>
|
||||
|
||||
{%- if club.children.all()|length != 0 %}
|
||||
<ul>
|
||||
{%- for c in club.children.order_by('name') %}
|
||||
{{ display_club(c) }}
|
||||
{%- endfor %}
|
||||
</ul>
|
||||
{%- endif -%}
|
||||
</li>
|
||||
{% if not club.is_active %}
|
||||
({% trans %}inactive{% endtrans %})
|
||||
{% endif %}
|
||||
|
||||
{% if club.president %} - <a href="{{ url('core:user_profile', user_id=club.president.user.id) }}">{{ club.president.user }}</a>{% endif %}
|
||||
{% if club.short_description %}<p>{{ club.short_description|markdown }}</p>{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{%- if club.children.all()|length != 0 %}
|
||||
<ul>
|
||||
{%- for c in club.children.order_by('name') %}
|
||||
{{ display_club(c) }}
|
||||
{%- endfor %}
|
||||
</ul>
|
||||
{%- endif -%}
|
||||
</li>
|
||||
{%- endmacro %}
|
||||
|
||||
{% block content %}
|
||||
{% if user.is_root %}
|
||||
{% if user.is_root %}
|
||||
<p><a href="{{ url('club:club_new') }}">{% trans %}New club{% endtrans %}</a></p>
|
||||
{% endif %}
|
||||
{% if club_list %}
|
||||
{% endif %}
|
||||
{% if club_list %}
|
||||
<h3>{% trans %}Club list{% endtrans %}</h3>
|
||||
<ul>
|
||||
{%- for c in club_list.all().order_by('name') if c.parent is none %}
|
||||
{%- for c in club_list.all().order_by('name') if c.parent is none %}
|
||||
{{ display_club(c) }}
|
||||
{%- endfor %}
|
||||
{%- endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% else %}
|
||||
{% trans %}There is no club in this website.{% endtrans %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -2,81 +2,81 @@
|
||||
{% from 'core/macros.jinja' import user_profile_link, select_all_checkbox %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{% trans %}Club members{% endtrans %}</h2>
|
||||
{% if members %}
|
||||
<h2>{% trans %}Club members{% endtrans %}</h2>
|
||||
{% if members %}
|
||||
<form action="{{ url('club:club_members', club_id=club.id) }}" id="users_old" method="post">
|
||||
{% csrf_token %}
|
||||
{% set users_old = dict(form.users_old | groupby("choice_label")) %}
|
||||
{% if users_old %}
|
||||
{{ select_all_checkbox("users_old") }}
|
||||
<p></p>
|
||||
{% endif %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}User{% endtrans %}</td>
|
||||
<td>{% trans %}Role{% endtrans %}</td>
|
||||
<td>{% trans %}Description{% endtrans %}</td>
|
||||
<td>{% trans %}Since{% endtrans %}</td>
|
||||
{% if users_old %}
|
||||
<td>{% trans %}Mark as old{% endtrans %}</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for m in members %}
|
||||
<tr>
|
||||
<td>{{ user_profile_link(m.user) }}</td>
|
||||
<td>{{ settings.SITH_CLUB_ROLES[m.role] }}</td>
|
||||
<td>{{ m.description }}</td>
|
||||
<td>{{ m.start_date }}</td>
|
||||
{% if users_old %}
|
||||
<td>
|
||||
{% set user_old = users_old[m.user.get_display_name()] %}
|
||||
{% if user_old %}
|
||||
{{ user_old[0].tag() }}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{{ form.users_old.errors }}
|
||||
{% if users_old %}
|
||||
<p></p>
|
||||
<input type="submit" name="submit" value="{% trans %}Mark as old{% endtrans %}">
|
||||
{% endif %}
|
||||
{% csrf_token %}
|
||||
{% set users_old = dict(form.users_old | groupby("choice_label")) %}
|
||||
{% if users_old %}
|
||||
{{ select_all_checkbox("users_old") }}
|
||||
<p></p>
|
||||
{% endif %}
|
||||
<table id="club_members_table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}User{% endtrans %}</td>
|
||||
<td>{% trans %}Role{% endtrans %}</td>
|
||||
<td>{% trans %}Description{% endtrans %}</td>
|
||||
<td>{% trans %}Since{% endtrans %}</td>
|
||||
{% if users_old %}
|
||||
<td>{% trans %}Mark as old{% endtrans %}</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for m in members %}
|
||||
<tr>
|
||||
<td>{{ user_profile_link(m.user) }}</td>
|
||||
<td>{{ settings.SITH_CLUB_ROLES[m.role] }}</td>
|
||||
<td>{{ m.description }}</td>
|
||||
<td>{{ m.start_date }}</td>
|
||||
{% if users_old %}
|
||||
<td>
|
||||
{% set user_old = users_old[m.user.get_display_name()] %}
|
||||
{% if user_old %}
|
||||
{{ user_old[0].tag() }}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{{ form.users_old.errors }}
|
||||
{% if users_old %}
|
||||
<p></p>
|
||||
<input type="submit" name="submit" value="{% trans %}Mark as old{% endtrans %}">
|
||||
{% endif %}
|
||||
</form>
|
||||
{% else %}
|
||||
{% else %}
|
||||
<p>{% trans %}There are no members in this club.{% endtrans %}</p>
|
||||
{% endif %}
|
||||
<form action="{{ url('club:club_members', club_id=club.id) }}" id="add_users" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.non_field_errors() }}
|
||||
<p>
|
||||
{{ form.users.errors }}
|
||||
<label for="{{ form.users.id_for_label }}">{{ form.users.label }} :</label>
|
||||
{{ form.users }}
|
||||
<span class="helptext">{{ form.users.help_text }}</span>
|
||||
</p>
|
||||
<p>
|
||||
{{ form.role.errors }}
|
||||
<label for="{{ form.role.id_for_label }}">{{ form.role.label }} :</label>
|
||||
{{ form.role }}
|
||||
</p>
|
||||
{% if form.start_date %}
|
||||
<p>
|
||||
{{ form.start_date.errors }}
|
||||
<label for="{{ form.start_date.id_for_label }}">{{ form.start_date.label }} :</label>
|
||||
{{ form.start_date }}
|
||||
</p>
|
||||
{% endif %}
|
||||
<form action="{{ url('club:club_members', club_id=club.id) }}" id="add_users" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.non_field_errors() }}
|
||||
<p>
|
||||
{{ form.users.errors }}
|
||||
<label for="{{ form.users.id_for_label }}">{{ form.users.label }} :</label>
|
||||
{{ form.users }}
|
||||
<span class="helptext">{{ form.users.help_text }}</span>
|
||||
</p>
|
||||
<p>
|
||||
{{ form.role.errors }}
|
||||
<label for="{{ form.role.id_for_label }}">{{ form.role.label }} :</label>
|
||||
{{ form.role }}
|
||||
</p>
|
||||
{% if form.start_date %}
|
||||
<p>
|
||||
{{ form.start_date.errors }}
|
||||
<label for="{{ form.start_date.id_for_label }}">{{ form.start_date.label }} :</label>
|
||||
{{ form.start_date }}
|
||||
</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
{{ form.description.errors }}
|
||||
<label for="{{ form.description.id_for_label }}">{{ form.description.label }} :</label>
|
||||
{{ form.description }}
|
||||
</p>
|
||||
<p><input type="submit" value="{% trans %}Add{% endtrans %}" /></p>
|
||||
</form>
|
||||
<p>
|
||||
{{ form.description.errors }}
|
||||
<label for="{{ form.description.id_for_label }}">{{ form.description.label }} :</label>
|
||||
{{ form.description }}
|
||||
</p>
|
||||
<p><input type="submit" value="{% trans %}Add{% endtrans %}" /></p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
@ -2,27 +2,27 @@
|
||||
{% from 'core/macros.jinja' import user_profile_link %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{% trans %}Club old members{% endtrans %}</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<td>{% trans %}User{% endtrans %}</td>
|
||||
<td>{% trans %}Role{% endtrans %}</td>
|
||||
<td>{% trans %}Description{% endtrans %}</td>
|
||||
<td>{% trans %}From{% endtrans %}</td>
|
||||
<td>{% trans %}To{% endtrans %}</td>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for m in club.members.exclude(end_date=None).order_by('-role', 'description', '-end_date').all() %}
|
||||
<tr>
|
||||
<td>{{ user_profile_link(m.user) }}</td>
|
||||
<td>{{ settings.SITH_CLUB_ROLES[m.role] }}</td>
|
||||
<td>{{ m.description }}</td>
|
||||
<td>{{ m.start_date }}</td>
|
||||
<td>{{ m.end_date }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>{% trans %}Club old members{% endtrans %}</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<td>{% trans %}User{% endtrans %}</td>
|
||||
<td>{% trans %}Role{% endtrans %}</td>
|
||||
<td>{% trans %}Description{% endtrans %}</td>
|
||||
<td>{% trans %}From{% endtrans %}</td>
|
||||
<td>{% trans %}To{% endtrans %}</td>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for m in club.members.exclude(end_date=None).order_by('-role', 'description', '-end_date').all() %}
|
||||
<tr>
|
||||
<td>{{ user_profile_link(m.user) }}</td>
|
||||
<td>{{ settings.SITH_CLUB_ROLES[m.role] }}</td>
|
||||
<td>{{ m.description }}</td>
|
||||
<td>{{ m.start_date }}</td>
|
||||
<td>{{ m.end_date }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user