Update to Active Record #647
This commit is contained in:
parent
ec6c7cd623
commit
803ad60544
|
@ -0,0 +1,15 @@
|
|||
Copyright (C) 2010-2013 Openlabs Technologies & Consulting (P) Limited.
|
||||
Copyright (C) 2010 Sharoon Thomas
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://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 <http://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
|
||||
<http://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
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
41
__init__.py
41
__init__.py
|
@ -1,17 +1,32 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
'''
|
||||
trytond_nereid.file
|
||||
from trytond.pool import Pool
|
||||
|
||||
Tryton module to support Nereid
|
||||
from .party import *
|
||||
from .routing import *
|
||||
from .static_file import *
|
||||
from .currency import *
|
||||
from .template import *
|
||||
|
||||
:copyright: (c) 2010 by Sharoon Thomas.
|
||||
:copyright: (c) 2010-2013 by Openlabs Technologies & Consulting (P) Limited.
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
'''
|
||||
import party
|
||||
import routing
|
||||
import static_file
|
||||
import currency
|
||||
import template
|
||||
import lang
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
Address,
|
||||
Party,
|
||||
NereidUser,
|
||||
ContactMechanism,
|
||||
Permission,
|
||||
UserPermission,
|
||||
URLMap,
|
||||
WebSite,
|
||||
URLRule,
|
||||
URLRuleDefaults,
|
||||
WebsiteCountry,
|
||||
WebsiteCurrency,
|
||||
NereidStaticFolder,
|
||||
NereidStaticFile,
|
||||
Currency,
|
||||
ContextProcessors,
|
||||
Language,
|
||||
module='nereid', type_='model'
|
||||
)
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
{
|
||||
'name': 'Nereid',
|
||||
'version': '2.4.0.8dev',
|
||||
'author': 'Openlabs Technologies & Consulting (P) Limited',
|
||||
'email': 'info@openlabs.co.in',
|
||||
'website': 'http://www.openlabs.co.in/',
|
||||
'description': '''Base configuration of Nereid:
|
||||
|
||||
1. Routing: Sites, URL Maps
|
||||
''',
|
||||
'depends': [
|
||||
'ir',
|
||||
'res',
|
||||
'company',
|
||||
],
|
||||
'xml': [
|
||||
'configuration.xml',
|
||||
'static_file.xml',
|
||||
'urls.xml',
|
||||
'party.xml',
|
||||
'lang.xml',
|
||||
],
|
||||
'translation': [
|
||||
],
|
||||
}
|
||||
|
|
@ -23,37 +23,21 @@
|
|||
<menuitem name="Configuration" sequence="10"
|
||||
id="menu_nereid_configuration" parent="menu_nereid" />
|
||||
|
||||
|
||||
<!--Party Address-->
|
||||
<record model="ir.ui.view" id="party_address_view_form_nereid">
|
||||
<field name="model">party.address</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit" ref="party.address_view_form"/>
|
||||
<record model="ir.ui.view" id="lang_view_tree">
|
||||
<field name="model">ir.lang</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="inherit" ref="ir.lang_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<data>
|
||||
<xpath expr="/form/field[@name="subdivision"]"
|
||||
position="after">
|
||||
<newline/>
|
||||
<label name="email"/>
|
||||
<field name="email"/>
|
||||
<label name="phone"/>
|
||||
<field name="phone"/>
|
||||
<newline/>
|
||||
<button string="Create/Reset Web Account"
|
||||
name="create_web_account" type="object"
|
||||
confirm="Do you want to create a web login for this contact?
|
||||
This will send an email with password to user."
|
||||
colspan="3"/>
|
||||
<newline/>
|
||||
<field name="additional_details" colspan="4"/>
|
||||
<data>
|
||||
<xpath expr="/tree/field[@name='active']" position="after">
|
||||
<field name="default_currency"/>
|
||||
</xpath>
|
||||
</data>
|
||||
</data>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- Routing -->
|
||||
<menuitem name="Routing" id="menu_nereid_routing"
|
||||
sequence="10" parent="menu_nereid_configuration" />
|
||||
|
|
44
currency.py
44
currency.py
|
@ -1,30 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
currency
|
||||
|
||||
Currency handling at core level
|
||||
|
||||
:copyright: © 2011-2012 by Openlabs Technologies & Consulting (P) Limited
|
||||
:license: GPLv3, see LICENSE for more details.
|
||||
"""
|
||||
from trytond.model import ModelView, ModelSQL
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from nereid import request
|
||||
|
||||
__all__ = ['Currency', 'Language']
|
||||
|
||||
class Currency(ModelSQL, ModelView):
|
||||
'''Currency Manipulation for core.'''
|
||||
_name = 'currency.currency'
|
||||
__name__ = 'currency.currency'
|
||||
|
||||
def convert(self, amount):
|
||||
@classmethod
|
||||
def convert(cls, amount):
|
||||
"""A helper method which converts the amount from the currency of the
|
||||
company which owns the current website to the currency of the current
|
||||
session.
|
||||
"""
|
||||
return self.compute(
|
||||
request.nereid_website.company.currency.id,
|
||||
return cls.compute(
|
||||
request.nereid_website.company.currency,
|
||||
amount,
|
||||
request.nereid_currency.id)
|
||||
request.nereid_currency
|
||||
)
|
||||
|
||||
def context_processor(self):
|
||||
@classmethod
|
||||
def context_processor(cls):
|
||||
"""Register compute as convert template context function.
|
||||
|
||||
Usage:
|
||||
|
@ -32,8 +30,14 @@ class Currency(ModelSQL, ModelView):
|
|||
Eg: convert
|
||||
"""
|
||||
return {
|
||||
'compute': self.compute,
|
||||
'convert': self.convert
|
||||
}
|
||||
'compute': cls.compute,
|
||||
'convert': cls.convert
|
||||
}
|
||||
|
||||
Currency()
|
||||
|
||||
class Language(ModelSQL, ModelView):
|
||||
__name__ = "ir.lang"
|
||||
|
||||
default_currency = fields.Many2One(
|
||||
'currency.currency', 'Default Currency'
|
||||
)
|
||||
|
|
20
lang.py
20
lang.py
|
@ -1,20 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
lang
|
||||
|
||||
Language
|
||||
|
||||
:copyright: © 2013 by Openlabs Technologies & Consulting (P) Limited
|
||||
:license: GPLv3, see LICENSE for more details.
|
||||
"""
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
|
||||
|
||||
class Language(ModelSQL, ModelView):
|
||||
_name = "ir.lang"
|
||||
|
||||
default_currency = fields.Many2One(
|
||||
'currency.currency', 'Default Currency'
|
||||
)
|
||||
|
||||
Language()
|
24
lang.xml
24
lang.xml
|
@ -1,24 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
This file is part of Tryton & Nereid. The COPYRIGHT file at the
|
||||
top level of this repository contains the full copyright notices
|
||||
and license terms.
|
||||
-->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="lang_view_tree">
|
||||
<field name="model">ir.lang</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="inherit" ref="ir.lang_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<data>
|
||||
<xpath expr="/tree/field[@name='active']" position="after">
|
||||
<field name="default_currency"/>
|
||||
</xpath>
|
||||
</data>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
386
party.py
386
party.py
|
@ -1,18 +1,15 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
'''
|
||||
nereid_trytond.party
|
||||
|
||||
Partner Address is also considered as the login user
|
||||
|
||||
:copyright: (c) 2010 by Sharoon Thomas.
|
||||
:copyright: (c) 2010-2013 by Openlabs Technologies & Consulting (P) Ltd.
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
'''
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import random
|
||||
import string
|
||||
import hashlib
|
||||
import urllib
|
||||
|
||||
try:
|
||||
import hashlib
|
||||
except ImportError:
|
||||
hashlib = None
|
||||
import sha
|
||||
|
||||
import pytz
|
||||
from wtforms import Form, TextField, IntegerField, SelectField, validators, \
|
||||
PasswordField
|
||||
|
@ -32,6 +29,9 @@ from trytond.tools import get_smtp_server
|
|||
|
||||
from .i18n import _, get_translations
|
||||
|
||||
__all__ = ['Address', 'Party', 'NereidUser',
|
||||
'ContactMechanism', 'Permission', 'UserPermission']
|
||||
|
||||
|
||||
class RegistrationForm(Form):
|
||||
"Simple Registration form"
|
||||
|
@ -112,80 +112,18 @@ STATES = {
|
|||
}
|
||||
|
||||
|
||||
# pylint: disable-msg=E1101
|
||||
class AdditionalDetails(ModelSQL, ModelView):
|
||||
"Additional Details for Address"
|
||||
_name = "address.additional_details"
|
||||
_description = __doc__
|
||||
_rec_name = 'value'
|
||||
|
||||
def get_types(self):
|
||||
"""
|
||||
Wrapper to convert _get_types dictionary
|
||||
into a `list of tuple` for the use of Type Selection field
|
||||
|
||||
This hook will scan all methods which start with _type_address_extend
|
||||
|
||||
Your hook extension should look like:
|
||||
|
||||
def _type_address_extend_<name>(self, cursor, user, context=None):
|
||||
return {
|
||||
'<name>': '<value>'
|
||||
}
|
||||
|
||||
An example from ups:
|
||||
|
||||
return {'type': 'value'
|
||||
}
|
||||
|
||||
:return: the list of tuple for Selection field
|
||||
"""
|
||||
type_dict = {}
|
||||
for attribute in dir(self):
|
||||
if attribute.startswith('_type_address_extend'):
|
||||
type_dict.update(getattr(self, attribute).__call__())
|
||||
return type_dict.items()
|
||||
|
||||
type = fields.Selection(
|
||||
'get_types', 'Type', required=True, states=STATES, select=1
|
||||
)
|
||||
value = fields.Char('Value', select=1, states=STATES)
|
||||
comment = fields.Text('Comment', states=STATES)
|
||||
address = fields.Many2One('party.address', 'Address', required=True,
|
||||
ondelete='CASCADE', states=STATES, select=1)
|
||||
active = fields.Boolean('Active', select=1)
|
||||
sequence = fields.Integer('Sequence')
|
||||
|
||||
def default_active(self):
|
||||
return True
|
||||
|
||||
def _type_address_extend_default(self):
|
||||
return {
|
||||
'dob': 'Date of Birth',
|
||||
'other': 'Other',
|
||||
}
|
||||
|
||||
AdditionalDetails()
|
||||
|
||||
|
||||
class Address(ModelSQL, ModelView):
|
||||
"""Party Address"""
|
||||
_name = 'party.address'
|
||||
__name__ = 'party.address'
|
||||
|
||||
registration_form = RegistrationForm
|
||||
|
||||
#: Extra fields to cater to extended registration
|
||||
#: This field is retained only for legacy purposes.
|
||||
#: Additional details is now directly stored on the user object
|
||||
additional_details = fields.One2Many(
|
||||
'address.additional_details',
|
||||
'address', 'Additional Details', states=STATES
|
||||
)
|
||||
email = fields.Char('Email')
|
||||
phone = fields.Char('Phone')
|
||||
|
||||
@classmethod
|
||||
@login_required
|
||||
def edit_address(self, address=None):
|
||||
def edit_address(cls, address=None):
|
||||
"""
|
||||
Create/Edit an Address
|
||||
|
||||
|
@ -204,7 +142,7 @@ class Address(ModelSQL, ModelView):
|
|||
address = None
|
||||
if request.method == 'POST' and form.validate():
|
||||
if address is not None:
|
||||
self.write(address, {
|
||||
cls.write([cls(address)], {
|
||||
'name': form.name.data,
|
||||
'street': form.street.data,
|
||||
'streetbis': form.streetbis.data,
|
||||
|
@ -216,7 +154,7 @@ class Address(ModelSQL, ModelView):
|
|||
'phone': form.phone.data,
|
||||
})
|
||||
else:
|
||||
self.create({
|
||||
cls.create({
|
||||
'name': form.name.data,
|
||||
'street': form.street.data,
|
||||
'streetbis': form.streetbis.data,
|
||||
|
@ -231,7 +169,7 @@ class Address(ModelSQL, ModelView):
|
|||
return redirect(url_for('party.address.view_address'))
|
||||
elif request.method == 'GET' and address:
|
||||
# Its an edit of existing address, prefill data
|
||||
record = self.browse(address)
|
||||
record = cls(address)
|
||||
form = AddressForm(
|
||||
name=record.name,
|
||||
street=record.street,
|
||||
|
@ -246,55 +184,33 @@ class Address(ModelSQL, ModelView):
|
|||
form.country.choices = countries
|
||||
return render_template('address-edit.jinja', form=form, address=address)
|
||||
|
||||
@classmethod
|
||||
@login_required
|
||||
def view_address(self):
|
||||
def view_address(cls):
|
||||
"View the addresses of user"
|
||||
return render_template('address.jinja')
|
||||
|
||||
Address()
|
||||
|
||||
|
||||
class Party(ModelSQL, ModelView):
|
||||
"Party"
|
||||
_name = 'party.party'
|
||||
__name__ = 'party.party'
|
||||
|
||||
nereid_users = fields.One2Many('nereid.user', 'party', 'Nereid Users')
|
||||
|
||||
Party()
|
||||
|
||||
|
||||
class NereidUser(ModelSQL, ModelView):
|
||||
"""
|
||||
Nereid Users
|
||||
"""
|
||||
_name = "nereid.user"
|
||||
_description = __doc__
|
||||
__name__ = "nereid.user"
|
||||
_inherits = {"party.party": 'party'}
|
||||
_rec_name = 'display_name'
|
||||
|
||||
party = fields.Many2One('party.party', 'Party', required=True,
|
||||
ondelete='CASCADE', select=1)
|
||||
|
||||
#: It is recommended to use this field to display the name of the user, as
|
||||
#: the behaviour of how the name of the user will be displayed depends on
|
||||
#: the context (b2b or b2c)
|
||||
#:
|
||||
#: In a b2c context, the nereid_user is the same as party, so the name
|
||||
#: field from nereid_user (inherited from party) will do the job of being
|
||||
#: both the name of the user and of the party (in the context of Tryton)
|
||||
#:
|
||||
#: In a b2b context the party becomes the entity with which Tryton does
|
||||
#: business with and that party could have multiple users. Though the
|
||||
#: data model allows this, the name of the user will be confusing without
|
||||
#: a display name as the default name of the user in the case will be that
|
||||
#: of the company.
|
||||
#:
|
||||
#: The default implementation of display_name uses it for a b2c context
|
||||
#: and is a proxy for the name of the party
|
||||
display_name = fields.Function(
|
||||
fields.Char('Display Name'),
|
||||
'get_display_name', setter='set_display_name',
|
||||
searcher='search_display_name'
|
||||
)
|
||||
display_name = fields.Char('Display Name', required=True)
|
||||
|
||||
#: The email of the user is also the login name/username of the user
|
||||
email = fields.Char("e-Mail", select=1)
|
||||
|
@ -327,17 +243,15 @@ class NereidUser(ModelSQL, ModelView):
|
|||
permissions = fields.Many2Many('nereid.permission-nereid.user',
|
||||
'nereid_user', 'permission', 'Permissions')
|
||||
|
||||
def get_permissions(self, user):
|
||||
def get_permissions(self):
|
||||
"""
|
||||
Returns all the permissions as a list of names
|
||||
|
||||
:param user: Browse Record of the user
|
||||
"""
|
||||
# TODO: Cache this value for each user to avoid hitting the database
|
||||
# everytime.
|
||||
return frozenset([p.value for p in user.permissions])
|
||||
return frozenset([p.value for p in self.permissions])
|
||||
|
||||
def has_permissions(self, nereid_user, permissions):
|
||||
def has_permissions(self, permissions):
|
||||
"""Check if the user has required permissions for access
|
||||
|
||||
:param permissions: A set/frozenset of permission values/keywords
|
||||
|
@ -346,25 +260,28 @@ class NereidUser(ModelSQL, ModelView):
|
|||
"""
|
||||
if not isinstance(permissions, (set, frozenset)):
|
||||
permissions = frozenset(permissions)
|
||||
current_user_permissions = self.get_permissions(nereid_user)
|
||||
current_user_permissions = self.get_permissions()
|
||||
if permissions.issubset(current_user_permissions):
|
||||
return True
|
||||
return False
|
||||
|
||||
def default_timezone(self):
|
||||
@staticmethod
|
||||
def default_timezone():
|
||||
return "UTC"
|
||||
|
||||
def default_company(self):
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company') or False
|
||||
|
||||
def __init__(self):
|
||||
super(NereidUser, self).__init__()
|
||||
self._sql_constraints += [
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(NereidUser, cls).__setup__()
|
||||
cls._sql_constraints += [
|
||||
('unique_email_company', 'UNIQUE(email, company)',
|
||||
'Email must be unique in a company'),
|
||||
]
|
||||
|
||||
def _activate(self, user_id, activation_code):
|
||||
def _activate(self, activation_code):
|
||||
"""
|
||||
Activate the User account
|
||||
|
||||
|
@ -372,38 +289,15 @@ class NereidUser(ModelSQL, ModelView):
|
|||
This method will raise an assertion error if the activation_code is
|
||||
not valid.
|
||||
|
||||
:param user_id: ID of the user
|
||||
:param activation_code: The activation code used
|
||||
:return: True if the activation code was correct
|
||||
"""
|
||||
user = self.browse(user_id)
|
||||
assert user.activation_code == activation_code, \
|
||||
assert self.activation_code == activation_code, \
|
||||
'Invalid Activation Code'
|
||||
return self.write(user.id, {'activation_code': None})
|
||||
return self.write([self], {'activation_code': None})
|
||||
|
||||
def get_display_name(self, ids, name):
|
||||
"""
|
||||
Returns the name of the party as the name of the user
|
||||
|
||||
:param ids: List of ids
|
||||
:param name: Name of the field
|
||||
"""
|
||||
res = {}
|
||||
for user in self.browse(ids):
|
||||
res[user.id] = user.party.name
|
||||
return res
|
||||
|
||||
def set_display_name(self, ids, name, value):
|
||||
"""
|
||||
Do nothing for now as the name field and the display name are the same
|
||||
|
||||
:param ids: List of ids
|
||||
:param name: Name of the field
|
||||
:param value: The value of the field
|
||||
"""
|
||||
return True
|
||||
|
||||
def search_display_name(self, name, clause):
|
||||
@classmethod
|
||||
def search_display_name(cls, name, clause):
|
||||
"""
|
||||
Alter the display_name search pattern to search in the name field
|
||||
|
||||
|
@ -412,7 +306,8 @@ class NereidUser(ModelSQL, ModelView):
|
|||
"""
|
||||
return [('name') + clause[1:]]
|
||||
|
||||
def get_registration_form(self):
|
||||
@staticmethod
|
||||
def get_registration_form():
|
||||
"""
|
||||
Returns a registration form for use in the site
|
||||
|
||||
|
@ -433,14 +328,15 @@ class NereidUser(ModelSQL, ModelView):
|
|||
|
||||
return registration_form
|
||||
|
||||
def registration(self):
|
||||
@classmethod
|
||||
def registration(cls):
|
||||
"""
|
||||
Invokes registration of an user
|
||||
"""
|
||||
registration_form = self.get_registration_form()
|
||||
registration_form = cls.get_registration_form()
|
||||
|
||||
if request.method == 'POST' and registration_form.validate():
|
||||
existing = self.search([
|
||||
existing = cls.search([
|
||||
('email', '=', request.form['email']),
|
||||
('company', '=', request.nereid_website.company.id),
|
||||
])
|
||||
|
@ -449,17 +345,16 @@ class NereidUser(ModelSQL, ModelView):
|
|||
'Please contact customer care')
|
||||
)
|
||||
else:
|
||||
user_id = self.create({
|
||||
nereid_user = cls.create({
|
||||
'name': registration_form.name.data,
|
||||
'display_name': registration_form.name.data,
|
||||
'email': registration_form.email.data,
|
||||
'password': registration_form.password.data,
|
||||
'company': request.nereid_website.company.id,
|
||||
})
|
||||
self.create_act_code(user_id)
|
||||
registration.send(user_id)
|
||||
user = self.browse(user_id)
|
||||
self.send_activation_email(user)
|
||||
nereid_user.create_act_code()
|
||||
registration.send(nereid_user)
|
||||
nereid_user.send_activation_email()
|
||||
flash(
|
||||
_('Registration Complete. Check your email for activation')
|
||||
)
|
||||
|
@ -469,26 +364,27 @@ class NereidUser(ModelSQL, ModelView):
|
|||
|
||||
return render_template('registration.jinja', form=registration_form)
|
||||
|
||||
def send_activation_email(self, nereid_user):
|
||||
def send_activation_email(self):
|
||||
"""
|
||||
Send an activation email to the user
|
||||
|
||||
:param nereid_user: The browse record of the user
|
||||
"""
|
||||
email_message = render_email(
|
||||
CONFIG['smtp_from'], nereid_user.email, _('Account Activation'),
|
||||
CONFIG['smtp_from'], self.email, _('Account Activation'),
|
||||
text_template = 'emails/activation-text.jinja',
|
||||
html_template = 'emails/activation-html.jinja',
|
||||
nereid_user = nereid_user
|
||||
nereid_user = self
|
||||
)
|
||||
server = get_smtp_server()
|
||||
server.sendmail(
|
||||
CONFIG['smtp_from'], [nereid_user.email], email_message.as_string()
|
||||
CONFIG['smtp_from'], [self.email], email_message.as_string()
|
||||
)
|
||||
server.quit()
|
||||
|
||||
@classmethod
|
||||
@login_required
|
||||
def change_password(self):
|
||||
def change_password(cls):
|
||||
"""
|
||||
Changes the password
|
||||
|
||||
|
@ -499,18 +395,9 @@ class NereidUser(ModelSQL, ModelView):
|
|||
form = ChangePasswordForm(request.form)
|
||||
|
||||
if request.method == 'POST' and form.validate():
|
||||
user = request.nereid_user
|
||||
|
||||
# Confirm the current password
|
||||
password = form.old_password.data
|
||||
password += user.salt or ''
|
||||
if isinstance(password, unicode):
|
||||
password = password.encode('utf-8')
|
||||
password_sha = hashlib.sha1(password).hexdigest()
|
||||
|
||||
if password_sha == user.password:
|
||||
self.write(
|
||||
request.nereid_user.id,
|
||||
if request.nereid_user.match_password(form.old_password.data):
|
||||
cls.write(
|
||||
[request.nereid_user],
|
||||
{'password': form.password.data}
|
||||
)
|
||||
flash(
|
||||
|
@ -526,8 +413,9 @@ class NereidUser(ModelSQL, ModelView):
|
|||
'change-password.jinja', change_password_form=form
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@login_required
|
||||
def new_password(self):
|
||||
def new_password(cls):
|
||||
"""Create a new password
|
||||
|
||||
.. tip::
|
||||
|
@ -549,8 +437,8 @@ class NereidUser(ModelSQL, ModelView):
|
|||
current_app.logger.debug('New password not allowed in session')
|
||||
abort(403)
|
||||
|
||||
self.write(
|
||||
request.nereid_user.id,
|
||||
cls.write(
|
||||
[request.nereid_user],
|
||||
{'password': form.password.data}
|
||||
)
|
||||
session.pop('allow_new_password')
|
||||
|
@ -562,19 +450,19 @@ class NereidUser(ModelSQL, ModelView):
|
|||
|
||||
return render_template('new-password.jinja', password_form=form)
|
||||
|
||||
def activate(self, user_id, activation_code):
|
||||
def activate(self, activation_code):
|
||||
"""A web request handler for activation
|
||||
|
||||
:param activation_code: A 12 character activation code indicates reset
|
||||
while 16 character activation code indicates a new registration
|
||||
"""
|
||||
try:
|
||||
self._activate(user_id, activation_code)
|
||||
self._activate(activation_code)
|
||||
except AssertionError:
|
||||
flash(_('Invalid Activation Code'))
|
||||
else:
|
||||
# Log the user in since the activation code is correct
|
||||
session['user'] = user_id
|
||||
session['user'] = self.id
|
||||
|
||||
# Redirect the user to the correct location according to the type
|
||||
# of activation code.
|
||||
|
@ -587,7 +475,7 @@ class NereidUser(ModelSQL, ModelView):
|
|||
|
||||
return redirect(url_for('nereid.website.login'))
|
||||
|
||||
def create_act_code(self, user_id, code_type="new"):
|
||||
def create_act_code(self, code_type="new"):
|
||||
"""Create activation code
|
||||
|
||||
A 12 character activation code indicates reset while 16
|
||||
|
@ -603,9 +491,10 @@ class NereidUser(ModelSQL, ModelView):
|
|||
act_code = ''.join(
|
||||
random.sample(string.letters + string.digits, length)
|
||||
)
|
||||
return self.write(user_id, {'activation_code': act_code})
|
||||
return self.write([self], {'activation_code': act_code})
|
||||
|
||||
def reset_account(self):
|
||||
@classmethod
|
||||
def reset_account(cls):
|
||||
"""
|
||||
Reset the password for the user.
|
||||
|
||||
|
@ -615,7 +504,7 @@ class NereidUser(ModelSQL, ModelView):
|
|||
the link, he can change his password.
|
||||
"""
|
||||
if request.method == 'POST':
|
||||
user_ids = self.search([
|
||||
user_ids = cls.search([
|
||||
('email', '=', request.form['email']),
|
||||
('company', '=', request.nereid_website.company.id),
|
||||
])
|
||||
|
@ -624,34 +513,52 @@ class NereidUser(ModelSQL, ModelView):
|
|||
flash(_('Invalid email address'))
|
||||
return render_template('reset-password.jinja')
|
||||
|
||||
self.create_act_code(user_ids[0], "reset")
|
||||
user = self.browse(user_ids[0])
|
||||
self.send_reset_email(user)
|
||||
nereid_user, = user_ids
|
||||
|
||||
nereid_user.create_act_code("reset")
|
||||
nereid_user.send_reset_email()
|
||||
flash(_('An email has been sent to your account for resetting'
|
||||
' your credentials'))
|
||||
return redirect(url_for('nereid.website.login'))
|
||||
|
||||
return render_template('reset-password.jinja')
|
||||
|
||||
def send_reset_email(self, nereid_user):
|
||||
def send_reset_email(self):
|
||||
"""
|
||||
Send an account reset email to the user
|
||||
|
||||
:param nereid_user: The browse record of the user
|
||||
"""
|
||||
email_message = render_email(
|
||||
CONFIG['smtp_from'], nereid_user.email, _('Account Password Reset'),
|
||||
CONFIG['smtp_from'], self.email, _('Account Password Reset'),
|
||||
text_template = 'emails/reset-text.jinja',
|
||||
html_template = 'emails/reset-html.jinja',
|
||||
nereid_user = nereid_user
|
||||
nereid_user = self
|
||||
)
|
||||
server = get_smtp_server()
|
||||
server.sendmail(
|
||||
CONFIG['smtp_from'], [nereid_user.email], email_message.as_string()
|
||||
CONFIG['smtp_from'], [self.email], email_message.as_string()
|
||||
)
|
||||
server.quit()
|
||||
|
||||
def authenticate(self, email, password):
|
||||
def match_password(self, password):
|
||||
"""
|
||||
Checks if 'password' is the same as the current users password.
|
||||
|
||||
:param password: The password of the user (string or unicode)
|
||||
:return: True or False
|
||||
"""
|
||||
password += self.salt or ''
|
||||
if isinstance(password, unicode):
|
||||
password = password.encode('utf-8')
|
||||
if hashlib:
|
||||
digest = hashlib.sha1(password).hexdigest()
|
||||
else:
|
||||
digest = sha.new(password).hexdigest()
|
||||
return (digest == self.password)
|
||||
|
||||
@classmethod
|
||||
def authenticate(cls, email, password):
|
||||
"""Assert credentials and if correct return the
|
||||
browse record of the user
|
||||
|
||||
|
@ -663,42 +570,37 @@ class NereidUser(ModelSQL, ModelView):
|
|||
False: Account is inactive
|
||||
"""
|
||||
|
||||
user_ids = self.search([
|
||||
users = cls.search([
|
||||
('email', '=', request.form['email']),
|
||||
('company', '=', request.nereid_website.company.id),
|
||||
])
|
||||
])
|
||||
|
||||
if not user_ids:
|
||||
if not users:
|
||||
current_app.logger.debug("No user with email %s" % email)
|
||||
return None
|
||||
|
||||
if len(user_ids) > 1:
|
||||
if len(users) > 1:
|
||||
current_app.logger.debug('%s has too many accounts' % email)
|
||||
return None
|
||||
|
||||
user = self.browse(user_ids[0])
|
||||
user, = users
|
||||
if user.activation_code and len(user.activation_code) == 16:
|
||||
# A new account with activation pending
|
||||
current_app.logger.debug('%s not activated' % email)
|
||||
flash(_("Your account has not been activated yet!"))
|
||||
return False # False so to avoid `invalid credentials` flash
|
||||
|
||||
password += user.salt or ''
|
||||
|
||||
if isinstance(password, unicode):
|
||||
password = password.encode('utf-8')
|
||||
|
||||
password_sha = hashlib.sha1(password).hexdigest()
|
||||
if password_sha == user.password:
|
||||
if user.match_password(password):
|
||||
# Reset any reset activation code that might be there since its a
|
||||
# successful login with the old password
|
||||
if user.activation_code:
|
||||
self.write(user.id, {'activation_code': None})
|
||||
cls.write([user], {'activation_code': None})
|
||||
return user
|
||||
|
||||
return None
|
||||
|
||||
def _convert_values(self, values):
|
||||
@staticmethod
|
||||
def _convert_values(values):
|
||||
"""
|
||||
A helper method which looks if the password is specified in the values.
|
||||
If it is, then the salt is also made and added
|
||||
|
@ -709,29 +611,36 @@ class NereidUser(ModelSQL, ModelView):
|
|||
values['salt'] = ''.join(random.sample(
|
||||
string.ascii_letters + string.digits, 8))
|
||||
values['password'] += values['salt']
|
||||
|
||||
return values
|
||||
|
||||
def create(self, values):
|
||||
@classmethod
|
||||
def create(cls, values):
|
||||
"""
|
||||
Create, but add salt before saving
|
||||
|
||||
:param values: Dictionary of Values
|
||||
"""
|
||||
return super(NereidUser, self).create(self._convert_values(values))
|
||||
values = cls._convert_values(values.copy())
|
||||
if 'display_name' not in values:
|
||||
values['display_name'] = values['name']
|
||||
return super(NereidUser, cls).create(values)
|
||||
|
||||
def write(self, ids, values):
|
||||
@classmethod
|
||||
def write(cls, nereid_users, values):
|
||||
"""
|
||||
Update salt before saving
|
||||
|
||||
:param ids: IDs of the records
|
||||
:param values: Dictionary of values
|
||||
"""
|
||||
return super(NereidUser, self).write(ids, self._convert_values(values))
|
||||
return super(NereidUser, cls).write(
|
||||
nereid_users, cls._convert_values(values)
|
||||
)
|
||||
|
||||
def get_gravatar_url(self, user, **kwargs):
|
||||
@staticmethod
|
||||
def get_gravatar_url(email, **kwargs):
|
||||
"""
|
||||
Return a gravatar url for the given email
|
||||
|
||||
:param email: e-mail of the user
|
||||
:param https: To get a secure URL
|
||||
:param default: The default image to return if there is no profile pic
|
||||
For example a unisex avatar
|
||||
|
@ -741,7 +650,7 @@ class NereidUser(ModelSQL, ModelView):
|
|||
url = 'https://secure.gravatar.com/avatar/%s?'
|
||||
else:
|
||||
url = 'http://www.gravatar.com/avatar/%s?'
|
||||
url = url % hashlib.md5(user.email.lower()).hexdigest()
|
||||
url = url % hashlib.md5(email.lower()).hexdigest()
|
||||
|
||||
params = []
|
||||
default = kwargs.get('default', None)
|
||||
|
@ -754,41 +663,47 @@ class NereidUser(ModelSQL, ModelView):
|
|||
|
||||
return url + urllib.urlencode(params)
|
||||
|
||||
def get_profile_picture(self, user, **kwargs):
|
||||
def get_profile_picture(self, **kwargs):
|
||||
"""
|
||||
Return the url to the profile picture of the user.
|
||||
|
||||
The default implementation fetches the profile image of the user from
|
||||
gravatar using :meth:`get_gravatar_url`
|
||||
"""
|
||||
return self.get_gravatar_url(user, **kwargs)
|
||||
return self.get_gravatar_url(self.email, **kwargs)
|
||||
|
||||
def aslocaltime(self, naive_date, user=None):
|
||||
@staticmethod
|
||||
def aslocaltime(naive_date, local_tz_name=None):
|
||||
"""
|
||||
Returns a localized time using `pytz.astimezone` method.
|
||||
|
||||
:param naive_date: a naive datetime (datetime with no timezone
|
||||
information), which is assumed to be the UTC time.
|
||||
:param user: If a user is provided, the timezone of the user is taken
|
||||
to build the offset or the user from nereid context is
|
||||
used. The value if provided must be a browse record.
|
||||
:param local_tz_name: The timezone in which the date has to be returned
|
||||
:type local_tz_name: string
|
||||
|
||||
:return: A datetime object with local time
|
||||
"""
|
||||
if user is None:
|
||||
user = request.nereid_user
|
||||
|
||||
utc_date = pytz.utc.localize(naive_date)
|
||||
|
||||
if not user.timezone:
|
||||
if not local_tz_name:
|
||||
return utc_date
|
||||
|
||||
user_tz = pytz.timezone(user.timezone)
|
||||
if user_tz == pytz.utc:
|
||||
local_tz = pytz.timezone(local_tz_name)
|
||||
if local_tz == pytz.utc:
|
||||
return utc_date
|
||||
|
||||
return utc_date.astimezone(user_tz)
|
||||
return utc_date.astimezone(local_tz)
|
||||
|
||||
NereidUser()
|
||||
def as_user_local_time(self, naive_date):
|
||||
"""
|
||||
Returns a date localized in the user's timezone.
|
||||
|
||||
:param naive_date: a naive datetime (datetime with no timezone
|
||||
information), which is assumed to be the UTC time.
|
||||
"""
|
||||
return self.aslocaltime(naive_date, self.timezone)
|
||||
|
||||
|
||||
class ContactMechanismForm(Form):
|
||||
|
@ -801,7 +716,7 @@ class ContactMechanism(ModelSQL, ModelView):
|
|||
"""
|
||||
Allow modification of contact mechanisms
|
||||
"""
|
||||
_name = "party.contact_mechanism"
|
||||
__name__ = "party.contact_mechanism"
|
||||
|
||||
def get_form(self):
|
||||
"""
|
||||
|
@ -858,13 +773,11 @@ class ContactMechanism(ModelSQL, ModelView):
|
|||
})
|
||||
return redirect(request.referrer)
|
||||
|
||||
ContactMechanism()
|
||||
|
||||
|
||||
class Permission(ModelSQL, ModelView):
|
||||
"Nereid Permissions"
|
||||
_name = 'nereid.permission'
|
||||
_description = __doc__
|
||||
__name__ = 'nereid.permission'
|
||||
|
||||
name = fields.Char('Name', required=True, select=True)
|
||||
value = fields.Char('Value', required=True, select=True)
|
||||
|
@ -872,24 +785,21 @@ class Permission(ModelSQL, ModelView):
|
|||
'permission', 'nereid_user', 'Nereid Users'
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
super(Permission, self).__init__()
|
||||
self._sql_constraints += [
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Permission, cls).__setup__()
|
||||
cls._sql_constraints += [
|
||||
('unique_value', 'UNIQUE(value)',
|
||||
'Permissions must be unique by value'),
|
||||
]
|
||||
|
||||
Permission()
|
||||
|
||||
|
||||
class UserPermission(ModelSQL):
|
||||
"Nereid User Permissions"
|
||||
_name = 'nereid.permission-nereid.user'
|
||||
_description = __doc__
|
||||
__name__ = 'nereid.permission-nereid.user'
|
||||
|
||||
permission = fields.Many2One('nereid.permission', 'Permission',
|
||||
ondelete='CASCADE', select=True, required=True)
|
||||
nereid_user = fields.Many2One('nereid.user', 'User',
|
||||
ondelete='CASCADE', select=True, required=True)
|
||||
|
||||
UserPermission()
|
||||
|
|
20
party.xml
20
party.xml
|
@ -24,6 +24,26 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="party_address_view_form">
|
||||
<field name="model">party.address</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit" ref="party.address_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<data>
|
||||
<xpath expr="/form/field[@name="subdivision"]"
|
||||
position="after">
|
||||
<newline/>
|
||||
<label name="email"/>
|
||||
<field name="email"/>
|
||||
<label name="phone"/>
|
||||
<field name="phone"/>
|
||||
</xpath>
|
||||
</data>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="nereid_user_form" model="ir.ui.view">
|
||||
<field name="model">nereid.user</field>
|
||||
<field name="type">form</field>
|
||||
|
|
230
routing.py
230
routing.py
|
@ -1,13 +1,5 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
"""
|
||||
nereid.routing
|
||||
|
||||
Routing: Sites, URLs
|
||||
|
||||
:copyright: (c) 2010 by Sharoon Thomas
|
||||
:copyright: (c) 2010-2012 by Openlabs Technologies & Consulting (P) Ltd.
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from ast import literal_eval
|
||||
|
||||
import pytz
|
||||
|
@ -25,7 +17,10 @@ from trytond.pool import Pool
|
|||
|
||||
from .i18n import _
|
||||
|
||||
# pylint: disable-msg=E1101
|
||||
__all__ = ['URLMap', 'WebSite', 'URLRule', 'URLRuleDefaults',
|
||||
'WebsiteCountry', 'WebsiteCurrency']
|
||||
|
||||
|
||||
class URLMap(ModelSQL, ModelView):
|
||||
"""
|
||||
URL Map
|
||||
|
@ -49,8 +44,7 @@ class URLMap(ModelSQL, ModelView):
|
|||
:param unique_urls: Enable `redirect_defaults` in the URL Map and
|
||||
redirects the defaults to the URL
|
||||
"""
|
||||
_name = "nereid.url_map"
|
||||
_description = "Nereid URL Map"
|
||||
__name__ = "nereid.url_map"
|
||||
|
||||
name = fields.Char(
|
||||
'Name', required=True, select=True,
|
||||
|
@ -68,31 +62,27 @@ class URLMap(ModelSQL, ModelView):
|
|||
unique_urls = fields.Boolean('Unique URLs')
|
||||
active = fields.Boolean('Active')
|
||||
|
||||
def default_active(self):
|
||||
@staticmethod
|
||||
def default_active():
|
||||
"By default URL is active"
|
||||
return True
|
||||
|
||||
def default_charset(self):
|
||||
@staticmethod
|
||||
def default_charset():
|
||||
"By default characterset is utf-8"
|
||||
return 'utf-8'
|
||||
|
||||
def get_rules_arguments(self, map_id):
|
||||
def get_rules_arguments(self):
|
||||
"""
|
||||
Constructs a list of dictionary of arguments needed
|
||||
for URL Rule construction. A wrapper around the
|
||||
URL RULE get_rule_arguments
|
||||
"""
|
||||
rule_args = [ ]
|
||||
rule_obj = Pool().get('nereid.url_rule')
|
||||
url_map = self.browse(map_id)
|
||||
for rule in url_map.rules:
|
||||
rule_args.append(
|
||||
rule_obj.get_rule_arguments(rule.id)
|
||||
)
|
||||
for rule in self.rules:
|
||||
rule_args.append(rule.get_rule_arguments())
|
||||
return rule_args
|
||||
|
||||
URLMap()
|
||||
|
||||
|
||||
class LoginForm(Form):
|
||||
"Default Login Form"
|
||||
|
@ -114,8 +104,7 @@ class WebSite(ModelSQL, ModelView):
|
|||
:param active: Whether the website is active or not.
|
||||
|
||||
"""
|
||||
_name = "nereid.website"
|
||||
_description = "Nereid WebSite"
|
||||
__name__ = "nereid.website"
|
||||
|
||||
#: The name field is used for both information and also as
|
||||
#: the site identifier for nereid. The WSGI application requires
|
||||
|
@ -162,20 +151,24 @@ class WebSite(ModelSQL, ModelView):
|
|||
[(x, x) for x in pytz.common_timezones], 'Timezone', translate=False
|
||||
)
|
||||
|
||||
def default_timezone(self):
|
||||
@staticmethod
|
||||
def default_timezone():
|
||||
return 'UTC'
|
||||
|
||||
def default_active(self):
|
||||
@staticmethod
|
||||
def default_active():
|
||||
return True
|
||||
|
||||
def __init__(self):
|
||||
super(WebSite, self).__init__()
|
||||
self._sql_constraints = [
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(WebSite, cls).__setup__()
|
||||
cls._sql_constraints = [
|
||||
('name_uniq', 'UNIQUE(name)',
|
||||
'Another site with the same name already exists!')
|
||||
]
|
||||
|
||||
def country_list(self):
|
||||
@classmethod
|
||||
def country_list(cls):
|
||||
"""
|
||||
Return the list of countries in JSON
|
||||
"""
|
||||
|
@ -184,7 +177,8 @@ class WebSite(ModelSQL, ModelView):
|
|||
for c in request.nereid_website.countries
|
||||
])
|
||||
|
||||
def subdivision_list(self):
|
||||
@staticmethod
|
||||
def subdivision_list():
|
||||
"""
|
||||
Return the list of states for given country
|
||||
"""
|
||||
|
@ -192,9 +186,8 @@ class WebSite(ModelSQL, ModelView):
|
|||
if country not in [c.id for c in request.nereid_website.countries]:
|
||||
abort(404)
|
||||
|
||||
subdivision_obj = Pool().get('country.subdivision')
|
||||
ids = subdivision_obj.search([('country', '=', country)])
|
||||
subdivisions = subdivision_obj.browse(ids)
|
||||
Subdivision = Pool().get('country.subdivision')
|
||||
subdivisions = Subdivision.search([('country', '=', country)])
|
||||
return jsonify(
|
||||
result = [{
|
||||
'id': s.id,
|
||||
|
@ -208,13 +201,12 @@ class WebSite(ModelSQL, ModelView):
|
|||
"""
|
||||
Return complete list of URLs
|
||||
"""
|
||||
url_map_obj = Pool().get('nereid.url_map')
|
||||
website_id = self.search([('name', '=', name)])
|
||||
if not website_id:
|
||||
URLMap = Pool().get('nereid.url_map')
|
||||
websites = self.search([('name', '=', name)])
|
||||
if not websites:
|
||||
raise RuntimeError("Website with Name %s not found" % name)
|
||||
|
||||
website = self.browse(website_id[0])
|
||||
return url_map_obj.get_rules_arguments(website.url_map.id)
|
||||
return URLMap.get_rules_arguments(websites[0].url_map.id)
|
||||
|
||||
def stats(self, **arguments):
|
||||
"""
|
||||
|
@ -223,11 +215,13 @@ class WebSite(ModelSQL, ModelView):
|
|||
return u'Request: %s\nArguments: %s\nEnviron: %s\n' \
|
||||
% (request, arguments, request.environ)
|
||||
|
||||
def home(self):
|
||||
@classmethod
|
||||
def home(cls):
|
||||
"A dummy home method which just renders home.jinja"
|
||||
return render_template('home.jinja')
|
||||
|
||||
def login(self):
|
||||
@classmethod
|
||||
def login(cls):
|
||||
"""
|
||||
Simple login based on the email and password
|
||||
|
||||
|
@ -239,8 +233,8 @@ class WebSite(ModelSQL, ModelView):
|
|||
return redirect(request.args['next'])
|
||||
|
||||
if request.method == 'POST' and login_form.validate():
|
||||
user_obj = Pool().get('nereid.user')
|
||||
result = user_obj.authenticate(
|
||||
NereidUser = Pool().get('nereid.user')
|
||||
result = NereidUser.authenticate(
|
||||
login_form.email.data, login_form.password.data
|
||||
)
|
||||
# Result can be the following:
|
||||
|
@ -253,7 +247,7 @@ class WebSite(ModelSQL, ModelView):
|
|||
flash(_("You are now logged in. Welcome %(name)s",
|
||||
name=result.name))
|
||||
session['user'] = result.id
|
||||
login.send(self)
|
||||
login.send()
|
||||
if request.is_xhr:
|
||||
return 'OK'
|
||||
else:
|
||||
|
@ -265,28 +259,29 @@ class WebSite(ModelSQL, ModelView):
|
|||
elif result is None:
|
||||
flash(_("Invalid login credentials"))
|
||||
|
||||
failed_login.send(self, form=login_form)
|
||||
failed_login.send(form=login_form)
|
||||
|
||||
if request.is_xhr:
|
||||
return 'NOK'
|
||||
|
||||
return render_template('login.jinja', login_form=login_form)
|
||||
|
||||
def logout(self):
|
||||
@classmethod
|
||||
def logout(cls):
|
||||
"Log the user out"
|
||||
session.pop('user', None)
|
||||
logout.send(self)
|
||||
logout.send()
|
||||
flash(
|
||||
_('You have been logged out successfully. Thanks for visiting us')
|
||||
)
|
||||
return redirect(
|
||||
request.args.get('next',
|
||||
url_for('nereid.website.home'))
|
||||
request.args.get('next', url_for('nereid.website.home'))
|
||||
)
|
||||
|
||||
def account_context(self):
|
||||
@staticmethod
|
||||
def account_context():
|
||||
"""This fills the account context for the template
|
||||
rendering my account. Additional modules might want to fill extra
|
||||
rendering my account. Additional modules might want to fill extra
|
||||
data into the context
|
||||
"""
|
||||
return dict(
|
||||
|
@ -294,15 +289,15 @@ class WebSite(ModelSQL, ModelView):
|
|||
party = request.nereid_user.party,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@login_required
|
||||
def account(self):
|
||||
context = self.account_context()
|
||||
return render_template('account.jinja', **context)
|
||||
def account(cls):
|
||||
return render_template('account.jinja', **cls.account_context())
|
||||
|
||||
def get_currencies(self):
|
||||
"""Returns available currencies for current site
|
||||
|
||||
.. note::
|
||||
.. note::
|
||||
A special method is required so that the fetch can be speeded up,
|
||||
by pushing the categories to the central cache which cannot be
|
||||
done directly on a browse node.
|
||||
|
@ -319,36 +314,37 @@ class WebSite(ModelSQL, ModelView):
|
|||
'id': c.id,
|
||||
'name': c.name,
|
||||
'symbol': c.symbol,
|
||||
} for c in request.nereid_website.currencies]
|
||||
} for c in self.currencies]
|
||||
cache.set(cache_key, rv, 60*60)
|
||||
return rv
|
||||
|
||||
def _user_status(self):
|
||||
@staticmethod
|
||||
def _user_status():
|
||||
"""Returns the commonly required status parameters of the user
|
||||
|
||||
This method could be inherited and components could be added
|
||||
"""
|
||||
rv = {
|
||||
'messages': get_flashed_messages()
|
||||
}
|
||||
}
|
||||
if request.is_guest_user:
|
||||
rv.update({
|
||||
'logged_id': False
|
||||
})
|
||||
})
|
||||
else:
|
||||
rv.update({
|
||||
'logged_in': True,
|
||||
'name': request.nereid_user.display_name
|
||||
})
|
||||
})
|
||||
return rv
|
||||
|
||||
def user_status(self):
|
||||
@classmethod
|
||||
def user_status(cls):
|
||||
"""
|
||||
Returns a JSON of the user_status
|
||||
"""
|
||||
return jsonify(status=self._user_status())
|
||||
return jsonify(status=cls._user_status())
|
||||
|
||||
WebSite()
|
||||
|
||||
|
||||
class URLRule(ModelSQL, ModelView):
|
||||
|
@ -394,8 +390,7 @@ class URLRule(ModelSQL, ModelView):
|
|||
:param sequence: Numeric sequence of the URL Map.
|
||||
:param url_map: Relation field for url_rule o2m
|
||||
"""
|
||||
_name = "nereid.url_rule"
|
||||
_description = "Nereid URL Rule"
|
||||
__name__ = "nereid.url_rule"
|
||||
_rec_name = 'rule'
|
||||
|
||||
rule = fields.Char('Rule', required=True, select=True,)
|
||||
|
@ -434,17 +429,19 @@ class URLRule(ModelSQL, ModelView):
|
|||
sequence = fields.Integer('Sequence', required=True,)
|
||||
url_map = fields.Many2One('nereid.url_map', 'URL Map')
|
||||
|
||||
def __init__(self):
|
||||
super(URLRule, self).__init__()
|
||||
self._order.insert(0, ('sequence', 'ASC'))
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(URLRule, cls).__setup__()
|
||||
cls._order.insert(0, ('sequence', 'ASC'))
|
||||
|
||||
def init(self, module_name):
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
"""Migrations
|
||||
|
||||
:param module_name: Module Name (Automatically passed by caller)
|
||||
"""
|
||||
cursor = Transaction().cursor
|
||||
table = TableHandler(cursor, self, module_name)
|
||||
table = TableHandler(cursor, cls, module_name)
|
||||
|
||||
# Drop the required index on methods
|
||||
table.not_null_action('methods', action="remove")
|
||||
|
@ -455,23 +452,25 @@ class URLRule(ModelSQL, ModelView):
|
|||
# Check if the new boolean fields exist
|
||||
http_method_fields_exists = table.column_exist('http_method_get')
|
||||
|
||||
super(URLRule, self).init(module_name)
|
||||
super(URLRule, cls).__register__(module_name)
|
||||
|
||||
if not http_method_fields_exists:
|
||||
# if the http method fields did not exist before this method
|
||||
# should transition old_methods to the boolean fields
|
||||
rule_ids = self.search([])
|
||||
for rule in self.browse(rule_ids):
|
||||
self.set_methods([rule.id], 'methods', rule.old_methods)
|
||||
rules = cls.search([])
|
||||
for rule in rules:
|
||||
cls.set_methods([rule.id], 'methods', rule.old_methods)
|
||||
|
||||
|
||||
def default_active(self):
|
||||
@staticmethod
|
||||
def default_active():
|
||||
return True
|
||||
|
||||
def default_methods(self):
|
||||
return '("GET",)'
|
||||
@staticmethod
|
||||
def default_http_method_get():
|
||||
return True
|
||||
|
||||
def get_methods(self, ids, name):
|
||||
def get_methods(self, name):
|
||||
"""
|
||||
The methods field will be deprecated in 2.6.0.1. Till then display the
|
||||
field value based on the boolean fields which replaces the selection
|
||||
|
@ -480,20 +479,17 @@ class URLRule(ModelSQL, ModelView):
|
|||
Note that this only handles GET and POST methods as they were the only
|
||||
ones handled before v2.4.0.6.
|
||||
|
||||
:param ids: List of ids
|
||||
:param name: Name of the function field
|
||||
"""
|
||||
res = {}
|
||||
for rule in self.browse(ids):
|
||||
if rule.http_method_get and rule.http_method_post:
|
||||
res[rule.id] = '("GET", "POST")'
|
||||
elif rule.http_method_post and not rule.http_method_get:
|
||||
res[rule.id] = '("POST",)'
|
||||
else:
|
||||
res[rule.id] = '("GET",)'
|
||||
return res
|
||||
if self.http_method_get and self.http_method_post:
|
||||
return'("GET", "POST")'
|
||||
elif self.http_method_post and not self.http_method_get:
|
||||
return '("POST",)'
|
||||
else:
|
||||
return '("GET",)'
|
||||
|
||||
def set_methods(self, ids, name, value):
|
||||
@classmethod
|
||||
def set_methods(cls, urls, name, value):
|
||||
"""
|
||||
Set the values of http_* boolean fields based on the value of methods
|
||||
|
||||
|
@ -507,49 +503,44 @@ class URLRule(ModelSQL, ModelView):
|
|||
if 'POST' in methods:
|
||||
write_vals['http_method_post'] = True
|
||||
if write_vals:
|
||||
self.write(ids, write_vals)
|
||||
cls.write(urls, write_vals)
|
||||
return
|
||||
|
||||
def get_http_methods(self, rule):
|
||||
def get_http_methods(self):
|
||||
"""
|
||||
Returns an iterable of HTTP methods that the URL has to support.
|
||||
|
||||
.. versionadded: 2.4.0.6
|
||||
|
||||
:param rule: Browse record of the rule
|
||||
"""
|
||||
methods = []
|
||||
if rule.http_method_get:
|
||||
if self.http_method_get:
|
||||
methods.append('GET')
|
||||
if rule.http_method_post:
|
||||
if self.http_method_post:
|
||||
methods.append('POST')
|
||||
if rule.http_method_put:
|
||||
if self.http_method_put:
|
||||
methods.append('PUT')
|
||||
if rule.http_method_delete:
|
||||
if self.http_method_delete:
|
||||
methods.append('DELETE')
|
||||
if rule.http_method_patch:
|
||||
if self.http_method_patch:
|
||||
methods.append('PATCH')
|
||||
return methods
|
||||
|
||||
def get_rule_arguments(self, rule_id):
|
||||
def get_rule_arguments(self):
|
||||
"""
|
||||
Return the arguments of a Rule in the corresponding format
|
||||
"""
|
||||
rule = self.browse(rule_id)
|
||||
defaults = dict(
|
||||
[(i.key, i.value) for i in rule.defaults]
|
||||
[(i.key, i.value) for i in self.defaults]
|
||||
)
|
||||
return {
|
||||
'rule': rule.rule,
|
||||
'endpoint': rule.endpoint,
|
||||
'methods': self.get_http_methods(rule),
|
||||
'build_only': rule.only_for_genaration,
|
||||
'rule': self.rule,
|
||||
'endpoint': self.endpoint,
|
||||
'methods': self.get_http_methods(),
|
||||
'build_only': self.only_for_genaration,
|
||||
'defaults': defaults,
|
||||
'redirect_to': rule.redirect_to or None,
|
||||
'redirect_to': self.redirect_to or None,
|
||||
}
|
||||
|
||||
URLRule()
|
||||
|
||||
|
||||
class URLRuleDefaults(ModelSQL, ModelView):
|
||||
"""
|
||||
|
@ -559,8 +550,7 @@ class URLRuleDefaults(ModelSQL, ModelView):
|
|||
:param value: The Value for the default's Value
|
||||
:param Rule: M2O Rule
|
||||
"""
|
||||
_name = "nereid.url_rule_defaults"
|
||||
_description = "Nereid URL Rule Defaults"
|
||||
__name__ = "nereid.url_rule_defaults"
|
||||
_rec_name = 'key'
|
||||
|
||||
key = fields.Char('Key', required=True, select=True)
|
||||
|
@ -568,31 +558,23 @@ class URLRuleDefaults(ModelSQL, ModelView):
|
|||
rule = fields.Many2One('nereid.url_rule', 'Rule', required=True,
|
||||
select=True)
|
||||
|
||||
URLRuleDefaults()
|
||||
|
||||
|
||||
class WebsiteCountry(ModelSQL):
|
||||
"Website Country Relations"
|
||||
_name = 'nereid.website-country.country'
|
||||
_description = __doc__
|
||||
__name__ = 'nereid.website-country.country'
|
||||
|
||||
website = fields.Many2One('nereid.website', 'Website')
|
||||
country = fields.Many2One('country.country', 'Country')
|
||||
|
||||
WebsiteCountry()
|
||||
|
||||
|
||||
class WebsiteCurrency(ModelSQL):
|
||||
"Currencies to be made available on website"
|
||||
_name = 'nereid.website-currency.currency'
|
||||
__name__ = 'nereid.website-currency.currency'
|
||||
_table = 'website_currency_rel'
|
||||
_description = __doc__
|
||||
|
||||
website = fields.Many2One(
|
||||
'nereid.website', 'Website',
|
||||
'nereid.website', 'Website',
|
||||
ondelete='CASCADE', select=1, required=True)
|
||||
currency = fields.Many2One(
|
||||
'currency.currency', 'Currency',
|
||||
'currency.currency', 'Currency',
|
||||
ondelete='CASCADE', select=1, required=True)
|
||||
|
||||
WebsiteCurrency()
|
||||
|
|
109
setup.py
109
setup.py
|
@ -7,11 +7,21 @@
|
|||
:license: GPLv3, see LICENSE for more details
|
||||
'''
|
||||
import re
|
||||
|
||||
import os
|
||||
import ConfigParser
|
||||
from setuptools import setup, Command
|
||||
|
||||
class RunTests(Command):
|
||||
description = "Run tests"
|
||||
|
||||
class XMLTests(Command):
|
||||
"""Runs the tests and save the result to an XML file
|
||||
|
||||
Running this requires unittest-xml-reporting which can
|
||||
be installed using::
|
||||
|
||||
pip install unittest-xml-reporting
|
||||
|
||||
"""
|
||||
description = "Run tests with coverage and produce jUnit style report"
|
||||
|
||||
user_options = []
|
||||
|
||||
|
@ -22,34 +32,86 @@ class RunTests(Command):
|
|||
pass
|
||||
|
||||
def run(self):
|
||||
import sys,subprocess
|
||||
errno = subprocess.call([sys.executable, 'tests/__init__.py'])
|
||||
raise SystemExit(errno)
|
||||
import coverage
|
||||
import xmlrunner
|
||||
cov = coverage.coverage(source=["trytond.modules.nereid"])
|
||||
cov.start()
|
||||
from tests import suite
|
||||
xmlrunner.XMLTestRunner(output="xml-test-results").run(suite())
|
||||
cov.stop()
|
||||
cov.save()
|
||||
cov.xml_report(outfile="coverage.xml")
|
||||
|
||||
|
||||
trytond_module_info = eval(open('__tryton__.py').read())
|
||||
major_version, minor_version, _ = trytond_module_info.get(
|
||||
'version', '0.0.1').split('.', 2)
|
||||
class RunAudit(Command):
|
||||
"""Audits source code using PyFlakes for following issues:
|
||||
- Names which are used but not defined or used before they are defined.
|
||||
- Names which are redefined without having been used.
|
||||
"""
|
||||
description = "Audit source code with PyFlakes"
|
||||
user_options = []
|
||||
|
||||
def initialize_options(self):
|
||||
pass
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
import sys
|
||||
try:
|
||||
import pyflakes.scripts.pyflakes as flakes
|
||||
except ImportError:
|
||||
print "Audit requires PyFlakes installed in your system."
|
||||
sys.exit(-1)
|
||||
|
||||
warns = 0
|
||||
# Define top-level directories
|
||||
dirs = ('.')
|
||||
for dir in dirs:
|
||||
for root, _, files in os.walk(dir):
|
||||
if root.startswith(('./build')):
|
||||
continue
|
||||
for file in files:
|
||||
if file != '__init__.py' and file.endswith('.py'):
|
||||
warns += flakes.checkPath(os.path.join(root, file))
|
||||
if warns > 0:
|
||||
print "Audit finished with total %d warnings." % warns
|
||||
else:
|
||||
print "No problems found in sourcecode."
|
||||
|
||||
|
||||
def read(fname):
|
||||
return open(os.path.join(os.path.dirname(__file__), fname)).read()
|
||||
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.readfp(open('tryton.cfg'))
|
||||
info = dict(config.items('tryton'))
|
||||
for key in ('depends', 'extras_depend', 'xml'):
|
||||
if key in info:
|
||||
info[key] = info[key].strip().splitlines()
|
||||
major_version, minor_version, _ = info.get('version', '0.0.1').split('.', 2)
|
||||
major_version = int(major_version)
|
||||
minor_version = int(minor_version)
|
||||
|
||||
tryton_requires = []
|
||||
for dep in trytond_module_info.get('depends', []):
|
||||
if not re.match(r'(ir|res|workflow|webdav)(\W|$)', dep):
|
||||
tryton_requires.append('trytond_%s >= %s.%s, < %s.%s' %
|
||||
requires = []
|
||||
for dep in info.get('depends', []):
|
||||
if not re.match(r'(ir|res|webdav)(\W|$)', dep):
|
||||
requires.append('trytond_%s >= %s.%s, < %s.%s' %
|
||||
(dep, major_version, minor_version, major_version,
|
||||
minor_version + 1))
|
||||
|
||||
requires.append('trytond >= %s.%s, < %s.%s' %
|
||||
(major_version, minor_version, major_version, minor_version + 1))
|
||||
|
||||
setup(
|
||||
name='trytond_nereid',
|
||||
version=trytond_module_info.get('version'),
|
||||
version=info.get('version'),
|
||||
url='http://nereid.openlabs.co.in/docs/',
|
||||
license='GPLv3',
|
||||
author='Openlabs Technologies & Consulting (P) Limited',
|
||||
author_email='info@openlabs.co.in',
|
||||
description='Tryton - Web Framework',
|
||||
long_description=__doc__,
|
||||
long_description=read('README.rst'),
|
||||
classifiers=[
|
||||
'Development Status :: 4 - Beta',
|
||||
'Environment :: Web Environment',
|
||||
|
@ -61,8 +123,7 @@ setup(
|
|||
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
|
||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||
],
|
||||
|
||||
install_requires=tryton_requires,
|
||||
install_requires=requires,
|
||||
packages=[
|
||||
'trytond.modules.nereid',
|
||||
'trytond.modules.nereid.tests',
|
||||
|
@ -72,8 +133,8 @@ setup(
|
|||
'trytond.modules.nereid.tests': 'tests',
|
||||
},
|
||||
package_data = {
|
||||
'trytond.modules.nereid': trytond_module_info.get('xml', []) \
|
||||
+ trytond_module_info.get('translation', []) \
|
||||
'trytond.modules.nereid': info.get('xml', []) \
|
||||
+ ['tryton.cfg', 'locale/*.po', 'tests/*.rst']
|
||||
+ ['i18n/*.pot', 'i18n/pt_BR/LC_MESSAGES/*'],
|
||||
},
|
||||
zip_safe=False,
|
||||
|
@ -82,10 +143,14 @@ setup(
|
|||
[trytond.modules]
|
||||
nereid = trytond.modules.nereid
|
||||
""",
|
||||
test_suite='tests',
|
||||
test_loader='trytond.test_loader:Loader',
|
||||
tests_require=[
|
||||
'mock',
|
||||
'pycountry',
|
||||
],
|
||||
test_suite='tests',
|
||||
test_loader='trytond.test_loader:Loader',
|
||||
cmdclass={
|
||||
'xmltests': XMLTests,
|
||||
'audit': RunAudit,
|
||||
},
|
||||
)
|
||||
|
|
146
static_file.py
146
static_file.py
|
@ -1,13 +1,5 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
'''
|
||||
nereid.static_file
|
||||
|
||||
Static file
|
||||
|
||||
:copyright: (c) 2011-2012 Openlabs Technologies & Consulting (P) Limited
|
||||
:copyright: (c) 2010 by Sharoon Thomas.
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
'''
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import os
|
||||
import urllib
|
||||
|
||||
|
@ -20,13 +12,12 @@ from trytond.config import CONFIG
|
|||
from trytond.transaction import Transaction
|
||||
from trytond.pyson import Eval, Not, Equal
|
||||
|
||||
__all__ = ['NereidStaticFolder', 'NereidStaticFile']
|
||||
|
||||
# pylint: disable-msg=E1101
|
||||
|
||||
class NereidStaticFolder(ModelSQL, ModelView):
|
||||
"Static folder for Nereid"
|
||||
_name = "nereid.static.folder"
|
||||
_description = __doc__
|
||||
__name__ = "nereid.static.folder"
|
||||
_rec_name = 'folder_name'
|
||||
|
||||
folder_name = fields.Char(
|
||||
|
@ -36,45 +27,44 @@ class NereidStaticFolder(ModelSQL, ModelView):
|
|||
description = fields.Char('Description', select=1)
|
||||
files = fields.One2Many('nereid.static.file', 'folder', 'Files')
|
||||
|
||||
def __init__(self):
|
||||
super(NereidStaticFolder, self).__init__()
|
||||
self._constraints += [
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(NereidStaticFolder, cls).__setup__()
|
||||
cls._constraints += [
|
||||
('check_folder_name', 'invalid_folder_name'),
|
||||
]
|
||||
self._sql_constraints += [
|
||||
cls._sql_constraints += [
|
||||
('unique_folder', 'UNIQUE(folder_name)',
|
||||
'Folder name needs to be unique')
|
||||
]
|
||||
self._error_messages.update({
|
||||
cls._error_messages.update({
|
||||
'invalid_folder_name': """Invalid folder name:
|
||||
(1) '.' in folder name (OR)
|
||||
(2) folder name begins with '/'""",
|
||||
'folder_cannot_change': "Folder name cannot be changed"
|
||||
})
|
||||
|
||||
def on_change_with_folder_name(self, vals):
|
||||
def on_change_with_folder_name(self):
|
||||
"""
|
||||
Fills the name field with a slugified name
|
||||
"""
|
||||
if vals.get('name'):
|
||||
if not vals.get('folder_name'):
|
||||
vals['folder_name'] = slugify(vals['name'])
|
||||
return vals['folder_name']
|
||||
if self.get('name'):
|
||||
if not self.get('folder_name'):
|
||||
self['folder_name'] = slugify(self['name'])
|
||||
return self['folder_name']
|
||||
|
||||
def check_folder_name(self, ids):
|
||||
def check_folder_name(self):
|
||||
'''
|
||||
Check the validity of folder name
|
||||
Allowing the use of / or . will be risky as that could
|
||||
eventually lead to previlege escalation
|
||||
|
||||
:param ids: ID of current record.
|
||||
'''
|
||||
folder = self.browse(ids[0])
|
||||
if ('.' in folder.folder_name) or (folder.folder_name.startswith('/')):
|
||||
if ('.' in self.folder_name) or (self.folder_name.startswith('/')):
|
||||
return False
|
||||
return True
|
||||
|
||||
def write(self, ids, vals):
|
||||
@classmethod
|
||||
def write(cls, folders, vals):
|
||||
"""
|
||||
Check if the folder_name has been modified.
|
||||
If yes, raise an error.
|
||||
|
@ -83,17 +73,13 @@ class NereidStaticFolder(ModelSQL, ModelView):
|
|||
"""
|
||||
if vals.get('folder_name'):
|
||||
# TODO: Support this feature in future versions
|
||||
self.raise_user_error('folder_cannot_change')
|
||||
return super(NereidStaticFolder, self).write(ids, vals)
|
||||
|
||||
|
||||
NereidStaticFolder()
|
||||
cls.raise_user_error('folder_cannot_change')
|
||||
return super(NereidStaticFolder, cls).write(folders, vals)
|
||||
|
||||
|
||||
class NereidStaticFile(ModelSQL, ModelView):
|
||||
"Static files for Nereid"
|
||||
_name = "nereid.static.file"
|
||||
_description = __doc__
|
||||
__name__ = "nereid.static.file"
|
||||
|
||||
name = fields.Char('File Name', select=True, required=True)
|
||||
folder = fields.Many2One(
|
||||
|
@ -126,43 +112,43 @@ class NereidStaticFile(ModelSQL, ModelView):
|
|||
#: In other words the URL is valid only when called in a nereid request.
|
||||
url = fields.Function(fields.Char('URL'), 'get_url')
|
||||
|
||||
def __init__(self):
|
||||
super(NereidStaticFile, self).__init__()
|
||||
self._constraints += [
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(NereidStaticFile, cls).__setup__()
|
||||
cls._constraints += [
|
||||
('check_file_name', 'invalid_file_name'),
|
||||
]
|
||||
self._sql_constraints += [
|
||||
cls._sql_constraints += [
|
||||
('name_folder_uniq', 'UNIQUE(name, folder)',
|
||||
'The Name of the Static File must be unique in a folder.!'),
|
||||
]
|
||||
self._error_messages.update({
|
||||
cls._error_messages.update({
|
||||
'invalid_file_name': """Invalid file name:
|
||||
(1) '..' in file name (OR)
|
||||
(2) file name contains '/'""",
|
||||
})
|
||||
|
||||
def default_type(self):
|
||||
@staticmethod
|
||||
def default_type():
|
||||
return 'local'
|
||||
|
||||
def get_url(self, ids, name):
|
||||
def get_url(self, name):
|
||||
"""Return the url if within an active request context or return
|
||||
False values
|
||||
"""
|
||||
res = {}.fromkeys(ids, False)
|
||||
if _request_ctx_stack.top is None:
|
||||
return res
|
||||
return None
|
||||
|
||||
for f in self.browse(ids):
|
||||
if f.type == 'local':
|
||||
res[f.id] = url_for(
|
||||
'nereid.static.file.send_static_file',
|
||||
folder=f.folder.folder_name, name=f.name
|
||||
)
|
||||
elif f.type == 'remote':
|
||||
res[f.id] = f.remote_path
|
||||
return res
|
||||
if self.type == 'local':
|
||||
return url_for(
|
||||
'nereid.static.file.send_static_file',
|
||||
folder=self.folder.folder_name, name=self.name
|
||||
)
|
||||
elif self.type == 'remote':
|
||||
return self.remote_path
|
||||
|
||||
def get_nereid_base_path(self):
|
||||
@staticmethod
|
||||
def get_nereid_base_path():
|
||||
"""
|
||||
Returns base path for nereid, where all the static files would be
|
||||
stored.
|
||||
|
@ -176,7 +162,8 @@ class NereidStaticFile(ModelSQL, ModelView):
|
|||
CONFIG['data_path'], cursor.database_name, "nereid"
|
||||
)
|
||||
|
||||
def set_file_binary(self, ids, name, value):
|
||||
@classmethod
|
||||
def set_file_binary(cls, files, name, value):
|
||||
"""
|
||||
Setter for the functional binary field.
|
||||
|
||||
|
@ -184,7 +171,7 @@ class NereidStaticFile(ModelSQL, ModelView):
|
|||
:param name: Ignored
|
||||
:param value: The file buffer
|
||||
"""
|
||||
for f in self.browse(ids):
|
||||
for f in files:
|
||||
if f.type == 'local':
|
||||
file_binary = buffer(value)
|
||||
# If the folder does not exist, create it recursively
|
||||
|
@ -194,7 +181,7 @@ class NereidStaticFile(ModelSQL, ModelView):
|
|||
with open(f.file_path, 'wb') as file_writer:
|
||||
file_writer.write(file_binary)
|
||||
|
||||
def get_file_binary(self, ids, name):
|
||||
def get_file_binary(self, name):
|
||||
'''
|
||||
Getter for the binary_file field. This fetches the file from the
|
||||
file system, coverts it to buffer and returns it.
|
||||
|
@ -202,45 +189,37 @@ class NereidStaticFile(ModelSQL, ModelView):
|
|||
:param ids: the ids of the sales
|
||||
:return: Dictionary with ID as key and file buffer as value
|
||||
'''
|
||||
res = {}
|
||||
for f in self.browse(ids):
|
||||
location = f.file_path if f.type == 'local' \
|
||||
else urllib.urlretrieve(f.remote_path)[0]
|
||||
with open(location, 'rb') as file_reader:
|
||||
res[f.id] = buffer(file_reader.read())
|
||||
return res
|
||||
location = self.file_path if self.type == 'local' \
|
||||
else urllib.urlretrieve(self.remote_path)[0]
|
||||
with open(location, 'rb') as file_reader:
|
||||
return buffer(file_reader.read())
|
||||
|
||||
def get_file_path(self, ids, name):
|
||||
def get_file_path(self, name):
|
||||
"""
|
||||
Returns the full path to the file in the file system
|
||||
|
||||
:param ids: the ids of the sales
|
||||
:return: Dictionary with ID as key and binary
|
||||
"""
|
||||
res = {}
|
||||
for f in self.browse(ids):
|
||||
|
||||
res[f.id] = os.path.abspath(
|
||||
return os.path.abspath(
|
||||
os.path.join(
|
||||
self.get_nereid_base_path(), f.folder.folder_name, f.name
|
||||
self.get_nereid_base_path(),
|
||||
self.folder.folder_name, self.name
|
||||
)) \
|
||||
if f.type == 'local' else f.remote_path
|
||||
return res
|
||||
if self.type == 'local' else self.remote_path
|
||||
|
||||
def check_file_name(self, ids):
|
||||
def check_file_name(self):
|
||||
'''
|
||||
Check the validity of folder name
|
||||
Allowing the use of / or . will be risky as that could
|
||||
eventually lead to previlege escalation
|
||||
|
||||
:param ids: ID of current record.
|
||||
'''
|
||||
file_ = self.browse(ids[0])
|
||||
if ('..' in file_.name) or ('/' in file_.name):
|
||||
if ('..' in self.name) or ('/' in self.name):
|
||||
return False
|
||||
return True
|
||||
|
||||
def send_static_file(self, folder, name):
|
||||
@classmethod
|
||||
def send_static_file(cls, folder, name):
|
||||
"""
|
||||
Invokes the send_file method in nereid.helpers to send a file as the
|
||||
response to the reuqest. The file is sent in a way which is as
|
||||
|
@ -252,13 +231,10 @@ class NereidStaticFile(ModelSQL, ModelView):
|
|||
"""
|
||||
#TODO: Separate this search and find into separate cached method
|
||||
|
||||
ids = self.search([
|
||||
files = cls.search([
|
||||
('folder.folder_name', '=', folder),
|
||||
('name', '=', name)
|
||||
])
|
||||
if not ids:
|
||||
if not files:
|
||||
abort(404)
|
||||
file_ = self.browse(ids[0])
|
||||
return send_file(file_.file_path)
|
||||
|
||||
NereidStaticFile()
|
||||
return send_file(files[0].file_path)
|
||||
|
|
25
template.py
25
template.py
|
@ -1,20 +1,14 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
"""
|
||||
|
||||
Template Management
|
||||
|
||||
:copyright: (c) 2010-2013 by Openlabs Technologies & Consulting (P) Ltd
|
||||
:copyright: (c) 2010 by Sharoon Thomas
|
||||
:license: GPLv3, see LICENSE for more details
|
||||
"""
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pool import Pool
|
||||
|
||||
__all__ = ['ContextProcessors']
|
||||
|
||||
|
||||
class ContextProcessors(ModelSQL, ModelView):
|
||||
"Temlate Context Processor Registry"
|
||||
_name = 'nereid.template.context_processor'
|
||||
_description = __doc__
|
||||
__name__ = 'nereid.template.context_processor'
|
||||
_rec_name = 'method'
|
||||
|
||||
method = fields.Char('Method', required=True,
|
||||
|
@ -23,18 +17,17 @@ class ContextProcessors(ModelSQL, ModelView):
|
|||
help="This will restrict the loading when URLs with"
|
||||
" the model are called")
|
||||
|
||||
def get_processors(self):
|
||||
@classmethod
|
||||
def get_processors(cls):
|
||||
"""
|
||||
Return the list of processors. Separate function
|
||||
since its important to have caching on this
|
||||
"""
|
||||
result = { }
|
||||
ids = self.search([])
|
||||
for ctx_proc in self.browse(ids):
|
||||
ctx_processors = cls.search([])
|
||||
for ctx_proc in ctx_processors:
|
||||
model, method = ctx_proc.method.rsplit('.', 1)
|
||||
ctx_proc_as_func = getattr(Pool().get(model), method)
|
||||
result.setdefault(ctx_proc.model or None, []).append(
|
||||
ctx_proc_as_func)
|
||||
return result
|
||||
|
||||
ContextProcessors()
|
||||
|
|
|
@ -14,6 +14,7 @@ from test_auth import TestAuth
|
|||
from test_address import TestAddress
|
||||
from test_i18n import TestI18N
|
||||
from test_static_file import TestStaticFile
|
||||
from test_currency import TestCurrency
|
||||
|
||||
|
||||
def suite():
|
||||
|
@ -30,6 +31,9 @@ def suite():
|
|||
test_suite.addTests(
|
||||
unittest.TestLoader().loadTestsFromTestCase(TestStaticFile)
|
||||
)
|
||||
test_suite.addTests(
|
||||
unittest.TestLoader().loadTestsFromTestCase(TestCurrency)
|
||||
)
|
||||
return test_suite
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
|
||||
Test the configuration features for nereid
|
||||
|
||||
:copyright: (c) 2010-2013 by Openlabs Technologies & Consulting (P) Ltd.
|
||||
:license: GPLv3, see LICENSE for more details.
|
||||
"""
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import json
|
||||
import unittest
|
||||
|
||||
|
@ -149,7 +143,7 @@ class TestAddress(NereidTestCase):
|
|||
self.setup_defaults()
|
||||
app = self.get_app()
|
||||
|
||||
registered_user = self.nereid_user_obj.browse(
|
||||
registered_user = self.nereid_user_obj(
|
||||
self.registered_user_id
|
||||
)
|
||||
address_data = {
|
||||
|
@ -158,9 +152,10 @@ class TestAddress(NereidTestCase):
|
|||
'streetbis': 'StreetBis',
|
||||
'zip': 'zip',
|
||||
'city': 'City',
|
||||
'country': self.available_countries[0],
|
||||
'subdivision': self.country_obj.browse(
|
||||
self.available_countries[0]).subdivisions[0].id,
|
||||
'country': self.available_countries[0].id,
|
||||
'subdivision': self.country_obj(
|
||||
self.available_countries[0]
|
||||
).subdivisions[0].id,
|
||||
}
|
||||
|
||||
with app.test_client() as c:
|
||||
|
@ -183,7 +178,7 @@ class TestAddress(NereidTestCase):
|
|||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
# Re browse the record
|
||||
registered_user = self.nereid_user_obj.browse(
|
||||
registered_user = self.nereid_user_obj(
|
||||
self.registered_user_id
|
||||
)
|
||||
# Check if the user has two addresses now
|
||||
|
@ -212,7 +207,7 @@ class TestAddress(NereidTestCase):
|
|||
self.setup_defaults()
|
||||
app = self.get_app()
|
||||
|
||||
registered_user = self.nereid_user_obj.browse(
|
||||
registered_user = self.nereid_user_obj(
|
||||
self.registered_user_id
|
||||
)
|
||||
address_data = {
|
||||
|
@ -221,8 +216,8 @@ class TestAddress(NereidTestCase):
|
|||
'streetbis': 'StreetBis',
|
||||
'zip': 'zip',
|
||||
'city': 'City',
|
||||
'country': self.available_countries[0],
|
||||
'subdivision': self.country_obj.browse(
|
||||
'country': self.available_countries[0].id,
|
||||
'subdivision': self.country_obj(
|
||||
self.available_countries[0]).subdivisions[0].id,
|
||||
}
|
||||
|
||||
|
@ -252,7 +247,7 @@ class TestAddress(NereidTestCase):
|
|||
# automatically with the party
|
||||
self.assertEqual(len(registered_user.party.addresses), 1)
|
||||
|
||||
address = self.address_obj.browse(existing_address.id)
|
||||
address = self.address_obj(existing_address.id)
|
||||
self.assertEqual(address.name, address_data['name'])
|
||||
self.assertEqual(address.street, address_data['street'])
|
||||
self.assertEqual(address.streetbis, address_data['streetbis'])
|
||||
|
@ -294,6 +289,7 @@ class TestAddress(NereidTestCase):
|
|||
app = self.get_app()
|
||||
with app.test_client() as c:
|
||||
response = c.get('/en_US/countries')
|
||||
self.assertEqual(response.status_code, 200) # Login success
|
||||
self.assertEqual(len(json.loads(response.data)['result']), 5)
|
||||
|
||||
def test_0050_subdivision_list(self):
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
|
||||
Test the Auth layer
|
||||
|
||||
:copyright: (c) 2010-2013 by Openlabs Technologies & Consulting (P) Ltd.
|
||||
:license: GPLv3, see LICENSE for more details.
|
||||
"""
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import unittest
|
||||
|
||||
from mock import patch
|
||||
|
@ -57,27 +51,27 @@ class TestAuth(NereidTestCase):
|
|||
'code': 'USD',
|
||||
'symbol': '$',
|
||||
})
|
||||
self.company_id = self.company_obj.create({
|
||||
self.company = self.company_obj.create({
|
||||
'name': 'Openlabs',
|
||||
'currency': usd
|
||||
})
|
||||
self.guest_user_id = self.nereid_user_obj.create({
|
||||
self.guest_user = self.nereid_user_obj.create({
|
||||
'name': 'Guest User',
|
||||
'display_name': 'Guest User',
|
||||
'email': 'guest@openlabs.co.in',
|
||||
'password': 'password',
|
||||
'company': self.company_id,
|
||||
'company': self.company,
|
||||
})
|
||||
|
||||
url_map_id, = self.url_map_obj.search([], limit=1)
|
||||
url_map, = self.url_map_obj.search([], limit=1)
|
||||
en_us, = self.language_obj.search([('code', '=', 'en_US')])
|
||||
self.nereid_website_obj.create({
|
||||
'name': 'localhost',
|
||||
'url_map': url_map_id,
|
||||
'company': self.company_id,
|
||||
'url_map': url_map,
|
||||
'company': self.company,
|
||||
'application_user': USER,
|
||||
'default_language': en_us,
|
||||
'guest_user': self.guest_user_id,
|
||||
'guest_user': self.guest_user,
|
||||
})
|
||||
self.templates = {
|
||||
'localhost/home.jinja': '{{get_flashed_messages()}}',
|
||||
|
@ -156,6 +150,29 @@ class TestAuth(NereidTestCase):
|
|||
), 1
|
||||
)
|
||||
|
||||
def test_0015_match_password(self):
|
||||
"""
|
||||
Assert that matching of password works
|
||||
"""
|
||||
with Transaction().start(DB_NAME, USER, CONTEXT):
|
||||
usd = self.currency_obj.create({
|
||||
'name': 'US Dollar',
|
||||
'code': 'USD',
|
||||
'symbol': '$',
|
||||
})
|
||||
company = self.company_obj.create({
|
||||
'name': 'Openlabs',
|
||||
'currency': usd
|
||||
})
|
||||
registered_user = self.nereid_user_obj.create({
|
||||
'name': 'Registered User',
|
||||
'display_name': 'Registered User',
|
||||
'email': 'email@example.com',
|
||||
'password': 'password',
|
||||
'company': company,
|
||||
})
|
||||
self.assertTrue(registered_user.match_password('password'))
|
||||
|
||||
def test_0020_activation(self):
|
||||
"""
|
||||
Activation must happen before login is possible
|
||||
|
@ -175,10 +192,9 @@ class TestAuth(NereidTestCase):
|
|||
response = c.post('/en_US/registration', data=data)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
regd_user_id, = self.nereid_user_obj.search(
|
||||
registered_user, = self.nereid_user_obj.search(
|
||||
[('email', '=', data['email'])]
|
||||
)
|
||||
registered_user = self.nereid_user_obj.browse(regd_user_id)
|
||||
self.assertTrue(registered_user.activation_code)
|
||||
|
||||
# Login should fail since there is activation code
|
||||
|
@ -200,7 +216,7 @@ class TestAuth(NereidTestCase):
|
|||
)
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
registered_user = self.nereid_user_obj.browse(regd_user_id)
|
||||
registered_user = self.nereid_user_obj(registered_user.id)
|
||||
|
||||
# Activation code must be cleared
|
||||
self.assertFalse(registered_user.activation_code)
|
||||
|
@ -213,6 +229,7 @@ class TestAuth(NereidTestCase):
|
|||
'password': data['password'],
|
||||
}
|
||||
)
|
||||
registered_user = self.nereid_user_obj(registered_user.id)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
def test_0030_change_password(self):
|
||||
|
@ -228,7 +245,7 @@ class TestAuth(NereidTestCase):
|
|||
'display_name': 'Registered User',
|
||||
'email': 'email@example.com',
|
||||
'password': 'password',
|
||||
'company': self.company_id,
|
||||
'company': self.company,
|
||||
}
|
||||
self.nereid_user_obj.create(data.copy())
|
||||
|
||||
|
@ -308,9 +325,9 @@ class TestAuth(NereidTestCase):
|
|||
'display_name': 'Registered User',
|
||||
'email': 'email@example.com',
|
||||
'password': 'password',
|
||||
'company': self.company_id,
|
||||
'company': self.company,
|
||||
}
|
||||
registered_user_id = self.nereid_user_obj.create(data.copy())
|
||||
regd_user = self.nereid_user_obj.create(data.copy())
|
||||
|
||||
with app.test_client() as c:
|
||||
|
||||
|
@ -324,7 +341,6 @@ class TestAuth(NereidTestCase):
|
|||
})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
regd_user = self.nereid_user_obj.browse(registered_user_id)
|
||||
self.assertTrue(regd_user.activation_code)
|
||||
|
||||
# A successful login after requesting activation code should
|
||||
|
@ -337,7 +353,7 @@ class TestAuth(NereidTestCase):
|
|||
}
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
regd_user = self.nereid_user_obj.browse(registered_user_id)
|
||||
regd_user = self.nereid_user_obj(regd_user.id)
|
||||
self.assertFalse(regd_user.activation_code)
|
||||
|
||||
with app.test_client() as c:
|
||||
|
@ -347,7 +363,7 @@ class TestAuth(NereidTestCase):
|
|||
})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
regd_user = self.nereid_user_obj.browse(registered_user_id)
|
||||
regd_user = self.nereid_user_obj(regd_user.id)
|
||||
self.assertTrue(regd_user.activation_code)
|
||||
|
||||
response = c.get(
|
||||
|
@ -364,7 +380,7 @@ class TestAuth(NereidTestCase):
|
|||
})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
regd_user = self.nereid_user_obj.browse(registered_user_id)
|
||||
regd_user = self.nereid_user_obj(regd_user.id)
|
||||
self.assertFalse(regd_user.activation_code)
|
||||
|
||||
response = c.post('/en_US/login',
|
||||
|
@ -396,7 +412,7 @@ class TestAuth(NereidTestCase):
|
|||
'display_name': 'Registered User',
|
||||
'email': 'email@example.com',
|
||||
'password': 'password',
|
||||
'company': self.company_id,
|
||||
'company': self.company,
|
||||
}
|
||||
self.nereid_user_obj.create(data.copy())
|
||||
|
||||
|
@ -444,7 +460,7 @@ class TestAuth(NereidTestCase):
|
|||
})
|
||||
|
||||
self.nereid_user_obj.write(
|
||||
self.guest_user_id, {'permissions': [('set', [perm_admin])]}
|
||||
[self.guest_user], {'permissions': [('set', [perm_admin])]}
|
||||
)
|
||||
@permissions_required(['admin'])
|
||||
def test_permission_2():
|
||||
|
@ -461,7 +477,7 @@ class TestAuth(NereidTestCase):
|
|||
self.assertRaises(Forbidden, test_permission_3)
|
||||
|
||||
self.nereid_user_obj.write(
|
||||
self.guest_user_id,
|
||||
[self.guest_user],
|
||||
{'permissions': [('set', [perm_admin, perm_nereid_admin])]}
|
||||
)
|
||||
with app.test_request_context():
|
||||
|
@ -476,7 +492,7 @@ class TestAuth(NereidTestCase):
|
|||
app = self.get_app()
|
||||
|
||||
self.templates['localhost/home.jinja'] = """
|
||||
{{ request.nereid_user.get_profile_picture(request.nereid_user) }}
|
||||
{{ request.nereid_user.get_profile_picture() }}
|
||||
"""
|
||||
|
||||
with app.test_client() as c:
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
|
||||
Test the currency URL handling
|
||||
|
||||
:copyright: (c) 2010-2013 by Openlabs Technologies & Consulting (P) Ltd.
|
||||
:license: GPLv3, see LICENSE for more details.
|
||||
"""
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import unittest
|
||||
from decimal import Decimal
|
||||
|
||||
import trytond.tests.test_tryton
|
||||
from trytond.tests.test_tryton import POOL, USER, DB_NAME, CONTEXT
|
||||
|
@ -39,64 +35,69 @@ class TestCurrency(NereidTestCase):
|
|||
'name': 'US Dollar',
|
||||
'code': 'USD',
|
||||
'symbol': '$',
|
||||
'rates': [('create', {'rate': Decimal('1')})],
|
||||
})
|
||||
self.company_id = self.company_obj.create({
|
||||
self.company = self.company_obj.create({
|
||||
'name': 'Openlabs',
|
||||
'currency': usd
|
||||
})
|
||||
self.company = self.company_obj.browse(self.company_id)
|
||||
self.guest_user_id = self.nereid_user_obj.create({
|
||||
'name': 'Guest User',
|
||||
'display_name': 'Guest User',
|
||||
'email': 'guest@openlabs.co.in',
|
||||
'password': 'password',
|
||||
'company': self.company_id,
|
||||
'company': self.company,
|
||||
})
|
||||
c1 = self.currency_obj.create({
|
||||
'code': 'C1',
|
||||
'symbol': 'C1',
|
||||
'name': 'Currency 1',
|
||||
'rates': [('create', {'rate': Decimal('10')})],
|
||||
|
||||
})
|
||||
c2 = self.currency_obj.create({
|
||||
'code': 'C2',
|
||||
'symbol': 'C2',
|
||||
'name': 'Currency 2',
|
||||
'rates': [('create', {'rate': Decimal('20')})],
|
||||
})
|
||||
self.lang_currency = self.currency_obj.create({
|
||||
'code': 'C3',
|
||||
'symbol': 'C3',
|
||||
'name': 'Currency 3',
|
||||
'rates': [('create', {'rate': Decimal('30')})],
|
||||
})
|
||||
self.currency_obj.create({
|
||||
'code': 'C4',
|
||||
'symbol': 'C4',
|
||||
'name': 'Currency 4',
|
||||
'rates': [('create', {'rate': Decimal('40')})],
|
||||
})
|
||||
self.website_currency_ids = [c1, c2]
|
||||
url_map_id, = self.url_map_obj.search([], limit=1)
|
||||
self.en_us_id, = self.language_obj.search([('code', '=', 'en_US')])
|
||||
self.website_currencies = [c1, c2]
|
||||
url_map, = self.url_map_obj.search([], limit=1)
|
||||
self.en_us, = self.language_obj.search([('code', '=', 'en_US')])
|
||||
self.nereid_website_obj.create({
|
||||
'name': 'localhost',
|
||||
'url_map': url_map_id,
|
||||
'company': self.company_id,
|
||||
'url_map': url_map,
|
||||
'company': self.company,
|
||||
'application_user': USER,
|
||||
'default_language': self.en_us_id,
|
||||
'default_language': self.en_us,
|
||||
'guest_user': self.guest_user_id,
|
||||
'currencies': [('set', self.website_currency_ids)],
|
||||
'currencies': [('set', self.website_currencies)],
|
||||
})
|
||||
self.templates = {
|
||||
'localhost/home.jinja': '{{ request.nereid_currency.id }}',
|
||||
}
|
||||
|
||||
def get_template_source(self, name):
|
||||
"""
|
||||
Return templates
|
||||
"""
|
||||
templates = {
|
||||
'localhost/home.jinja': '{{ request.nereid_currency.id }}',
|
||||
}
|
||||
return templates.get(name)
|
||||
return self.templates.get(name)
|
||||
|
||||
def test_0010_currency_from_company(self):
|
||||
"""
|
||||
Do not set a currency for the language, and the failover of
|
||||
Do not set a currency for the language, and the fail over of
|
||||
picking currency from company should work.
|
||||
"""
|
||||
with Transaction().start(DB_NAME, USER, CONTEXT):
|
||||
|
@ -109,6 +110,12 @@ class TestCurrency(NereidTestCase):
|
|||
|
||||
self.assertEqual(int(rv.data), self.company.currency.id)
|
||||
|
||||
with app.test_request_context('/en_US/'):
|
||||
self.assertEqual(
|
||||
self.currency_obj.convert(Decimal('100')), Decimal('100')
|
||||
)
|
||||
|
||||
|
||||
def test_0020_currency_from_language(self):
|
||||
"""
|
||||
Set the currency for the language and check if the currency
|
||||
|
@ -119,13 +126,19 @@ class TestCurrency(NereidTestCase):
|
|||
app = self.get_app()
|
||||
|
||||
self.language_obj.write(
|
||||
self.en_us_id, {'default_currency': self.lang_currency}
|
||||
[self.en_us], {'default_currency': self.lang_currency}
|
||||
)
|
||||
with app.test_client() as c:
|
||||
rv = c.get('/en_US/')
|
||||
self.assertEqual(rv.status_code, 200)
|
||||
|
||||
self.assertEqual(int(rv.data), self.lang_currency)
|
||||
self.assertEqual(int(rv.data), int(self.lang_currency))
|
||||
|
||||
with app.test_request_context('/en_US/'):
|
||||
self.assertEqual(
|
||||
self.currency_obj.convert(Decimal('100')), Decimal('3000')
|
||||
)
|
||||
|
||||
|
||||
def suite():
|
||||
"Currency test suite"
|
||||
|
|
|
@ -93,7 +93,7 @@ class TestStaticFile(NereidTestCase):
|
|||
templates = {
|
||||
'localhost/home.jinja':
|
||||
'''
|
||||
{% set static_file = static_file_obj.browse(static_file_id) %}
|
||||
{% set static_file = static_file_obj(static_file_id) %}
|
||||
{{ static_file.url }}
|
||||
''',
|
||||
|
||||
|
@ -124,8 +124,7 @@ class TestStaticFile(NereidTestCase):
|
|||
self.setup_defaults()
|
||||
|
||||
file_buffer = buffer('test-content')
|
||||
file_id = self.create_static_file(file_buffer)
|
||||
static_file = self.static_file_obj.browse(file_id)
|
||||
static_file = self.create_static_file(file_buffer)
|
||||
self.assertEqual(static_file.file_binary, file_buffer)
|
||||
|
||||
app = self.get_app()
|
||||
|
@ -141,8 +140,7 @@ class TestStaticFile(NereidTestCase):
|
|||
self.setup_defaults()
|
||||
|
||||
file_buffer = buffer('test-content')
|
||||
file_id = self.create_static_file(file_buffer)
|
||||
file = self.static_file_obj.browse(file_id)
|
||||
file = self.create_static_file(file_buffer)
|
||||
self.assertFalse(file.url)
|
||||
|
||||
app = self.get_app()
|
||||
|
@ -155,7 +153,7 @@ class TestStaticFile(NereidTestCase):
|
|||
static_file_obj=static_file_obj,
|
||||
static_file_id=file_id,
|
||||
)
|
||||
home_func = functools.partial(home_func, file_id=file_id)
|
||||
home_func = functools.partial(home_func, file_id=file.id)
|
||||
c.application.view_functions[
|
||||
'nereid.website.home'] = new.instancemethod(
|
||||
home_func, self.nereid_website_obj
|
||||
|
@ -178,13 +176,12 @@ class TestStaticFile(NereidTestCase):
|
|||
'folder_name': 'test',
|
||||
'description': 'Test Folder'
|
||||
})
|
||||
file_id = self.static_file_obj.create({
|
||||
file = self.static_file_obj.create({
|
||||
'name': 'remote.png',
|
||||
'folder': folder_id,
|
||||
'type': 'remote',
|
||||
'remote_path': 'http://openlabs.co.in/logo.png',
|
||||
})
|
||||
file = self.static_file_obj.browse(file_id)
|
||||
self.assertFalse(file.url)
|
||||
|
||||
app = self.get_app()
|
||||
|
@ -197,7 +194,7 @@ class TestStaticFile(NereidTestCase):
|
|||
static_file_obj=static_file_obj,
|
||||
static_file_id=file_id,
|
||||
)
|
||||
home_func = functools.partial(home_func, file_id=file_id)
|
||||
home_func = functools.partial(home_func, file_id=file.id)
|
||||
c.application.view_functions[
|
||||
'nereid.website.home'] = new.instancemethod(
|
||||
home_func, self.nereid_website_obj
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
[tryton]
|
||||
version=2.6.0.1
|
||||
depends:
|
||||
ir
|
||||
res
|
||||
company
|
||||
xml:
|
||||
configuration.xml
|
||||
static_file.xml
|
||||
urls.xml
|
||||
party.xml
|
38
urls.xml
38
urls.xml
|
@ -15,6 +15,7 @@
|
|||
<field name="rule">/</field>
|
||||
<field name="endpoint">nereid.website.home</field>
|
||||
<field name="sequence" eval="05" />
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -22,6 +23,7 @@
|
|||
<field name="rule">/<language>/</field>
|
||||
<field name="endpoint">nereid.website.home</field>
|
||||
<field name="sequence" eval="10" />
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -29,7 +31,8 @@
|
|||
<field name="rule">/<language>/login</field>
|
||||
<field name="endpoint">nereid.website.login</field>
|
||||
<field name="sequence" eval="20" />
|
||||
<field name="methods">("GET", "POST")</field>
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="http_method_post" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -37,14 +40,16 @@
|
|||
<field name="rule">/<language>/logout</field>
|
||||
<field name="endpoint">nereid.website.logout</field>
|
||||
<field name="sequence" eval="30" />
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
<record id="registration_url" model="nereid.url_rule">
|
||||
<field name="rule">/<language>/registration</field>
|
||||
<field name="endpoint">nereid.user.registration</field>
|
||||
<field name="methods">("GET", "POST")</field>
|
||||
<field name="sequence" eval="40" />
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="http_method_post" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -52,6 +57,7 @@
|
|||
<field name="rule">/<language>/account</field>
|
||||
<field name="endpoint">nereid.website.account</field>
|
||||
<field name="sequence" eval="50" />
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -59,7 +65,8 @@
|
|||
<field name="rule">/<language>/change-password</field>
|
||||
<field name="endpoint">nereid.user.change_password</field>
|
||||
<field name="sequence" eval="60" />
|
||||
<field name="methods">("GET", "POST")</field>
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="http_method_post" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -67,15 +74,17 @@
|
|||
<field name="rule">/<language>/new-password</field>
|
||||
<field name="endpoint">nereid.user.new_password</field>
|
||||
<field name="sequence" eval="65" />
|
||||
<field name="methods">("GET", "POST")</field>
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="http_method_post" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
<record id="activate_url" model="nereid.url_rule">
|
||||
<field name="rule">/<language>/activate-account/<int:user_id>/<activation_code></field>
|
||||
<field name="rule">/<language>/activate-account/<int:active_id>/<activation_code></field>
|
||||
<field name="endpoint">nereid.user.activate</field>
|
||||
<field name="sequence" eval="70" />
|
||||
<field name="methods">("GET", "POST")</field>
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="http_method_post" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -83,7 +92,8 @@
|
|||
<field name="rule">/<language>/reset-account</field>
|
||||
<field name="endpoint">nereid.user.reset_account</field>
|
||||
<field name="sequence" eval="80" />
|
||||
<field name="methods">("GET", "POST")</field>
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="http_method_post" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -91,7 +101,8 @@
|
|||
<field name="rule">/<language>/save-new-address</field>
|
||||
<field name="endpoint">party.address.edit_address</field>
|
||||
<field name="sequence" eval="90" />
|
||||
<field name="methods">("GET", "POST")</field>
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="http_method_post" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -100,7 +111,8 @@
|
|||
<field name="rule">/<language>/edit-address/<int:address></field>
|
||||
<field name="endpoint">party.address.edit_address</field>
|
||||
<field name="sequence" eval="90" />
|
||||
<field name="methods">("GET", "POST")</field>
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="http_method_post" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -108,6 +120,7 @@
|
|||
<field name="rule">/<language>/view-address</field>
|
||||
<field name="endpoint">party.address.view_address</field>
|
||||
<field name="sequence" eval="100" />
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -115,6 +128,7 @@
|
|||
<field name="rule">/<language>/countries</field>
|
||||
<field name="endpoint">nereid.website.country_list</field>
|
||||
<field name="sequence" eval="110" />
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -122,6 +136,7 @@
|
|||
<field name="rule">/<language>/subdivisions</field>
|
||||
<field name="endpoint">nereid.website.subdivision_list</field>
|
||||
<field name="sequence" eval="120" />
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -129,6 +144,7 @@
|
|||
<field name="rule">/<language>/static-file/<folder>/<name></field>
|
||||
<field name="endpoint">nereid.static.file.send_static_file</field>
|
||||
<field name="sequence" eval="130" />
|
||||
<field name="http_method_get" eval="True"/>
|
||||
<field name="url_map" ref="default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -143,7 +159,7 @@
|
|||
<field name="rule">/<language>/contact-mechanisms/add</field>
|
||||
<field name="endpoint">party.contact_mechanism.add</field>
|
||||
<field name="sequence" eval="140" />
|
||||
<field name="methods">("POST",)</field>
|
||||
<field name="http_method_post" eval="True"/>
|
||||
<field name="url_map" ref="nereid.default_url_map" />
|
||||
</record>
|
||||
|
||||
|
@ -151,7 +167,7 @@
|
|||
<field name="rule">/<language>/contact-mechanisms/remove</field>
|
||||
<field name="endpoint">party.contact_mechanism.remove</field>
|
||||
<field name="sequence" eval="140" />
|
||||
<field name="methods">("POST",)</field>
|
||||
<field name="http_method_post" eval="True"/>
|
||||
<field name="url_map" ref="nereid.default_url_map" />
|
||||
</record>
|
||||
|
||||
|
|
Loading…
Reference in New Issue