Merge branch 'beta' into traduction
3
.gitignore
vendored
@ -47,6 +47,3 @@ backups/
|
|||||||
env/
|
env/
|
||||||
venv/
|
venv/
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
|
|
||||||
# Ignore migrations during first phase dev
|
|
||||||
migrations/
|
|
||||||
|
@ -2,6 +2,10 @@ stages:
|
|||||||
- test
|
- test
|
||||||
- quality-assurance
|
- quality-assurance
|
||||||
|
|
||||||
|
# Also fetch submodules
|
||||||
|
variables:
|
||||||
|
GIT_SUBMODULE_STRATEGY: recursive
|
||||||
|
|
||||||
# Debian Buster
|
# Debian Buster
|
||||||
py37-django22:
|
py37-django22:
|
||||||
stage: test
|
stage: test
|
||||||
@ -14,8 +18,7 @@ py37-django22:
|
|||||||
python3-django-extensions python3-django-filters python3-django-polymorphic
|
python3-django-extensions python3-django-filters python3-django-polymorphic
|
||||||
python3-djangorestframework python3-django-cas-server python3-psycopg2 python3-pil
|
python3-djangorestframework python3-django-cas-server python3-psycopg2 python3-pil
|
||||||
python3-babel python3-lockfile python3-pip python3-phonenumbers
|
python3-babel python3-lockfile python3-pip python3-phonenumbers
|
||||||
python3-bs4 python3-setuptools tox
|
python3-bs4 python3-setuptools tox texlive-xetex
|
||||||
texlive-latex-base texlive-lang-french lmodern texlive-fonts-recommended
|
|
||||||
script: tox -e py37-django22
|
script: tox -e py37-django22
|
||||||
|
|
||||||
# Ubuntu 20.04
|
# Ubuntu 20.04
|
||||||
@ -32,23 +35,14 @@ py38-django22:
|
|||||||
python3-django-extensions python3-django-filters python3-django-polymorphic
|
python3-django-extensions python3-django-filters python3-django-polymorphic
|
||||||
python3-djangorestframework python3-django-cas-server python3-psycopg2 python3-pil
|
python3-djangorestframework python3-django-cas-server python3-psycopg2 python3-pil
|
||||||
python3-babel python3-lockfile python3-pip python3-phonenumbers
|
python3-babel python3-lockfile python3-pip python3-phonenumbers
|
||||||
python3-bs4 python3-setuptools tox
|
python3-bs4 python3-setuptools tox texlive-xetex
|
||||||
texlive-latex-base texlive-lang-french lmodern texlive-fonts-recommended
|
|
||||||
script: tox -e py38-django22
|
script: tox -e py38-django22
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
stage: quality-assurance
|
stage: quality-assurance
|
||||||
image: debian:buster-backports
|
image: debian:buster-backports
|
||||||
before_script:
|
before_script:
|
||||||
- >
|
- apt-get update && apt-get install -y tox
|
||||||
apt-get update &&
|
|
||||||
apt-get install --no-install-recommends -t buster-backports -y
|
|
||||||
python3-django python3-django-crispy-forms
|
|
||||||
python3-django-extensions python3-django-filters python3-django-polymorphic
|
|
||||||
python3-djangorestframework python3-django-cas-server python3-psycopg2 python3-pil
|
|
||||||
python3-babel python3-lockfile python3-pip python3-phonenumbers
|
|
||||||
python3-bs4 python3-setuptools tox
|
|
||||||
texlive-latex-extra texlive-lang-french lmodern texlive-fonts-recommended
|
|
||||||
script: tox -e linters
|
script: tox -e linters
|
||||||
|
|
||||||
# Be nice to new contributors, but please use `tox`
|
# Be nice to new contributors, but please use `tox`
|
||||||
|
@ -12,8 +12,7 @@ RUN apt-get update && \
|
|||||||
python3-babel python3-lockfile python3-pip python3-phonenumbers ipython3 \
|
python3-babel python3-lockfile python3-pip python3-phonenumbers ipython3 \
|
||||||
python3-bs4 python3-setuptools \
|
python3-bs4 python3-setuptools \
|
||||||
uwsgi uwsgi-plugin-python3 \
|
uwsgi uwsgi-plugin-python3 \
|
||||||
texlive-latex-base texlive-lang-french lmodern texlive-fonts-recommended \
|
texlive-xetex gettext libjs-bootstrap4 fonts-font-awesome && \
|
||||||
gettext libjs-bootstrap4 fonts-font-awesome && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Instal PyPI requirements
|
# Instal PyPI requirements
|
||||||
|
674
LICENSE
@ -1,674 +0,0 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
14
README.md
@ -23,14 +23,13 @@ Bien que cela permette de créer une instance sur toutes les distributions,
|
|||||||
$ sudo apt update
|
$ sudo apt update
|
||||||
$ sudo apt install --no-install-recommends -y \
|
$ sudo apt install --no-install-recommends -y \
|
||||||
ipython3 python3-setuptools python3-venv python3-dev \
|
ipython3 python3-setuptools python3-venv python3-dev \
|
||||||
texlive-latex-base texlive-lang-french lmodern texlive-fonts-recommended \
|
texlive-xetex gettext libjs-bootstrap4 fonts-font-awesome git
|
||||||
gettext libjs-bootstrap4 fonts-font-awesome git
|
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Clonage du dépot** là où vous voulez :
|
2. **Clonage du dépot** là où vous voulez :
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ git clone git@gitlab.crans.org:bde/nk20.git && cd nk20
|
$ git clone git@gitlab.crans.org:bde/nk20.git --recursive && cd nk20
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Création d'un environment de travail Python décorrélé du système.**
|
3. **Création d'un environment de travail Python décorrélé du système.**
|
||||||
@ -98,8 +97,7 @@ Sinon vous pouvez suivre les étapes décrites ci-dessous.
|
|||||||
python3-babel python3-lockfile python3-pip python3-phonenumbers ipython3 \
|
python3-babel python3-lockfile python3-pip python3-phonenumbers ipython3 \
|
||||||
python3-bs4 python3-setuptools \
|
python3-bs4 python3-setuptools \
|
||||||
uwsgi uwsgi-plugin-python3 \
|
uwsgi uwsgi-plugin-python3 \
|
||||||
texlive-latex-base texlive-lang-french lmodern texlive-fonts-recommended \
|
texlive-xetex gettext libjs-bootstrap4 fonts-font-awesome \
|
||||||
gettext libjs-bootstrap4 fonts-font-awesome \
|
|
||||||
nginx python3-venv git acl
|
nginx python3-venv git acl
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -109,7 +107,7 @@ Sinon vous pouvez suivre les étapes décrites ci-dessous.
|
|||||||
$ sudo mkdir -p /var/www/note_kfet && cd /var/www/note_kfet
|
$ sudo mkdir -p /var/www/note_kfet && cd /var/www/note_kfet
|
||||||
$ sudo chown www-data:www-data .
|
$ sudo chown www-data:www-data .
|
||||||
$ sudo chmod g+rwx .
|
$ sudo chmod g+rwx .
|
||||||
$ sudo -u www-data git clone https://gitlab.crans.org/bde/nk20.git
|
$ sudo -u www-data git clone https://gitlab.crans.org/bde/nk20.git --recursive
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Création d'un environment de travail Python décorrélé du système.**
|
3. **Création d'un environment de travail Python décorrélé du système.**
|
||||||
@ -195,7 +193,6 @@ Sinon vous pouvez suivre les étapes décrites ci-dessous.
|
|||||||
DJANGO_SECRET_KEY=CHANGE_ME
|
DJANGO_SECRET_KEY=CHANGE_ME
|
||||||
DJANGO_SETTINGS_MODULE="note_kfet.settings
|
DJANGO_SETTINGS_MODULE="note_kfet.settings
|
||||||
NOTE_URL=localhost # URL où accéder à la note
|
NOTE_URL=localhost # URL où accéder à la note
|
||||||
DOMAIN=localhost # note.example.com
|
|
||||||
CONTACT_EMAIL=tresorerie.bde@localhost
|
CONTACT_EMAIL=tresorerie.bde@localhost
|
||||||
# Le reste n'est utile qu'en production, pour configurer l'envoi des mails
|
# Le reste n'est utile qu'en production, pour configurer l'envoi des mails
|
||||||
NOTE_MAIL=notekfet@localhost
|
NOTE_MAIL=notekfet@localhost
|
||||||
@ -211,7 +208,6 @@ Sinon vous pouvez suivre les étapes décrites ci-dessous.
|
|||||||
|
|
||||||
$ source /env/bin/activate
|
$ source /env/bin/activate
|
||||||
(env)$ ./manage.py check # pas de bêtise qui traine
|
(env)$ ./manage.py check # pas de bêtise qui traine
|
||||||
(env)$ ./manage.py makemigrations
|
|
||||||
(env)$ ./manage.py migrate
|
(env)$ ./manage.py migrate
|
||||||
|
|
||||||
7. *Enjoy \o/*
|
7. *Enjoy \o/*
|
||||||
@ -223,7 +219,7 @@ Il est possible de travailler sur une instance Docker.
|
|||||||
Pour construire l'image Docker `nk20`,
|
Pour construire l'image Docker `nk20`,
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone https://gitlab.crans.org/bde/nk20/ && cd nk20
|
git clone https://gitlab.crans.org/bde/nk20/ --recursive && cd nk20
|
||||||
docker build . -t nk20
|
docker build . -t nk20
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#!/usr/bin/env ansible-playbook
|
#!/usr/bin/env ansible-playbook
|
||||||
---
|
---
|
||||||
|
|
||||||
- hosts: bde-nk20-beta.adh.crans.org
|
- hosts: all
|
||||||
vars_prompt:
|
vars_prompt:
|
||||||
- name: DB_PASSWORD
|
- name: DB_PASSWORD
|
||||||
prompt: "Password of the database"
|
prompt: "Password of the database (leave it blank to skip database init)"
|
||||||
private: yes
|
private: yes
|
||||||
vars:
|
vars:
|
||||||
mirror: deb.debian.org
|
mirror: deb.debian.org
|
||||||
@ -12,7 +12,7 @@
|
|||||||
- 1-apt-basic
|
- 1-apt-basic
|
||||||
- 2-nk20
|
- 2-nk20
|
||||||
- 3-pip
|
- 3-pip
|
||||||
- 4-nginx
|
- 4-certbot
|
||||||
- 5-certbot
|
- 5-nginx
|
||||||
- 6-psql
|
- 6-psql
|
||||||
- 7-postinstall
|
- 7-postinstall
|
||||||
|
5
ansible/host_vars/bde-nk20-beta.adh.crans.org.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
note:
|
||||||
|
server_name: note-beta.crans.org
|
||||||
|
git_branch: beta
|
||||||
|
cron_enabled: false
|
5
ansible/host_vars/bde-note.adh.crans.org.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
note:
|
||||||
|
server_name: note.crans.org
|
||||||
|
git_branch: master
|
||||||
|
cron_enabled: true
|
5
ansible/host_vars/bde3-virt.adh.crans.org.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
note:
|
||||||
|
server_name: note-dev.crans.org
|
||||||
|
git_branch: beta
|
||||||
|
cron_enabled: false
|
@ -1,5 +1,9 @@
|
|||||||
[server]
|
[dev]
|
||||||
|
bde3-virt.adh.crans.org
|
||||||
bde-nk20-beta.adh.crans.org
|
bde-nk20-beta.adh.crans.org
|
||||||
|
|
||||||
|
[prod]
|
||||||
|
bde-note.adh.crans.org
|
||||||
|
|
||||||
[all:vars]
|
[all:vars]
|
||||||
ansible_python_interpreter=/usr/bin/python3
|
ansible_python_interpreter=/usr/bin/python3
|
||||||
|
@ -38,9 +38,7 @@
|
|||||||
- python3-venv
|
- python3-venv
|
||||||
|
|
||||||
# LaTeX (PDF generation)
|
# LaTeX (PDF generation)
|
||||||
- texlive-fonts-recommended
|
- texlive-xetex
|
||||||
- texlive-lang-french
|
|
||||||
- texlive-latex-base
|
|
||||||
|
|
||||||
# WSGI server
|
# WSGI server
|
||||||
- uwsgi
|
- uwsgi
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
git:
|
git:
|
||||||
repo: https://gitlab.crans.org/bde/nk20.git
|
repo: https://gitlab.crans.org/bde/nk20.git
|
||||||
dest: /var/www/note_kfet
|
dest: /var/www/note_kfet
|
||||||
version: beta
|
version: "{{ note.git_branch }}"
|
||||||
force: true
|
force: true
|
||||||
|
|
||||||
- name: Use default env vars (should be updated!)
|
- name: Use default env vars (should be updated!)
|
||||||
@ -30,6 +30,7 @@
|
|||||||
group: www-data
|
group: www-data
|
||||||
|
|
||||||
- name: Setup cron jobs
|
- name: Setup cron jobs
|
||||||
|
when: "note.cron_enabled"
|
||||||
template:
|
template:
|
||||||
src: note.cron.j2
|
src: note.cron.j2
|
||||||
dest: /etc/cron.d/note
|
dest: /etc/cron.d/note
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
# {{ ansible_managed }}
|
|
||||||
# Les cronjobs dont a besoin la Note Kfet
|
|
||||||
|
|
||||||
# m h dom mon dow user command
|
|
||||||
# Envoyer les mails en attente
|
|
||||||
* * * * * root cd /var/www/note_kfet && env/bin/python manage.py send_mail >> /var/www/note_kfet/cron_mail.log
|
|
||||||
* * * * * root cd /var/www/note_kfet && env/bin/python manage.py retry_deferred >> /var/www/note_kfet/cron_mail_deferred.log
|
|
||||||
00 0 * * * root cd /var/www/note_kfet && env/bin/python manage.py purge_mail_log 7 >> /var/www/note_kfet/cron_mail_purge.log
|
|
||||||
# Faire une sauvegarde de la base de données
|
|
||||||
00 2 * * * root cd /var/www/note_kfet && apps/scripts/shell/backup_db
|
|
||||||
# Vérifier la cohérence de la base et mailer en cas de problème
|
|
||||||
00 4 * * * root cd /var/www/note_kfet && env/bin/python manage.py check_consistency --sum-all --check-all --mail
|
|
||||||
# Mettre à jour le wiki (modification sans (dé)validation, activités passées)
|
|
||||||
#30 5 * * * root cd /var/www/note_kfet && env/bin/python manage.py refresh_activities --raw --comment refresh
|
|
||||||
# Spammer les gens en négatif
|
|
||||||
00 5 * * 2 root cd /var/www/note_kfet && env/bin/python manage.py send_mail_to_negative_balances --spam
|
|
||||||
# Envoyer le rapport mensuel aux trésoriers et respos info
|
|
||||||
00 8 6 * * root cd /var/www/note_kfet && env/bin/python manage.py send_mail_to_negative_balances --report
|
|
||||||
# Envoyer les rapports aux gens
|
|
||||||
55 6 * * * root cd /var/www/note_kfet && env/bin/python manage.py send_reports
|
|
||||||
# Envoyer les rapports aux gens
|
|
||||||
00 9 * * * root cd /var/www/note_kfet && env/bin/python manage.py refresh_highlighted_buttons
|
|
1
ansible/roles/2-nk20/templates/note.cron.j2
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../../../note.cron
|
@ -9,7 +9,7 @@ server {
|
|||||||
listen [::]:80 default_server;
|
listen [::]:80 default_server;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
return 301 https://nk20-beta.crans.org$request_uri;
|
return 301 https://{{ note.server_name }}$request_uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,11 +19,11 @@ server {
|
|||||||
listen [::]:443 ssl default_server;
|
listen [::]:443 ssl default_server;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
return 301 https://nk20-beta.crans.org$request_uri;
|
return 301 https://{{ note.server_name }}$request_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssl_certificate /etc/letsencrypt/live/nk20-beta.crans.org/fullchain.pem;
|
ssl_certificate /etc/letsencrypt/live/{{ note.server_name }}/fullchain.pem;
|
||||||
ssl_certificate_key /etc/letsencrypt/live/nk20-beta.crans.org/privkey.pem;
|
ssl_certificate_key /etc/letsencrypt/live/{{ note.server_name }}/privkey.pem;
|
||||||
include /etc/letsencrypt/options-ssl-nginx.conf;
|
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ server {
|
|||||||
|
|
||||||
# the port your site will be served on
|
# the port your site will be served on
|
||||||
# the domain name it will serve for
|
# the domain name it will serve for
|
||||||
server_name nk20-beta.crans.org; # substitute your machine's IP address or FQDN
|
server_name {{ note.server_name }}; # substitute your machine's IP address or FQDN
|
||||||
charset utf-8;
|
charset utf-8;
|
||||||
|
|
||||||
# max upload size
|
# max upload size
|
||||||
@ -56,8 +56,8 @@ server {
|
|||||||
include /etc/nginx/uwsgi_params;
|
include /etc/nginx/uwsgi_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssl_certificate /etc/letsencrypt/live/nk20-beta.crans.org/fullchain.pem;
|
ssl_certificate /etc/letsencrypt/live/{{ note.server_name }}/fullchain.pem;
|
||||||
ssl_certificate_key /etc/letsencrypt/live/nk20-beta.crans.org/privkey.pem;
|
ssl_certificate_key /etc/letsencrypt/live/{{ note.server_name }}/privkey.pem;
|
||||||
include /etc/letsencrypt/options-ssl-nginx.conf;
|
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||||
}
|
}
|
@ -10,17 +10,15 @@
|
|||||||
retries: 3
|
retries: 3
|
||||||
until: pkg_result is succeeded
|
until: pkg_result is succeeded
|
||||||
|
|
||||||
- name: Install Psycopg2
|
|
||||||
pip:
|
|
||||||
name: psycopg2-binary
|
|
||||||
|
|
||||||
- name: Create role note
|
- name: Create role note
|
||||||
|
when: "DB_PASSWORD|bool" # If the password is not defined, skip the installation
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: note
|
name: note
|
||||||
password: "{{ DB_PASSWORD }}"
|
password: "{{ DB_PASSWORD }}"
|
||||||
become_user: postgres
|
become_user: postgres
|
||||||
|
|
||||||
- name: Create NK20 database
|
- name: Create NK20 database
|
||||||
|
when: "DB_PASSWORD|bool"
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
name: note_db
|
name: note_db
|
||||||
owner: note
|
owner: note
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
---
|
---
|
||||||
- name: Make Django migrations
|
|
||||||
command: /var/www/note_kfet/env/bin/python manage.py makemigrations
|
|
||||||
args:
|
|
||||||
chdir: /var/www/note_kfet
|
|
||||||
become_user: www-data
|
|
||||||
|
|
||||||
- name: Migrate Django database
|
- name: Migrate Django database
|
||||||
command: /var/www/note_kfet/env/bin/python manage.py migrate
|
command: /var/www/note_kfet/env/bin/python manage.py migrate
|
||||||
args:
|
args:
|
||||||
@ -22,3 +16,9 @@
|
|||||||
args:
|
args:
|
||||||
chdir: /var/www/note_kfet
|
chdir: /var/www/note_kfet
|
||||||
become_user: postgres
|
become_user: postgres
|
||||||
|
|
||||||
|
- name: Collect static files
|
||||||
|
command: /var/www/note_kfet/env/bin/python manage.py collectstatic --noinput
|
||||||
|
args:
|
||||||
|
chdir: /var/www/note_kfet
|
||||||
|
become_user: www-data
|
||||||
|
69
apps/activity/migrations/0001_initial.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-04 21:41
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Activity',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255, verbose_name='name')),
|
||||||
|
('description', models.TextField(verbose_name='description')),
|
||||||
|
('location', models.CharField(blank=True, default='', help_text='Place where the activity is organized, eg. Kfet.', max_length=255, verbose_name='location')),
|
||||||
|
('date_start', models.DateTimeField(verbose_name='start date')),
|
||||||
|
('date_end', models.DateTimeField(verbose_name='end date')),
|
||||||
|
('valid', models.BooleanField(default=False, verbose_name='valid')),
|
||||||
|
('open', models.BooleanField(default=False, verbose_name='open')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'activity',
|
||||||
|
'verbose_name_plural': 'activities',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ActivityType',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255, verbose_name='name')),
|
||||||
|
('manage_entries', models.BooleanField(default=False, help_text='Enable the support of entries for this activity.', verbose_name='manage entries')),
|
||||||
|
('can_invite', models.BooleanField(default=False, verbose_name='can invite')),
|
||||||
|
('guest_entry_fee', models.PositiveIntegerField(default=0, verbose_name='guest entry fee')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'activity type',
|
||||||
|
'verbose_name_plural': 'activity types',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Entry',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('time', models.DateTimeField(default=django.utils.timezone.now, verbose_name='entry time')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'entry',
|
||||||
|
'verbose_name_plural': 'entries',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Guest',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('last_name', models.CharField(max_length=255, verbose_name='last name')),
|
||||||
|
('first_name', models.CharField(max_length=255, verbose_name='first name')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'guest',
|
||||||
|
'verbose_name_plural': 'guests',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
89
apps/activity/migrations/0002_auto_20200904_2341.py
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-04 21:41
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('activity', '0001_initial'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('member', '0001_initial'),
|
||||||
|
('note', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='GuestTransaction',
|
||||||
|
fields=[
|
||||||
|
('transaction_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='note.Transaction')),
|
||||||
|
('entry', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, to='activity.Entry')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
'base_manager_name': 'objects',
|
||||||
|
},
|
||||||
|
bases=('note.transaction',),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='guest',
|
||||||
|
name='activity',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='activity.Activity'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='guest',
|
||||||
|
name='inviter',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='guests', to='note.NoteUser', verbose_name='inviter'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='entry',
|
||||||
|
name='activity',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='entries', to='activity.Activity', verbose_name='activity'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='entry',
|
||||||
|
name='guest',
|
||||||
|
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.PROTECT, to='activity.Guest'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='entry',
|
||||||
|
name='note',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='note.NoteUser', verbose_name='note'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='activity',
|
||||||
|
name='activity_type',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='activity.ActivityType', verbose_name='type'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='activity',
|
||||||
|
name='attendees_club',
|
||||||
|
field=models.ForeignKey(help_text='Club that is authorized to join the activity. Mostly the Kfet club.', on_delete=django.db.models.deletion.PROTECT, related_name='+', to='member.Club', verbose_name='attendees club'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='activity',
|
||||||
|
name='creater',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='user'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='activity',
|
||||||
|
name='organizer',
|
||||||
|
field=models.ForeignKey(help_text='Club that organizes the activity. The entry fees will go to this club.', on_delete=django.db.models.deletion.PROTECT, related_name='+', to='member.Club', verbose_name='organizer'),
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='guest',
|
||||||
|
unique_together={('activity', 'last_name', 'first_name')},
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='entry',
|
||||||
|
unique_together={('activity', 'note', 'guest')},
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='activity',
|
||||||
|
unique_together={('name', 'date_start', 'date_end')},
|
||||||
|
),
|
||||||
|
]
|
@ -1,6 +1,7 @@
|
|||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import os
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
@ -130,12 +131,16 @@ class Activity(models.Model):
|
|||||||
raise ValidationError(_("The end date must be after the start date."))
|
raise ValidationError(_("The end date must be after the start date."))
|
||||||
|
|
||||||
ret = super().save(*args, **kwargs)
|
ret = super().save(*args, **kwargs)
|
||||||
if settings.DEBUG and self.pk and "scripts" in settings.INSTALLED_APPS:
|
if not settings.DEBUG and self.pk and "scripts" in settings.INSTALLED_APPS:
|
||||||
def refresh_activities():
|
def refresh_activities():
|
||||||
from scripts.management.commands.refresh_activities import Command as RefreshActivitiesCommand
|
from scripts.management.commands.refresh_activities import Command as RefreshActivitiesCommand
|
||||||
RefreshActivitiesCommand.refresh_human_readable_wiki_page("Modification de l'activité " + self.name)
|
# Consider that we can update the wiki iff the WIKI_PASSWORD env var is not empty
|
||||||
RefreshActivitiesCommand.refresh_raw_wiki_page("Modification de l'activité " + self.name)
|
RefreshActivitiesCommand.refresh_human_readable_wiki_page("Modification de l'activité " + self.name,
|
||||||
Thread(daemon=True, target=refresh_activities).start()
|
False, os.getenv("WIKI_PASSWORD"))
|
||||||
|
RefreshActivitiesCommand.refresh_raw_wiki_page("Modification de l'activité " + self.name,
|
||||||
|
False, os.getenv("WIKI_PASSWORD"))
|
||||||
|
Thread(daemon=True, target=refresh_activities).start()\
|
||||||
|
if settings.DATABASES["default"]["ENGINE"] == 'django.db.backends.postgresql' else refresh_activities()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@ -183,6 +188,12 @@ class Entry(models.Model):
|
|||||||
verbose_name = _("entry")
|
verbose_name = _("entry")
|
||||||
verbose_name_plural = _("entries")
|
verbose_name_plural = _("entries")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return _("Entry for {guest}, invited by {note} to the activity {activity}").format(
|
||||||
|
guest=str(self.guest), note=str(self.note), activity=str(self.activity)) if self.guest \
|
||||||
|
else _("Entry for {note} to the activity {activity}").format(
|
||||||
|
guest=str(self.guest), note=str(self.note), activity=str(self.activity))
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
|
||||||
qs = Entry.objects.filter(~Q(pk=self.pk), activity=self.activity, note=self.note, guest=self.guest)
|
qs = Entry.objects.filter(~Q(pk=self.pk), activity=self.activity, note=self.note, guest=self.guest)
|
||||||
|
@ -9,7 +9,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
<h1 class="text-white">{{ title }}</h1>
|
<h1 class="text-white">{{ title }}</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xl-12">
|
<div class="col-xl-12">
|
||||||
<div class="btn-group btn-group-toggle bg-light" style="width: 100%" data-toggle="buttons">
|
<div class="btn-group btn-group-toggle bg-light" style="width: 100%">
|
||||||
<a href="{% url "note:transfer" %}#transfer" class="btn btn-sm btn-outline-primary">
|
<a href="{% url "note:transfer" %}#transfer" class="btn btn-sm btn-outline-primary">
|
||||||
{% trans "Transfer" %}
|
{% trans "Transfer" %}
|
||||||
</a>
|
</a>
|
||||||
|
175
apps/activity/tests/test_activities.py
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils import timezone
|
||||||
|
from activity.models import Activity, ActivityType, Guest, Entry
|
||||||
|
from member.models import Club
|
||||||
|
|
||||||
|
|
||||||
|
class TestActivities(TestCase):
|
||||||
|
"""
|
||||||
|
Test activities
|
||||||
|
"""
|
||||||
|
fixtures = ('initial',)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.user = User.objects.create_superuser(
|
||||||
|
username="admintoto",
|
||||||
|
password="tototototo",
|
||||||
|
email="toto@example.com"
|
||||||
|
)
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
|
||||||
|
sess = self.client.session
|
||||||
|
sess["permission_mask"] = 42
|
||||||
|
sess.save()
|
||||||
|
|
||||||
|
self.activity = Activity.objects.create(
|
||||||
|
name="Activity",
|
||||||
|
description="This is a test activity\non two very very long lines\nbecause this is very important.",
|
||||||
|
location="Earth",
|
||||||
|
activity_type=ActivityType.objects.get(name="Pot"),
|
||||||
|
creater=self.user,
|
||||||
|
organizer=Club.objects.get(name="Kfet"),
|
||||||
|
attendees_club=Club.objects.get(name="Kfet"),
|
||||||
|
date_start=timezone.now(),
|
||||||
|
date_end=timezone.now() + timedelta(days=2),
|
||||||
|
valid=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.guest = Guest.objects.create(
|
||||||
|
activity=self.activity,
|
||||||
|
inviter=self.user.note,
|
||||||
|
last_name="GUEST",
|
||||||
|
first_name="Guest",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_activity_list(self):
|
||||||
|
"""
|
||||||
|
Display the list of all activities
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("activity:activity_list"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_activity_create(self):
|
||||||
|
"""
|
||||||
|
Create a new activity
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("activity:activity_create"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.post(reverse("activity:activity_create"), data=dict(
|
||||||
|
name="Activity created",
|
||||||
|
description="This activity was successfully created.",
|
||||||
|
location="Earth",
|
||||||
|
activity_type=ActivityType.objects.get(name="Soirée de club").id,
|
||||||
|
creater=self.user.id,
|
||||||
|
organizer=Club.objects.get(name="Kfet").id,
|
||||||
|
attendees_club=Club.objects.get(name="Kfet").id,
|
||||||
|
date_start="{:%Y-%m-%d %H:%M}".format(timezone.now()),
|
||||||
|
date_end="{:%Y-%m-%d %H:%M}".format(timezone.now() + timedelta(days=2)),
|
||||||
|
valid=True,
|
||||||
|
))
|
||||||
|
self.assertTrue(Activity.objects.filter(name="Activity created").exists())
|
||||||
|
activity = Activity.objects.get(name="Activity created")
|
||||||
|
self.assertRedirects(response, reverse("activity:activity_detail", args=(activity.pk,)), 302, 200)
|
||||||
|
|
||||||
|
def test_activity_detail(self):
|
||||||
|
"""
|
||||||
|
Display the detail of an activity
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("activity:activity_detail", args=(self.activity.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_activity_update(self):
|
||||||
|
"""
|
||||||
|
Update an activity
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("activity:activity_update", args=(self.activity.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.post(reverse("activity:activity_update", args=(self.activity.pk,)), data=dict(
|
||||||
|
name=str(self.activity) + " updated",
|
||||||
|
description="This activity was successfully updated.",
|
||||||
|
location="Earth",
|
||||||
|
activity_type=ActivityType.objects.get(name="Autre").id,
|
||||||
|
creater=self.user.id,
|
||||||
|
organizer=Club.objects.get(name="Kfet").id,
|
||||||
|
attendees_club=Club.objects.get(name="Kfet").id,
|
||||||
|
date_start="{:%Y-%m-%d %H:%M}".format(timezone.now()),
|
||||||
|
date_end="{:%Y-%m-%d %H:%M}".format(timezone.now() + timedelta(days=2)),
|
||||||
|
valid=True,
|
||||||
|
))
|
||||||
|
self.assertTrue(Activity.objects.filter(name="Activity updated").exists())
|
||||||
|
self.assertRedirects(response, reverse("activity:activity_detail", args=(self.activity.pk,)), 302, 200)
|
||||||
|
|
||||||
|
def test_activity_entry(self):
|
||||||
|
"""
|
||||||
|
Create some entries
|
||||||
|
"""
|
||||||
|
self.activity.open = True
|
||||||
|
self.activity.save()
|
||||||
|
|
||||||
|
response = self.client.get(reverse("activity:activity_entry", args=(self.activity.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
response = self.client.get(reverse("activity:activity_entry", args=(self.activity.pk,)) + "?search=guest")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
response = self.client.get(reverse("activity:activity_entry", args=(self.activity.pk,)) + "?search=admin")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# User entry
|
||||||
|
response = self.client.post("/api/activity/entry/", data=dict(
|
||||||
|
activity=self.activity.id,
|
||||||
|
note=self.user.note.id,
|
||||||
|
guest="",
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 201) # 201 = Created
|
||||||
|
self.assertTrue(Entry.objects.filter(note=self.user.note, guest=None, activity=self.activity).exists())
|
||||||
|
|
||||||
|
# Guest entry
|
||||||
|
response = self.client.post("/api/activity/entry/", data=dict(
|
||||||
|
activity=self.activity.id,
|
||||||
|
note=self.user.note.id,
|
||||||
|
guest=self.guest.id,
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 201) # 201 = Created
|
||||||
|
self.assertTrue(Entry.objects.filter(note=self.user.note, guest=self.guest.id, activity=self.activity).exists())
|
||||||
|
|
||||||
|
def test_activity_invite(self):
|
||||||
|
"""
|
||||||
|
Try to invite people to an activity
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("activity:activity_invite", args=(self.activity.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# The activity is started, can't invite
|
||||||
|
response = self.client.post(reverse("activity:activity_invite", args=(self.activity.pk,)), data=dict(
|
||||||
|
activity=self.activity.id,
|
||||||
|
inviter=self.user.note.id,
|
||||||
|
last_name="GUEST2",
|
||||||
|
first_name="Guest",
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
self.activity.date_start += timedelta(days=1)
|
||||||
|
self.activity.save()
|
||||||
|
|
||||||
|
response = self.client.post(reverse("activity:activity_invite", args=(self.activity.pk,)), data=dict(
|
||||||
|
activity=self.activity.id,
|
||||||
|
inviter=self.user.note.id,
|
||||||
|
last_name="GUEST2",
|
||||||
|
first_name="Guest",
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, reverse("activity:activity_detail", args=(self.activity.pk,)), 302, 200)
|
||||||
|
|
||||||
|
def test_activity_ics(self):
|
||||||
|
"""
|
||||||
|
Render the ICS calendar
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("activity:calendar_ics"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
@ -14,4 +14,5 @@ urlpatterns = [
|
|||||||
path('<int:pk>/entry/', views.ActivityEntryView.as_view(), name='activity_entry'),
|
path('<int:pk>/entry/', views.ActivityEntryView.as_view(), name='activity_entry'),
|
||||||
path('<int:pk>/update/', views.ActivityUpdateView.as_view(), name='activity_update'),
|
path('<int:pk>/update/', views.ActivityUpdateView.as_view(), name='activity_update'),
|
||||||
path('new/', views.ActivityCreateView.as_view(), name='activity_create'),
|
path('new/', views.ActivityCreateView.as_view(), name='activity_create'),
|
||||||
|
path('calendar.ics', views.CalendarView.as_view(), name='calendar_ics'),
|
||||||
]
|
]
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from hashlib import md5
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.db.models import F, Q
|
from django.db.models import F, Q
|
||||||
|
from django.http import HttpResponse
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.views import View
|
||||||
from django.views.generic import DetailView, TemplateView, UpdateView
|
from django.views.generic import DetailView, TemplateView, UpdateView
|
||||||
from django_tables2.views import SingleTableView
|
from django_tables2.views import SingleTableView
|
||||||
from note.models import Alias, NoteSpecial, NoteUser
|
from note.models import Alias, NoteSpecial, NoteUser
|
||||||
@ -190,10 +194,10 @@ class ActivityEntryView(LoginRequiredMixin, TemplateView):
|
|||||||
if pattern[0] != "^":
|
if pattern[0] != "^":
|
||||||
pattern = "^" + pattern
|
pattern = "^" + pattern
|
||||||
guest_qs = guest_qs.filter(
|
guest_qs = guest_qs.filter(
|
||||||
Q(first_name__regex=pattern)
|
Q(first_name__iregex=pattern)
|
||||||
| Q(last_name__regex=pattern)
|
| Q(last_name__iregex=pattern)
|
||||||
| Q(inviter__alias__name__regex=pattern)
|
| Q(inviter__alias__name__iregex=pattern)
|
||||||
| Q(inviter__alias__normalized_name__regex=Alias.normalize(pattern))
|
| Q(inviter__alias__normalized_name__iregex=Alias.normalize(pattern))
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
guest_qs = guest_qs.none()
|
guest_qs = guest_qs.none()
|
||||||
@ -226,21 +230,19 @@ class ActivityEntryView(LoginRequiredMixin, TemplateView):
|
|||||||
if "search" in self.request.GET and self.request.GET["search"]:
|
if "search" in self.request.GET and self.request.GET["search"]:
|
||||||
pattern = self.request.GET["search"]
|
pattern = self.request.GET["search"]
|
||||||
note_qs = note_qs.filter(
|
note_qs = note_qs.filter(
|
||||||
Q(note__noteuser__user__first_name__regex=pattern)
|
Q(note__noteuser__user__first_name__iregex=pattern)
|
||||||
| Q(note__noteuser__user__last_name__regex=pattern)
|
| Q(note__noteuser__user__last_name__iregex=pattern)
|
||||||
| Q(name__regex=pattern)
|
| Q(name__iregex=pattern)
|
||||||
| Q(normalized_name__regex=Alias.normalize(pattern))
|
| Q(normalized_name__iregex=Alias.normalize(pattern))
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
note_qs = note_qs.none()
|
note_qs = note_qs.none()
|
||||||
|
|
||||||
if settings.DATABASES[note_qs.db]["ENGINE"] == 'django.db.backends.postgresql':
|
|
||||||
note_qs = note_qs.distinct('note__pk')[:20]
|
|
||||||
else:
|
|
||||||
# SQLite doesn't support distinct fields. For compatibility reason (in dev mode), the note list will only
|
# SQLite doesn't support distinct fields. For compatibility reason (in dev mode), the note list will only
|
||||||
# have distinct aliases rather than distinct notes with a SQLite DB, but it can fill the result page.
|
# have distinct aliases rather than distinct notes with a SQLite DB, but it can fill the result page.
|
||||||
# In production mode, please use PostgreSQL.
|
# In production mode, please use PostgreSQL.
|
||||||
note_qs = note_qs.distinct()[:20]
|
note_qs = note_qs.distinct('note__pk')[:20]\
|
||||||
|
if settings.DATABASES[note_qs.db]["ENGINE"] == 'django.db.backends.postgresql' else note_qs.distinct()[:20]
|
||||||
return note_qs
|
return note_qs
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
@ -281,3 +283,60 @@ class ActivityEntryView(LoginRequiredMixin, TemplateView):
|
|||||||
Entry(activity=a, note=self.request.user.note,))]
|
Entry(activity=a, note=self.request.user.note,))]
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class CalendarView(View):
|
||||||
|
"""
|
||||||
|
Render an ICS calendar with all valid activities.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def multilines(self, string, maxlength, offset=0):
|
||||||
|
newstring = string[:maxlength - offset]
|
||||||
|
string = string[maxlength - offset:]
|
||||||
|
while string:
|
||||||
|
newstring += "\r\n "
|
||||||
|
newstring += string[:maxlength - 1]
|
||||||
|
string = string[maxlength - 1:]
|
||||||
|
return newstring
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
ics = """BEGIN:VCALENDAR
|
||||||
|
VERSION: 2.0
|
||||||
|
PRODID:Note Kfet 2020
|
||||||
|
X-WR-CALNAME:Kfet Calendar
|
||||||
|
NAME:Kfet Calendar
|
||||||
|
CALSCALE:GREGORIAN
|
||||||
|
BEGIN:VTIMEZONE
|
||||||
|
TZID:Europe/Berlin
|
||||||
|
X-LIC-LOCATION:Europe/Berlin
|
||||||
|
BEGIN:DAYLIGHT
|
||||||
|
TZOFFSETFROM:+0100
|
||||||
|
TZOFFSETTO:+0200
|
||||||
|
TZNAME:CEST
|
||||||
|
DTSTART:19700329T020000
|
||||||
|
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
|
||||||
|
END:DAYLIGHT
|
||||||
|
BEGIN:STANDARD
|
||||||
|
TZOFFSETFROM:+0200
|
||||||
|
TZOFFSETTO:+0100
|
||||||
|
TZNAME:CET
|
||||||
|
DTSTART:19701025T030000
|
||||||
|
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
|
||||||
|
END:STANDARD
|
||||||
|
END:VTIMEZONE
|
||||||
|
"""
|
||||||
|
for activity in Activity.objects.filter(valid=True).order_by("-date_start").all():
|
||||||
|
ics += f"""BEGIN:VEVENT
|
||||||
|
DTSTAMP:{"{:%Y%m%dT%H%M%S}".format(activity.date_start)}Z
|
||||||
|
UID:{md5((activity.name + "$" + str(activity.id) + str(activity.date_start)).encode("UTF-8")).hexdigest()}
|
||||||
|
SUMMARY;CHARSET=UTF-8:{self.multilines(activity.name, 75, 22)}
|
||||||
|
DTSTART;TZID=Europe/Berlin:{"{:%Y%m%dT%H%M%S}".format(activity.date_start)}
|
||||||
|
DTEND;TZID=Europe/Berlin:{"{:%Y%m%dT%H%M%S}".format(activity.date_end)}
|
||||||
|
LOCATION:{self.multilines(activity.location, 75, 9) if activity.location else "Kfet"}
|
||||||
|
DESCRIPTION;CHARSET=UTF-8:""" + self.multilines(activity.description.replace("\n", "\\n"), 75, 26) + """
|
||||||
|
-- {activity.organizer.name}
|
||||||
|
END:VEVENT
|
||||||
|
"""
|
||||||
|
ics += "END:VCALENDAR"
|
||||||
|
ics = ics.replace("\r", "").replace("\n", "\r\n")
|
||||||
|
return HttpResponse(ics, content_type="text/calendar; charset=UTF-8")
|
||||||
|
@ -6,6 +6,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from rest_framework.serializers import ModelSerializer
|
from rest_framework.serializers import ModelSerializer
|
||||||
|
|
||||||
|
|
||||||
class UserSerializer(ModelSerializer):
|
class UserSerializer(ModelSerializer):
|
||||||
"""
|
"""
|
||||||
REST API Serializer for Users.
|
REST API Serializer for Users.
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
from .viewsets import ContentTypeViewSet, UserViewSet
|
from .viewsets import ContentTypeViewSet, UserViewSet
|
||||||
|
|
||||||
# Routers provide an easy way of automatically determining the URL conf.
|
# Routers provide an easy way of automatically determining the URL conf.
|
||||||
|
@ -6,11 +6,8 @@ from django_filters.rest_framework import DjangoFilterBackend
|
|||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from rest_framework.viewsets import ReadOnlyModelViewSet, ModelViewSet
|
from rest_framework.viewsets import ReadOnlyModelViewSet, ModelViewSet
|
||||||
|
|
||||||
from permission.backends import PermissionBackend
|
from permission.backends import PermissionBackend
|
||||||
|
|
||||||
from note_kfet.middlewares import get_current_session
|
from note_kfet.middlewares import get_current_session
|
||||||
from note.models import Alias
|
from note.models import Alias
|
||||||
|
|
||||||
@ -29,7 +26,7 @@ class ReadProtectedModelViewSet(ModelViewSet):
|
|||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
get_current_session().setdefault("permission_mask", 42)
|
get_current_session().setdefault("permission_mask", 42)
|
||||||
return self.model.objects.filter(PermissionBackend.filter_queryset(user, self.model, "view")).distinct()
|
return self.queryset.filter(PermissionBackend.filter_queryset(user, self.model, "view")).distinct()
|
||||||
|
|
||||||
|
|
||||||
class ReadOnlyProtectedModelViewSet(ReadOnlyModelViewSet):
|
class ReadOnlyProtectedModelViewSet(ReadOnlyModelViewSet):
|
||||||
@ -44,8 +41,7 @@ class ReadOnlyProtectedModelViewSet(ReadOnlyModelViewSet):
|
|||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
get_current_session().setdefault("permission_mask", 42)
|
get_current_session().setdefault("permission_mask", 42)
|
||||||
return self.model.objects.filter(PermissionBackend.filter_queryset(user, self.model, "view")).distinct()
|
return self.queryset.filter(PermissionBackend.filter_queryset(user, self.model, "view")).distinct()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UserViewSet(ReadProtectedModelViewSet):
|
class UserViewSet(ReadProtectedModelViewSet):
|
||||||
@ -68,28 +64,36 @@ class UserViewSet(ReadProtectedModelViewSet):
|
|||||||
if "search" in self.request.GET:
|
if "search" in self.request.GET:
|
||||||
pattern = self.request.GET["search"]
|
pattern = self.request.GET["search"]
|
||||||
|
|
||||||
# We match first a user by its username, then if an alias is matched without normalization
|
# Filter with different rules
|
||||||
# And finally if the normalized pattern matches a normalized alias.
|
# We use union-all to keep each filter rule sorted in result
|
||||||
queryset = queryset.filter(
|
queryset = queryset.filter(
|
||||||
username__iregex="^" + pattern).union(
|
# Match without normalization
|
||||||
queryset.filter(
|
note__alias__name__iregex="^" + pattern
|
||||||
Q(note__alias__name__iregex="^" + pattern)
|
).union(
|
||||||
& ~Q(username__iregex="^" + pattern)), all=True).union(
|
|
||||||
queryset.filter(
|
queryset.filter(
|
||||||
|
# Match with normalization
|
||||||
Q(note__alias__normalized_name__iregex="^" + Alias.normalize(pattern))
|
Q(note__alias__normalized_name__iregex="^" + Alias.normalize(pattern))
|
||||||
& ~Q(note__alias__name__iregex="^" + pattern)
|
& ~Q(note__alias__name__iregex="^" + pattern)
|
||||||
& ~Q(username__iregex="^" + pattern)), all=True).union(
|
),
|
||||||
|
all=True,
|
||||||
|
).union(
|
||||||
queryset.filter(
|
queryset.filter(
|
||||||
|
# Match on lower pattern
|
||||||
Q(note__alias__normalized_name__iregex="^" + pattern.lower())
|
Q(note__alias__normalized_name__iregex="^" + pattern.lower())
|
||||||
& ~Q(note__alias__normalized_name__iregex="^" + Alias.normalize(pattern))
|
& ~Q(note__alias__normalized_name__iregex="^" + Alias.normalize(pattern))
|
||||||
& ~Q(note__alias__name__iregex="^" + pattern)
|
& ~Q(note__alias__name__iregex="^" + pattern)
|
||||||
& ~Q(username__iregex="^" + pattern)), all=True).union(
|
),
|
||||||
|
all=True,
|
||||||
|
).union(
|
||||||
queryset.filter(
|
queryset.filter(
|
||||||
|
# Match on firstname or lastname
|
||||||
(Q(last_name__iregex="^" + pattern) | Q(first_name__iregex="^" + pattern))
|
(Q(last_name__iregex="^" + pattern) | Q(first_name__iregex="^" + pattern))
|
||||||
& ~Q(note__alias__normalized_name__iregex="^" + pattern.lower())
|
& ~Q(note__alias__normalized_name__iregex="^" + pattern.lower())
|
||||||
& ~Q(note__alias__normalized_name__iregex="^" + Alias.normalize(pattern))
|
& ~Q(note__alias__normalized_name__iregex="^" + Alias.normalize(pattern))
|
||||||
& ~Q(note__alias__name__iregex="^" + pattern)
|
& ~Q(note__alias__name__iregex="^" + pattern)
|
||||||
& ~Q(username__iregex="^" + pattern)), all=True)
|
),
|
||||||
|
all=True,
|
||||||
|
)
|
||||||
|
|
||||||
queryset = queryset if settings.DATABASES[queryset.db]["ENGINE"] == 'django.db.backends.postgresql' \
|
queryset = queryset if settings.DATABASES[queryset.db]["ENGINE"] == 'django.db.backends.postgresql' \
|
||||||
else queryset.order_by("username")
|
else queryset.order_by("username")
|
||||||
|
37
apps/logs/migrations/0001_initial.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-04 21:41
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('contenttypes', '0002_remove_content_type_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Changelog',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('ip', models.GenericIPAddressField(blank=True, null=True, verbose_name='IP Address')),
|
||||||
|
('instance_pk', models.CharField(max_length=255, verbose_name='identifier')),
|
||||||
|
('previous', models.TextField(null=True, verbose_name='previous data')),
|
||||||
|
('data', models.TextField(null=True, verbose_name='new data')),
|
||||||
|
('action', models.CharField(choices=[('create', 'create'), ('edit', 'edit'), ('delete', 'delete')], default='edit', max_length=16, verbose_name='action')),
|
||||||
|
('timestamp', models.DateTimeField(default=django.utils.timezone.now, verbose_name='timestamp')),
|
||||||
|
('model', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='contenttypes.ContentType', verbose_name='model')),
|
||||||
|
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='user')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'changelog',
|
||||||
|
'verbose_name_plural': 'changelogs',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
17
apps/logs/migrations/0002_replace_null_by_blank.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('logs', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunSQL(
|
||||||
|
"UPDATE logs_changelog SET previous = '' WHERE previous IS NULL;"
|
||||||
|
),
|
||||||
|
migrations.RunSQL(
|
||||||
|
"UPDATE logs_changelog SET data = '' WHERE data IS NULL;"
|
||||||
|
),
|
||||||
|
]
|
23
apps/logs/migrations/0003_remove_null_tag_on_charfields.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-06 19:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('logs', '0002_replace_null_by_blank'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='changelog',
|
||||||
|
name='data',
|
||||||
|
field=models.TextField(blank=True, default='', verbose_name='new data'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='changelog',
|
||||||
|
name='previous',
|
||||||
|
field=models.TextField(blank=True, default='', verbose_name='previous data'),
|
||||||
|
),
|
||||||
|
]
|
@ -44,12 +44,14 @@ class Changelog(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
previous = models.TextField(
|
previous = models.TextField(
|
||||||
null=True,
|
blank=True,
|
||||||
|
default="",
|
||||||
verbose_name=_('previous data'),
|
verbose_name=_('previous data'),
|
||||||
)
|
)
|
||||||
|
|
||||||
data = models.TextField(
|
data = models.TextField(
|
||||||
null=True,
|
blank=True,
|
||||||
|
default="",
|
||||||
verbose_name=_('new data'),
|
verbose_name=_('new data'),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,3 +82,7 @@ class Changelog(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("changelog")
|
verbose_name = _("changelog")
|
||||||
verbose_name_plural = _("changelogs")
|
verbose_name_plural = _("changelogs")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return _("Changelog of type \"{action}\" for model {model} at {timestamp}").format(
|
||||||
|
action=self.get_action_display(), model=str(self.model), timestamp=str(self.timestamp))
|
||||||
|
@ -50,10 +50,7 @@ def save_object(sender, instance, **kwargs):
|
|||||||
in order to store each modification made
|
in order to store each modification made
|
||||||
"""
|
"""
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
if instance._meta.label_lower in EXCLUDED:
|
if instance._meta.label_lower in EXCLUDED or hasattr(instance, "_no_signal"):
|
||||||
return
|
|
||||||
|
|
||||||
if hasattr(instance, "_no_log"):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
@ -102,7 +99,7 @@ def save_object(sender, instance, **kwargs):
|
|||||||
model = instance.__class__
|
model = instance.__class__
|
||||||
fields = changed_fields
|
fields = changed_fields
|
||||||
|
|
||||||
previous_json = JSONRenderer().render(CustomSerializer(previous).data).decode("UTF-8") if previous else None
|
previous_json = JSONRenderer().render(CustomSerializer(previous).data).decode("UTF-8") if previous else ""
|
||||||
instance_json = JSONRenderer().render(CustomSerializer(instance).data).decode("UTF-8")
|
instance_json = JSONRenderer().render(CustomSerializer(instance).data).decode("UTF-8")
|
||||||
|
|
||||||
Changelog.objects.create(user=user,
|
Changelog.objects.create(user=user,
|
||||||
@ -120,10 +117,7 @@ def delete_object(sender, instance, **kwargs):
|
|||||||
Each time a model is deleted, an entry in the table `Changelog` is added in the database
|
Each time a model is deleted, an entry in the table `Changelog` is added in the database
|
||||||
"""
|
"""
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
if instance._meta.label_lower in EXCLUDED:
|
if instance._meta.label_lower in EXCLUDED or hasattr(instance, "_no_signal"):
|
||||||
return
|
|
||||||
|
|
||||||
if hasattr(instance, "_no_log"):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Si un utilisateur est connecté, on récupère l'utilisateur courant ainsi que son adresse IP
|
# Si un utilisateur est connecté, on récupère l'utilisateur courant ainsi que son adresse IP
|
||||||
@ -155,6 +149,6 @@ def delete_object(sender, instance, **kwargs):
|
|||||||
model=ContentType.objects.get_for_model(instance),
|
model=ContentType.objects.get_for_model(instance),
|
||||||
instance_pk=instance.pk,
|
instance_pk=instance.pk,
|
||||||
previous=instance_json,
|
previous=instance_json,
|
||||||
data=None,
|
data="",
|
||||||
action="delete"
|
action="delete"
|
||||||
).save()
|
).save()
|
||||||
|
@ -31,9 +31,7 @@ class CustomUserAdmin(UserAdmin):
|
|||||||
"""
|
"""
|
||||||
When creating a new user don't show profile one the first step
|
When creating a new user don't show profile one the first step
|
||||||
"""
|
"""
|
||||||
if not obj:
|
return super().get_inline_instances(request, obj) if obj else []
|
||||||
return list()
|
|
||||||
return super().get_inline_instances(request, obj)
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Club, site=admin_site)
|
@admin.register(Club, site=admin_site)
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"model": "member.club",
|
|
||||||
"pk": 1,
|
|
||||||
"fields": {
|
|
||||||
"name": "BDE",
|
|
||||||
"email": "tresorerie.bde@example.com",
|
|
||||||
"require_memberships": true,
|
|
||||||
"membership_fee_paid": 500,
|
|
||||||
"membership_fee_unpaid": 500,
|
|
||||||
"membership_duration": 396,
|
|
||||||
"membership_start": "2019-08-31",
|
|
||||||
"membership_end": "2020-09-30"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "member.club",
|
|
||||||
"pk": 2,
|
|
||||||
"fields": {
|
|
||||||
"name": "Kfet",
|
|
||||||
"email": "tresorerie.bde@example.com",
|
|
||||||
"parent_club": 1,
|
|
||||||
"require_memberships": true,
|
|
||||||
"membership_fee_paid": 3500,
|
|
||||||
"membership_fee_unpaid": 3500,
|
|
||||||
"membership_duration": 396,
|
|
||||||
"membership_start": "2019-08-31",
|
|
||||||
"membership_end": "2020-09-30"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
@ -1,7 +1,11 @@
|
|||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import io
|
||||||
|
|
||||||
|
from PIL import Image, ImageSequence
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth.forms import AuthenticationForm
|
from django.contrib.auth.forms import AuthenticationForm
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.forms import CheckboxSelectMultiple
|
from django.forms import CheckboxSelectMultiple
|
||||||
@ -16,7 +20,7 @@ from .models import Profile, Club, Membership
|
|||||||
|
|
||||||
class CustomAuthenticationForm(AuthenticationForm):
|
class CustomAuthenticationForm(AuthenticationForm):
|
||||||
permission_mask = forms.ModelChoiceField(
|
permission_mask = forms.ModelChoiceField(
|
||||||
label="Masque de permissions",
|
label=_("Permission mask"),
|
||||||
queryset=PermissionMask.objects.order_by("rank"),
|
queryset=PermissionMask.objects.order_by("rank"),
|
||||||
empty_label=None,
|
empty_label=None,
|
||||||
)
|
)
|
||||||
@ -77,6 +81,54 @@ class ImageForm(forms.Form):
|
|||||||
width = forms.FloatField(widget=forms.HiddenInput())
|
width = forms.FloatField(widget=forms.HiddenInput())
|
||||||
height = forms.FloatField(widget=forms.HiddenInput())
|
height = forms.FloatField(widget=forms.HiddenInput())
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
"""
|
||||||
|
Load image and crop
|
||||||
|
|
||||||
|
In the future, when Pillow will support APNG we will be able to
|
||||||
|
simplify this code to save only PNG/APNG.
|
||||||
|
"""
|
||||||
|
cleaned_data = super().clean()
|
||||||
|
|
||||||
|
# Image size is limited by Django DATA_UPLOAD_MAX_MEMORY_SIZE
|
||||||
|
image = cleaned_data.get('image')
|
||||||
|
if image:
|
||||||
|
# Let Pillow detect and load image
|
||||||
|
# If it is an animation, then there will be multiple frames
|
||||||
|
try:
|
||||||
|
im = Image.open(image)
|
||||||
|
except OSError:
|
||||||
|
# Rare case in which Django consider the upload file as an image
|
||||||
|
# but Pil is unable to load it
|
||||||
|
raise forms.ValidationError(_('This image cannot be loaded.'))
|
||||||
|
|
||||||
|
# Crop each frame
|
||||||
|
x = cleaned_data.get('x', 0)
|
||||||
|
y = cleaned_data.get('y', 0)
|
||||||
|
w = cleaned_data.get('width', 200)
|
||||||
|
h = cleaned_data.get('height', 200)
|
||||||
|
frames = []
|
||||||
|
for frame in ImageSequence.Iterator(im):
|
||||||
|
frame = frame.crop((x, y, x + w, y + h))
|
||||||
|
frame = frame.resize(
|
||||||
|
(settings.PIC_WIDTH, settings.PIC_RATIO * settings.PIC_WIDTH),
|
||||||
|
Image.ANTIALIAS,
|
||||||
|
)
|
||||||
|
frames.append(frame)
|
||||||
|
|
||||||
|
# Save
|
||||||
|
om = frames.pop(0) # Get first frame
|
||||||
|
om.info = im.info # Copy metadata
|
||||||
|
image.file = io.BytesIO()
|
||||||
|
if len(frames) > 1:
|
||||||
|
# Save as GIF
|
||||||
|
om.save(image.file, "GIF", save_all=True, append_images=list(frames), loop=0)
|
||||||
|
else:
|
||||||
|
# Save as PNG
|
||||||
|
om.save(image.file, "PNG")
|
||||||
|
|
||||||
|
return cleaned_data
|
||||||
|
|
||||||
|
|
||||||
class ClubForm(forms.ModelForm):
|
class ClubForm(forms.ModelForm):
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
76
apps/member/migrations/0001_initial.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-04 21:41
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.utils.timezone
|
||||||
|
import phonenumber_field.modelfields
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Club',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255, unique=True, verbose_name='name')),
|
||||||
|
('email', models.EmailField(max_length=254, verbose_name='email')),
|
||||||
|
('require_memberships', models.BooleanField(default=True, help_text="Uncheck if this club don't require memberships.", verbose_name='require memberships')),
|
||||||
|
('membership_fee_paid', models.PositiveIntegerField(default=0, verbose_name='membership fee (paid students)')),
|
||||||
|
('membership_fee_unpaid', models.PositiveIntegerField(default=0, verbose_name='membership fee (unpaid students)')),
|
||||||
|
('membership_duration', models.PositiveIntegerField(blank=True, help_text='The longest time (in days) a membership can last (NULL = infinite).', null=True, verbose_name='membership duration')),
|
||||||
|
('membership_start', models.DateField(blank=True, help_text='Date from which the members can renew their membership.', null=True, verbose_name='membership start')),
|
||||||
|
('membership_end', models.DateField(blank=True, help_text='Maximal date of a membership, after which members must renew it.', null=True, verbose_name='membership end')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'club',
|
||||||
|
'verbose_name_plural': 'clubs',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Profile',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('phone_number', phonenumber_field.modelfields.PhoneNumberField(blank=True, max_length=50, null=True, region=None, verbose_name='phone number')),
|
||||||
|
('section', models.CharField(blank=True, help_text='e.g. "1A0", "9A♥", "SAPHIRE"', max_length=255, null=True, verbose_name='section')),
|
||||||
|
('department', models.CharField(choices=[('A0', 'Informatics (A0)'), ('A1', 'Mathematics (A1)'), ('A2', 'Physics (A2)'), ("A'2", "Applied physics (A'2)"), ('A2', "Chemistry (A''2)"), ('A3', 'Biology (A3)'), ('B1234', 'SAPHIRE (B1234)'), ('B1', 'Mechanics (B1)'), ('B2', 'Civil engineering (B2)'), ('B3', 'Mechanical engineering (B3)'), ('B4', 'EEA (B4)'), ('C', 'Design (C)'), ('D2', 'Economy-management (D2)'), ('D3', 'Social sciences (D3)'), ('E', 'English (E)'), ('EXT', 'External (EXT)')], max_length=8, verbose_name='department')),
|
||||||
|
('promotion', models.PositiveSmallIntegerField(default=2020, help_text='Year of entry to the school (None if not ENS student)', null=True, verbose_name='promotion')),
|
||||||
|
('address', models.CharField(blank=True, max_length=255, null=True, verbose_name='address')),
|
||||||
|
('paid', models.BooleanField(default=False, help_text='Tells if the user receive a salary.', verbose_name='paid')),
|
||||||
|
('ml_events_registration', models.CharField(blank=True, choices=[(None, 'No'), ('fr', 'Yes (receive them in french)'), ('en', 'Yes (receive them in english)')], default=None, max_length=2, null=True, verbose_name='Register on the mailing list to stay informed of the events of the campus (1 mail/week)')),
|
||||||
|
('ml_sport_registration', models.BooleanField(default=False, verbose_name='Register on the mailing list to stay informed of the sport events of the campus (1 mail/week)')),
|
||||||
|
('ml_art_registration', models.BooleanField(default=False, verbose_name='Register on the mailing list to stay informed of the art events of the campus (1 mail/week)')),
|
||||||
|
('report_frequency', models.PositiveSmallIntegerField(default=0, verbose_name='report frequency (in days)')),
|
||||||
|
('last_report', models.DateTimeField(default=django.utils.timezone.now, verbose_name='last report date')),
|
||||||
|
('email_confirmed', models.BooleanField(default=False, verbose_name='email confirmed')),
|
||||||
|
('registration_valid', models.BooleanField(default=False, verbose_name='registration valid')),
|
||||||
|
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'user profile',
|
||||||
|
'verbose_name_plural': 'user profile',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Membership',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('date_start', models.DateField(default=datetime.date.today, verbose_name='membership starts on')),
|
||||||
|
('date_end', models.DateField(null=True, verbose_name='membership ends on')),
|
||||||
|
('fee', models.PositiveIntegerField(verbose_name='fee')),
|
||||||
|
('club', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='member.Club', verbose_name='club')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'membership',
|
||||||
|
'verbose_name_plural': 'memberships',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
42
apps/member/migrations/0002_auto_20200904_2341.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-04 21:41
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('permission', '0001_initial'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('member', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='membership',
|
||||||
|
name='roles',
|
||||||
|
field=models.ManyToManyField(to='permission.Role', verbose_name='roles'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='membership',
|
||||||
|
name='user',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='memberships', to=settings.AUTH_USER_MODEL, verbose_name='user'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='club',
|
||||||
|
name='parent_club',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='member.Club', verbose_name='parent club'),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name='profile',
|
||||||
|
index=models.Index(fields=['user'], name='member_prof_user_id_30c316_idx'),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name='membership',
|
||||||
|
index=models.Index(fields=['user'], name='member_memb_user_id_945dbc_idx'),
|
||||||
|
),
|
||||||
|
]
|
57
apps/member/migrations/0003_create_bde_and_kfet.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def create_bde_and_kfet(apps, schema_editor):
|
||||||
|
"""
|
||||||
|
The clubs BDE and Kfet are pre-injected.
|
||||||
|
"""
|
||||||
|
Club = apps.get_model("member", "club")
|
||||||
|
NoteClub = apps.get_model("note", "noteclub")
|
||||||
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||||
|
polymorphic_ctype_id = ContentType.objects.get_for_model(NoteClub).id
|
||||||
|
|
||||||
|
Club.objects.get_or_create(
|
||||||
|
id=1,
|
||||||
|
name="BDE",
|
||||||
|
email="tresorerie.bde@example.com",
|
||||||
|
require_memberships=True,
|
||||||
|
membership_fee_paid=500,
|
||||||
|
membership_fee_unpaid=500,
|
||||||
|
membership_duration=396,
|
||||||
|
membership_start="2020-08-01",
|
||||||
|
membership_end="2021-09-30",
|
||||||
|
)
|
||||||
|
Club.objects.get_or_create(
|
||||||
|
id=2,
|
||||||
|
name="Kfet",
|
||||||
|
parent_club_id=1,
|
||||||
|
email="tresorerie.bde@example.com",
|
||||||
|
require_memberships=True,
|
||||||
|
membership_fee_paid=3500,
|
||||||
|
membership_fee_unpaid=3500,
|
||||||
|
membership_duration=396,
|
||||||
|
membership_start="2020-08-01",
|
||||||
|
membership_end="2021-09-30",
|
||||||
|
)
|
||||||
|
|
||||||
|
NoteClub.objects.get_or_create(
|
||||||
|
id=5,
|
||||||
|
club_id=1,
|
||||||
|
polymorphic_ctype_id=polymorphic_ctype_id,
|
||||||
|
)
|
||||||
|
NoteClub.objects.get_or_create(
|
||||||
|
id=6,
|
||||||
|
club_id=2,
|
||||||
|
polymorphic_ctype_id=polymorphic_ctype_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('member', '0002_auto_20200904_2341'),
|
||||||
|
('note', '0002_create_special_notes'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(create_bde_and_kfet),
|
||||||
|
]
|
20
apps/member/migrations/0004_replace_null_by_blank.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('member', '0003_create_bde_and_kfet'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunSQL(
|
||||||
|
"UPDATE member_profile SET address = '' WHERE address IS NULL;",
|
||||||
|
),
|
||||||
|
migrations.RunSQL(
|
||||||
|
"UPDATE member_profile SET ml_events_registration = '' WHERE ml_events_registration IS NULL;",
|
||||||
|
),
|
||||||
|
migrations.RunSQL(
|
||||||
|
"UPDATE member_profile SET section = '' WHERE section IS NULL;",
|
||||||
|
),
|
||||||
|
]
|
28
apps/member/migrations/0005_remove_null_tag_on_charfields.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-06 19:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('member', '0004_replace_null_by_blank'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='profile',
|
||||||
|
name='address',
|
||||||
|
field=models.CharField(blank=True, default='', max_length=255, verbose_name='address'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='profile',
|
||||||
|
name='ml_events_registration',
|
||||||
|
field=models.CharField(blank=True, choices=[('', 'No'), ('fr', 'Yes (receive them in french)'), ('en', 'Yes (receive them in english)')], default='', max_length=2, verbose_name='Register on the mailing list to stay informed of the events of the campus (1 mail/week)'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='profile',
|
||||||
|
name='section',
|
||||||
|
field=models.CharField(blank=True, default='', help_text='e.g. "1A0", "9A♥", "SAPHIRE"', max_length=255, verbose_name='section'),
|
||||||
|
),
|
||||||
|
]
|
@ -46,7 +46,7 @@ class Profile(models.Model):
|
|||||||
help_text=_('e.g. "1A0", "9A♥", "SAPHIRE"'),
|
help_text=_('e.g. "1A0", "9A♥", "SAPHIRE"'),
|
||||||
max_length=255,
|
max_length=255,
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
default="",
|
||||||
)
|
)
|
||||||
|
|
||||||
department = models.CharField(
|
department = models.CharField(
|
||||||
@ -83,7 +83,7 @@ class Profile(models.Model):
|
|||||||
verbose_name=_('address'),
|
verbose_name=_('address'),
|
||||||
max_length=255,
|
max_length=255,
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
default="",
|
||||||
)
|
)
|
||||||
|
|
||||||
paid = models.BooleanField(
|
paid = models.BooleanField(
|
||||||
@ -94,11 +94,10 @@ class Profile(models.Model):
|
|||||||
|
|
||||||
ml_events_registration = models.CharField(
|
ml_events_registration = models.CharField(
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
default='',
|
||||||
default=None,
|
|
||||||
max_length=2,
|
max_length=2,
|
||||||
choices=[
|
choices=[
|
||||||
(None, _("No")),
|
('', _("No")),
|
||||||
('fr', _("Yes (receive them in french)")),
|
('fr', _("Yes (receive them in french)")),
|
||||||
('en', _("Yes (receive them in english)")),
|
('en', _("Yes (receive them in english)")),
|
||||||
],
|
],
|
||||||
@ -172,19 +171,21 @@ class Profile(models.Model):
|
|||||||
|
|
||||||
def send_email_validation_link(self):
|
def send_email_validation_link(self):
|
||||||
subject = "[Note Kfet] " + str(_("Activate your Note Kfet account"))
|
subject = "[Note Kfet] " + str(_("Activate your Note Kfet account"))
|
||||||
|
token = email_validation_token.make_token(self.user)
|
||||||
|
uid = urlsafe_base64_encode(force_bytes(self.user_id))
|
||||||
message = loader.render_to_string('registration/mails/email_validation_email.txt',
|
message = loader.render_to_string('registration/mails/email_validation_email.txt',
|
||||||
{
|
{
|
||||||
'user': self.user,
|
'user': self.user,
|
||||||
'domain': os.getenv("NOTE_URL", "note.example.com"),
|
'domain': os.getenv("NOTE_URL", "note.example.com"),
|
||||||
'token': email_validation_token.make_token(self.user),
|
'token': token,
|
||||||
'uid': urlsafe_base64_encode(force_bytes(self.user.pk)),
|
'uid': uid,
|
||||||
})
|
})
|
||||||
html = loader.render_to_string('registration/mails/email_validation_email.html',
|
html = loader.render_to_string('registration/mails/email_validation_email.html',
|
||||||
{
|
{
|
||||||
'user': self.user,
|
'user': self.user,
|
||||||
'domain': os.getenv("NOTE_URL", "note.example.com"),
|
'domain': os.getenv("NOTE_URL", "note.example.com"),
|
||||||
'token': email_validation_token.make_token(self.user),
|
'token': token,
|
||||||
'uid': urlsafe_base64_encode(force_bytes(self.user.pk)),
|
'uid': uid,
|
||||||
})
|
})
|
||||||
self.user.email_user(subject, message, html_message=html)
|
self.user.email_user(subject, message, html_message=html)
|
||||||
|
|
||||||
@ -339,13 +340,15 @@ class Membership(models.Model):
|
|||||||
return self.date_start.toordinal() <= datetime.datetime.now().toordinal()
|
return self.date_start.toordinal() <= datetime.datetime.now().toordinal()
|
||||||
|
|
||||||
def renew(self):
|
def renew(self):
|
||||||
if Membership.objects.filter(
|
"""
|
||||||
|
If the current membership comes to expiration, create a new membership that starts immediately after this one.
|
||||||
|
"""
|
||||||
|
if not Membership.objects.filter(
|
||||||
user=self.user,
|
user=self.user,
|
||||||
club=self.club,
|
club=self.club,
|
||||||
date_start__gte=self.club.membership_start,
|
date_start__gte=self.club.membership_start,
|
||||||
).exists():
|
).exists():
|
||||||
# Membership is already renewed
|
# Membership is not renewed yet
|
||||||
return
|
|
||||||
new_membership = Membership(
|
new_membership = Membership(
|
||||||
user=self.user,
|
user=self.user,
|
||||||
club=self.club,
|
club=self.club,
|
||||||
@ -361,37 +364,10 @@ class Membership(models.Model):
|
|||||||
new_membership.roles.set(self.roles.all())
|
new_membership.roles.set(self.roles.all())
|
||||||
new_membership.save()
|
new_membership.save()
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def renew_parent(self):
|
||||||
"""
|
"""
|
||||||
Calculate fee and end date before saving the membership and creating the transaction if needed.
|
Ensure that the parent membership is renewed, and renew/create it if needed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.pk:
|
|
||||||
for role in self.roles.all():
|
|
||||||
club = role.for_club
|
|
||||||
if club is not None:
|
|
||||||
if club.pk != self.club_id:
|
|
||||||
raise ValidationError(_('The role {role} does not apply to the club {club}.')
|
|
||||||
.format(role=role.name, club=club.name))
|
|
||||||
|
|
||||||
created = not self.pk
|
|
||||||
if created:
|
|
||||||
if Membership.objects.filter(
|
|
||||||
user=self.user,
|
|
||||||
club=self.club,
|
|
||||||
date_start__lte=self.date_start,
|
|
||||||
date_end__gte=self.date_start,
|
|
||||||
).exists():
|
|
||||||
raise ValidationError(_('User is already a member of the club'))
|
|
||||||
|
|
||||||
if self.club.parent_club is not None and not self.pk:
|
|
||||||
# Check that the user is already a member of the parent club if the membership is created
|
|
||||||
if not Membership.objects.filter(
|
|
||||||
user=self.user,
|
|
||||||
club=self.club.parent_club,
|
|
||||||
date_start__gte=self.club.parent_club.membership_start,
|
|
||||||
).exists():
|
|
||||||
if hasattr(self, '_force_renew_parent') and self._force_renew_parent:
|
|
||||||
parent_membership = Membership.objects.filter(
|
parent_membership = Membership.objects.filter(
|
||||||
user=self.user,
|
user=self.user,
|
||||||
club=self.club.parent_club,
|
club=self.club.parent_club,
|
||||||
@ -429,19 +405,45 @@ class Membership(models.Model):
|
|||||||
else:
|
else:
|
||||||
parent_membership.roles.set(Role.objects.filter(name="Membre de club").all())
|
parent_membership.roles.set(Role.objects.filter(name="Membre de club").all())
|
||||||
parent_membership.save()
|
parent_membership.save()
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Calculate fee and end date before saving the membership and creating the transaction if needed.
|
||||||
|
"""
|
||||||
|
created = not self.pk
|
||||||
|
if not created:
|
||||||
|
for role in self.roles.all():
|
||||||
|
club = role.for_club
|
||||||
|
if club is not None:
|
||||||
|
if club.pk != self.club_id:
|
||||||
|
raise ValidationError(_('The role {role} does not apply to the club {club}.')
|
||||||
|
.format(role=role.name, club=club.name))
|
||||||
|
else:
|
||||||
|
if Membership.objects.filter(
|
||||||
|
user=self.user,
|
||||||
|
club=self.club,
|
||||||
|
date_start__lte=self.date_start,
|
||||||
|
date_end__gte=self.date_start,
|
||||||
|
).exists():
|
||||||
|
raise ValidationError(_('User is already a member of the club'))
|
||||||
|
|
||||||
|
if self.club.parent_club is not None:
|
||||||
|
# Check that the user is already a member of the parent club if the membership is created
|
||||||
|
if not Membership.objects.filter(
|
||||||
|
user=self.user,
|
||||||
|
club=self.club.parent_club,
|
||||||
|
date_start__gte=self.club.parent_club.membership_start,
|
||||||
|
).exists():
|
||||||
|
if hasattr(self, '_force_renew_parent') and self._force_renew_parent:
|
||||||
|
self.renew_parent()
|
||||||
else:
|
else:
|
||||||
raise ValidationError(_('User is not a member of the parent club')
|
raise ValidationError(_('User is not a member of the parent club')
|
||||||
+ ' ' + self.club.parent_club.name)
|
+ ' ' + self.club.parent_club.name)
|
||||||
|
|
||||||
if self.user.profile.paid:
|
self.fee = self.club.membership_fee_paid if self.user.profile.paid else self.club.membership_fee_unpaid
|
||||||
self.fee = self.club.membership_fee_paid
|
|
||||||
else:
|
|
||||||
self.fee = self.club.membership_fee_unpaid
|
|
||||||
|
|
||||||
if self.club.membership_duration is not None:
|
self.date_end = self.date_start + datetime.timedelta(days=self.club.membership_duration) \
|
||||||
self.date_end = self.date_start + datetime.timedelta(days=self.club.membership_duration)
|
if self.club.membership_duration is not None else self.date_start + datetime.timedelta(days=424242)
|
||||||
else:
|
|
||||||
self.date_end = self.date_start + datetime.timedelta(days=424242)
|
|
||||||
if self.club.membership_end is not None and self.date_end > self.club.membership_end:
|
if self.club.membership_end is not None and self.date_end > self.club.membership_end:
|
||||||
self.date_end = self.club.membership_end
|
self.date_end = self.club.membership_end
|
||||||
|
|
||||||
|
@ -6,11 +6,7 @@ def save_user_profile(instance, created, raw, **_kwargs):
|
|||||||
"""
|
"""
|
||||||
Hook to create and save a profile when an user is updated if it is not registered with the signup form
|
Hook to create and save a profile when an user is updated if it is not registered with the signup form
|
||||||
"""
|
"""
|
||||||
if raw:
|
if not raw and created and instance.is_active and not hasattr(instance, "_no_signal"):
|
||||||
# When provisionning data, do not try to autocreate
|
|
||||||
return
|
|
||||||
|
|
||||||
if created and instance.is_active:
|
|
||||||
from .models import Profile
|
from .models import Profile
|
||||||
Profile.objects.get_or_create(user=instance)
|
Profile.objects.get_or_create(user=instance)
|
||||||
if instance.is_superuser:
|
if instance.is_superuser:
|
||||||
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
@ -3,21 +3,21 @@
|
|||||||
*/
|
*/
|
||||||
function create_alias (e) {
|
function create_alias (e) {
|
||||||
// Do not submit HTML form
|
// Do not submit HTML form
|
||||||
e.preventDefault();
|
e.preventDefault()
|
||||||
|
|
||||||
// Get data and send to API
|
// Get data and send to API
|
||||||
const formData = new FormData(e.target);
|
const formData = new FormData(e.target)
|
||||||
$.post("/api/note/alias/", {
|
$.post('/api/note/alias/', {
|
||||||
"csrfmiddlewaretoken": formData.get("csrfmiddlewaretoken"),
|
csrfmiddlewaretoken: formData.get('csrfmiddlewaretoken'),
|
||||||
"name": formData.get("name"),
|
name: formData.get('name'),
|
||||||
"note": formData.get("note")
|
note: formData.get('note')
|
||||||
}).done(function () {
|
}).done(function () {
|
||||||
// Reload table
|
// Reload table
|
||||||
$("#alias_table").load(location.pathname + " #alias_table");
|
$('#alias_table').load(location.pathname + ' #alias_table')
|
||||||
addMsg("Alias ajouté", "success");
|
addMsg('Alias ajouté', 'success')
|
||||||
}).fail(function (xhr, _textStatus, _error) {
|
}).fail(function (xhr, _textStatus, _error) {
|
||||||
errMsg(xhr.responseJSON);
|
errMsg(xhr.responseJSON)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,18 +26,18 @@ function create_alias (e) {
|
|||||||
*/
|
*/
|
||||||
function delete_button (button_id) {
|
function delete_button (button_id) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/api/note/alias/" + button_id + "/",
|
url: '/api/note/alias/' + button_id + '/',
|
||||||
method: "DELETE",
|
method: 'DELETE',
|
||||||
headers: { "X-CSRFTOKEN": CSRF_TOKEN }
|
headers: { 'X-CSRFTOKEN': CSRF_TOKEN }
|
||||||
}).done(function () {
|
}).done(function () {
|
||||||
addMsg('Alias supprimé', 'success');
|
addMsg('Alias supprimé', 'success')
|
||||||
$("#alias_table").load(location.pathname + " #alias_table");
|
$('#alias_table').load(location.pathname + ' #alias_table')
|
||||||
}).fail(function (xhr, _textStatus, _error) {
|
}).fail(function (xhr, _textStatus, _error) {
|
||||||
errMsg(xhr.responseJSON);
|
errMsg(xhr.responseJSON)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
// Attach event
|
// Attach event
|
||||||
document.getElementById("form_alias").addEventListener("submit", create_alias);
|
document.getElementById('form_alias').addEventListener('submit', create_alias)
|
||||||
})
|
})
|
@ -48,7 +48,7 @@
|
|||||||
<dd class="col-xl-6">
|
<dd class="col-xl-6">
|
||||||
<a class="badge badge-secondary" href="{% url 'member:club_alias' club.pk %}">
|
<a class="badge badge-secondary" href="{% url 'member:club_alias' club.pk %}">
|
||||||
<i class="fa fa-edit"></i>
|
<i class="fa fa-edit"></i>
|
||||||
{% trans 'Manage aliases' %} ({{ user_object.note.alias_set.all|length }})
|
{% trans 'Manage aliases' %} ({{ club.note.alias_set.all|length }})
|
||||||
</a>
|
</a>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{% extends "member/base.html" %}
|
{% extends "base.html" %}
|
||||||
{% comment %}
|
{% comment %}
|
||||||
SPDX-License-Identifier: GPL-3.0-or-later
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
|
@ -32,8 +32,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
<span class="glyphicon glyphicon-zoom-out"></span>
|
<span class="glyphicon glyphicon-zoom-out"></span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">Nevermind</button>
|
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Nevermind" %}</button>
|
||||||
<button type="button" class="btn btn-primary js-crop-and-upload">Crop and upload</button>
|
<button type="button" class="btn btn-primary js-crop-and-upload">{% trans "Crop and upload" %}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -55,6 +55,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
/* SCRIPT TO OPEN THE MODAL WITH THE PREVIEW */
|
/* SCRIPT TO OPEN THE MODAL WITH THE PREVIEW */
|
||||||
$("#id_image").change(function (e) {
|
$("#id_image").change(function (e) {
|
||||||
if (this.files && this.files[0]) {
|
if (this.files && this.files[0]) {
|
||||||
|
// Check the image size
|
||||||
|
if (this.files[0].size > 2*1024*1024) {
|
||||||
|
alert("Ce fichier est trop volumineux.")
|
||||||
|
} else {
|
||||||
|
// Read the selected image file
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onload = function (e) {
|
reader.onload = function (e) {
|
||||||
$("#modal-image").attr("src", e.target.result);
|
$("#modal-image").attr("src", e.target.result);
|
||||||
@ -62,6 +67,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
}
|
}
|
||||||
reader.readAsDataURL(this.files[0]);
|
reader.readAsDataURL(this.files[0]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* SCRIPTS TO HANDLE THE CROPPER BOX */
|
/* SCRIPTS TO HANDLE THE CROPPER BOX */
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from note.models import TransactionTemplate, TemplateCategory
|
from django.urls import reverse
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Test that login page still works
|
Test that login page still works
|
||||||
@ -31,7 +31,20 @@ class TemplateLoggedInTests(TestCase):
|
|||||||
sess.save()
|
sess.save()
|
||||||
|
|
||||||
def test_login_page(self):
|
def test_login_page(self):
|
||||||
response = self.client.get('/accounts/login/')
|
response = self.client.get(reverse("login"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
self.client.logout()
|
||||||
|
|
||||||
|
response = self.client.post('/accounts/login/', data=dict(
|
||||||
|
username="admin",
|
||||||
|
password="adminadmin",
|
||||||
|
permission_mask=3,
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, settings.LOGIN_REDIRECT_URL, 302, 200)
|
||||||
|
|
||||||
|
def test_logout(self):
|
||||||
|
response = self.client.get(reverse("logout"))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_admin_index(self):
|
def test_admin_index(self):
|
||||||
@ -41,22 +54,3 @@ class TemplateLoggedInTests(TestCase):
|
|||||||
def test_accounts_password_reset(self):
|
def test_accounts_password_reset(self):
|
||||||
response = self.client.get('/accounts/password_reset/')
|
response = self.client.get('/accounts/password_reset/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_logout_page(self):
|
|
||||||
response = self.client.get('/accounts/logout/')
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
def test_transfer_page(self):
|
|
||||||
response = self.client.get('/note/transfer/')
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
def test_consos_page(self):
|
|
||||||
# Create one button and ensure that it is visible
|
|
||||||
cat = TemplateCategory.objects.create()
|
|
||||||
TransactionTemplate.objects.create(
|
|
||||||
destination_id=5,
|
|
||||||
category=cat,
|
|
||||||
amount=0,
|
|
||||||
)
|
|
||||||
response = self.client.get('/note/consos/')
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
405
apps/member/tests/test_memberships.py
Normal file
@ -0,0 +1,405 @@
|
|||||||
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
import os
|
||||||
|
from datetime import date, timedelta
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
|
from django.db.models import Q
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils import timezone
|
||||||
|
from member.models import Club, Membership, Profile
|
||||||
|
from note.models import Alias, NoteSpecial
|
||||||
|
from permission.models import Role
|
||||||
|
from treasury.models import SogeCredit
|
||||||
|
|
||||||
|
"""
|
||||||
|
Create some users and clubs and test that all pages are rendering properly
|
||||||
|
and that memberships are working.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class TestMemberships(TestCase):
|
||||||
|
fixtures = ('initial', )
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
"""
|
||||||
|
Create a sample superuser, a club and a membership for all tests.
|
||||||
|
"""
|
||||||
|
self.user = User.objects.create_superuser(
|
||||||
|
username="toto",
|
||||||
|
email="toto@example.com",
|
||||||
|
password="toto",
|
||||||
|
)
|
||||||
|
self.user.profile.registration_valid = True
|
||||||
|
self.user.profile.email_confirmed = True
|
||||||
|
self.user.profile.save()
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
|
||||||
|
sess = self.client.session
|
||||||
|
sess["permission_mask"] = 42
|
||||||
|
sess.save()
|
||||||
|
|
||||||
|
self.club = Club.objects.create(name="totoclub", parent_club=Club.objects.get(name="BDE"))
|
||||||
|
self.bde_membership = Membership.objects.create(user=self.user, club=Club.objects.get(name="BDE"))
|
||||||
|
self.membership = Membership.objects.create(user=self.user, club=self.club)
|
||||||
|
self.membership.roles.add(Role.objects.get(name="Bureau de club"))
|
||||||
|
self.membership.save()
|
||||||
|
|
||||||
|
def test_admin_pages(self):
|
||||||
|
"""
|
||||||
|
Check that Django Admin pages for the member app are loading successfully.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("admin:index") + "member/membership/")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
response = self.client.get(reverse("admin:index") + "member/club/")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
response = self.client.get(reverse("admin:index") + "auth/user/")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
response = self.client.get(reverse("admin:index") + "auth/user/" + str(self.user.pk) + "/change/")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_render_club_list(self):
|
||||||
|
"""
|
||||||
|
Render the list of all clubs, with a search.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:club_list"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
response = self.client.get(reverse("member:club_list") + "?search=toto")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_render_club_create(self):
|
||||||
|
"""
|
||||||
|
Try to create a new club.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:club_create"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.post(reverse("member:club_create"), data=dict(
|
||||||
|
name="Club toto",
|
||||||
|
email="clubtoto@example.com",
|
||||||
|
parent_club=self.club.pk,
|
||||||
|
require_memberships=False,
|
||||||
|
membership_fee_paid=0,
|
||||||
|
membership_fee_unpaid=0,
|
||||||
|
))
|
||||||
|
self.assertTrue(Club.objects.filter(name="Club toto").exists())
|
||||||
|
club = Club.objects.get(name="Club toto")
|
||||||
|
self.assertRedirects(response, club.get_absolute_url(), 302, 200)
|
||||||
|
|
||||||
|
def test_render_club_detail(self):
|
||||||
|
"""
|
||||||
|
Display the detail of a club.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:club_detail", args=(self.club.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_render_club_update(self):
|
||||||
|
"""
|
||||||
|
Try to update the information about a club.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:club_update", args=(self.club.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.post(reverse("member:club_update", args=(self.club.pk, )), data=dict(
|
||||||
|
name="Toto club updated",
|
||||||
|
email="clubtoto@example.com",
|
||||||
|
require_memberships=True,
|
||||||
|
membership_fee_paid=0,
|
||||||
|
membership_fee_unpaid=0,
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, self.club.get_absolute_url(), 302, 200)
|
||||||
|
self.assertTrue(Club.objects.exclude(name="Toto club updated"))
|
||||||
|
|
||||||
|
def test_render_club_update_picture(self):
|
||||||
|
"""
|
||||||
|
Try to update the picture of the note of a club.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:club_update_pic", args=(self.club.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
old_pic = self.club.note.display_image
|
||||||
|
|
||||||
|
with open("apps/member/static/member/img/default_picture.png", "rb") as f:
|
||||||
|
image = SimpleUploadedFile("image.png", f.read(), "image/png")
|
||||||
|
response = self.client.post(reverse("member:club_update_pic", args=(self.club.pk,)), dict(
|
||||||
|
image=image,
|
||||||
|
x=0,
|
||||||
|
y=0,
|
||||||
|
width=200,
|
||||||
|
height=200,
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, self.club.get_absolute_url(), 302, 200)
|
||||||
|
|
||||||
|
self.club.note.refresh_from_db()
|
||||||
|
self.assertTrue(os.path.exists(self.club.note.display_image.path))
|
||||||
|
os.remove(self.club.note.display_image.path)
|
||||||
|
|
||||||
|
self.club.note.display_image = old_pic
|
||||||
|
self.club.note.save()
|
||||||
|
|
||||||
|
def test_render_club_aliases(self):
|
||||||
|
"""
|
||||||
|
Display the list of the aliases of a club.
|
||||||
|
"""
|
||||||
|
# Alias creation and deletion is already tested in the note app
|
||||||
|
response = self.client.get(reverse("member:club_alias", args=(self.club.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_render_club_members(self):
|
||||||
|
"""
|
||||||
|
Display the list of the members of a club.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:club_members", args=(self.club.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("member:club_members", args=(self.club.pk,)) + "?search=toto&roles="
|
||||||
|
+ ",".join([str(role.pk) for role in
|
||||||
|
Role.objects.filter(weirole__isnull=True).all()]))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_render_club_add_member(self):
|
||||||
|
"""
|
||||||
|
Try to add memberships and renew them.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:club_add_member", args=(Club.objects.get(name="BDE").pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
user = User.objects.create(username="totototo")
|
||||||
|
user.profile.registration_valid = True
|
||||||
|
user.profile.email_confirmed = True
|
||||||
|
user.profile.save()
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
# We create a club without any parent and one club with parent BDE (that is the club Kfet)
|
||||||
|
for bde_parent in False, True:
|
||||||
|
if bde_parent:
|
||||||
|
club = Club.objects.get(name="Kfet")
|
||||||
|
else:
|
||||||
|
club = Club.objects.create(
|
||||||
|
name="Second club " + ("with BDE" if bde_parent else "without BDE"),
|
||||||
|
parent_club=None,
|
||||||
|
email="newclub@example.com",
|
||||||
|
require_memberships=True,
|
||||||
|
membership_fee_paid=1000,
|
||||||
|
membership_fee_unpaid=500,
|
||||||
|
membership_start=date.today(),
|
||||||
|
membership_end=date.today() + timedelta(days=366),
|
||||||
|
membership_duration=366,
|
||||||
|
)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("member:club_add_member", args=(club.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# Create a new membership
|
||||||
|
response = self.client.post(reverse("member:club_add_member", args=(club.pk,)), data=dict(
|
||||||
|
user=user.pk,
|
||||||
|
date_start="{:%Y-%m-%d}".format(date.today()),
|
||||||
|
soge=False,
|
||||||
|
credit_type=NoteSpecial.objects.get(special_type="Espèces").id,
|
||||||
|
credit_amount=4200,
|
||||||
|
last_name="TOTO",
|
||||||
|
first_name="Toto",
|
||||||
|
bank="Le matelas",
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, club.get_absolute_url(), 302, 200)
|
||||||
|
|
||||||
|
self.assertTrue(Membership.objects.filter(user=user, club=club).exists())
|
||||||
|
|
||||||
|
# Membership is sent to the past to check renewals
|
||||||
|
membership = Membership.objects.get(user=user, club=club)
|
||||||
|
self.assertTrue(membership.valid)
|
||||||
|
membership.date_start = date(year=2000, month=1, day=1)
|
||||||
|
membership.date_end = date(year=2000, month=12, day=31)
|
||||||
|
membership.save()
|
||||||
|
self.assertFalse(membership.valid)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("member:club_members", args=(club.pk,)) + "?only_active=0")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
bde_membership = self.bde_membership
|
||||||
|
if bde_parent:
|
||||||
|
bde_membership = Membership.objects.get(club__name="BDE", user=user)
|
||||||
|
bde_membership.date_start = date(year=2000, month=1, day=1)
|
||||||
|
bde_membership.date_end = date(year=2000, month=12, day=31)
|
||||||
|
bde_membership.save()
|
||||||
|
|
||||||
|
response = self.client.get(reverse("member:club_renew_membership", args=(bde_membership.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("member:club_renew_membership", args=(membership.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# Renew membership
|
||||||
|
response = self.client.post(reverse("member:club_renew_membership", args=(membership.pk,)), data=dict(
|
||||||
|
user=user.pk,
|
||||||
|
date_start="{:%Y-%m-%d}".format(date.today()),
|
||||||
|
soge=bde_parent,
|
||||||
|
credit_type=NoteSpecial.objects.get(special_type="Chèque").id,
|
||||||
|
credit_amount=14242,
|
||||||
|
last_name="TOTO",
|
||||||
|
first_name="Toto",
|
||||||
|
bank="Bank",
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, club.get_absolute_url(), 302, 200)
|
||||||
|
|
||||||
|
response = self.client.get(user.profile.get_absolute_url())
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_auto_join_kfet_when_join_bde_with_soge(self):
|
||||||
|
"""
|
||||||
|
When we join the BDE club with a Soge registration, a Kfet membership is automatically created.
|
||||||
|
We check that it is the case.
|
||||||
|
"""
|
||||||
|
user = User.objects.create(username="new1A")
|
||||||
|
user.profile.registration_valid = True
|
||||||
|
user.profile.email_confirmed = True
|
||||||
|
user.profile.save()
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
bde = Club.objects.get(name="BDE")
|
||||||
|
kfet = Club.objects.get(name="Kfet")
|
||||||
|
|
||||||
|
response = self.client.post(reverse("member:club_add_member", args=(bde.pk,)), data=dict(
|
||||||
|
user=user.pk,
|
||||||
|
date_start="{:%Y-%m-%d}".format(date.today()),
|
||||||
|
soge=True,
|
||||||
|
credit_type=NoteSpecial.objects.get(special_type="Virement bancaire").id,
|
||||||
|
credit_amount=(bde.membership_fee_paid + kfet.membership_fee_paid) / 100,
|
||||||
|
last_name="TOTO",
|
||||||
|
first_name="Toto",
|
||||||
|
bank="Société générale",
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, bde.get_absolute_url(), 302, 200)
|
||||||
|
|
||||||
|
self.assertTrue(Membership.objects.filter(user=user, club=bde).exists())
|
||||||
|
self.assertTrue(Membership.objects.filter(user=user, club=kfet).exists())
|
||||||
|
self.assertTrue(SogeCredit.objects.filter(user=user).exists())
|
||||||
|
|
||||||
|
def test_change_roles(self):
|
||||||
|
"""
|
||||||
|
Check to change the roles of a membership.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:club_manage_roles", args=(self.membership.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.post(reverse("member:club_manage_roles", args=(self.membership.pk,)), data=dict(
|
||||||
|
roles=[role.id for role in Role.objects.filter(
|
||||||
|
Q(name="Membre de club") | Q(name="Trésorier·ère de club") | Q(name="Bureau de club")).all()],
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, self.user.profile.get_absolute_url(), 302, 200)
|
||||||
|
self.membership.refresh_from_db()
|
||||||
|
self.assertEqual(self.membership.roles.count(), 3)
|
||||||
|
|
||||||
|
def test_render_user_list(self):
|
||||||
|
"""
|
||||||
|
Display the user search page.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:user_list"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
response = self.client.get(reverse("member:user_list") + "?search=toto")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_render_user_detail(self):
|
||||||
|
"""
|
||||||
|
Display the user detail page.
|
||||||
|
"""
|
||||||
|
response = self.client.get(self.user.profile.get_absolute_url())
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_render_user_update(self):
|
||||||
|
"""
|
||||||
|
Update some data about the user.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:user_update_profile", args=(self.user.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.post(reverse("member:user_update_profile", args=(self.user.pk,)), data=dict(
|
||||||
|
first_name="Toto",
|
||||||
|
last_name="Toto",
|
||||||
|
username="toto changed",
|
||||||
|
email="updated@example.com",
|
||||||
|
phone_number="+33600000000",
|
||||||
|
section="",
|
||||||
|
department="A0",
|
||||||
|
promotion=timezone.now().year,
|
||||||
|
address="Earth",
|
||||||
|
paid=True,
|
||||||
|
ml_events_registration="en",
|
||||||
|
ml_sports_registration=True,
|
||||||
|
ml_art_registration=True,
|
||||||
|
report_frequency=7,
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, self.user.profile.get_absolute_url(), 302, 200)
|
||||||
|
self.assertTrue(User.objects.filter(username="toto changed").exists())
|
||||||
|
self.assertTrue(Profile.objects.filter(address="Earth").exists())
|
||||||
|
self.assertTrue(Alias.objects.filter(normalized_name="totochanged").exists())
|
||||||
|
|
||||||
|
def test_render_user_update_picture(self):
|
||||||
|
"""
|
||||||
|
Update the note picture of the user.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:user_update_pic", args=(self.user.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
old_pic = self.user.note.display_image
|
||||||
|
|
||||||
|
with open("apps/member/static/member/img/default_picture.png", "rb") as f:
|
||||||
|
image = SimpleUploadedFile("image.png", f.read(), "image/png")
|
||||||
|
response = self.client.post(reverse("member:user_update_pic", args=(self.user.pk,)), dict(
|
||||||
|
image=image,
|
||||||
|
x=0,
|
||||||
|
y=0,
|
||||||
|
width=200,
|
||||||
|
height=200,
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, self.user.profile.get_absolute_url(), 302, 200)
|
||||||
|
|
||||||
|
self.user.note.refresh_from_db()
|
||||||
|
self.assertTrue(os.path.exists(self.user.note.display_image.path))
|
||||||
|
os.remove(self.user.note.display_image.path)
|
||||||
|
|
||||||
|
self.user.note.display_image = old_pic
|
||||||
|
self.user.note.save()
|
||||||
|
|
||||||
|
def test_render_user_aliases(self):
|
||||||
|
"""
|
||||||
|
Display the list of aliases of the user.
|
||||||
|
"""
|
||||||
|
# Alias creation and deletion is already tested in the note app
|
||||||
|
response = self.client.get(reverse("member:user_alias", args=(self.user.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_manage_auth_token(self):
|
||||||
|
"""
|
||||||
|
Display the page to see the API authentication token, see it and regenerate it.
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("member:auth_token"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
response = self.client.get(reverse("member:auth_token") + "?view")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
response = self.client.get(reverse("member:auth_token") + "?regenerate")
|
||||||
|
self.assertRedirects(response, reverse("member:auth_token") + "?view", 302, 200)
|
||||||
|
|
||||||
|
def test_random_coverage(self):
|
||||||
|
# Useless, only for coverage
|
||||||
|
self.assertEqual(str(self.user), str(self.user.profile))
|
||||||
|
self.user.profile.promotion = None
|
||||||
|
self.assertEqual(self.user.profile.ens_year, 0)
|
||||||
|
self.membership.date_end = None
|
||||||
|
self.assertTrue(self.membership.valid)
|
||||||
|
|
||||||
|
def test_nk15_hasher(self):
|
||||||
|
"""
|
||||||
|
Test that NK15 passwords are successfully imported.
|
||||||
|
"""
|
||||||
|
salt = "42"
|
||||||
|
password = "strongpassword42"
|
||||||
|
hashed = hashlib.sha256((salt + password).encode("utf-8")).hexdigest()
|
||||||
|
self.user.password = "custom_nk15$1$" + salt + "|" + hashed
|
||||||
|
self.user.save()
|
||||||
|
self.assertTrue(self.user.check_password(password))
|
@ -1,10 +1,8 @@
|
|||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import io
|
|
||||||
from datetime import timedelta, date
|
from datetime import timedelta, date
|
||||||
|
|
||||||
from PIL import Image
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import logout
|
from django.contrib.auth import logout
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
@ -97,8 +95,7 @@ class UserUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
|||||||
note = NoteUser.objects.filter(
|
note = NoteUser.objects.filter(
|
||||||
alias__normalized_name=Alias.normalize(new_username))
|
alias__normalized_name=Alias.normalize(new_username))
|
||||||
if note.exists() and note.get().user != self.object:
|
if note.exists() and note.get().user != self.object:
|
||||||
form.add_error('username',
|
form.add_error('username', _("An alias with a similar name already exists."))
|
||||||
_("An alias with a similar name already exists."))
|
|
||||||
return super().form_invalid(form)
|
return super().form_invalid(form)
|
||||||
# Check if the username is one of user's aliases.
|
# Check if the username is one of user's aliases.
|
||||||
alias = Alias.objects.filter(name=new_username)
|
alias = Alias.objects.filter(name=new_username)
|
||||||
@ -141,10 +138,7 @@ class UserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
|||||||
"""
|
"""
|
||||||
We can't display information of a not registered user.
|
We can't display information of a not registered user.
|
||||||
"""
|
"""
|
||||||
qs = super().get_queryset()
|
return super().get_queryset(**kwargs).filter(profile__registration_valid=True)
|
||||||
if self.request.user.is_superuser and self.request.session.get("permission_mask", -1) >= 42:
|
|
||||||
return qs
|
|
||||||
return qs.filter(profile__registration_valid=True)
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -204,14 +198,16 @@ class UserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
|||||||
"""
|
"""
|
||||||
Filter the user list with the given pattern.
|
Filter the user list with the given pattern.
|
||||||
"""
|
"""
|
||||||
qs = super().get_queryset().distinct("username").annotate(alias=F("note__alias__name"))\
|
qs = super().get_queryset().annotate(alias=F("note__alias__name"))\
|
||||||
.annotate(normalized_alias=F("note__alias__normalized_name"))\
|
.annotate(normalized_alias=F("note__alias__normalized_name"))\
|
||||||
.filter(profile__registration_valid=True).order_by("username")
|
.filter(profile__registration_valid=True)
|
||||||
if "search" in self.request.GET:
|
|
||||||
pattern = self.request.GET["search"]
|
|
||||||
|
|
||||||
if not pattern:
|
# Sqlite doesn't support order by in subqueries
|
||||||
return qs.none()
|
qs = qs.order_by("username").distinct("username")\
|
||||||
|
if settings.DATABASES[qs.db]["ENGINE"] == 'django.db.backends.postgresql' else qs.distinct()
|
||||||
|
|
||||||
|
if "search" in self.request.GET and self.request.GET["search"]:
|
||||||
|
pattern = self.request.GET["search"]
|
||||||
|
|
||||||
qs = qs.filter(
|
qs = qs.filter(
|
||||||
username__iregex="^" + pattern
|
username__iregex="^" + pattern
|
||||||
@ -265,40 +261,27 @@ class PictureUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, FormMixin, Det
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
"""Redirect to profile page after upload"""
|
||||||
return reverse_lazy('member:user_detail', kwargs={'pk': self.object.id})
|
return reverse_lazy('member:user_detail', kwargs={'pk': self.object.id})
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
form = self.get_form()
|
form = self.get_form()
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
if form.is_valid():
|
return self.form_valid(form) if form.is_valid() else self.form_invalid(form)
|
||||||
return self.form_valid(form)
|
|
||||||
else:
|
|
||||||
print('is_invalid')
|
|
||||||
print(form)
|
|
||||||
return self.form_invalid(form)
|
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
image_field = form.cleaned_data['image']
|
"""Save image to note"""
|
||||||
x = form.cleaned_data['x']
|
image = form.cleaned_data['image']
|
||||||
y = form.cleaned_data['y']
|
|
||||||
w = form.cleaned_data['width']
|
# Rename as a PNG or GIF
|
||||||
h = form.cleaned_data['height']
|
extension = image.name.split(".")[-1]
|
||||||
# image crop and resize
|
if extension == "gif":
|
||||||
image_file = io.BytesIO(image_field.read())
|
image.name = "{}_pic.gif".format(self.object.note.pk)
|
||||||
# ext = image_field.name.split('.')[-1].lower()
|
else:
|
||||||
# TODO: support GIF format
|
image.name = "{}_pic.png".format(self.object.note.pk)
|
||||||
image = Image.open(image_file)
|
|
||||||
image = image.crop((x, y, x + w, y + h))
|
# Save
|
||||||
image_clean = image.resize((settings.PIC_WIDTH,
|
self.object.note.display_image = image
|
||||||
settings.PIC_RATIO * settings.PIC_WIDTH),
|
|
||||||
Image.ANTIALIAS)
|
|
||||||
image_file = io.BytesIO()
|
|
||||||
image_clean.save(image_file, "PNG")
|
|
||||||
image_field.file = image_file
|
|
||||||
# renaming
|
|
||||||
filename = "{}_pic.png".format(self.object.note.pk)
|
|
||||||
image_field.name = filename
|
|
||||||
self.object.note.display_image = image_field
|
|
||||||
self.object.note.save()
|
self.object.note.save()
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
@ -320,8 +303,7 @@ class ManageAuthTokens(LoginRequiredMixin, TemplateView):
|
|||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if 'regenerate' in request.GET and Token.objects.filter(user=request.user).exists():
|
if 'regenerate' in request.GET and Token.objects.filter(user=request.user).exists():
|
||||||
Token.objects.get(user=self.request.user).delete()
|
Token.objects.get(user=self.request.user).delete()
|
||||||
return redirect(reverse_lazy('member:auth_token') + "?show",
|
return redirect(reverse_lazy('member:auth_token') + "?show")
|
||||||
permanent=True)
|
|
||||||
|
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
@ -351,8 +333,9 @@ class ClubCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||||||
email="",
|
email="",
|
||||||
)
|
)
|
||||||
|
|
||||||
def form_valid(self, form):
|
def get_success_url(self):
|
||||||
return super().form_valid(form)
|
self.object.refresh_from_db()
|
||||||
|
return reverse_lazy("member:club_detail", kwargs={"pk": self.object.pk})
|
||||||
|
|
||||||
|
|
||||||
class ClubListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
class ClubListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
||||||
@ -609,6 +592,64 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
def perform_verifications(self, form, user, club, fee):
|
||||||
|
"""
|
||||||
|
Make some additional verifications to check that the membership can be created.
|
||||||
|
:return: True if the form is clean, False if there is an error.
|
||||||
|
"""
|
||||||
|
error = False
|
||||||
|
|
||||||
|
# Retrieve form data
|
||||||
|
credit_type = form.cleaned_data["credit_type"]
|
||||||
|
credit_amount = form.cleaned_data["credit_amount"]
|
||||||
|
last_name = form.cleaned_data["last_name"]
|
||||||
|
first_name = form.cleaned_data["first_name"]
|
||||||
|
bank = form.cleaned_data["bank"]
|
||||||
|
soge = form.cleaned_data["soge"] and not user.profile.soge and (club.name == "BDE" or club.name == "Kfet")
|
||||||
|
|
||||||
|
if not soge and user.note.balance + credit_amount < fee and not Membership.objects.filter(
|
||||||
|
club__name="Kfet",
|
||||||
|
user=user,
|
||||||
|
date_start__lte=date.today(),
|
||||||
|
date_end__gte=date.today(),
|
||||||
|
).exists():
|
||||||
|
# Users without a valid Kfet membership can't have a negative balance.
|
||||||
|
# TODO Send a notification to the user (with a mail?) to tell her/him to credit her/his note
|
||||||
|
form.add_error('user',
|
||||||
|
_("This user don't have enough money to join this club, and can't have a negative balance."))
|
||||||
|
error = True
|
||||||
|
|
||||||
|
if Membership.objects.filter(
|
||||||
|
user=form.instance.user,
|
||||||
|
club=club,
|
||||||
|
date_start__lte=form.instance.date_start,
|
||||||
|
date_end__gte=form.instance.date_start,
|
||||||
|
).exists():
|
||||||
|
form.add_error('user', _('User is already a member of the club'))
|
||||||
|
error = True
|
||||||
|
|
||||||
|
if club.membership_start and form.instance.date_start < club.membership_start:
|
||||||
|
form.add_error('user', _("The membership must start after {:%m-%d-%Y}.")
|
||||||
|
.format(form.instance.club.membership_start))
|
||||||
|
error = True
|
||||||
|
|
||||||
|
if club.membership_end and form.instance.date_start > club.membership_end:
|
||||||
|
form.add_error('user', _("The membership must begin before {:%m-%d-%Y}.")
|
||||||
|
.format(form.instance.club.membership_end))
|
||||||
|
error = True
|
||||||
|
|
||||||
|
if credit_amount:
|
||||||
|
if not last_name or not first_name or (not bank and credit_type.special_type == "Chèque"):
|
||||||
|
if not last_name:
|
||||||
|
form.add_error('last_name', _("This field is required."))
|
||||||
|
if not first_name:
|
||||||
|
form.add_error('first_name', _("This field is required."))
|
||||||
|
if not bank and credit_type.special_type == "Chèque":
|
||||||
|
form.add_error('bank', _("This field is required."))
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
return not error
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
"""
|
"""
|
||||||
Create membership, check that all is good, make transactions
|
Create membership, check that all is good, make transactions
|
||||||
@ -655,36 +696,9 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||||||
fee += c.membership_fee_paid if user.profile.paid else c.membership_fee_unpaid
|
fee += c.membership_fee_paid if user.profile.paid else c.membership_fee_unpaid
|
||||||
c = c.parent_club
|
c = c.parent_club
|
||||||
|
|
||||||
if user.note.balance + credit_amount < fee and not Membership.objects.filter(
|
# Make some verifications about the form, and if there is an error, then assume that the form is invalid
|
||||||
club__name="Kfet",
|
if not self.perform_verifications(form, user, club, fee):
|
||||||
user=user,
|
return self.form_invalid(form)
|
||||||
date_start__lte=date.today(),
|
|
||||||
date_end__gte=date.today(),
|
|
||||||
).exists():
|
|
||||||
# Users without a valid Kfet membership can't have a negative balance.
|
|
||||||
# TODO Send a notification to the user (with a mail?) to tell her/him to credit her/his note
|
|
||||||
form.add_error('user',
|
|
||||||
_("This user don't have enough money to join this club, and can't have a negative balance."))
|
|
||||||
return super().form_invalid(form)
|
|
||||||
|
|
||||||
if Membership.objects.filter(
|
|
||||||
user=form.instance.user,
|
|
||||||
club=club,
|
|
||||||
date_start__lte=form.instance.date_start,
|
|
||||||
date_end__gte=form.instance.date_start,
|
|
||||||
).exists():
|
|
||||||
form.add_error('user', _('User is already a member of the club'))
|
|
||||||
return super().form_invalid(form)
|
|
||||||
|
|
||||||
if club.membership_start and form.instance.date_start < club.membership_start:
|
|
||||||
form.add_error('user', _("The membership must start after {:%m-%d-%Y}.")
|
|
||||||
.format(form.instance.club.membership_start))
|
|
||||||
return super().form_invalid(form)
|
|
||||||
|
|
||||||
if club.membership_end and form.instance.date_start > club.membership_end:
|
|
||||||
form.add_error('user', _("The membership must begin before {:%m-%d-%Y}.")
|
|
||||||
.format(form.instance.club.membership_start))
|
|
||||||
return super().form_invalid(form)
|
|
||||||
|
|
||||||
# Now, all is fine, the membership can be created.
|
# Now, all is fine, the membership can be created.
|
||||||
|
|
||||||
@ -696,15 +710,6 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||||||
|
|
||||||
# Credit note before the membership is created.
|
# Credit note before the membership is created.
|
||||||
if credit_amount > 0:
|
if credit_amount > 0:
|
||||||
if not last_name or not first_name or (not bank and credit_type.special_type == "Chèque"):
|
|
||||||
if not last_name:
|
|
||||||
form.add_error('last_name', _("This field is required."))
|
|
||||||
if not first_name:
|
|
||||||
form.add_error('first_name', _("This field is required."))
|
|
||||||
if not bank and credit_type.special_type == "Chèque":
|
|
||||||
form.add_error('bank', _("This field is required."))
|
|
||||||
return self.form_invalid(form)
|
|
||||||
|
|
||||||
transaction = SpecialTransaction(
|
transaction = SpecialTransaction(
|
||||||
source=credit_type,
|
source=credit_type,
|
||||||
destination=user.note,
|
destination=user.note,
|
||||||
@ -719,46 +724,38 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||||||
transaction._force_save = True
|
transaction._force_save = True
|
||||||
transaction.save()
|
transaction.save()
|
||||||
|
|
||||||
|
# Parent club memberships are automatically renewed / created.
|
||||||
|
# For example, a Kfet membership creates a BDE membership if it does not exist.
|
||||||
form.instance._force_renew_parent = True
|
form.instance._force_renew_parent = True
|
||||||
|
|
||||||
ret = super().form_valid(form)
|
ret = super().form_valid(form)
|
||||||
|
|
||||||
if club.name == "BDE":
|
member_role = Role.objects.filter(Q(name="Adhérent BDE") | Q(name="Membre de club")).all() \
|
||||||
member_role = Role.objects.filter(Q(name="Adhérent BDE") | Q(name="Membre de club")).all()
|
if club.name == "BDE" else Role.objects.filter(Q(name="Adhérent Kfet") | Q(name="Membre de club")).all() \
|
||||||
elif club.name == "Kfet":
|
if club.name == "Kfet"else Role.objects.filter(name="Membre de club").all()
|
||||||
member_role = Role.objects.filter(Q(name="Adhérent Kfet") | Q(name="Membre de club")).all()
|
|
||||||
else:
|
|
||||||
member_role = Role.objects.filter(name="Membre de club").all()
|
|
||||||
form.instance.roles.set(member_role)
|
form.instance.roles.set(member_role)
|
||||||
form.instance._force_save = True
|
form.instance._force_save = True
|
||||||
form.instance.save()
|
form.instance.save()
|
||||||
|
|
||||||
# If Société générale pays, then we assume that this is the BDE membership, and we auto-renew the
|
# If Société générale pays, then we assume that this is the BDE membership, and we auto-renew the
|
||||||
# Kfet membership.
|
# Kfet membership.
|
||||||
if soge:
|
if soge and club.name == "BDE":
|
||||||
# If not already done, create BDE and Kfet memberships
|
|
||||||
bde = Club.objects.get(name="BDE")
|
|
||||||
kfet = Club.objects.get(name="Kfet")
|
kfet = Club.objects.get(name="Kfet")
|
||||||
|
fee = kfet.membership_fee_paid if user.profile.paid else kfet.membership_fee_unpaid
|
||||||
soge_clubs = [bde, kfet]
|
|
||||||
for club in soge_clubs:
|
|
||||||
fee = club.membership_fee_paid if user.profile.paid else club.membership_fee_unpaid
|
|
||||||
|
|
||||||
# Get current membership, to get the end date
|
# Get current membership, to get the end date
|
||||||
old_membership = Membership.objects.filter(
|
old_membership = Membership.objects.filter(
|
||||||
club=club,
|
club=kfet,
|
||||||
user=user,
|
user=user,
|
||||||
).order_by("-date_start")
|
).order_by("-date_start")
|
||||||
|
|
||||||
if old_membership.filter(date_start__gte=club.membership_start).exists():
|
if not old_membership.filter(date_start__gte=kfet.membership_start).exists():
|
||||||
# Membership is already renewed
|
# If the membership is not already renewed
|
||||||
continue
|
|
||||||
|
|
||||||
membership = Membership(
|
membership = Membership(
|
||||||
club=club,
|
club=kfet,
|
||||||
user=user,
|
user=user,
|
||||||
fee=fee,
|
fee=fee,
|
||||||
date_start=max(old_membership.first().date_end + timedelta(days=1), club.membership_start)
|
date_start=max(old_membership.first().date_end + timedelta(days=1), kfet.membership_start)
|
||||||
if old_membership.exists() else form.instance.date_start,
|
if old_membership.exists() else form.instance.date_start,
|
||||||
)
|
)
|
||||||
membership._force_save = True
|
membership._force_save = True
|
||||||
@ -767,9 +764,6 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||||||
membership.refresh_from_db()
|
membership.refresh_from_db()
|
||||||
if old_membership.exists():
|
if old_membership.exists():
|
||||||
membership.roles.set(old_membership.get().roles.all())
|
membership.roles.set(old_membership.get().roles.all())
|
||||||
elif c.name == "BDE":
|
|
||||||
membership.roles.set(Role.objects.filter(Q(name="Adhérent BDE") | Q(name="Membre de club")).all())
|
|
||||||
elif c.name == "Kfet":
|
|
||||||
membership.roles.set(Role.objects.filter(Q(name="Adhérent Kfet") | Q(name="Membre de club")).all())
|
membership.roles.set(Role.objects.filter(Q(name="Adhérent Kfet") | Q(name="Membre de club")).all())
|
||||||
membership.save()
|
membership.save()
|
||||||
|
|
||||||
@ -830,9 +824,7 @@ class ClubMembersListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableV
|
|||||||
qs = qs.filter(date_start__lte=timezone.now().today(), date_end__gte=timezone.now().today())
|
qs = qs.filter(date_start__lte=timezone.now().today(), date_end__gte=timezone.now().today())
|
||||||
|
|
||||||
if "roles" in self.request.GET:
|
if "roles" in self.request.GET:
|
||||||
if not self.request.GET["roles"]:
|
roles_str = self.request.GET["roles"].replace(' ', '').split(',') if self.request.GET["roles"] else ['0']
|
||||||
return qs.none()
|
|
||||||
roles_str = self.request.GET["roles"].replace(' ', '').split(',')
|
|
||||||
roles_int = map(int, roles_str)
|
roles_int = map(int, roles_str)
|
||||||
qs = qs.filter(roles__in=roles_int)
|
qs = qs.filter(roles__in=roles_int)
|
||||||
|
|
||||||
|
@ -127,7 +127,12 @@ class ConsumerSerializer(serializers.ModelSerializer):
|
|||||||
# If the user has no right to see the note, then we only display the note identifier
|
# If the user has no right to see the note, then we only display the note identifier
|
||||||
return NotePolymorphicSerializer().to_representation(obj.note)\
|
return NotePolymorphicSerializer().to_representation(obj.note)\
|
||||||
if PermissionBackend.check_perm(get_current_authenticated_user(), "note.view_note", obj.note)\
|
if PermissionBackend.check_perm(get_current_authenticated_user(), "note.view_note", obj.note)\
|
||||||
else dict(id=obj.note.id, name=str(obj.note))
|
else dict(
|
||||||
|
id=obj.note.id,
|
||||||
|
name=str(obj.note),
|
||||||
|
is_active=obj.note.is_active,
|
||||||
|
display_image=obj.note.display_image.url,
|
||||||
|
)
|
||||||
|
|
||||||
def get_email_confirmed(self, obj):
|
def get_email_confirmed(self, obj):
|
||||||
if isinstance(obj.note, NoteUser):
|
if isinstance(obj.note, NoteUser):
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
@ -56,8 +57,9 @@ class AliasViewSet(ReadProtectedModelViewSet):
|
|||||||
"""
|
"""
|
||||||
queryset = Alias.objects.all()
|
queryset = Alias.objects.all()
|
||||||
serializer_class = AliasSerializer
|
serializer_class = AliasSerializer
|
||||||
filter_backends = [SearchFilter, OrderingFilter]
|
filter_backends = [SearchFilter, DjangoFilterBackend, OrderingFilter]
|
||||||
search_fields = ['$normalized_name', '$name', '$note__polymorphic_ctype__model', ]
|
search_fields = ['$normalized_name', '$name', '$note__polymorphic_ctype__model', ]
|
||||||
|
filterset_fields = ['note']
|
||||||
ordering_fields = ['name', 'normalized_name']
|
ordering_fields = ['name', 'normalized_name']
|
||||||
|
|
||||||
def get_serializer_class(self):
|
def get_serializer_class(self):
|
||||||
@ -106,8 +108,9 @@ class AliasViewSet(ReadProtectedModelViewSet):
|
|||||||
class ConsumerViewSet(ReadOnlyProtectedModelViewSet):
|
class ConsumerViewSet(ReadOnlyProtectedModelViewSet):
|
||||||
queryset = Alias.objects.all()
|
queryset = Alias.objects.all()
|
||||||
serializer_class = ConsumerSerializer
|
serializer_class = ConsumerSerializer
|
||||||
filter_backends = [SearchFilter, OrderingFilter]
|
filter_backends = [SearchFilter, OrderingFilter, DjangoFilterBackend]
|
||||||
search_fields = ['$normalized_name', '$name', '$note__polymorphic_ctype__model', ]
|
search_fields = ['$normalized_name', '$name', '$note__polymorphic_ctype__model', ]
|
||||||
|
filterset_fields = ['note']
|
||||||
ordering_fields = ['name', 'normalized_name']
|
ordering_fields = ['name', 'normalized_name']
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
@ -116,13 +119,15 @@ class ConsumerViewSet(ReadOnlyProtectedModelViewSet):
|
|||||||
:return: The filtered set of requested aliases
|
:return: The filtered set of requested aliases
|
||||||
"""
|
"""
|
||||||
|
|
||||||
queryset = super().get_queryset()
|
queryset = super().get_queryset().distinct()
|
||||||
# Sqlite doesn't support ORDER BY in subqueries
|
# Sqlite doesn't support ORDER BY in subqueries
|
||||||
queryset = queryset.order_by("username") \
|
queryset = queryset.order_by("name") \
|
||||||
if settings.DATABASES[queryset.db]["ENGINE"] == 'django.db.backends.postgresql' else queryset
|
if settings.DATABASES[queryset.db]["ENGINE"] == 'django.db.backends.postgresql' else queryset
|
||||||
|
|
||||||
alias = self.request.query_params.get("alias", ".*")
|
alias = self.request.query_params.get("alias", None)
|
||||||
queryset = queryset.prefetch_related('note')
|
queryset = queryset.prefetch_related('note')
|
||||||
|
|
||||||
|
if alias:
|
||||||
# We match first an alias if it is matched without normalization,
|
# We match first an alias if it is matched without normalization,
|
||||||
# then if the normalized pattern matches a normalized alias.
|
# then if the normalized pattern matches a normalized alias.
|
||||||
queryset = queryset.filter(
|
queryset = queryset.filter(
|
||||||
@ -140,6 +145,9 @@ class ConsumerViewSet(ReadOnlyProtectedModelViewSet):
|
|||||||
),
|
),
|
||||||
all=True)
|
all=True)
|
||||||
|
|
||||||
|
queryset = queryset if settings.DATABASES[queryset.db]["ENGINE"] == 'django.db.backends.postgresql' \
|
||||||
|
else queryset.order_by("name")
|
||||||
|
|
||||||
return queryset.distinct()
|
return queryset.distinct()
|
||||||
|
|
||||||
|
|
||||||
@ -176,8 +184,11 @@ class TransactionViewSet(ReadProtectedModelViewSet):
|
|||||||
"""
|
"""
|
||||||
queryset = Transaction.objects.order_by("-created_at").all()
|
queryset = Transaction.objects.order_by("-created_at").all()
|
||||||
serializer_class = TransactionPolymorphicSerializer
|
serializer_class = TransactionPolymorphicSerializer
|
||||||
filter_backends = [SearchFilter]
|
filter_backends = [SearchFilter, DjangoFilterBackend, OrderingFilter]
|
||||||
|
filterset_fields = ["source", "source_alias", "destination", "destination_alias", "quantity",
|
||||||
|
"polymorphic_ctype", "amount", "created_at", ]
|
||||||
search_fields = ['$reason', ]
|
search_fields = ['$reason', ]
|
||||||
|
ordering_fields = ['created_at', 'amount']
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save, pre_delete
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from . import signals
|
from . import signals
|
||||||
@ -25,3 +25,8 @@ class NoteConfig(AppConfig):
|
|||||||
signals.save_club_note,
|
signals.save_club_note,
|
||||||
sender='member.Club',
|
sender='member.Club',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pre_delete.connect(
|
||||||
|
signals.delete_transaction,
|
||||||
|
sender='note.transaction',
|
||||||
|
)
|
||||||
|
@ -1,188 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"model": "note.note",
|
|
||||||
"pk": 1,
|
|
||||||
"fields": {
|
|
||||||
"polymorphic_ctype": [
|
|
||||||
"note",
|
|
||||||
"notespecial"
|
|
||||||
],
|
|
||||||
"balance": 0,
|
|
||||||
"last_negative": null,
|
|
||||||
"is_active": true,
|
|
||||||
"display_image": "",
|
|
||||||
"created_at": "2020-02-20T20:02:48.778Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.note",
|
|
||||||
"pk": 2,
|
|
||||||
"fields": {
|
|
||||||
"polymorphic_ctype": [
|
|
||||||
"note",
|
|
||||||
"notespecial"
|
|
||||||
],
|
|
||||||
"balance": 0,
|
|
||||||
"last_negative": null,
|
|
||||||
"is_active": true,
|
|
||||||
"display_image": "",
|
|
||||||
"created_at": "2020-02-20T20:06:39.546Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.note",
|
|
||||||
"pk": 3,
|
|
||||||
"fields": {
|
|
||||||
"polymorphic_ctype": [
|
|
||||||
"note",
|
|
||||||
"notespecial"
|
|
||||||
],
|
|
||||||
"balance": 0,
|
|
||||||
"last_negative": null,
|
|
||||||
"is_active": true,
|
|
||||||
"display_image": "",
|
|
||||||
"created_at": "2020-02-20T20:06:43.049Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.note",
|
|
||||||
"pk": 4,
|
|
||||||
"fields": {
|
|
||||||
"polymorphic_ctype": [
|
|
||||||
"note",
|
|
||||||
"notespecial"
|
|
||||||
],
|
|
||||||
"balance": 0,
|
|
||||||
"last_negative": null,
|
|
||||||
"is_active": true,
|
|
||||||
"display_image": "",
|
|
||||||
"created_at": "2020-02-20T20:06:50.996Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.note",
|
|
||||||
"pk": 5,
|
|
||||||
"fields": {
|
|
||||||
"polymorphic_ctype": [
|
|
||||||
"note",
|
|
||||||
"noteclub"
|
|
||||||
],
|
|
||||||
"balance": 0,
|
|
||||||
"last_negative": null,
|
|
||||||
"is_active": true,
|
|
||||||
"display_image": "pic/default.png",
|
|
||||||
"created_at": "2020-02-20T20:09:38.615Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.note",
|
|
||||||
"pk": 6,
|
|
||||||
"fields": {
|
|
||||||
"polymorphic_ctype": [
|
|
||||||
"note",
|
|
||||||
"noteclub"
|
|
||||||
],
|
|
||||||
"balance": 0,
|
|
||||||
"last_negative": null,
|
|
||||||
"is_active": true,
|
|
||||||
"display_image": "pic/default.png",
|
|
||||||
"created_at": "2020-02-20T20:16:14.753Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.noteclub",
|
|
||||||
"pk": 5,
|
|
||||||
"fields": {
|
|
||||||
"club": 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.noteclub",
|
|
||||||
"pk": 6,
|
|
||||||
"fields": {
|
|
||||||
"club": 2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.notespecial",
|
|
||||||
"pk": 1,
|
|
||||||
"fields": {
|
|
||||||
"special_type": "Esp\u00e8ces"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.notespecial",
|
|
||||||
"pk": 2,
|
|
||||||
"fields": {
|
|
||||||
"special_type": "Carte bancaire"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.notespecial",
|
|
||||||
"pk": 3,
|
|
||||||
"fields": {
|
|
||||||
"special_type": "Ch\u00e8que"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.notespecial",
|
|
||||||
"pk": 4,
|
|
||||||
"fields": {
|
|
||||||
"special_type": "Virement bancaire"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.alias",
|
|
||||||
"pk": 1,
|
|
||||||
"fields": {
|
|
||||||
"name": "Esp\u00e8ces",
|
|
||||||
"normalized_name": "especes",
|
|
||||||
"note": 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.alias",
|
|
||||||
"pk": 2,
|
|
||||||
"fields": {
|
|
||||||
"name": "Carte bancaire",
|
|
||||||
"normalized_name": "cartebancaire",
|
|
||||||
"note": 2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.alias",
|
|
||||||
"pk": 3,
|
|
||||||
"fields": {
|
|
||||||
"name": "Ch\u00e8que",
|
|
||||||
"normalized_name": "cheque",
|
|
||||||
"note": 3
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.alias",
|
|
||||||
"pk": 4,
|
|
||||||
"fields": {
|
|
||||||
"name": "Virement bancaire",
|
|
||||||
"normalized_name": "virementbancaire",
|
|
||||||
"note": 4
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.alias",
|
|
||||||
"pk": 5,
|
|
||||||
"fields": {
|
|
||||||
"name": "BDE",
|
|
||||||
"normalized_name": "bde",
|
|
||||||
"note": 5
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"model": "note.alias",
|
|
||||||
"pk": 6,
|
|
||||||
"fields": {
|
|
||||||
"name": "Kfet",
|
|
||||||
"normalized_name": "kfet",
|
|
||||||
"note": 6
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
209
apps/note/migrations/0001_initial.py
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-04 21:41
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('member', '0001_initial'),
|
||||||
|
('contenttypes', '0002_remove_content_type_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Note',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('balance', models.BigIntegerField(default=0, help_text='in centimes, money credited for this instance', verbose_name='account balance')),
|
||||||
|
('last_negative', models.DateTimeField(blank=True, help_text='last time the balance was negative', null=True, verbose_name='last negative date')),
|
||||||
|
('display_image', models.ImageField(default='pic/default.png', max_length=255, upload_to='pic/', verbose_name='display image')),
|
||||||
|
('created_at', models.DateTimeField(default=django.utils.timezone.now, verbose_name='created at')),
|
||||||
|
('is_active', models.BooleanField(default=True, help_text='Designates whether this note should be treated as active. Unselect this instead of deleting notes.', verbose_name='active')),
|
||||||
|
('inactivity_reason', models.CharField(choices=[('manual', 'The user blocked his/her note manually, eg. when he/she left the school for holidays. It can be reactivated at any time.'), ('forced', "The note is blocked by the the BDE and can't be manually reactivated.")], default=None, max_length=255, null=True)),
|
||||||
|
('polymorphic_ctype', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_note.note_set+', to='contenttypes.ContentType')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'note',
|
||||||
|
'verbose_name_plural': 'notes',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='TemplateCategory',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=31, unique=True, verbose_name='name')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'transaction category',
|
||||||
|
'verbose_name_plural': 'transaction categories',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Transaction',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('source_alias', models.CharField(default='', max_length=255, verbose_name='used alias')),
|
||||||
|
('destination_alias', models.CharField(default='', max_length=255, verbose_name='used alias')),
|
||||||
|
('created_at', models.DateTimeField(default=django.utils.timezone.now, verbose_name='created at')),
|
||||||
|
('quantity', models.PositiveIntegerField(default=1, verbose_name='quantity')),
|
||||||
|
('amount', models.PositiveIntegerField(verbose_name='amount')),
|
||||||
|
('reason', models.CharField(max_length=255, verbose_name='reason')),
|
||||||
|
('valid', models.BooleanField(default=True, verbose_name='valid')),
|
||||||
|
('invalidity_reason', models.CharField(blank=True, default=None, max_length=255, null=True, verbose_name='invalidity reason')),
|
||||||
|
('destination', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='note.Note', verbose_name='destination')),
|
||||||
|
('polymorphic_ctype', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_note.transaction_set+', to='contenttypes.ContentType')),
|
||||||
|
('source', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='note.Note', verbose_name='source')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'transaction',
|
||||||
|
'verbose_name_plural': 'transactions',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='MembershipTransaction',
|
||||||
|
fields=[
|
||||||
|
('transaction_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='note.Transaction')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'membership transaction',
|
||||||
|
'verbose_name_plural': 'membership transactions',
|
||||||
|
},
|
||||||
|
bases=('note.transaction',),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='NoteClub',
|
||||||
|
fields=[
|
||||||
|
('note_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='note.Note')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'club note',
|
||||||
|
'verbose_name_plural': 'clubs notes',
|
||||||
|
},
|
||||||
|
bases=('note.note',),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='NoteSpecial',
|
||||||
|
fields=[
|
||||||
|
('note_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='note.Note')),
|
||||||
|
('special_type', models.CharField(max_length=255, unique=True, verbose_name='type')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'special note',
|
||||||
|
'verbose_name_plural': 'special notes',
|
||||||
|
},
|
||||||
|
bases=('note.note',),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='NoteUser',
|
||||||
|
fields=[
|
||||||
|
('note_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='note.Note')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': "one's note",
|
||||||
|
'verbose_name_plural': 'users note',
|
||||||
|
},
|
||||||
|
bases=('note.note',),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RecurrentTransaction',
|
||||||
|
fields=[
|
||||||
|
('transaction_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='note.Transaction')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'recurrent transaction',
|
||||||
|
'verbose_name_plural': 'recurrent transactions',
|
||||||
|
},
|
||||||
|
bases=('note.transaction',),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SpecialTransaction',
|
||||||
|
fields=[
|
||||||
|
('transaction_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='note.Transaction')),
|
||||||
|
('last_name', models.CharField(max_length=255, verbose_name='name')),
|
||||||
|
('first_name', models.CharField(max_length=255, verbose_name='first_name')),
|
||||||
|
('bank', models.CharField(blank=True, max_length=255, verbose_name='bank')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Special transaction',
|
||||||
|
'verbose_name_plural': 'Special transactions',
|
||||||
|
},
|
||||||
|
bases=('note.transaction',),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Alias',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255, unique=True, verbose_name='name')),
|
||||||
|
('normalized_name', models.CharField(editable=False, max_length=255, unique=True)),
|
||||||
|
('note', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='note.Note')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'alias',
|
||||||
|
'verbose_name_plural': 'aliases',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='TransactionTemplate',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(error_messages={'unique': 'A template with this name already exist'}, max_length=255, unique=True, verbose_name='name')),
|
||||||
|
('amount', models.PositiveIntegerField(verbose_name='amount')),
|
||||||
|
('display', models.BooleanField(default=True, verbose_name='display')),
|
||||||
|
('highlighted', models.BooleanField(default=False, verbose_name='highlighted')),
|
||||||
|
('description', models.CharField(blank=True, max_length=255, verbose_name='description')),
|
||||||
|
('category', models.ForeignKey(max_length=31, on_delete=django.db.models.deletion.PROTECT, related_name='templates', to='note.TemplateCategory', verbose_name='type')),
|
||||||
|
('destination', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='note.NoteClub', verbose_name='destination')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'transaction template',
|
||||||
|
'verbose_name_plural': 'transaction templates',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name='transaction',
|
||||||
|
index=models.Index(fields=['created_at'], name='note_transa_created_bea8b1_idx'),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name='transaction',
|
||||||
|
index=models.Index(fields=['source'], name='note_transa_source__4a1a1e_idx'),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name='transaction',
|
||||||
|
index=models.Index(fields=['destination'], name='note_transa_destina_6e1bb4_idx'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='recurrenttransaction',
|
||||||
|
name='template',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='note.TransactionTemplate'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='noteuser',
|
||||||
|
name='user',
|
||||||
|
field=models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='note', to=settings.AUTH_USER_MODEL, verbose_name='user'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='noteclub',
|
||||||
|
name='club',
|
||||||
|
field=models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='note', to='member.Club', verbose_name='club'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='membershiptransaction',
|
||||||
|
name='membership',
|
||||||
|
field=models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='transaction', to='member.Membership'),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name='alias',
|
||||||
|
index=models.Index(fields=['name'], name='note_alias_name_a89405_idx'),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name='alias',
|
||||||
|
index=models.Index(fields=['normalized_name'], name='note_alias_normali_bd52b4_idx'),
|
||||||
|
),
|
||||||
|
]
|
25
apps/note/migrations/0002_create_special_notes.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def create_special_notes(apps, schema_editor):
|
||||||
|
"""
|
||||||
|
We create the four special note to make transfers.
|
||||||
|
"""
|
||||||
|
NoteSpecial = apps.get_model("note", "notespecial")
|
||||||
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||||
|
polymorphic_ctype_id = ContentType.objects.get_for_model(NoteSpecial).id
|
||||||
|
|
||||||
|
NoteSpecial.objects.get_or_create(id=1, special_type="Espèces", polymorphic_ctype_id=polymorphic_ctype_id)
|
||||||
|
NoteSpecial.objects.get_or_create(id=2, special_type="Carte bancaire", polymorphic_ctype_id=polymorphic_ctype_id)
|
||||||
|
NoteSpecial.objects.get_or_create(id=3, special_type="Chèque", polymorphic_ctype_id=polymorphic_ctype_id)
|
||||||
|
NoteSpecial.objects.get_or_create(id=4, special_type="Virement bancaire", polymorphic_ctype_id=polymorphic_ctype_id)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('note', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(create_special_notes),
|
||||||
|
]
|
17
apps/note/migrations/0003_replace_null_by_blank.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('note', '0002_create_special_notes'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunSQL(
|
||||||
|
"UPDATE note_note SET inactivity_reason = '' WHERE inactivity_reason IS NULL;"
|
||||||
|
),
|
||||||
|
migrations.RunSQL(
|
||||||
|
"UPDATE note_transaction SET invalidity_reason = '' WHERE invalidity_reason IS NULL;"
|
||||||
|
),
|
||||||
|
]
|
23
apps/note/migrations/0004_remove_null_tag_on_charfields.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-06 19:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('note', '0003_replace_null_by_blank'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='note',
|
||||||
|
name='inactivity_reason',
|
||||||
|
field=models.CharField(blank=True, choices=[('manual', 'The user blocked his/her note manually, eg. when he/she left the school for holidays. It can be reactivated at any time.'), ('forced', "The note is blocked by the the BDE and can't be manually reactivated.")], default='', max_length=255),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='transaction',
|
||||||
|
name='invalidity_reason',
|
||||||
|
field=models.CharField(blank=True, default='', max_length=255, verbose_name='invalidity reason'),
|
||||||
|
),
|
||||||
|
]
|
@ -70,8 +70,8 @@ class Note(PolymorphicModel):
|
|||||||
"It can be reactivated at any time.")),
|
"It can be reactivated at any time.")),
|
||||||
('forced', _("The note is blocked by the the BDE and can't be manually reactivated.")),
|
('forced', _("The note is blocked by the the BDE and can't be manually reactivated.")),
|
||||||
],
|
],
|
||||||
null=True,
|
blank=True,
|
||||||
default=None,
|
default="",
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -102,13 +102,19 @@ class Note(PolymorphicModel):
|
|||||||
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
if not Alias.objects.filter(name=str(self)).exists():
|
if not Alias.objects.filter(normalized_name=Alias.normalize(str(self))).exists():
|
||||||
a = Alias(name=str(self))
|
a = Alias(name=str(self))
|
||||||
a.clean()
|
a.clean()
|
||||||
|
|
||||||
# Save alias
|
# Save alias
|
||||||
a.note = self
|
a.note = self
|
||||||
a.save(force_insert=True)
|
a.save(force_insert=True)
|
||||||
|
else:
|
||||||
|
# Check if the name of the note changed without changing the normalized form of the alias
|
||||||
|
alias = Alias.objects.get(normalized_name=Alias.normalize(str(self)))
|
||||||
|
if alias.name != str(self):
|
||||||
|
alias.name = str(self)
|
||||||
|
alias.save()
|
||||||
|
|
||||||
def clean(self, *args, **kwargs):
|
def clean(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -90,6 +90,9 @@ class TransactionTemplate(models.Model):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('note:template_update', args=(self.pk,))
|
return reverse('note:template_update', args=(self.pk,))
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Transaction(PolymorphicModel):
|
class Transaction(PolymorphicModel):
|
||||||
"""
|
"""
|
||||||
@ -150,8 +153,7 @@ class Transaction(PolymorphicModel):
|
|||||||
invalidity_reason = models.CharField(
|
invalidity_reason = models.CharField(
|
||||||
verbose_name=_('invalidity reason'),
|
verbose_name=_('invalidity reason'),
|
||||||
max_length=255,
|
max_length=255,
|
||||||
default=None,
|
default='',
|
||||||
null=True,
|
|
||||||
blank=True,
|
blank=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -173,7 +175,7 @@ class Transaction(PolymorphicModel):
|
|||||||
|
|
||||||
created = self.pk is None
|
created = self.pk is None
|
||||||
to_transfer = self.amount * self.quantity
|
to_transfer = self.amount * self.quantity
|
||||||
if not created:
|
if not created and not self.valid and not hasattr(self, "_force_save"):
|
||||||
# Revert old transaction
|
# Revert old transaction
|
||||||
old_transaction = Transaction.objects.get(pk=self.pk)
|
old_transaction = Transaction.objects.get(pk=self.pk)
|
||||||
# Check that nothing important changed
|
# Check that nothing important changed
|
||||||
@ -195,7 +197,7 @@ class Transaction(PolymorphicModel):
|
|||||||
|
|
||||||
# When a transaction is declared valid, we ensure that the invalidity reason is null, if it was
|
# When a transaction is declared valid, we ensure that the invalidity reason is null, if it was
|
||||||
# previously invalid
|
# previously invalid
|
||||||
self.invalidity_reason = None
|
self.invalidity_reason = ""
|
||||||
|
|
||||||
if source_balance > 9223372036854775807 or source_balance < -9223372036854775808\
|
if source_balance > 9223372036854775807 or source_balance < -9223372036854775808\
|
||||||
or dest_balance > 9223372036854775807 or dest_balance < -9223372036854775808:
|
or dest_balance > 9223372036854775807 or dest_balance < -9223372036854775808:
|
||||||
@ -242,14 +244,6 @@ class Transaction(PolymorphicModel):
|
|||||||
self.destination._force_save = True
|
self.destination._force_save = True
|
||||||
self.destination.save()
|
self.destination.save()
|
||||||
|
|
||||||
def delete(self, **kwargs):
|
|
||||||
"""
|
|
||||||
Whenever we want to delete a transaction (caution with this), we ensure the transaction is invalid first.
|
|
||||||
"""
|
|
||||||
self.valid = False
|
|
||||||
self.save(**kwargs)
|
|
||||||
super().delete(**kwargs)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def total(self):
|
def total(self):
|
||||||
return self.amount * self.quantity
|
return self.amount * self.quantity
|
||||||
@ -356,4 +350,4 @@ class MembershipTransaction(Transaction):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
return _('membership transaction')
|
return _('membership').capitalize()
|
||||||
|
@ -6,7 +6,8 @@ def save_user_note(instance, raw, **_kwargs):
|
|||||||
"""
|
"""
|
||||||
Hook to create and save a note when an user is updated
|
Hook to create and save a note when an user is updated
|
||||||
"""
|
"""
|
||||||
if not raw and (instance.is_superuser or instance.profile.registration_valid):
|
if not raw and (instance.is_superuser or instance.profile.registration_valid)\
|
||||||
|
and not hasattr(instance, "_no_signal"):
|
||||||
# Create note only when the registration is validated
|
# Create note only when the registration is validated
|
||||||
from note.models import NoteUser
|
from note.models import NoteUser
|
||||||
NoteUser.objects.get_or_create(user=instance)
|
NoteUser.objects.get_or_create(user=instance)
|
||||||
@ -17,10 +18,17 @@ def save_club_note(instance, raw, **_kwargs):
|
|||||||
"""
|
"""
|
||||||
Hook to create and save a note when a club is updated
|
Hook to create and save a note when a club is updated
|
||||||
"""
|
"""
|
||||||
if raw:
|
|
||||||
# When provisionning data, do not try to autocreate
|
# When provisionning data, do not try to autocreate
|
||||||
return
|
if not raw and not hasattr(instance, "_no_signal"):
|
||||||
|
|
||||||
from .models import NoteClub
|
from .models import NoteClub
|
||||||
NoteClub.objects.get_or_create(club=instance)
|
NoteClub.objects.get_or_create(club=instance)
|
||||||
instance.note.save()
|
instance.note.save()
|
||||||
|
|
||||||
|
|
||||||
|
def delete_transaction(instance, **_kwargs):
|
||||||
|
"""
|
||||||
|
Whenever we want to delete a transaction (caution with this), we ensure the transaction is invalid first.
|
||||||
|
"""
|
||||||
|
if not hasattr(instance, "_no_signal"):
|
||||||
|
instance.valid = False
|
||||||
|
instance.save()
|
||||||
|
262
apps/note/static/note/js/consos.js
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
// Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// When a transaction is performed, lock the interface to prevent spam clicks.
|
||||||
|
var LOCK = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh the history table on the consumptions page.
|
||||||
|
*/
|
||||||
|
function refreshHistory () {
|
||||||
|
$('#history').load('/note/consos/ #history')
|
||||||
|
$('#most_used').load('/note/consos/ #most_used')
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
// If hash of a category in the URL, then select this category
|
||||||
|
// else select the first one
|
||||||
|
if (location.hash) {
|
||||||
|
$("a[href='" + location.hash + "']").tab('show')
|
||||||
|
} else {
|
||||||
|
$("a[data-toggle='tab']").first().tab('show')
|
||||||
|
}
|
||||||
|
|
||||||
|
// When selecting a category, change URL
|
||||||
|
$(document.body).on('click', "a[data-toggle='tab']", function () {
|
||||||
|
location.hash = this.getAttribute('href')
|
||||||
|
})
|
||||||
|
|
||||||
|
// Switching in double consumptions mode should update the layout
|
||||||
|
$('#double_conso').change(function () {
|
||||||
|
$('#consos_list_div').removeClass('d-none')
|
||||||
|
$('#infos_div').attr('class', 'col-sm-5 col-xl-6')
|
||||||
|
|
||||||
|
const note_list_obj = $('#note_list')
|
||||||
|
if (buttons.length > 0 && note_list_obj.text().length > 0) {
|
||||||
|
$('#consos_list').html(note_list_obj.html())
|
||||||
|
note_list_obj.html('')
|
||||||
|
|
||||||
|
buttons.forEach(function (button) {
|
||||||
|
$('#conso_button_' + button.id).click(function () {
|
||||||
|
if (LOCK) { return }
|
||||||
|
removeNote(button, 'conso_button', buttons, 'consos_list')()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#single_conso').change(function () {
|
||||||
|
$('#consos_list_div').addClass('d-none')
|
||||||
|
$('#infos_div').attr('class', 'col-sm-5 col-md-4')
|
||||||
|
|
||||||
|
const consos_list_obj = $('#consos_list')
|
||||||
|
if (buttons.length > 0) {
|
||||||
|
if (notes_display.length === 0 && consos_list_obj.text().length > 0) {
|
||||||
|
$('#note_list').html(consos_list_obj.html())
|
||||||
|
consos_list_obj.html('')
|
||||||
|
buttons.forEach(function (button) {
|
||||||
|
$('#conso_button_' + button.id).click(function () {
|
||||||
|
if (LOCK) { return }
|
||||||
|
removeNote(button, 'conso_button', buttons, 'note_list')()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
buttons.length = 0
|
||||||
|
consos_list_obj.html('')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Ensure we begin in single consumption. Fix issue with TurboLinks and BootstrapJS
|
||||||
|
$("label[for='double_conso']").removeClass('active')
|
||||||
|
|
||||||
|
$('#consume_all').click(consumeAll)
|
||||||
|
})
|
||||||
|
|
||||||
|
notes = []
|
||||||
|
notes_display = []
|
||||||
|
buttons = []
|
||||||
|
|
||||||
|
// When the user searches an alias, we update the auto-completion
|
||||||
|
autoCompleteNote('note', 'note_list', notes, notes_display,
|
||||||
|
'alias', 'note', 'user_note', 'profile_pic', function () {
|
||||||
|
if (buttons.length > 0 && $('#single_conso').is(':checked')) {
|
||||||
|
consumeAll()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a transaction from a button.
|
||||||
|
* @param dest Where the money goes
|
||||||
|
* @param amount The price of the item
|
||||||
|
* @param type The type of the transaction (content type id for RecurrentTransaction)
|
||||||
|
* @param category_id The category identifier
|
||||||
|
* @param category_name The category name
|
||||||
|
* @param template_id The identifier of the button
|
||||||
|
* @param template_name The name of the button
|
||||||
|
*/
|
||||||
|
function addConso (dest, amount, type, category_id, category_name, template_id, template_name) {
|
||||||
|
var button = null
|
||||||
|
buttons.forEach(function (b) {
|
||||||
|
if (b.id === template_id) {
|
||||||
|
b.quantity += 1
|
||||||
|
button = b
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (button == null) {
|
||||||
|
button = {
|
||||||
|
id: template_id,
|
||||||
|
name: template_name,
|
||||||
|
dest: dest,
|
||||||
|
quantity: 1,
|
||||||
|
amount: amount,
|
||||||
|
type: type,
|
||||||
|
category_id: category_id,
|
||||||
|
category_name: category_name
|
||||||
|
}
|
||||||
|
buttons.push(button)
|
||||||
|
}
|
||||||
|
|
||||||
|
const dc_obj = $('#double_conso')
|
||||||
|
if (dc_obj.is(':checked') || notes_display.length === 0) {
|
||||||
|
const list = dc_obj.is(':checked') ? 'consos_list' : 'note_list'
|
||||||
|
let html = ''
|
||||||
|
buttons.forEach(function (button) {
|
||||||
|
html += li('conso_button_' + button.id, button.name +
|
||||||
|
'<span class="badge badge-dark badge-pill">' + button.quantity + '</span>')
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#' + list).html(html)
|
||||||
|
|
||||||
|
buttons.forEach(function (button) {
|
||||||
|
$('#conso_button_' + button.id).click(function () {
|
||||||
|
if (LOCK) { return }
|
||||||
|
removeNote(button, 'conso_button', buttons, list)()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else { consumeAll() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the page as its initial state.
|
||||||
|
*/
|
||||||
|
function reset () {
|
||||||
|
notes_display.length = 0
|
||||||
|
notes.length = 0
|
||||||
|
buttons.length = 0
|
||||||
|
$('#note_list').html('')
|
||||||
|
$('#consos_list').html('')
|
||||||
|
$('#note').val('')
|
||||||
|
$('#note').attr('data-original-title', '').tooltip('hide')
|
||||||
|
$('#profile_pic').attr('src', '/static/member/img/default_picture.png')
|
||||||
|
$('#profile_pic_link').attr('href', '#')
|
||||||
|
refreshHistory()
|
||||||
|
refreshBalance()
|
||||||
|
LOCK = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply all transactions: all notes in `notes` buy each item in `buttons`
|
||||||
|
*/
|
||||||
|
function consumeAll () {
|
||||||
|
if (LOCK) { return }
|
||||||
|
|
||||||
|
LOCK = true
|
||||||
|
|
||||||
|
let error = false
|
||||||
|
|
||||||
|
if (notes_display.length === 0) {
|
||||||
|
$('#note').addClass('is-invalid')
|
||||||
|
$('#note_list').html(li('', '<strong>Ajoutez des émetteurs.</strong>', 'text-danger'))
|
||||||
|
error = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buttons.length === 0) {
|
||||||
|
$('#consos_list').html(li('', '<strong>Ajoutez des consommations.</strong>', 'text-danger'))
|
||||||
|
error = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
LOCK = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
notes_display.forEach(function (note_display) {
|
||||||
|
buttons.forEach(function (button) {
|
||||||
|
consume(note_display.note, note_display.name, button.dest, button.quantity * note_display.quantity, button.amount,
|
||||||
|
button.name + ' (' + button.category_name + ')', button.type, button.category_id, button.id)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new transaction from a button through the API.
|
||||||
|
* @param source The note that paid the item (type: note)
|
||||||
|
* @param source_alias The alias used for the source (type: str)
|
||||||
|
* @param dest The note that sold the item (type: int)
|
||||||
|
* @param quantity The quantity sold (type: int)
|
||||||
|
* @param amount The price of one item, in cents (type: int)
|
||||||
|
* @param reason The transaction details (type: str)
|
||||||
|
* @param type The type of the transaction (content type id for RecurrentTransaction)
|
||||||
|
* @param category The category id of the button (type: int)
|
||||||
|
* @param template The button id (type: int)
|
||||||
|
*/
|
||||||
|
function consume (source, source_alias, dest, quantity, amount, reason, type, category, template) {
|
||||||
|
$.post('/api/note/transaction/transaction/',
|
||||||
|
{
|
||||||
|
csrfmiddlewaretoken: CSRF_TOKEN,
|
||||||
|
quantity: quantity,
|
||||||
|
amount: amount,
|
||||||
|
reason: reason,
|
||||||
|
valid: true,
|
||||||
|
polymorphic_ctype: type,
|
||||||
|
resourcetype: 'RecurrentTransaction',
|
||||||
|
source: source.id,
|
||||||
|
source_alias: source_alias,
|
||||||
|
destination: dest,
|
||||||
|
template: template
|
||||||
|
})
|
||||||
|
.done(function () {
|
||||||
|
if (!isNaN(source.balance)) {
|
||||||
|
const newBalance = source.balance - quantity * amount
|
||||||
|
if (newBalance <= -5000) {
|
||||||
|
addMsg('Attention, La transaction depuis la note ' + source_alias + ' a été réalisée avec ' +
|
||||||
|
'succès, mais la note émettrice ' + source_alias + ' est en négatif sévère.',
|
||||||
|
'danger', 30000)
|
||||||
|
} else if (newBalance < 0) {
|
||||||
|
addMsg('Attention, La transaction depuis la note ' + source_alias + ' a été réalisée avec ' +
|
||||||
|
'succès, mais la note émettrice ' + source_alias + ' est en négatif.',
|
||||||
|
'warning', 30000)
|
||||||
|
}
|
||||||
|
if (source.membership && source.membership.date_end < new Date().toISOString()) {
|
||||||
|
addMsg('Attention : la note émettrice ' + source.name + " n'est plus adhérente.",
|
||||||
|
'danger', 30000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reset()
|
||||||
|
}).fail(function (e) {
|
||||||
|
$.post('/api/note/transaction/transaction/',
|
||||||
|
{
|
||||||
|
csrfmiddlewaretoken: CSRF_TOKEN,
|
||||||
|
quantity: quantity,
|
||||||
|
amount: amount,
|
||||||
|
reason: reason,
|
||||||
|
valid: false,
|
||||||
|
invalidity_reason: 'Solde insuffisant',
|
||||||
|
polymorphic_ctype: type,
|
||||||
|
resourcetype: 'RecurrentTransaction',
|
||||||
|
source: source,
|
||||||
|
source_alias: source_alias,
|
||||||
|
destination: dest,
|
||||||
|
template: template
|
||||||
|
}).done(function () {
|
||||||
|
reset()
|
||||||
|
addMsg("La transaction n'a pas pu être validée pour cause de solde insuffisant.", 'danger', 10000)
|
||||||
|
}).fail(function () {
|
||||||
|
reset()
|
||||||
|
errMsg(e.responseJSON)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
422
apps/note/static/note/js/transfer.js
Normal file
@ -0,0 +1,422 @@
|
|||||||
|
var LOCK = false
|
||||||
|
|
||||||
|
sources = []
|
||||||
|
sources_notes_display = []
|
||||||
|
dests = []
|
||||||
|
dests_notes_display = []
|
||||||
|
|
||||||
|
function refreshHistory () {
|
||||||
|
$('#history').load('/note/transfer/ #history')
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset (refresh = true) {
|
||||||
|
sources_notes_display.length = 0
|
||||||
|
sources.length = 0
|
||||||
|
dests_notes_display.length = 0
|
||||||
|
dests.length = 0
|
||||||
|
$('#source_note_list').html('')
|
||||||
|
$('#dest_note_list').html('')
|
||||||
|
const source_field = $('#source_note')
|
||||||
|
source_field.val('')
|
||||||
|
const event = jQuery.Event('keyup')
|
||||||
|
event.originalEvent = { charCode: 97 }
|
||||||
|
source_field.trigger(event)
|
||||||
|
source_field.removeClass('is-invalid')
|
||||||
|
source_field.attr('data-original-title', '').tooltip('hide')
|
||||||
|
const dest_field = $('#dest_note')
|
||||||
|
dest_field.val('')
|
||||||
|
dest_field.trigger(event)
|
||||||
|
dest_field.removeClass('is-invalid')
|
||||||
|
dest_field.attr('data-original-title', '').tooltip('hide')
|
||||||
|
const amount_field = $('#amount')
|
||||||
|
amount_field.val('')
|
||||||
|
amount_field.removeClass('is-invalid')
|
||||||
|
$('#amount-required').html('')
|
||||||
|
const reason_field = $('#reason')
|
||||||
|
reason_field.val('')
|
||||||
|
reason_field.removeClass('is-invalid')
|
||||||
|
$('#reason-required').html('')
|
||||||
|
$('#last_name').val('')
|
||||||
|
$('#first_name').val('')
|
||||||
|
$('#bank').val('')
|
||||||
|
$('#user_note').val('')
|
||||||
|
$('#profile_pic').attr('src', '/static/member/img/default_picture.png')
|
||||||
|
$('#profile_pic_link').attr('href', '#')
|
||||||
|
if (refresh) {
|
||||||
|
refreshBalance()
|
||||||
|
refreshHistory()
|
||||||
|
}
|
||||||
|
|
||||||
|
LOCK = false
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
/**
|
||||||
|
* If we are in credit/debit mode, check that only one note is entered.
|
||||||
|
* More over, get first name and last name to autocomplete fields.
|
||||||
|
*/
|
||||||
|
function checkUniqueNote () {
|
||||||
|
if ($('#type_credit').is(':checked') || $('#type_debit').is(':checked')) {
|
||||||
|
const arr = $('#type_credit').is(':checked') ? dests_notes_display : sources_notes_display
|
||||||
|
|
||||||
|
if (arr.length === 0) { return }
|
||||||
|
|
||||||
|
const last = arr[arr.length - 1]
|
||||||
|
arr.length = 0
|
||||||
|
arr.push(last)
|
||||||
|
|
||||||
|
last.quantity = 1
|
||||||
|
|
||||||
|
if (!last.note.user) {
|
||||||
|
$.getJSON('/api/note/note/' + last.note.id + '/?format=json', function (note) {
|
||||||
|
last.note.user = note.user
|
||||||
|
$.getJSON('/api/user/' + last.note.user + '/', function (user) {
|
||||||
|
$('#last_name').val(user.last_name)
|
||||||
|
$('#first_name').val(user.first_name)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
$.getJSON('/api/user/' + last.note.user + '/', function (user) {
|
||||||
|
$('#last_name').val(user.last_name)
|
||||||
|
$('#first_name').val(user.first_name)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
autoCompleteNote('source_note', 'source_note_list', sources, sources_notes_display,
|
||||||
|
'source_alias', 'source_note', 'user_note', 'profile_pic', checkUniqueNote)
|
||||||
|
autoCompleteNote('dest_note', 'dest_note_list', dests, dests_notes_display,
|
||||||
|
'dest_alias', 'dest_note', 'user_note', 'profile_pic', checkUniqueNote)
|
||||||
|
|
||||||
|
const source = $('#source_note')
|
||||||
|
const dest = $('#dest_note')
|
||||||
|
|
||||||
|
$('#type_transfer').change(function () {
|
||||||
|
if (LOCK) { return }
|
||||||
|
|
||||||
|
$('#source_me_div').removeClass('d-none')
|
||||||
|
$('#source_note').removeClass('is-invalid')
|
||||||
|
$('#dest_note').removeClass('is-invalid')
|
||||||
|
$('#special_transaction_div').addClass('d-none')
|
||||||
|
source.removeClass('d-none')
|
||||||
|
$('#source_note_list').removeClass('d-none')
|
||||||
|
$('#credit_type').addClass('d-none')
|
||||||
|
dest.removeClass('d-none')
|
||||||
|
$('#dest_note_list').removeClass('d-none')
|
||||||
|
$('#debit_type').addClass('d-none')
|
||||||
|
|
||||||
|
$('#source_note_label').text(select_emitters_label)
|
||||||
|
$('#dest_note_label').text(select_receveirs_label)
|
||||||
|
|
||||||
|
location.hash = 'transfer'
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#type_credit').change(function () {
|
||||||
|
if (LOCK) { return }
|
||||||
|
|
||||||
|
$('#source_me_div').addClass('d-none')
|
||||||
|
$('#source_note').removeClass('is-invalid')
|
||||||
|
$('#dest_note').removeClass('is-invalid')
|
||||||
|
$('#special_transaction_div').removeClass('d-none')
|
||||||
|
$('#source_note_list').addClass('d-none')
|
||||||
|
$('#dest_note_list').removeClass('d-none')
|
||||||
|
source.addClass('d-none')
|
||||||
|
source.tooltip('hide')
|
||||||
|
$('#credit_type').removeClass('d-none')
|
||||||
|
dest.removeClass('d-none')
|
||||||
|
dest.val('')
|
||||||
|
dest.tooltip('hide')
|
||||||
|
$('#debit_type').addClass('d-none')
|
||||||
|
|
||||||
|
$('#source_note_label').text(transfer_type_label)
|
||||||
|
$('#dest_note_label').text(select_receveir_label)
|
||||||
|
|
||||||
|
if (dests_notes_display.length > 1) {
|
||||||
|
$('#dest_note_list').html('')
|
||||||
|
dests_notes_display.length = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
location.hash = 'credit'
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#type_debit').change(function () {
|
||||||
|
if (LOCK) { return }
|
||||||
|
|
||||||
|
$('#source_me_div').addClass('d-none')
|
||||||
|
$('#source_note').removeClass('is-invalid')
|
||||||
|
$('#dest_note').removeClass('is-invalid')
|
||||||
|
$('#special_transaction_div').removeClass('d-none')
|
||||||
|
$('#source_note_list').removeClass('d-none')
|
||||||
|
$('#dest_note_list').addClass('d-none')
|
||||||
|
source.removeClass('d-none')
|
||||||
|
source.val('')
|
||||||
|
source.tooltip('hide')
|
||||||
|
$('#credit_type').addClass('d-none')
|
||||||
|
dest.addClass('d-none')
|
||||||
|
dest.tooltip('hide')
|
||||||
|
$('#debit_type').removeClass('d-none')
|
||||||
|
|
||||||
|
$('#source_note_label').text(select_emitter_label)
|
||||||
|
$('#dest_note_label').text(transfer_type_label)
|
||||||
|
|
||||||
|
if (sources_notes_display.length > 1) {
|
||||||
|
$('#source_note_list').html('')
|
||||||
|
sources_notes_display.length = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
location.hash = 'debit'
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#credit_type').change(function () {
|
||||||
|
const type = $('#credit_type option:selected').text()
|
||||||
|
if ($('#type_credit').is(':checked')) { source.val(type) } else { dest.val(type) }
|
||||||
|
})
|
||||||
|
|
||||||
|
// Ensure we begin in transfer mode. Removing these lines may cause problems when reloading.
|
||||||
|
const type_transfer = $('#type_transfer') // Default mode
|
||||||
|
type_transfer.removeAttr('checked')
|
||||||
|
$('#type_credit').removeAttr('checked')
|
||||||
|
$('#type_debit').removeAttr('checked')
|
||||||
|
|
||||||
|
if (location.hash) { $('#type_' + location.hash.substr(1)).click() } else { type_transfer.click() }
|
||||||
|
|
||||||
|
$('#source_me').click(function () {
|
||||||
|
if (LOCK) { return }
|
||||||
|
|
||||||
|
// Shortcut to set the current user as the only emitter
|
||||||
|
sources_notes_display.length = 0
|
||||||
|
sources.length = 0
|
||||||
|
$('#source_note_list').html('')
|
||||||
|
|
||||||
|
const source_note = $('#source_note')
|
||||||
|
source_note.focus()
|
||||||
|
source_note.val('')
|
||||||
|
let event = jQuery.Event('keyup')
|
||||||
|
event.originalEvent = { charCode: 97 }
|
||||||
|
source_note.trigger(event)
|
||||||
|
source_note.val(username)
|
||||||
|
event = jQuery.Event('keyup')
|
||||||
|
event.originalEvent = { charCode: 97 }
|
||||||
|
source_note.trigger(event)
|
||||||
|
const fill_note = function () {
|
||||||
|
if (sources.length === 0) {
|
||||||
|
setTimeout(fill_note, 100)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
event = jQuery.Event('keypress')
|
||||||
|
event.originalEvent = { charCode: 13 }
|
||||||
|
source_note.trigger(event)
|
||||||
|
|
||||||
|
source_note.tooltip('hide')
|
||||||
|
source_note.val('')
|
||||||
|
$('#dest_note').focus()
|
||||||
|
}
|
||||||
|
fill_note()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#btn_transfer').click(function () {
|
||||||
|
if (LOCK) { return }
|
||||||
|
|
||||||
|
LOCK = true
|
||||||
|
|
||||||
|
let error = false
|
||||||
|
|
||||||
|
const amount_field = $('#amount')
|
||||||
|
amount_field.removeClass('is-invalid')
|
||||||
|
$('#amount-required').html('')
|
||||||
|
|
||||||
|
const reason_field = $('#reason')
|
||||||
|
reason_field.removeClass('is-invalid')
|
||||||
|
$('#reason-required').html('')
|
||||||
|
|
||||||
|
if (!amount_field.val() || isNaN(amount_field.val()) || amount_field.val() <= 0) {
|
||||||
|
amount_field.addClass('is-invalid')
|
||||||
|
$('#amount-required').html('<strong>Ce champ est requis et doit comporter un nombre décimal strictement positif.</strong>')
|
||||||
|
error = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const amount = Math.floor(100 * amount_field.val())
|
||||||
|
if (amount > 2147483647) {
|
||||||
|
amount_field.addClass('is-invalid')
|
||||||
|
$('#amount-required').html('<strong>Le montant ne doit pas excéder 21474836.47 €.</strong>')
|
||||||
|
error = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reason_field.val()) {
|
||||||
|
reason_field.addClass('is-invalid')
|
||||||
|
$('#reason-required').html('<strong>Ce champ est requis.</strong>')
|
||||||
|
error = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sources_notes_display.length && !$('#type_credit').is(':checked')) {
|
||||||
|
$('#source_note').addClass('is-invalid')
|
||||||
|
error = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dests_notes_display.length && !$('#type_debit').is(':checked')) {
|
||||||
|
$('#dest_note').addClass('is-invalid')
|
||||||
|
error = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
LOCK = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let reason = reason_field.val()
|
||||||
|
|
||||||
|
if ($('#type_transfer').is(':checked')) {
|
||||||
|
// We copy the arrays to ensure that transactions are well-processed even if the form is reset
|
||||||
|
[...sources_notes_display].forEach(function (source) {
|
||||||
|
[...dests_notes_display].forEach(function (dest) {
|
||||||
|
if (source.note.id === dest.note.id) {
|
||||||
|
addMsg('Attention : la transaction de ' + pretty_money(amount) + ' de la note ' + source.name +
|
||||||
|
' vers la note ' + dest.name + " n'a pas été faite car il s'agit de la même note au départ" +
|
||||||
|
" et à l'arrivée.", 'warning', 10000)
|
||||||
|
LOCK = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$.post('/api/note/transaction/transaction/',
|
||||||
|
{
|
||||||
|
csrfmiddlewaretoken: CSRF_TOKEN,
|
||||||
|
quantity: source.quantity * dest.quantity,
|
||||||
|
amount: amount,
|
||||||
|
reason: reason,
|
||||||
|
valid: true,
|
||||||
|
polymorphic_ctype: TRANSFER_POLYMORPHIC_CTYPE,
|
||||||
|
resourcetype: 'Transaction',
|
||||||
|
source: source.note.id,
|
||||||
|
source_alias: source.name,
|
||||||
|
destination: dest.note.id,
|
||||||
|
destination_alias: dest.name
|
||||||
|
}).done(function () {
|
||||||
|
if (source.note.membership && source.note.membership.date_end < new Date().toISOString()) {
|
||||||
|
addMsg('Attention : la note émettrice ' + source.name + " n'est plus adhérente.",
|
||||||
|
'danger', 30000)
|
||||||
|
}
|
||||||
|
if (dest.note.membership && dest.note.membership.date_end < new Date().toISOString()) {
|
||||||
|
addMsg('Attention : la note destination ' + dest.name + " n'est plus adhérente.",
|
||||||
|
'danger', 30000)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isNaN(source.note.balance)) {
|
||||||
|
const newBalance = source.note.balance - source.quantity * dest.quantity * amount
|
||||||
|
if (newBalance <= -5000) {
|
||||||
|
addMsg('Le transfert de ' +
|
||||||
|
pretty_money(source.quantity * dest.quantity * amount) + ' de la note ' +
|
||||||
|
source.name + ' vers la note ' + dest.name + ' a été fait avec succès, ' +
|
||||||
|
'mais la note émettrice est en négatif sévère.', 'danger', 10000)
|
||||||
|
reset()
|
||||||
|
return
|
||||||
|
} else if (newBalance < 0) {
|
||||||
|
addMsg('Le transfert de ' +
|
||||||
|
pretty_money(source.quantity * dest.quantity * amount) + ' de la note ' +
|
||||||
|
source.name + ' vers la note ' + dest.name + ' a été fait avec succès, ' +
|
||||||
|
'mais la note émettrice est en négatif.', 'warning', 10000)
|
||||||
|
reset()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addMsg('Le transfert de ' +
|
||||||
|
pretty_money(source.quantity * dest.quantity * amount) + ' de la note ' + source.name +
|
||||||
|
' vers la note ' + dest.name + ' a été fait avec succès !', 'success', 10000)
|
||||||
|
|
||||||
|
reset()
|
||||||
|
}).fail(function (err) { // do it again but valid = false
|
||||||
|
const errObj = JSON.parse(err.responseText)
|
||||||
|
if (errObj.non_field_errors) {
|
||||||
|
addMsg('Le transfert de ' +
|
||||||
|
pretty_money(source.quantity * dest.quantity * amount) + ' de la note ' + source.name +
|
||||||
|
' vers la note ' + dest.name + ' a échoué : ' + errObj.non_field_errors, 'danger')
|
||||||
|
LOCK = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$.post('/api/note/transaction/transaction/',
|
||||||
|
{
|
||||||
|
csrfmiddlewaretoken: CSRF_TOKEN,
|
||||||
|
quantity: source.quantity * dest.quantity,
|
||||||
|
amount: amount,
|
||||||
|
reason: reason,
|
||||||
|
valid: false,
|
||||||
|
invalidity_reason: 'Solde insuffisant',
|
||||||
|
polymorphic_ctype: TRANSFER_POLYMORPHIC_CTYPE,
|
||||||
|
resourcetype: 'Transaction',
|
||||||
|
source: source.note.id,
|
||||||
|
source_alias: source.name,
|
||||||
|
destination: dest.note.id,
|
||||||
|
destination_alias: dest.name
|
||||||
|
}).done(function () {
|
||||||
|
addMsg('Le transfert de ' +
|
||||||
|
pretty_money(source.quantity * dest.quantity * amount) + ' de la note ' + source.name +
|
||||||
|
' vers la note ' + dest.name + ' a échoué : Solde insuffisant', 'danger', 10000)
|
||||||
|
reset()
|
||||||
|
}).fail(function (err) {
|
||||||
|
const errObj = JSON.parse(err.responseText)
|
||||||
|
let error = errObj.detail ? errObj.detail : errObj.non_field_errors
|
||||||
|
if (!error) { error = err.responseText }
|
||||||
|
addMsg('Le transfert de ' +
|
||||||
|
pretty_money(source.quantity * dest.quantity * amount) + ' de la note ' + source.name +
|
||||||
|
' vers la note ' + dest.name + ' a échoué : ' + error, 'danger')
|
||||||
|
LOCK = false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else if ($('#type_credit').is(':checked') || $('#type_debit').is(':checked')) {
|
||||||
|
let special_note
|
||||||
|
let user_note
|
||||||
|
let alias
|
||||||
|
const given_reason = reason
|
||||||
|
let source_id, dest_id
|
||||||
|
if ($('#type_credit').is(':checked')) {
|
||||||
|
special_note = $('#credit_type').val()
|
||||||
|
user_note = dests_notes_display[0].note
|
||||||
|
alias = dests_notes_display[0].name
|
||||||
|
source_id = special_note
|
||||||
|
dest_id = user_note.id
|
||||||
|
reason = 'Crédit ' + $('#credit_type option:selected').text().toLowerCase()
|
||||||
|
if (given_reason.length > 0) { reason += ' (' + given_reason + ')' }
|
||||||
|
} else {
|
||||||
|
special_note = $('#debit_type').val()
|
||||||
|
user_note = sources_notes_display[0].note
|
||||||
|
alias = sources_notes_display[0].name
|
||||||
|
source_id = user_note.id
|
||||||
|
dest_id = special_note
|
||||||
|
reason = 'Retrait ' + $('#credit_type option:selected').text().toLowerCase()
|
||||||
|
if (given_reason.length > 0) { reason += ' (' + given_reason + ')' }
|
||||||
|
}
|
||||||
|
$.post('/api/note/transaction/transaction/',
|
||||||
|
{
|
||||||
|
csrfmiddlewaretoken: CSRF_TOKEN,
|
||||||
|
quantity: 1,
|
||||||
|
amount: amount,
|
||||||
|
reason: reason,
|
||||||
|
valid: true,
|
||||||
|
polymorphic_ctype: SPECIAL_TRANSFER_POLYMORPHIC_CTYPE,
|
||||||
|
resourcetype: 'SpecialTransaction',
|
||||||
|
source: source_id,
|
||||||
|
source_alias: sources_notes_display.length ? alias : null,
|
||||||
|
destination: dest_id,
|
||||||
|
destination_alias: dests_notes_display.length ? alias : null,
|
||||||
|
last_name: $('#last_name').val(),
|
||||||
|
first_name: $('#first_name').val(),
|
||||||
|
bank: $('#bank').val()
|
||||||
|
}).done(function () {
|
||||||
|
addMsg('Le crédit/retrait a bien été effectué !', 'success', 10000)
|
||||||
|
if (user_note.membership && user_note.membership.date_end < new Date().toISOString()) { addMsg('Attention : la note ' + alias + " n'est plus adhérente.", 'danger', 10000) }
|
||||||
|
reset()
|
||||||
|
}).fail(function (err) {
|
||||||
|
const errObj = JSON.parse(err.responseText)
|
||||||
|
let error = errObj.detail ? errObj.detail : errObj.non_field_errors
|
||||||
|
if (!error) { error = err.responseText }
|
||||||
|
addMsg('Le crédit/retrait a échoué : ' + error, 'danger', 10000)
|
||||||
|
LOCK = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
@ -29,6 +29,7 @@ class HistoryTable(tables.Table):
|
|||||||
source = tables.Column(
|
source = tables.Column(
|
||||||
attrs={
|
attrs={
|
||||||
"td": {
|
"td": {
|
||||||
|
"class": "text-nowrap",
|
||||||
"data-toggle": "tooltip",
|
"data-toggle": "tooltip",
|
||||||
"title": lambda record: _("used alias").capitalize() + " : " + record.source_alias,
|
"title": lambda record: _("used alias").capitalize() + " : " + record.source_alias,
|
||||||
}
|
}
|
||||||
@ -38,15 +39,47 @@ class HistoryTable(tables.Table):
|
|||||||
destination = tables.Column(
|
destination = tables.Column(
|
||||||
attrs={
|
attrs={
|
||||||
"td": {
|
"td": {
|
||||||
|
"class": "text-nowrap",
|
||||||
"data-toggle": "tooltip",
|
"data-toggle": "tooltip",
|
||||||
"title": lambda record: _("used alias").capitalize() + " : " + record.destination_alias,
|
"title": lambda record: _("used alias").capitalize() + " : " + record.destination_alias,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
created_at = tables.DateTimeColumn(
|
||||||
|
format='Y-m-d H:i:s',
|
||||||
|
attrs={
|
||||||
|
"td": {
|
||||||
|
"class": "text-nowrap",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
amount = tables.Column(
|
||||||
|
attrs={
|
||||||
|
"td": {
|
||||||
|
"class": "text-nowrap",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
reason = tables.Column(
|
||||||
|
attrs={
|
||||||
|
"td": {
|
||||||
|
"class": "text-break",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
type = tables.Column()
|
type = tables.Column()
|
||||||
|
|
||||||
total = tables.Column() # will use Transaction.total() !!
|
total = tables.Column( # will use Transaction.total() !!
|
||||||
|
attrs={
|
||||||
|
"td": {
|
||||||
|
"class": "text-nowrap",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
valid = tables.Column(
|
valid = tables.Column(
|
||||||
attrs={
|
attrs={
|
||||||
|
@ -10,22 +10,22 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row mt-4">
|
<div class="row mt-4">
|
||||||
<div class="col-sm-5 col-md-4" id="infos_div">
|
<div class="col-sm-5 col-md-4" id="infos_div">
|
||||||
<div class="row">
|
<div class="row justify-content-center justify-content-md-end">
|
||||||
{# User details column #}
|
{# User details column #}
|
||||||
<div class="col">
|
<div class="col picture-col">
|
||||||
<div class="card bg-light border-success mb-4 text-center">
|
<div class="card bg-light mb-4 text-center">
|
||||||
<a id="profile_pic_link" href="#">
|
<a id="profile_pic_link" href="#">
|
||||||
<img src="/media/pic/default.png"
|
<img src="{% static "member/img/default_picture.png" %}"
|
||||||
id="profile_pic" alt="" class="card-img-top">
|
id="profile_pic" alt="" class="card-img-top d-none d-sm-block">
|
||||||
</a>
|
</a>
|
||||||
<div class="card-body text-center text-break">
|
<div class="card-body text-center text-break p-2">
|
||||||
<span id="user_note"></span>
|
<span id="user_note"><i class="small">{% trans "Please select a note" %}</i></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{# User selection column #}
|
{# User selection column #}
|
||||||
<div class="col-xl-7" id="user_select_div">
|
<div class="col-xl" id="user_select_div">
|
||||||
<div class="card bg-light border-success mb-4">
|
<div class="card bg-light border-success mb-4">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<p class="card-text font-weight-bold">
|
<p class="card-text font-weight-bold">
|
||||||
@ -44,6 +44,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{# Summary of consumption and consume button #}
|
{# Summary of consumption and consume button #}
|
||||||
<div class="col-xl-5 d-none" id="consos_list_div">
|
<div class="col-xl-5 d-none" id="consos_list_div">
|
||||||
<div class="card bg-light border-info mb-4">
|
<div class="card bg-light border-info mb-4">
|
||||||
@ -65,7 +66,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{# Show last used buttons #}
|
{# Show last used buttons #}
|
||||||
<div class="card bg-light mb-4">
|
<div class="card bg-light mb-4">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
@ -159,7 +159,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extrajavascript %}
|
{% block extrajavascript %}
|
||||||
<script type="text/javascript" src="{% static "js/consos.js" %}"></script>
|
<script type="text/javascript" src="{% static "note/js/consos.js" %}"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
{% for button in highlighted %}
|
{% for button in highlighted %}
|
||||||
{% if button.display %}
|
{% if button.display %}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
{% load pretty_money %}
|
{% load pretty_money %}
|
||||||
|
{% load getenv %}
|
||||||
{% load render_table from django_tables2 %}
|
{% load render_table from django_tables2 %}
|
||||||
|
{% load static %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@ -8,13 +10,8 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>[Note Kfet] Rapport de la Note Kfet</title>
|
<title>[Note Kfet] Rapport de la Note Kfet</title>
|
||||||
|
|
||||||
<link rel="stylesheet"
|
<link rel="stylesheet" href="https://{{ "NOTE_URL"|getenv }}{% static "bootstrap4/css/bootstrap.min.css" %}">
|
||||||
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
|
<script src="https://{{ "NOTE_URL"|getenv }}{% static "bootstrap4/js/bootstrap.min.js" %}"></script>
|
||||||
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
|
|
||||||
crossorigin="anonymous">
|
|
||||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
|
|
||||||
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
|
|
||||||
crossorigin="anonymous"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>
|
<p>
|
||||||
@ -27,7 +24,7 @@
|
|||||||
Ensuite, un rapport vous est envoyé à la fréquence demandée seulement si vous avez consommé
|
Ensuite, un rapport vous est envoyé à la fréquence demandée seulement si vous avez consommé
|
||||||
depuis le dernier rapport.<br>
|
depuis le dernier rapport.<br>
|
||||||
Pour arrêter de recevoir des rapports, il vous suffit de modifier votre profil Note et de
|
Pour arrêter de recevoir des rapports, il vous suffit de modifier votre profil Note et de
|
||||||
mettre la fréquence des rapports à 0 ou -1.<br>
|
mettre la fréquence des rapports à 0.<br>
|
||||||
Pour toutes suggestions par rapport à ce service, contactez
|
Pour toutes suggestions par rapport à ce service, contactez
|
||||||
<a href="mailto:notekfet2020@lists.crans.org">notekfet2020@lists.crans.org</a>.
|
<a href="mailto:notekfet2020@lists.crans.org">notekfet2020@lists.crans.org</a>.
|
||||||
</p>
|
</p>
|
||||||
|
32
apps/note/templates/note/mails/weekly_report.txt
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{% load pretty_money %}
|
||||||
|
{% load getenv %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
Bonjour,
|
||||||
|
|
||||||
|
Vous recevez ce mail car vous avez défini une « Fréquence des rapports » dans la Note.
|
||||||
|
Le premier rapport récapitule toutes vos consommations depuis la création de votre compte.
|
||||||
|
Ensuite, un rapport vous est envoyé à la fréquence demandée seulement si vous avez consommé
|
||||||
|
depuis le dernier rapport.
|
||||||
|
Pour arrêter de recevoir des rapports, il vous suffit de modifier votre profil Note et de
|
||||||
|
mettre la fréquence des rapports à 0.
|
||||||
|
Pour toutes suggestions par rapport à ce service, contactez notekfet2020@lists.crans.org.
|
||||||
|
|
||||||
|
Rapport d'activité de {{ user.first_name|safe }} {{ user.last_name|safe }} (note : {{ user|safe }})
|
||||||
|
depuis le {{ last_report }} jusqu'au {{ now }}.
|
||||||
|
|
||||||
|
Dépenses totales : {{ outcoming|pretty_money }}
|
||||||
|
Apports totaux : {{ incoming|pretty_money }}
|
||||||
|
Différentiel : {{ diff|pretty_money }}
|
||||||
|
Nouveau solde : {{ user.note.balance|pretty_money }}
|
||||||
|
|
||||||
|
|
||||||
|
Rapport détaillé :
|
||||||
|
|
||||||
|
| Source | Destination | Créée le | Quantité | Montant | Raison | Type | Total | Valide |
|
||||||
|
+----------------------+----------------------+---------------------+----------+----------+----------------------------------+------------------+----------+---------+
|
||||||
|
{% for tr in last_transactions %}| {{ tr.source|safe|truncatechars:20|center:"20" }} | {{ tr.destination|safe|truncatechars:20|center:"20" }} | {{ tr.created_at|date:"Y-m-d H:i:s" }} | {{ tr.quantity|center:"8" }} | {{ tr.amount|pretty_money|center:"8" }} | {{ tr.reason|safe|truncatechars:32|center:"32" }} | {{ tr.type|safe|center:"16" }} | {{ tr.total|pretty_money|center:"8" }} | {{ tr.valid|yesno|center:"7" }} |
|
||||||
|
{% endfor %}
|
||||||
|
--
|
||||||
|
Le BDE
|
||||||
|
{% trans "Mail generated by the Note Kfet on the" %} {% now "j F Y à H:i:s" %}
|
@ -34,21 +34,21 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div class="row">
|
<div class="row justify-content-center">
|
||||||
{# Preview note profile (picture, username and balance) #}
|
{# Preview note profile (picture, username and balance) #}
|
||||||
<div class="col-md-3" id="note_infos_div">
|
<div class="col-md picture-col" id="note_infos_div">
|
||||||
<div class="card bg-light border-success shadow mb-4">
|
<div class="card bg-light mb-4 text-center">
|
||||||
<a id="profile_pic_link" href="#"><img src="/media/pic/default.png"
|
<a id="profile_pic_link" href="#"><img src="{% static "member/img/default_picture.png" %}"
|
||||||
id="profile_pic" alt="" class="img-fluid rounded mx-auto"></a>
|
id="profile_pic" alt="" class="img-fluid rounded mx-auto"></a>
|
||||||
<div class="card-body text-center">
|
<div class="card-body text-center p-2">
|
||||||
<span id="user_note"></span>
|
<span id="user_note"><i class="small">{% trans "Please select a note" %}</i></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{# list of emitters #}
|
{# list of emitters #}
|
||||||
<div class="col-md-3" id="emitters_div">
|
<div class="col-md-3" id="emitters_div">
|
||||||
<div class="card bg-light border-success shadow mb-4">
|
<div class="card bg-light mb-4">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<p class="card-text font-weight-bold">
|
<p class="card-text font-weight-bold">
|
||||||
<label for="source_note" id="source_note_label">{% trans "Select emitters" %}</label>
|
<label for="source_note" id="source_note_label">{% trans "Select emitters" %}</label>
|
||||||
@ -65,9 +65,9 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
<input class="form-control mx-auto" type="text" id="source_note" placeholder="{% trans "Name or alias..." %}" />
|
<input class="form-control mx-auto" type="text" id="source_note" placeholder="{% trans "Name or alias..." %}" />
|
||||||
<div id="source_me_div">
|
<div id="source_me_div">
|
||||||
<hr>
|
<hr>
|
||||||
<span class="form-control mx-auto btn btn-secondary" id="source_me">
|
<a class="btn-block btn btn-secondary" href="#" id="source_me" data-turbolinks="false">
|
||||||
{% trans "I am the emitter" %}
|
{% trans "I am the emitter" %}
|
||||||
</span>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -75,7 +75,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
|
|
||||||
{# list of receiver #}
|
{# list of receiver #}
|
||||||
<div class="col-md-3" id="dests_div">
|
<div class="col-md-3" id="dests_div">
|
||||||
<div class="card bg-light border-info shadow mb-4">
|
<div class="card bg-light mb-4">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<p class="card-text font-weight-bold" id="dest_title">
|
<p class="card-text font-weight-bold" id="dest_title">
|
||||||
<label for="dest_note" id="dest_note_label">{% trans "Select receivers" %}</label>
|
<label for="dest_note" id="dest_note_label">{% trans "Select receivers" %}</label>
|
||||||
@ -97,8 +97,8 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{# Information on transaction (amount, reason, name,...) #}
|
{# Information on transaction (amount, reason, name,...) #}
|
||||||
<div class="col-md-3" id="external_div">
|
<div class="col-md" id="external_div">
|
||||||
<div class="card bg-light border-warning shadow mb-4">
|
<div class="card bg-light mb-4">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<p class="card-text font-weight-bold">
|
<p class="card-text font-weight-bold">
|
||||||
{% trans "Action" %}
|
{% trans "Action" %}
|
||||||
@ -153,7 +153,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{# transaction history #}
|
{# transaction history #}
|
||||||
<div class="card shadow mb-4" id="history">
|
<div class="card mb-4" id="history">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<p class="card-text font-weight-bold">
|
<p class="card-text font-weight-bold">
|
||||||
{% trans "Recent transactions history" %}
|
{% trans "Recent transactions history" %}
|
||||||
@ -176,5 +176,5 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
|||||||
select_receveirs_label = "{% trans "Select receivers" %}";
|
select_receveirs_label = "{% trans "Select receivers" %}";
|
||||||
transfer_type_label = "{% trans "Transfer type" %}";
|
transfer_type_label = "{% trans "Transfer type" %}";
|
||||||
</script>
|
</script>
|
||||||
<script src="/static/js/transfer.js"></script>
|
<script src="{% static "note/js/transfer.js" %}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -144,7 +144,7 @@ class TransactionTemplateUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, Up
|
|||||||
class ConsoView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
class ConsoView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
||||||
"""
|
"""
|
||||||
The Magic View that make people pay their beer and burgers.
|
The Magic View that make people pay their beer and burgers.
|
||||||
(Most of the magic happens in the dark world of Javascript see `note_kfet/static/js/consos.js`)
|
(Most of the magic happens in the dark world of Javascript see `static/note/js/consos.js`)
|
||||||
"""
|
"""
|
||||||
model = Transaction
|
model = Transaction
|
||||||
template_name = "note/conso_form.html"
|
template_name = "note/conso_form.html"
|
||||||
|
@ -1103,7 +1103,7 @@
|
|||||||
"treasury",
|
"treasury",
|
||||||
"sogecredit"
|
"sogecredit"
|
||||||
],
|
],
|
||||||
"query": "{\"credit_transaction\": null}",
|
"query": "{}",
|
||||||
"type": "add",
|
"type": "add",
|
||||||
"mask": 1,
|
"mask": 1,
|
||||||
"field": "",
|
"field": "",
|
||||||
@ -2567,6 +2567,182 @@
|
|||||||
"description": "(Dé)bloquer sa propre note et modifier la raison"
|
"description": "(Dé)bloquer sa propre note et modifier la raison"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"model": "permission.permission",
|
||||||
|
"pk": 165,
|
||||||
|
"fields": {
|
||||||
|
"model": [
|
||||||
|
"auth",
|
||||||
|
"user"
|
||||||
|
],
|
||||||
|
"query": "{}",
|
||||||
|
"type": "change",
|
||||||
|
"mask": 1,
|
||||||
|
"field": "password",
|
||||||
|
"permanent": true,
|
||||||
|
"description": "Changer son mot de passe"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "permission.permission",
|
||||||
|
"pk": 166,
|
||||||
|
"fields": {
|
||||||
|
"model": [
|
||||||
|
"note",
|
||||||
|
"transaction"
|
||||||
|
],
|
||||||
|
"query": "[\"OR\", {\"source__balance__gte\": {\"F\": [\"SUB\", [\"MUL\", [\"F\", \"amount\"], [\"F\", \"quantity\"]], 5000]}}, {\"valid\": false}]",
|
||||||
|
"type": "add",
|
||||||
|
"mask": 2,
|
||||||
|
"field": "",
|
||||||
|
"permanent": false,
|
||||||
|
"description": "Créer une transaction quelconque tant que la source reste au-dessus de -50 €"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "permission.permission",
|
||||||
|
"pk": 167,
|
||||||
|
"fields": {
|
||||||
|
"model": [
|
||||||
|
"note",
|
||||||
|
"transaction"
|
||||||
|
],
|
||||||
|
"query": "[\"OR\", {\"source__balance__gte\": {\"F\": [\"SUB\", [\"MUL\", [\"F\", \"amount\"], [\"F\", \"quantity\"]], 5000]}, \"valid\": true}, {\"destination__balance__gte\": {\"F\": [\"SUB\", [\"MUL\", [\"F\", \"amount\"], [\"F\", \"quantity\"]], 5000]}, \"valid\": false}]",
|
||||||
|
"type": "change",
|
||||||
|
"mask": 2,
|
||||||
|
"field": "valid",
|
||||||
|
"permanent": false,
|
||||||
|
"description": "Modifier le statut de validation d'une transaction si c'est possible"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "permission.permission",
|
||||||
|
"pk": 168,
|
||||||
|
"fields": {
|
||||||
|
"model": [
|
||||||
|
"note",
|
||||||
|
"transaction"
|
||||||
|
],
|
||||||
|
"query": "[\"OR\", {\"source__balance__gte\": {\"F\": [\"SUB\", [\"MUL\", [\"F\", \"amount\"], [\"F\", \"quantity\"]], 5000]}, \"valid\": true}, {\"destination__balance__gte\": {\"F\": [\"SUB\", [\"MUL\", [\"F\", \"amount\"], [\"F\", \"quantity\"]], 5000]}, \"valid\": false}]",
|
||||||
|
"type": "change",
|
||||||
|
"mask": 2,
|
||||||
|
"field": "invalidity_reason",
|
||||||
|
"permanent": false,
|
||||||
|
"description": "Modifier la raison d'invalidité d'une transaction si c'est possible"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "permission.permission",
|
||||||
|
"pk": 169,
|
||||||
|
"fields": {
|
||||||
|
"model": [
|
||||||
|
"note",
|
||||||
|
"noteclub"
|
||||||
|
],
|
||||||
|
"query": "{\"club\": [\"club\"]}",
|
||||||
|
"type": "change",
|
||||||
|
"mask": 1,
|
||||||
|
"field": "display_image",
|
||||||
|
"permanent": false,
|
||||||
|
"description": "Changer l'image de la note de son club"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "permission.permission",
|
||||||
|
"pk": 170,
|
||||||
|
"fields": {
|
||||||
|
"model": [
|
||||||
|
"note",
|
||||||
|
"alias"
|
||||||
|
],
|
||||||
|
"query": "{\"note__is_active\": true}",
|
||||||
|
"type": "add",
|
||||||
|
"mask": 1,
|
||||||
|
"field": "",
|
||||||
|
"permanent": false,
|
||||||
|
"description": "Ajouter n'importe quel alias à une note non bloquée"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "permission.permission",
|
||||||
|
"pk": 171,
|
||||||
|
"fields": {
|
||||||
|
"model": [
|
||||||
|
"note",
|
||||||
|
"alias"
|
||||||
|
],
|
||||||
|
"query": "{\"note__is_active\": true}",
|
||||||
|
"type": "delete",
|
||||||
|
"mask": 3,
|
||||||
|
"field": "",
|
||||||
|
"permanent": false,
|
||||||
|
"description": "Supprimer n'importe quel alias à une note non bloquée"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "permission.permission",
|
||||||
|
"pk": 172,
|
||||||
|
"fields": {
|
||||||
|
"model": [
|
||||||
|
"treasury",
|
||||||
|
"remittance"
|
||||||
|
],
|
||||||
|
"query": "{}",
|
||||||
|
"type": "view",
|
||||||
|
"mask": 3,
|
||||||
|
"field": "",
|
||||||
|
"permanent": false,
|
||||||
|
"description": "Voir toutes les remises"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "permission.permission",
|
||||||
|
"pk": 173,
|
||||||
|
"fields": {
|
||||||
|
"model": [
|
||||||
|
"treasury",
|
||||||
|
"remittance"
|
||||||
|
],
|
||||||
|
"query": "{}",
|
||||||
|
"type": "add",
|
||||||
|
"mask": 3,
|
||||||
|
"field": "",
|
||||||
|
"permanent": false,
|
||||||
|
"description": "Ajouter une remise"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "permission.permission",
|
||||||
|
"pk": 174,
|
||||||
|
"fields": {
|
||||||
|
"model": [
|
||||||
|
"treasury",
|
||||||
|
"remittance"
|
||||||
|
],
|
||||||
|
"query": "{}",
|
||||||
|
"type": "change",
|
||||||
|
"mask": 3,
|
||||||
|
"field": "",
|
||||||
|
"permanent": false,
|
||||||
|
"description": "Modifier une remise"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "permission.permission",
|
||||||
|
"pk": 175,
|
||||||
|
"fields": {
|
||||||
|
"model": [
|
||||||
|
"treasury",
|
||||||
|
"remittance"
|
||||||
|
],
|
||||||
|
"query": "{}",
|
||||||
|
"type": "delete",
|
||||||
|
"mask": 3,
|
||||||
|
"field": "",
|
||||||
|
"permanent": false,
|
||||||
|
"description": "Supprimer une remise"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"model": "permission.role",
|
"model": "permission.role",
|
||||||
"pk": 1,
|
"pk": 1,
|
||||||
@ -2591,7 +2767,8 @@
|
|||||||
52,
|
52,
|
||||||
126,
|
126,
|
||||||
161,
|
161,
|
||||||
162
|
162,
|
||||||
|
165
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2661,7 +2838,8 @@
|
|||||||
47,
|
47,
|
||||||
49,
|
49,
|
||||||
50,
|
50,
|
||||||
141
|
141,
|
||||||
|
169
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2696,8 +2874,14 @@
|
|||||||
62,
|
62,
|
||||||
127,
|
127,
|
||||||
133,
|
133,
|
||||||
|
135,
|
||||||
|
136,
|
||||||
141,
|
141,
|
||||||
142
|
142,
|
||||||
|
150,
|
||||||
|
166,
|
||||||
|
167,
|
||||||
|
168
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2711,8 +2895,7 @@
|
|||||||
24,
|
24,
|
||||||
25,
|
25,
|
||||||
26,
|
26,
|
||||||
27,
|
27
|
||||||
33
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2763,7 +2946,13 @@
|
|||||||
150,
|
150,
|
||||||
151,
|
151,
|
||||||
163,
|
163,
|
||||||
164
|
164,
|
||||||
|
170,
|
||||||
|
171,
|
||||||
|
172,
|
||||||
|
173,
|
||||||
|
174,
|
||||||
|
175
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2932,7 +3121,18 @@
|
|||||||
161,
|
161,
|
||||||
162,
|
162,
|
||||||
163,
|
163,
|
||||||
164
|
164,
|
||||||
|
165,
|
||||||
|
166,
|
||||||
|
167,
|
||||||
|
168,
|
||||||
|
169,
|
||||||
|
170,
|
||||||
|
171,
|
||||||
|
172,
|
||||||
|
173,
|
||||||
|
174,
|
||||||
|
175
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2944,7 +3144,6 @@
|
|||||||
"name": "GC Kfet",
|
"name": "GC Kfet",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
32,
|
32,
|
||||||
33,
|
|
||||||
56,
|
56,
|
||||||
58,
|
58,
|
||||||
55,
|
55,
|
||||||
@ -2959,7 +3158,13 @@
|
|||||||
29,
|
29,
|
||||||
30,
|
30,
|
||||||
31,
|
31,
|
||||||
143
|
70,
|
||||||
|
143,
|
||||||
|
166,
|
||||||
|
167,
|
||||||
|
168,
|
||||||
|
170,
|
||||||
|
171
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
71
apps/permission/migrations/0001_initial.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-04 21:41
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('member', '0001_initial'),
|
||||||
|
('contenttypes', '0002_remove_content_type_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Permission',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('query', models.TextField(verbose_name='query')),
|
||||||
|
('type', models.CharField(choices=[('add', 'add'), ('view', 'view'), ('change', 'change'), ('delete', 'delete')], max_length=15, verbose_name='type')),
|
||||||
|
('field', models.CharField(blank=True, max_length=255, verbose_name='field')),
|
||||||
|
('permanent', models.BooleanField(default=False, help_text='Tells if the permission should be granted even if the membership of the user is expired.', verbose_name='permanent')),
|
||||||
|
('description', models.CharField(blank=True, max_length=255, verbose_name='description')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'permission',
|
||||||
|
'verbose_name_plural': 'permissions',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='PermissionMask',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('rank', models.PositiveSmallIntegerField(unique=True, verbose_name='rank')),
|
||||||
|
('description', models.CharField(max_length=255, unique=True, verbose_name='description')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'permission mask',
|
||||||
|
'verbose_name_plural': 'permission masks',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Role',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255, verbose_name='name')),
|
||||||
|
('for_club', models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to='member.Club', verbose_name='for club')),
|
||||||
|
('permissions', models.ManyToManyField(to='permission.Permission', verbose_name='permissions')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'role permissions',
|
||||||
|
'verbose_name_plural': 'role permissions',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='permission',
|
||||||
|
name='mask',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='permissions', to='permission.PermissionMask', verbose_name='mask'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='permission',
|
||||||
|
name='model',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='contenttypes.ContentType', verbose_name='model'),
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='permission',
|
||||||
|
unique_together={('model', 'query', 'type', 'field')},
|
||||||
|
),
|
||||||
|
]
|
@ -57,8 +57,8 @@ class InstancedPermission:
|
|||||||
|
|
||||||
# Force insertion, no data verification, no trigger
|
# Force insertion, no data verification, no trigger
|
||||||
obj._force_save = True
|
obj._force_save = True
|
||||||
# We don't want log anything
|
# We don't want to trigger any signal (log, ...)
|
||||||
obj._no_log = True
|
obj._no_signal = True
|
||||||
Model.save(obj, force_insert=True)
|
Model.save(obj, force_insert=True)
|
||||||
ret = self.model.model_class().objects.filter(self.query & Q(pk=0)).exists()
|
ret = self.model.model_class().objects.filter(self.query & Q(pk=0)).exists()
|
||||||
# Delete testing object
|
# Delete testing object
|
||||||
|
@ -14,6 +14,7 @@ class StrongDjangoObjectPermissions(DjangoObjectPermissions):
|
|||||||
This is a simple patch of this class that controls view access.
|
This is a simple patch of this class that controls view access.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# The queryset is filtered, and permissions are more powerful than a simple check than just "can view this model"
|
||||||
perms_map = {
|
perms_map = {
|
||||||
'GET': ['%(app_label)s.view_%(model_name)s'],
|
'GET': ['%(app_label)s.view_%(model_name)s'],
|
||||||
'OPTIONS': [],
|
'OPTIONS': [],
|
||||||
|
@ -28,7 +28,7 @@ def pre_save_object(sender, instance, **kwargs):
|
|||||||
if instance._meta.label_lower in EXCLUDED:
|
if instance._meta.label_lower in EXCLUDED:
|
||||||
return
|
return
|
||||||
|
|
||||||
if hasattr(instance, "_force_save"):
|
if hasattr(instance, "_force_save") or hasattr(instance, "_no_signal"):
|
||||||
return
|
return
|
||||||
|
|
||||||
user = get_current_authenticated_user()
|
user = get_current_authenticated_user()
|
||||||
@ -82,7 +82,8 @@ def pre_delete_object(instance, **kwargs):
|
|||||||
if instance._meta.label_lower in EXCLUDED:
|
if instance._meta.label_lower in EXCLUDED:
|
||||||
return
|
return
|
||||||
|
|
||||||
if hasattr(instance, "_force_delete") or hasattr(instance, "pk") and instance.pk == 0:
|
if hasattr(instance, "_force_delete") or hasattr(instance, "pk") and instance.pk == 0 \
|
||||||
|
or hasattr(instance, "_no_signal"):
|
||||||
# Don't check permissions on force-deleted objects
|
# Don't check permissions on force-deleted objects
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
from json.decoder import JSONDecodeError
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.exceptions import FieldError
|
from django.core.exceptions import FieldError
|
||||||
@ -56,6 +57,7 @@ class PermissionQueryTestCase(TestCase):
|
|||||||
We use a random user with a random WEIClub (to use permissions for the WEI) in a random team in a random bus.
|
We use a random user with a random WEIClub (to use permissions for the WEI) in a random team in a random bus.
|
||||||
"""
|
"""
|
||||||
for perm in Permission.objects.all():
|
for perm in Permission.objects.all():
|
||||||
|
try:
|
||||||
instanced = perm.about(
|
instanced = perm.about(
|
||||||
user=User.objects.get(),
|
user=User.objects.get(),
|
||||||
club=WEIClub.objects.get(),
|
club=WEIClub.objects.get(),
|
||||||
@ -72,13 +74,11 @@ class PermissionQueryTestCase(TestCase):
|
|||||||
now=timezone.now(),
|
now=timezone.now(),
|
||||||
today=date.today(),
|
today=date.today(),
|
||||||
)
|
)
|
||||||
try:
|
|
||||||
instanced.update_query()
|
instanced.update_query()
|
||||||
query = instanced.query
|
query = instanced.query
|
||||||
model = perm.model.model_class()
|
model = perm.model.model_class()
|
||||||
model.objects.filter(query).all()
|
model.objects.filter(query).all()
|
||||||
# print("Good query for permission", perm)
|
except (FieldError, AttributeError, ValueError, TypeError, JSONDecodeError):
|
||||||
except (FieldError, AttributeError, ValueError, TypeError):
|
|
||||||
print("Query error for permission", perm)
|
print("Query error for permission", perm)
|
||||||
print("Query:", perm.query)
|
print("Query:", perm.query)
|
||||||
if instanced.query:
|
if instanced.query:
|
||||||
|
44
apps/permission/tests/test_rights_page.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
from member.models import Membership, Club
|
||||||
|
from permission.models import Role
|
||||||
|
|
||||||
|
|
||||||
|
class TestRightsPage(TestCase):
|
||||||
|
"""
|
||||||
|
Display the rights page.
|
||||||
|
"""
|
||||||
|
fixtures = ("initial",)
|
||||||
|
|
||||||
|
def test_anonymous_rights_page(self):
|
||||||
|
"""
|
||||||
|
Check that we can properly see the rights page even if we are not connected.
|
||||||
|
We can't nethertheless see the club managers.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("permission:rights"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertFalse("special_memberships_table" in response.context)
|
||||||
|
self.assertFalse("superusers" in response.context)
|
||||||
|
|
||||||
|
def test_authenticated_rights_page(self):
|
||||||
|
"""
|
||||||
|
Connect to the note and check that the club mangers are also displayed.
|
||||||
|
"""
|
||||||
|
user = User.objects.create_superuser(
|
||||||
|
username="ploptoto",
|
||||||
|
password="totototo",
|
||||||
|
email="toto@example.com",
|
||||||
|
)
|
||||||
|
self.client.force_login(user)
|
||||||
|
membership = Membership.objects.create(user=user, club=Club.objects.get(name="BDE"))
|
||||||
|
membership.roles.add(Role.objects.get(name="Respo info"))
|
||||||
|
membership.save()
|
||||||
|
|
||||||
|
response = self.client.get(reverse("permission:rights"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertIsNotNone(response.context["special_memberships_table"])
|
||||||
|
self.assertIsNotNone(response.context["superusers"])
|
@ -8,6 +8,7 @@ from django.contrib.auth.models import User
|
|||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.forms import HiddenInput
|
from django.forms import HiddenInput
|
||||||
|
from django.http import Http404
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic import UpdateView, TemplateView, CreateView
|
from django.views.generic import UpdateView, TemplateView, CreateView
|
||||||
from member.models import Membership
|
from member.models import Membership
|
||||||
@ -24,9 +25,20 @@ class ProtectQuerysetMixin:
|
|||||||
Display 404 error if the user can't see an object, remove the fields the user can't
|
Display 404 error if the user can't see an object, remove the fields the user can't
|
||||||
update on an update form (useful if the user can't change only specified fields).
|
update on an update form (useful if the user can't change only specified fields).
|
||||||
"""
|
"""
|
||||||
def get_queryset(self, **kwargs):
|
def get_queryset(self, filter_permissions=True, **kwargs):
|
||||||
qs = super().get_queryset(**kwargs)
|
qs = super().get_queryset(**kwargs)
|
||||||
return qs.filter(PermissionBackend.filter_queryset(self.request.user, qs.model, "view")).distinct()
|
return qs.filter(PermissionBackend.filter_queryset(self.request.user, qs.model, "view")).distinct()\
|
||||||
|
if filter_permissions else qs
|
||||||
|
|
||||||
|
def get_object(self, queryset=None):
|
||||||
|
try:
|
||||||
|
return super().get_object(queryset)
|
||||||
|
except Http404 as e:
|
||||||
|
try:
|
||||||
|
super().get_object(self.get_queryset(filter_permissions=False))
|
||||||
|
raise PermissionDenied()
|
||||||
|
except Http404:
|
||||||
|
raise e
|
||||||
|
|
||||||
def get_form(self, form_class=None):
|
def get_form(self, form_class=None):
|
||||||
form = super().get_form(form_class)
|
form = super().get_form(form_class)
|
||||||
|
@ -17,3 +17,7 @@ Font-Awesome attribution is already done inside SVG files
|
|||||||
-moz-appearance: none;
|
-moz-appearance: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#login-form .asteriskField {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
@ -5,14 +5,29 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="card bg-light">
|
||||||
|
<h3 class="card-header text-center">
|
||||||
|
{{ title }}
|
||||||
|
</h3>
|
||||||
|
<div class="card-body">
|
||||||
{% if validlink %}
|
{% if validlink %}
|
||||||
|
<p>
|
||||||
{% trans "Your email have successfully been validated." %}
|
{% trans "Your email have successfully been validated." %}
|
||||||
|
</p>
|
||||||
{% if user_object.profile.registration_valid %}
|
{% if user_object.profile.registration_valid %}
|
||||||
|
<p>
|
||||||
{% blocktrans %}You can now <a href="{{ login_url }}">log in</a>.{% endblocktrans %}
|
{% blocktrans %}You can now <a href="{{ login_url }}">log in</a>.{% endblocktrans %}
|
||||||
|
</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
<p>
|
||||||
{% trans "You must pay now your membership in the Kfet to complete your registration." %}
|
{% trans "You must pay now your membership in the Kfet to complete your registration." %}
|
||||||
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
<p>
|
||||||
{% trans "The link was invalid. The token may have expired. Please send us an email to activate your account." %}
|
{% trans "The link was invalid. The token may have expired. Please send us an email to activate your account." %}
|
||||||
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -5,13 +5,17 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>{% trans "Account activation" %}</h2>
|
<div class="card bg-light">
|
||||||
|
<h3 class="card-header text-center">
|
||||||
|
{% trans "Account activation" %}
|
||||||
|
</h3>
|
||||||
|
<div class="card-body">
|
||||||
<p>
|
<p>
|
||||||
{% trans "An email has been sent. Please click on the link to activate your account." %}
|
{% trans "An email has been sent. Please click on the link to activate your account." %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{% trans "You must also go to the Kfet to pay your membership. The WEI registration includes the BDE membership." %}
|
{% trans "You must also go to the Kfet to pay your membership." %}
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -27,7 +27,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{% trans "After that, you'll have to wait that someone validates your account before you can log in. You will need to pay your membership in the Kfet. Note that the WEI registration includes the Kfet membership." %}
|
{% trans "After that, you'll have to wait that someone validates your account before you can log in. You will need to pay your membership in the Kfet." %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -8,7 +8,7 @@ https://{{ domain }}{% url 'registration:email_validation' uidb64=uid token=toke
|
|||||||
|
|
||||||
{% trans "This link is only valid for a couple of days, after that you will need to contact us to validate your email." %}
|
{% trans "This link is only valid for a couple of days, after that you will need to contact us to validate your email." %}
|
||||||
|
|
||||||
{% trans "After that, you'll have to wait that someone validates your account before you can log in. You will need to pay your membership in the Kfet. Note that the WEI registration includes the Kfet membership." %}
|
{% trans "After that, you'll have to wait that someone validates your account before you can log in. You will need to pay your membership in the Kfet." %}
|
||||||
|
|
||||||
{% trans "Thanks" %},
|
{% trans "Thanks" %},
|
||||||
|
|
||||||
|
0
apps/registration/tests/__init__.py
Normal file
386
apps/registration/tests/test_registration.py
Normal file
@ -0,0 +1,386 @@
|
|||||||
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.db.models import Q
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils.encoding import force_bytes
|
||||||
|
from django.utils.http import urlsafe_base64_encode
|
||||||
|
from member.models import Club, Membership
|
||||||
|
from note.models import NoteUser, NoteSpecial, Transaction
|
||||||
|
from registration.tokens import email_validation_token
|
||||||
|
from treasury.models import SogeCredit
|
||||||
|
|
||||||
|
"""
|
||||||
|
Check that pre-registrations and validations are working as well.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class TestSignup(TestCase):
|
||||||
|
"""
|
||||||
|
Assume we are a new user.
|
||||||
|
Check that it can pre-register without any problem.
|
||||||
|
"""
|
||||||
|
|
||||||
|
fixtures = ("initial", )
|
||||||
|
|
||||||
|
def test_signup(self):
|
||||||
|
"""
|
||||||
|
A first year member signs up and validates its email address.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("registration:signup"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# Signup
|
||||||
|
response = self.client.post(reverse("registration:signup"), dict(
|
||||||
|
first_name="Toto",
|
||||||
|
last_name="TOTO",
|
||||||
|
username="toto",
|
||||||
|
email="toto@example.com",
|
||||||
|
password1="toto1234",
|
||||||
|
password2="toto1234",
|
||||||
|
phone_number="+33123456789",
|
||||||
|
department="EXT",
|
||||||
|
promotion=Club.objects.get(name="BDE").membership_start.year,
|
||||||
|
address="Earth",
|
||||||
|
paid=False,
|
||||||
|
ml_events_registration="en",
|
||||||
|
ml_sport_registration=True,
|
||||||
|
ml_art_registration=True,
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, reverse("registration:email_validation_sent"), 302, 200)
|
||||||
|
self.assertTrue(User.objects.filter(username="toto").exists())
|
||||||
|
user = User.objects.get(username="toto")
|
||||||
|
# A preregistred user has no note
|
||||||
|
self.assertFalse(NoteUser.objects.filter(user=user).exists())
|
||||||
|
self.assertFalse(user.profile.registration_valid)
|
||||||
|
self.assertFalse(user.profile.email_confirmed)
|
||||||
|
self.assertFalse(user.is_active)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("registration:email_validation_sent"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# Check that the email validation link is valid
|
||||||
|
token = email_validation_token.make_token(user)
|
||||||
|
uid = urlsafe_base64_encode(force_bytes(user.pk))
|
||||||
|
response = self.client.get(reverse("registration:email_validation", kwargs=dict(uidb64=uid, token=token)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
user.profile.refresh_from_db()
|
||||||
|
self.assertTrue(user.profile.email_confirmed)
|
||||||
|
|
||||||
|
# Token has expired
|
||||||
|
response = self.client.get(reverse("registration:email_validation", kwargs=dict(uidb64=uid, token=token)))
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
|
# Uid does not exist
|
||||||
|
response = self.client.get(reverse("registration:email_validation", kwargs=dict(uidb64=0, token="toto")))
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
|
def test_invalid_signup(self):
|
||||||
|
"""
|
||||||
|
Send wrong data and check that it is not valid
|
||||||
|
"""
|
||||||
|
User.objects.create_superuser(
|
||||||
|
first_name="Toto",
|
||||||
|
last_name="TOTO",
|
||||||
|
username="toto",
|
||||||
|
email="toto@example.com",
|
||||||
|
password="toto1234",
|
||||||
|
)
|
||||||
|
|
||||||
|
# The email is already used
|
||||||
|
response = self.client.post(reverse("registration:signup"), dict(
|
||||||
|
first_name="Toto",
|
||||||
|
last_name="TOTO",
|
||||||
|
username="tôtö",
|
||||||
|
email="toto@example.com",
|
||||||
|
password1="toto1234",
|
||||||
|
password2="toto1234",
|
||||||
|
phone_number="+33123456789",
|
||||||
|
department="EXT",
|
||||||
|
promotion=Club.objects.get(name="BDE").membership_start.year,
|
||||||
|
address="Earth",
|
||||||
|
paid=False,
|
||||||
|
ml_events_registration="en",
|
||||||
|
ml_sport_registration=True,
|
||||||
|
ml_art_registration=True,
|
||||||
|
))
|
||||||
|
self.assertTrue(response.status_code, 200)
|
||||||
|
|
||||||
|
# The username is similar to a known alias
|
||||||
|
response = self.client.post(reverse("registration:signup"), dict(
|
||||||
|
first_name="Toto",
|
||||||
|
last_name="TOTO",
|
||||||
|
username="tôtö",
|
||||||
|
email="othertoto@example.com",
|
||||||
|
password1="toto1234",
|
||||||
|
password2="toto1234",
|
||||||
|
phone_number="+33123456789",
|
||||||
|
department="EXT",
|
||||||
|
promotion=Club.objects.get(name="BDE").membership_start.year,
|
||||||
|
address="Earth",
|
||||||
|
paid=False,
|
||||||
|
ml_events_registration="en",
|
||||||
|
ml_sport_registration=True,
|
||||||
|
ml_art_registration=True,
|
||||||
|
))
|
||||||
|
self.assertTrue(response.status_code, 200)
|
||||||
|
|
||||||
|
# The phone number is invalid
|
||||||
|
response = self.client.post(reverse("registration:signup"), dict(
|
||||||
|
first_name="Toto",
|
||||||
|
last_name="TOTO",
|
||||||
|
username="Ihaveanotherusername",
|
||||||
|
email="othertoto@example.com",
|
||||||
|
password1="toto1234",
|
||||||
|
password2="toto1234",
|
||||||
|
phone_number="invalid phone number",
|
||||||
|
department="EXT",
|
||||||
|
promotion=Club.objects.get(name="BDE").membership_start.year,
|
||||||
|
address="Earth",
|
||||||
|
paid=False,
|
||||||
|
ml_events_registration="en",
|
||||||
|
ml_sport_registration=True,
|
||||||
|
ml_art_registration=True,
|
||||||
|
))
|
||||||
|
self.assertTrue(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
|
class TestValidateRegistration(TestCase):
|
||||||
|
"""
|
||||||
|
Test the admin interface to validate users
|
||||||
|
"""
|
||||||
|
|
||||||
|
fixtures = ('initial',)
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.superuser = User.objects.create_superuser(
|
||||||
|
username="admintoto",
|
||||||
|
password="toto1234",
|
||||||
|
email="admin.toto@example.com",
|
||||||
|
)
|
||||||
|
self.client.force_login(self.superuser)
|
||||||
|
|
||||||
|
self.user = User.objects.create(
|
||||||
|
username="toto",
|
||||||
|
first_name="Toto",
|
||||||
|
last_name="TOTO",
|
||||||
|
email="toto@example.com",
|
||||||
|
)
|
||||||
|
|
||||||
|
sess = self.client.session
|
||||||
|
sess["permission_mask"] = 42
|
||||||
|
sess.save()
|
||||||
|
|
||||||
|
def test_future_user_list(self):
|
||||||
|
"""
|
||||||
|
Display the list of pre-registered users
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("registration:future_user_list"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("registration:future_user_list") + "?search=toto")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_invalid_registrations(self):
|
||||||
|
"""
|
||||||
|
Send wrong data and check that errors are detected
|
||||||
|
"""
|
||||||
|
|
||||||
|
# BDE Membership is mandatory
|
||||||
|
response = self.client.post(reverse("registration:future_user_detail", args=(self.user.pk,)), data=dict(
|
||||||
|
soge=False,
|
||||||
|
credit_type=NoteSpecial.objects.get(special_type="Chèque").id,
|
||||||
|
credit_amount=4200,
|
||||||
|
last_name="TOTO",
|
||||||
|
first_name="Toto",
|
||||||
|
bank="Société générale",
|
||||||
|
join_BDE=False,
|
||||||
|
join_Kfet=False,
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue(response.context["form"].errors)
|
||||||
|
|
||||||
|
# Same
|
||||||
|
response = self.client.post(reverse("registration:future_user_detail", args=(self.user.pk,)), data=dict(
|
||||||
|
soge=False,
|
||||||
|
credit_type="",
|
||||||
|
credit_amount=0,
|
||||||
|
last_name="TOTO",
|
||||||
|
first_name="Toto",
|
||||||
|
bank="Société générale",
|
||||||
|
join_BDE=False,
|
||||||
|
join_Kfet=True,
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue(response.context["form"].errors)
|
||||||
|
|
||||||
|
# The BDE membership is not free
|
||||||
|
response = self.client.post(reverse("registration:future_user_detail", args=(self.user.pk,)), data=dict(
|
||||||
|
soge=False,
|
||||||
|
credit_type=NoteSpecial.objects.get(special_type="Espèces").id,
|
||||||
|
credit_amount=0,
|
||||||
|
last_name="TOTO",
|
||||||
|
first_name="Toto",
|
||||||
|
bank="J'ai pas d'argent",
|
||||||
|
join_BDE=True,
|
||||||
|
join_Kfet=True,
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue(response.context["form"].errors)
|
||||||
|
|
||||||
|
# Last and first names are required for a credit
|
||||||
|
response = self.client.post(reverse("registration:future_user_detail", args=(self.user.pk,)), data=dict(
|
||||||
|
soge=False,
|
||||||
|
credit_type=NoteSpecial.objects.get(special_type="Chèque").id,
|
||||||
|
credit_amount=4000,
|
||||||
|
last_name="",
|
||||||
|
first_name="",
|
||||||
|
bank="",
|
||||||
|
join_BDE=True,
|
||||||
|
join_Kfet=True,
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue(response.context["form"].errors)
|
||||||
|
|
||||||
|
# The username admïntoto is too similar with the alias admintoto.
|
||||||
|
# Since the form is valid, the user must update its username.
|
||||||
|
self.user.username = "admïntoto"
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.post(reverse("registration:future_user_detail", args=(self.user.pk,)), data=dict(
|
||||||
|
soge=False,
|
||||||
|
credit_type=NoteSpecial.objects.get(special_type="Chèque").id,
|
||||||
|
credit_amount=500,
|
||||||
|
last_name="TOTO",
|
||||||
|
first_name="Toto",
|
||||||
|
bank="Société générale",
|
||||||
|
join_BDE=True,
|
||||||
|
join_Kfet=False,
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue(response.context["form"].errors)
|
||||||
|
|
||||||
|
def test_validate_bde_registration(self):
|
||||||
|
"""
|
||||||
|
The user wants only to join the BDE. We validate the registration.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("registration:future_user_detail", args=(self.user.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.get(self.user.profile.get_absolute_url())
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
self.user.profile.email_confirmed = True
|
||||||
|
self.user.profile.save()
|
||||||
|
|
||||||
|
response = self.client.post(reverse("registration:future_user_detail", args=(self.user.pk,)), data=dict(
|
||||||
|
soge=False,
|
||||||
|
credit_type=NoteSpecial.objects.get(special_type="Chèque").id,
|
||||||
|
credit_amount=500,
|
||||||
|
last_name="TOTO",
|
||||||
|
first_name="Toto",
|
||||||
|
bank="Société générale",
|
||||||
|
join_BDE=True,
|
||||||
|
join_Kfet=False,
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, self.user.profile.get_absolute_url(), 302, 200)
|
||||||
|
self.user.profile.refresh_from_db()
|
||||||
|
self.assertTrue(self.user.profile.registration_valid)
|
||||||
|
self.assertTrue(NoteUser.objects.filter(user=self.user).exists())
|
||||||
|
self.assertTrue(Membership.objects.filter(club__name="BDE", user=self.user).exists())
|
||||||
|
self.assertFalse(Membership.objects.filter(club__name="Kfet", user=self.user).exists())
|
||||||
|
self.assertFalse(SogeCredit.objects.filter(user=self.user).exists())
|
||||||
|
self.assertEqual(Transaction.objects.filter(
|
||||||
|
Q(source=self.user.note) | Q(destination=self.user.note)).count(), 2)
|
||||||
|
|
||||||
|
response = self.client.get(self.user.profile.get_absolute_url())
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_validate_kfet_registration(self):
|
||||||
|
"""
|
||||||
|
The user joins the BDE and the Kfet.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("registration:future_user_detail", args=(self.user.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.get(self.user.profile.get_absolute_url())
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
self.user.profile.email_confirmed = True
|
||||||
|
self.user.profile.save()
|
||||||
|
|
||||||
|
response = self.client.post(reverse("registration:future_user_detail", args=(self.user.pk,)), data=dict(
|
||||||
|
soge=False,
|
||||||
|
credit_type=NoteSpecial.objects.get(special_type="Espèces").id,
|
||||||
|
credit_amount=4000,
|
||||||
|
last_name="TOTO",
|
||||||
|
first_name="Toto",
|
||||||
|
bank="Société générale",
|
||||||
|
join_BDE=True,
|
||||||
|
join_Kfet=True,
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, self.user.profile.get_absolute_url(), 302, 200)
|
||||||
|
self.user.profile.refresh_from_db()
|
||||||
|
self.assertTrue(self.user.profile.registration_valid)
|
||||||
|
self.assertTrue(NoteUser.objects.filter(user=self.user).exists())
|
||||||
|
self.assertTrue(Membership.objects.filter(club__name="BDE", user=self.user).exists())
|
||||||
|
self.assertTrue(Membership.objects.filter(club__name="Kfet", user=self.user).exists())
|
||||||
|
self.assertFalse(SogeCredit.objects.filter(user=self.user).exists())
|
||||||
|
self.assertEqual(Transaction.objects.filter(
|
||||||
|
Q(source=self.user.note) | Q(destination=self.user.note)).count(), 3)
|
||||||
|
|
||||||
|
response = self.client.get(self.user.profile.get_absolute_url())
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_validate_kfet_registration_with_soge(self):
|
||||||
|
"""
|
||||||
|
The user joins the BDE and the Kfet, but the membership is paid by the Société générale.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("registration:future_user_detail", args=(self.user.pk,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.get(self.user.profile.get_absolute_url())
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
self.user.profile.email_confirmed = True
|
||||||
|
self.user.profile.save()
|
||||||
|
|
||||||
|
response = self.client.post(reverse("registration:future_user_detail", args=(self.user.pk,)), data=dict(
|
||||||
|
soge=True,
|
||||||
|
credit_type=NoteSpecial.objects.get(special_type="Espèces").id,
|
||||||
|
credit_amount=4000,
|
||||||
|
last_name="TOTO",
|
||||||
|
first_name="Toto",
|
||||||
|
bank="Société générale",
|
||||||
|
join_BDE=True,
|
||||||
|
join_Kfet=True,
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, self.user.profile.get_absolute_url(), 302, 200)
|
||||||
|
self.user.profile.refresh_from_db()
|
||||||
|
self.assertTrue(self.user.profile.registration_valid)
|
||||||
|
self.assertTrue(NoteUser.objects.filter(user=self.user).exists())
|
||||||
|
self.assertTrue(Membership.objects.filter(club__name="BDE", user=self.user).exists())
|
||||||
|
self.assertTrue(Membership.objects.filter(club__name="Kfet", user=self.user).exists())
|
||||||
|
self.assertTrue(SogeCredit.objects.filter(user=self.user).exists())
|
||||||
|
self.assertEqual(Transaction.objects.filter(
|
||||||
|
Q(source=self.user.note) | Q(destination=self.user.note)).count(), 3)
|
||||||
|
self.assertFalse(Transaction.objects.filter(valid=True).exists())
|
||||||
|
|
||||||
|
response = self.client.get(self.user.profile.get_absolute_url())
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_invalidate_registration(self):
|
||||||
|
"""
|
||||||
|
Try to invalidate (= delete) pre-registration.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("registration:future_user_invalidate", args=(self.user.pk,)))
|
||||||
|
self.assertRedirects(response, reverse("registration:future_user_list"), 302, 200)
|
||||||
|
self.assertFalse(User.objects.filter(pk=self.user.pk).exists())
|
||||||
|
|
||||||
|
def test_resend_email_validation_link(self):
|
||||||
|
"""
|
||||||
|
Resend email validation linK.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("registration:email_validation_resend", args=(self.user.pk,)))
|
||||||
|
self.assertRedirects(response, reverse("registration:future_user_detail", args=(self.user.pk,)), 302, 200)
|
@ -16,11 +16,12 @@ from django.views.generic.edit import FormMixin
|
|||||||
from django_tables2 import SingleTableView
|
from django_tables2 import SingleTableView
|
||||||
from member.forms import ProfileForm
|
from member.forms import ProfileForm
|
||||||
from member.models import Membership, Club
|
from member.models import Membership, Club
|
||||||
from note.models import SpecialTransaction
|
from note.models import SpecialTransaction, Alias
|
||||||
from note.templatetags.pretty_money import pretty_money
|
from note.templatetags.pretty_money import pretty_money
|
||||||
from permission.backends import PermissionBackend
|
from permission.backends import PermissionBackend
|
||||||
from permission.models import Role
|
from permission.models import Role
|
||||||
from permission.views import ProtectQuerysetMixin
|
from permission.views import ProtectQuerysetMixin
|
||||||
|
from treasury.models import SogeCredit
|
||||||
|
|
||||||
from .forms import SignUpForm, ValidationForm
|
from .forms import SignUpForm, ValidationForm
|
||||||
from .tables import FutureUserTable
|
from .tables import FutureUserTable
|
||||||
@ -101,7 +102,7 @@ class UserValidateView(TemplateView):
|
|||||||
user.profile.email_confirmed = True
|
user.profile.email_confirmed = True
|
||||||
user.save()
|
user.save()
|
||||||
user.profile.save()
|
user.profile.save()
|
||||||
return self.render_to_response(self.get_context_data())
|
return self.render_to_response(self.get_context_data(), status=200 if self.validlink else 400)
|
||||||
|
|
||||||
def get_user(self, uidb64):
|
def get_user(self, uidb64):
|
||||||
"""
|
"""
|
||||||
@ -169,12 +170,9 @@ class FutureUserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableVi
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
qs = super().get_queryset().distinct().filter(profile__registration_valid=False)
|
qs = super().get_queryset().distinct().filter(profile__registration_valid=False)
|
||||||
if "search" in self.request.GET:
|
if "search" in self.request.GET and self.request.GET["search"]:
|
||||||
pattern = self.request.GET["search"]
|
pattern = self.request.GET["search"]
|
||||||
|
|
||||||
if not pattern:
|
|
||||||
return qs.none()
|
|
||||||
|
|
||||||
qs = qs.filter(
|
qs = qs.filter(
|
||||||
Q(first_name__iregex=pattern)
|
Q(first_name__iregex=pattern)
|
||||||
| Q(last_name__iregex=pattern)
|
| Q(last_name__iregex=pattern)
|
||||||
@ -205,10 +203,7 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, FormMixin,
|
|||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
form = self.get_form()
|
form = self.get_form()
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
if form.is_valid():
|
return self.form_valid(form) if form.is_valid() else self.form_invalid(form)
|
||||||
return self.form_valid(form)
|
|
||||||
else:
|
|
||||||
return self.form_invalid(form)
|
|
||||||
|
|
||||||
def get_queryset(self, **kwargs):
|
def get_queryset(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -225,6 +220,9 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, FormMixin,
|
|||||||
fee += bde.membership_fee_paid if user.profile.paid else bde.membership_fee_unpaid
|
fee += bde.membership_fee_paid if user.profile.paid else bde.membership_fee_unpaid
|
||||||
kfet = Club.objects.get(name="Kfet")
|
kfet = Club.objects.get(name="Kfet")
|
||||||
fee += kfet.membership_fee_paid if user.profile.paid else kfet.membership_fee_unpaid
|
fee += kfet.membership_fee_paid if user.profile.paid else kfet.membership_fee_unpaid
|
||||||
|
# In 2020, for COVID-19 reasons, the BDE offered 80 € to each new member that opens a Sogé account,
|
||||||
|
# since there is no WEI.
|
||||||
|
fee += 8000
|
||||||
ctx["total_fee"] = "{:.02f}".format(fee / 100, )
|
ctx["total_fee"] = "{:.02f}".format(fee / 100, )
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
@ -239,6 +237,10 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, FormMixin,
|
|||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
user = self.get_object()
|
user = self.get_object()
|
||||||
|
|
||||||
|
if Alias.objects.filter(normalized_name=Alias.normalize(user.username)).exists():
|
||||||
|
form.add_error(None, _("An alias with a similar name already exists."))
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
# Get form data
|
# Get form data
|
||||||
soge = form.cleaned_data["soge"]
|
soge = form.cleaned_data["soge"]
|
||||||
credit_type = form.cleaned_data["credit_type"]
|
credit_type = form.cleaned_data["credit_type"]
|
||||||
@ -276,9 +278,6 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, FormMixin,
|
|||||||
if credit_type is None:
|
if credit_type is None:
|
||||||
credit_amount = 0
|
credit_amount = 0
|
||||||
|
|
||||||
if join_Kfet and not join_BDE:
|
|
||||||
form.add_error('join_Kfet', _("You must join BDE club before joining Kfet club."))
|
|
||||||
|
|
||||||
if fee > credit_amount and not soge:
|
if fee > credit_amount and not soge:
|
||||||
# Check if the user credits enough money
|
# Check if the user credits enough money
|
||||||
form.add_error('credit_type',
|
form.add_error('credit_type',
|
||||||
@ -347,6 +346,11 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, FormMixin,
|
|||||||
membership.roles.add(Role.objects.get(name="Adhérent Kfet"))
|
membership.roles.add(Role.objects.get(name="Adhérent Kfet"))
|
||||||
membership.save()
|
membership.save()
|
||||||
|
|
||||||
|
if soge:
|
||||||
|
soge_credit = SogeCredit.objects.get(user=user)
|
||||||
|
# Update the credit transaction amount
|
||||||
|
soge_credit.save()
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 1145f75a968999f24f9feb3fc82946aba14fb45d
|
Subproject commit 7e27c3b71b04af0867d5fbe4916e2d1278637599
|
@ -24,9 +24,7 @@ class RemittanceAdmin(admin.ModelAdmin):
|
|||||||
list_display = ('remittance_type', 'date', 'comment', 'count', 'amount', 'closed', )
|
list_display = ('remittance_type', 'date', 'comment', 'count', 'amount', 'closed', )
|
||||||
|
|
||||||
def has_change_permission(self, request, obj=None):
|
def has_change_permission(self, request, obj=None):
|
||||||
if not obj:
|
return not obj or (not obj.closed and super().has_change_permission(request, obj))
|
||||||
return True
|
|
||||||
return not obj.closed and super().has_change_permission(request, obj)
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(SogeCredit, site=admin_site)
|
@admin.register(SogeCredit, site=admin_site)
|
||||||
|
@ -16,7 +16,7 @@ class InvoiceViewSet(ReadProtectedModelViewSet):
|
|||||||
The djangorestframework plugin will get all `Invoice` objects, serialize it to JSON with the given serializer,
|
The djangorestframework plugin will get all `Invoice` objects, serialize it to JSON with the given serializer,
|
||||||
then render it on /api/treasury/invoice/
|
then render it on /api/treasury/invoice/
|
||||||
"""
|
"""
|
||||||
queryset = Invoice.objects.all()
|
queryset = Invoice.objects.order_by("id").all()
|
||||||
serializer_class = InvoiceSerializer
|
serializer_class = InvoiceSerializer
|
||||||
filter_backends = [DjangoFilterBackend]
|
filter_backends = [DjangoFilterBackend]
|
||||||
filterset_fields = ['bde', ]
|
filterset_fields = ['bde', ]
|
||||||
@ -28,7 +28,7 @@ class ProductViewSet(ReadProtectedModelViewSet):
|
|||||||
The djangorestframework plugin will get all `Product` objects, serialize it to JSON with the given serializer,
|
The djangorestframework plugin will get all `Product` objects, serialize it to JSON with the given serializer,
|
||||||
then render it on /api/treasury/product/
|
then render it on /api/treasury/product/
|
||||||
"""
|
"""
|
||||||
queryset = Product.objects.all()
|
queryset = Product.objects.order_by("invoice_id", "id").all()
|
||||||
serializer_class = ProductSerializer
|
serializer_class = ProductSerializer
|
||||||
filter_backends = [SearchFilter]
|
filter_backends = [SearchFilter]
|
||||||
search_fields = ['$designation', ]
|
search_fields = ['$designation', ]
|
||||||
@ -40,7 +40,7 @@ class RemittanceTypeViewSet(ReadProtectedModelViewSet):
|
|||||||
The djangorestframework plugin will get all `RemittanceType` objects, serialize it to JSON with the given serializer
|
The djangorestframework plugin will get all `RemittanceType` objects, serialize it to JSON with the given serializer
|
||||||
then render it on /api/treasury/remittance_type/
|
then render it on /api/treasury/remittance_type/
|
||||||
"""
|
"""
|
||||||
queryset = RemittanceType.objects
|
queryset = RemittanceType.objects.order_by("id")
|
||||||
serializer_class = RemittanceTypeSerializer
|
serializer_class = RemittanceTypeSerializer
|
||||||
|
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class RemittanceViewSet(ReadProtectedModelViewSet):
|
|||||||
The djangorestframework plugin will get all `Remittance` objects, serialize it to JSON with the given serializer,
|
The djangorestframework plugin will get all `Remittance` objects, serialize it to JSON with the given serializer,
|
||||||
then render it on /api/treasury/remittance/
|
then render it on /api/treasury/remittance/
|
||||||
"""
|
"""
|
||||||
queryset = Remittance.objects
|
queryset = Remittance.objects.order_by("id")
|
||||||
serializer_class = RemittanceSerializer
|
serializer_class = RemittanceSerializer
|
||||||
|
|
||||||
|
|
||||||
@ -60,5 +60,5 @@ class SogeCreditViewSet(ReadProtectedModelViewSet):
|
|||||||
The djangorestframework plugin will get all `SogeCredit` objects, serialize it to JSON with the given serializer,
|
The djangorestframework plugin will get all `SogeCredit` objects, serialize it to JSON with the given serializer,
|
||||||
then render it on /api/treasury/soge_credit/
|
then render it on /api/treasury/soge_credit/
|
||||||
"""
|
"""
|
||||||
queryset = SogeCredit.objects
|
queryset = SogeCredit.objects.order_by("id")
|
||||||
serializer_class = SogeCreditSerializer
|
serializer_class = SogeCreditSerializer
|
||||||
|
@ -16,21 +16,15 @@ class InvoiceForm(forms.ModelForm):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
# If the invoice is locked, it can't be updated.
|
||||||
if self.instance and self.instance.locked:
|
if self.instance and self.instance.locked:
|
||||||
for field_name in self.fields:
|
for field_name in self.fields:
|
||||||
self.cleaned_data[field_name] = getattr(self.instance, field_name)
|
self.cleaned_data[field_name] = getattr(self.instance, field_name)
|
||||||
self.errors.clear()
|
self.errors.clear()
|
||||||
|
self.add_error(None, _('This invoice is locked and can no longer be edited.'))
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
return super().clean()
|
return super().clean()
|
||||||
|
|
||||||
def save(self, commit=True):
|
|
||||||
"""
|
|
||||||
If the invoice is locked, don't save it
|
|
||||||
"""
|
|
||||||
if not self.instance.locked:
|
|
||||||
super().save(commit)
|
|
||||||
return self.instance
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Invoice
|
model = Invoice
|
||||||
exclude = ('bde', 'date', 'tex', )
|
exclude = ('bde', 'date', 'tex', )
|
||||||
|
107
apps/treasury/migrations/0001_initial.py
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-04 21:41
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('note', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Invoice',
|
||||||
|
fields=[
|
||||||
|
('id', models.PositiveIntegerField(primary_key=True, serialize=False, verbose_name='Invoice identifier')),
|
||||||
|
('bde', models.CharField(choices=[('Saperlistpopette.png', 'Saper[list]popette'), ('Finalist.png', 'Fina[list]'), ('Listorique.png', '[List]orique'), ('Satellist.png', 'Satel[list]'), ('Monopolist.png', 'Monopo[list]'), ('Kataclist.png', 'Katac[list]')], default='Saperlistpopette.png', max_length=32, verbose_name='BDE')),
|
||||||
|
('object', models.CharField(max_length=255, verbose_name='Object')),
|
||||||
|
('description', models.TextField(verbose_name='Description')),
|
||||||
|
('name', models.CharField(max_length=255, verbose_name='Name')),
|
||||||
|
('address', models.TextField(verbose_name='Address')),
|
||||||
|
('date', models.DateField(default=datetime.date.today, verbose_name='Date')),
|
||||||
|
('acquitted', models.BooleanField(default=False, verbose_name='Acquitted')),
|
||||||
|
('locked', models.BooleanField(default=False, help_text="An invoice can't be edited when it is locked.", verbose_name='Locked')),
|
||||||
|
('tex', models.TextField(default='', verbose_name='tex source')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'invoice',
|
||||||
|
'verbose_name_plural': 'invoices',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Remittance',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Date')),
|
||||||
|
('comment', models.CharField(max_length=255, verbose_name='Comment')),
|
||||||
|
('closed', models.BooleanField(default=False, verbose_name='Closed')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'remittance',
|
||||||
|
'verbose_name_plural': 'remittances',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SpecialTransactionProxy',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('remittance', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='treasury.Remittance', verbose_name='Remittance')),
|
||||||
|
('transaction', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='note.SpecialTransaction')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'special transaction proxy',
|
||||||
|
'verbose_name_plural': 'special transaction proxies',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SogeCredit',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('credit_transaction', models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, to='note.SpecialTransaction', verbose_name='credit transaction')),
|
||||||
|
('transactions', models.ManyToManyField(related_name='_sogecredit_transactions_+', to='note.MembershipTransaction', verbose_name='membership transactions')),
|
||||||
|
('user', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='user')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Credit from the Société générale',
|
||||||
|
'verbose_name_plural': 'Credits from the Société générale',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RemittanceType',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('note', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='note.NoteSpecial')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'remittance type',
|
||||||
|
'verbose_name_plural': 'remittance types',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='remittance',
|
||||||
|
name='remittance_type',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='treasury.RemittanceType', verbose_name='Type'),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Product',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('designation', models.CharField(max_length=255, verbose_name='Designation')),
|
||||||
|
('quantity', models.PositiveIntegerField(verbose_name='Quantity')),
|
||||||
|
('amount', models.IntegerField(verbose_name='Unit price')),
|
||||||
|
('invoice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='products', to='treasury.Invoice', verbose_name='invoice')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'product',
|
||||||
|
'verbose_name_plural': 'products',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 2.2.16 on 2020-09-06 13:43
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('treasury', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoice',
|
||||||
|
name='bde',
|
||||||
|
field=models.CharField(choices=[('Saperlistpopette', 'Saper[list]popette'), ('Finalist', 'Fina[list]'), ('Listorique', '[List]orique'), ('Satellist', 'Satel[list]'), ('Monopolist', 'Monopo[list]'), ('Kataclist', 'Katac[list]')], default='Saperlistpopette', max_length=32, verbose_name='BDE'),
|
||||||
|
),
|
||||||
|
]
|
@ -25,14 +25,14 @@ class Invoice(models.Model):
|
|||||||
|
|
||||||
bde = models.CharField(
|
bde = models.CharField(
|
||||||
max_length=32,
|
max_length=32,
|
||||||
default='Saperlistpopette.png',
|
default='Saperlistpopette',
|
||||||
choices=(
|
choices=(
|
||||||
('Saperlistpopette.png', 'Saper[list]popette'),
|
('Saperlistpopette', 'Saper[list]popette'),
|
||||||
('Finalist.png', 'Fina[list]'),
|
('Finalist', 'Fina[list]'),
|
||||||
('Listorique.png', '[List]orique'),
|
('Listorique', '[List]orique'),
|
||||||
('Satellist.png', 'Satel[list]'),
|
('Satellist', 'Satel[list]'),
|
||||||
('Monopolist.png', 'Monopo[list]'),
|
('Monopolist', 'Monopo[list]'),
|
||||||
('Kataclist.png', 'Katac[list]'),
|
('Kataclist', 'Katac[list]'),
|
||||||
),
|
),
|
||||||
verbose_name=_("BDE"),
|
verbose_name=_("BDE"),
|
||||||
)
|
)
|
||||||
@ -85,7 +85,7 @@ class Invoice(models.Model):
|
|||||||
|
|
||||||
old_invoice = Invoice.objects.filter(id=self.id)
|
old_invoice = Invoice.objects.filter(id=self.id)
|
||||||
if old_invoice.exists():
|
if old_invoice.exists():
|
||||||
if old_invoice.get().locked:
|
if old_invoice.get().locked and not self._force_save:
|
||||||
raise ValidationError(_("This invoice is locked and can no longer be edited."))
|
raise ValidationError(_("This invoice is locked and can no longer be edited."))
|
||||||
|
|
||||||
products = self.products.all()
|
products = self.products.all()
|
||||||
@ -109,6 +109,9 @@ class Invoice(models.Model):
|
|||||||
verbose_name = _("invoice")
|
verbose_name = _("invoice")
|
||||||
verbose_name_plural = _("invoices")
|
verbose_name_plural = _("invoices")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return _("Invoice #{id}").format(id=self.id)
|
||||||
|
|
||||||
|
|
||||||
class Product(models.Model):
|
class Product(models.Model):
|
||||||
"""
|
"""
|
||||||
@ -151,6 +154,9 @@ class Product(models.Model):
|
|||||||
verbose_name = _("product")
|
verbose_name = _("product")
|
||||||
verbose_name_plural = _("products")
|
verbose_name_plural = _("products")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.designation} ({self.invoice})"
|
||||||
|
|
||||||
|
|
||||||
class RemittanceType(models.Model):
|
class RemittanceType(models.Model):
|
||||||
"""
|
"""
|
||||||
@ -224,7 +230,7 @@ class Remittance(models.Model):
|
|||||||
|
|
||||||
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
|
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
|
||||||
# Check if all transactions have the right type.
|
# Check if all transactions have the right type.
|
||||||
if self.transactions.filter(~Q(source=self.remittance_type.note)).exists():
|
if self.transactions.exists() and self.transactions.filter(~Q(source=self.remittance_type.note)).exists():
|
||||||
raise ValidationError("All transactions in a remittance must have the same type")
|
raise ValidationError("All transactions in a remittance must have the same type")
|
||||||
|
|
||||||
return super().save(force_insert, force_update, using, update_fields)
|
return super().save(force_insert, force_update, using, update_fields)
|
||||||
@ -256,6 +262,9 @@ class SpecialTransactionProxy(models.Model):
|
|||||||
verbose_name = _("special transaction proxy")
|
verbose_name = _("special transaction proxy")
|
||||||
verbose_name_plural = _("special transaction proxies")
|
verbose_name_plural = _("special transaction proxies")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.transaction)
|
||||||
|
|
||||||
|
|
||||||
class SogeCredit(models.Model):
|
class SogeCredit(models.Model):
|
||||||
"""
|
"""
|
||||||
@ -282,11 +291,12 @@ class SogeCredit(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def valid(self):
|
def valid(self):
|
||||||
return self.credit_transaction is not None
|
return self.credit_transaction.valid
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def amount(self):
|
def amount(self):
|
||||||
return sum(transaction.total for transaction in self.transactions.all())
|
return self.credit_transaction.total if self.valid \
|
||||||
|
else sum(transaction.total for transaction in self.transactions.all()) + 8000
|
||||||
|
|
||||||
def invalidate(self):
|
def invalidate(self):
|
||||||
"""
|
"""
|
||||||
@ -295,11 +305,7 @@ class SogeCredit(models.Model):
|
|||||||
"""
|
"""
|
||||||
if self.valid:
|
if self.valid:
|
||||||
self.credit_transaction.valid = False
|
self.credit_transaction.valid = False
|
||||||
self.credit_transaction._force_save = True
|
|
||||||
self.credit_transaction.save()
|
self.credit_transaction.save()
|
||||||
self.credit_transaction._force_delete = True
|
|
||||||
self.credit_transaction.delete()
|
|
||||||
self.credit_transaction = None
|
|
||||||
for transaction in self.transactions.all():
|
for transaction in self.transactions.all():
|
||||||
transaction.valid = False
|
transaction.valid = False
|
||||||
transaction._force_save = True
|
transaction._force_save = True
|
||||||
@ -312,17 +318,10 @@ class SogeCredit(models.Model):
|
|||||||
|
|
||||||
# First invalidate all transaction and delete the credit if already did (and force mode)
|
# First invalidate all transaction and delete the credit if already did (and force mode)
|
||||||
self.invalidate()
|
self.invalidate()
|
||||||
self.credit_transaction = SpecialTransaction.objects.create(
|
# Refresh credit amount
|
||||||
source=NoteSpecial.objects.get(special_type="Virement bancaire"),
|
self.save()
|
||||||
destination=self.user.note,
|
self.credit_transaction.valid = True
|
||||||
quantity=1,
|
self.credit_transaction.save()
|
||||||
amount=self.amount,
|
|
||||||
reason="Crédit société générale",
|
|
||||||
last_name=self.user.last_name,
|
|
||||||
first_name=self.user.first_name,
|
|
||||||
bank="Société générale",
|
|
||||||
created_at=self.transactions.order_by("-created_at").first().created_at,
|
|
||||||
)
|
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
for transaction in self.transactions.all():
|
for transaction in self.transactions.all():
|
||||||
@ -331,6 +330,25 @@ class SogeCredit(models.Model):
|
|||||||
transaction.created_at = timezone.now()
|
transaction.created_at = timezone.now()
|
||||||
transaction.save()
|
transaction.save()
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if not self.credit_transaction:
|
||||||
|
self.credit_transaction = SpecialTransaction.objects.create(
|
||||||
|
source=NoteSpecial.objects.get(special_type="Virement bancaire"),
|
||||||
|
destination=self.user.note,
|
||||||
|
quantity=1,
|
||||||
|
amount=0,
|
||||||
|
reason="Crédit société générale",
|
||||||
|
last_name=self.user.last_name,
|
||||||
|
first_name=self.user.first_name,
|
||||||
|
bank="Société générale",
|
||||||
|
valid=False,
|
||||||
|
)
|
||||||
|
elif not self.valid:
|
||||||
|
self.credit_transaction.amount = self.amount
|
||||||
|
self.credit_transaction._force_save = True
|
||||||
|
self.credit_transaction.save()
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def delete(self, **kwargs):
|
def delete(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Deleting a SogeCredit is equivalent to say that the Société générale didn't pay.
|
Deleting a SogeCredit is equivalent to say that the Société générale didn't pay.
|
||||||
@ -349,8 +367,14 @@ class SogeCredit(models.Model):
|
|||||||
transaction.valid = True
|
transaction.valid = True
|
||||||
transaction.created_at = timezone.now()
|
transaction.created_at = timezone.now()
|
||||||
transaction.save()
|
transaction.save()
|
||||||
|
self.credit_transaction.valid = False
|
||||||
|
self.credit_transaction.reason += " (invalide)"
|
||||||
|
self.credit_transaction.save()
|
||||||
super().delete(**kwargs)
|
super().delete(**kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("Credit from the Société générale")
|
verbose_name = _("Credit from the Société générale")
|
||||||
verbose_name_plural = _("Credits from the Société générale")
|
verbose_name_plural = _("Credits from the Société générale")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return _("Soge credit for {user}").format(user=str(self.user))
|
||||||
|
@ -9,6 +9,7 @@ def save_special_transaction(instance, created, **kwargs):
|
|||||||
When a special transaction is created, we create its linked proxy
|
When a special transaction is created, we create its linked proxy
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not hasattr(instance, "_no_signal"):
|
||||||
if instance.is_credit():
|
if instance.is_credit():
|
||||||
if created and RemittanceType.objects.filter(note=instance.source).exists():
|
if created and RemittanceType.objects.filter(note=instance.source).exists():
|
||||||
SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save()
|
SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save()
|
||||||
|
Before Width: | Height: | Size: 752 KiB After Width: | Height: | Size: 752 KiB |
BIN
apps/treasury/static/img/Finalist_bg.jpg
Normal file
After Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 664 KiB After Width: | Height: | Size: 664 KiB |
BIN
apps/treasury/static/img/Kataclist_bg.jpg
Normal file
After Width: | Height: | Size: 45 KiB |