mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-25 19:29:30 -05:00
Compare commits
231 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c92a4b39c | ||
|
|
3dad5132bb | ||
|
|
7d7890445e | ||
|
|
cea015f23d | ||
|
|
3e8610912e | ||
|
|
ba80ca42e6 | ||
|
|
c413db5460 | ||
|
|
0e319ff293 | ||
|
|
88e3b22dcd | ||
|
|
19e2094ecd | ||
|
|
215989682b | ||
|
|
1af2211010 | ||
|
|
724d57ecd7 | ||
|
|
4b04fada51 | ||
|
|
4ad7043f91 | ||
|
|
4dfda4439c | ||
|
|
591d185b9d | ||
|
|
8d582548bd | ||
|
|
209924e5b3 | ||
|
|
7e3e2aadaf | ||
|
|
0930e615f0 | ||
|
|
21c759b127 | ||
|
|
7d1a83440d | ||
|
|
2d75b303fd | ||
|
|
a1b15d46b8 | ||
|
|
69a6edee99 | ||
|
|
0ac23b4e3a | ||
|
|
085e777ee0 | ||
|
|
c31df3f7a6 | ||
|
|
98e2c0acaf | ||
|
|
1509b8243b | ||
|
|
e427d8b714 | ||
|
|
89b8dbe57f | ||
|
|
f2a17fe3bb | ||
|
|
14e0dae6e3 | ||
|
|
733c281dc8 | ||
|
|
c542f3154e | ||
|
|
c6f40db7e3 | ||
|
|
cb3b8c931e | ||
|
|
72bea14c3a | ||
|
|
cd46203d55 | ||
|
|
5c1cecb7e7 | ||
|
|
526cf13b8d | ||
|
|
3c21baf876 | ||
|
|
2d2c38517c | ||
|
|
163b259bd1 | ||
|
|
24ced66c69 | ||
|
|
6c1982cccb | ||
|
|
3bae7283d1 | ||
|
|
0b458f7565 | ||
|
|
675f30126c | ||
|
|
25b051323c | ||
|
|
697de3d9fc | ||
|
|
7bc09dfe89 | ||
|
|
711dfbe55f | ||
|
|
76108c66c6 | ||
|
|
db3c390d03 | ||
|
|
138fb14107 | ||
|
|
17ebdd7711 | ||
|
|
fc9a42029a | ||
|
|
7d942d551a | ||
|
|
78c94f2b64 | ||
|
|
b317d7ba29 | ||
|
|
71b8ddd1bf | ||
|
|
23de4d4239 | ||
|
|
4641b81f70 | ||
|
|
a9bad5e5f9 | ||
|
|
9f7106a325 | ||
|
|
73f13f56e1 | ||
|
|
312c364797 | ||
|
|
ad9b10c9c1 | ||
|
|
678cfaca12 | ||
|
|
9b36f51d16 | ||
|
|
fa8389d783 | ||
|
|
30d766be77 | ||
|
|
5e2dba7b04 | ||
|
|
70df7c5307 | ||
|
|
f91d9fcfe2 | ||
|
|
086a4aea47 | ||
|
|
148ce2faef | ||
|
|
4827364e37 | ||
|
|
da958faf33 | ||
|
|
f5117abcfb | ||
|
|
df79c8f889 | ||
|
|
0ff65d35dc | ||
|
|
8239dc3604 | ||
|
|
4a4d4b4486 | ||
|
|
34733a427f | ||
|
|
7f68bbd25d | ||
|
|
392ee73719 | ||
|
|
2a0a85018a | ||
|
|
62868cd2b2 | ||
|
|
4e92be3bbc | ||
|
|
14c94bf7ab | ||
|
|
ce3148ac89 | ||
|
|
bc39b53aad | ||
|
|
984192e479 | ||
|
|
3c73b084cf | ||
|
|
fc073124d4 | ||
|
|
f6fb07926e | ||
|
|
90dddd34f3 | ||
|
|
0b948618f3 | ||
|
|
78be002134 | ||
|
|
7acd72ff3a | ||
|
|
c5edeb7e8f | ||
|
|
5d5c5a8597 | ||
|
|
03bdcdf9b4 | ||
|
|
16d755fd76 | ||
|
|
587426e3d3 | ||
|
|
be55e034bf | ||
|
|
8055754455 | ||
|
|
82497c734a | ||
|
|
b39a55ee94 | ||
|
|
9d837cd633 | ||
|
|
968206a7ab | ||
|
|
a769fe6906 | ||
|
|
21cf4c5d70 | ||
|
|
6c02912dad | ||
|
|
c0756d87a6 | ||
|
|
2471c7982d | ||
|
|
b36e440920 | ||
|
|
a8b1ee9765 | ||
|
|
782d276724 | ||
|
|
9510562576 | ||
|
|
363a4b6ff7 | ||
|
|
f52dd9ba51 | ||
|
|
4ffc4dc248 | ||
|
|
696791d059 | ||
|
|
c9f1576b24 | ||
|
|
1cea0350c9 | ||
|
|
e0dac67b84 | ||
|
|
c45472689e | ||
|
|
5b7ec37637 | ||
|
|
4d08477b23 | ||
|
|
9b9fbd5cab | ||
|
|
8c118dbd3e | ||
|
|
bfe9e794c5 | ||
|
|
3e16361322 | ||
|
|
35e8dc4ce9 | ||
|
|
8e8c7fe563 | ||
|
|
69d5e628c5 | ||
|
|
e65c8436ef | ||
|
|
e83565b1f2 | ||
|
|
692811f84f | ||
|
|
0aa37d176f | ||
|
|
92341380bc | ||
|
|
19df215bd2 | ||
|
|
372dd0afa1 | ||
|
|
b89c38a696 | ||
|
|
f177fed8e2 | ||
|
|
1d2976b687 | ||
|
|
b490673866 | ||
|
|
5f2320a3e7 | ||
|
|
5b916e955c | ||
|
|
5bad507845 | ||
|
|
64603fca51 | ||
|
|
6018101012 | ||
|
|
ddaa9e6356 | ||
|
|
98f9555ef6 | ||
|
|
1619d4894c | ||
|
|
1e2d7f77af | ||
|
|
80423da16d | ||
|
|
67a4a2627b | ||
|
|
0005ca243c | ||
|
|
adbc7e4a39 | ||
|
|
9caec2dff2 | ||
|
|
41eef9a913 | ||
|
|
31357c552c | ||
|
|
5d70dca039 | ||
|
|
2c5fbc558e | ||
|
|
98bdad5955 | ||
|
|
6eb41fe33f | ||
|
|
e94bd32a70 | ||
|
|
29e2f9ee15 | ||
|
|
357771e81b | ||
|
|
941264731e | ||
|
|
2c59302fe9 | ||
|
|
a96bf9a4d7 | ||
|
|
e2508cbc6f | ||
|
|
577af85d38 | ||
|
|
38e5882376 | ||
|
|
08f06fe1d8 | ||
|
|
4ddc39f1c2 | ||
|
|
78275145f8 | ||
|
|
f7b518d890 | ||
|
|
8cff44df7d | ||
|
|
cdee31e9af | ||
|
|
06db7114ed | ||
|
|
8f28e4766d | ||
|
|
dbdb35e2f3 | ||
|
|
27963fcaa6 | ||
|
|
d613da7faf | ||
|
|
d481767154 | ||
|
|
8b9c7daaae | ||
|
|
3a2ba773cf | ||
|
|
642224fec9 | ||
|
|
3d4aebcd9d | ||
|
|
c178aea363 | ||
|
|
5e20833b7e | ||
|
|
db7f0d4988 | ||
|
|
381bc5ffb4 | ||
|
|
4a6b32d9af | ||
|
|
8b814669af | ||
|
|
ae0928f85f | ||
|
|
bf516d37a9 | ||
|
|
6979bf34d9 | ||
|
|
bda38f0647 | ||
|
|
df912b8865 | ||
|
|
f685253645 | ||
|
|
2c5e44d73c | ||
|
|
b6d98397b5 | ||
|
|
525ad6dd98 | ||
|
|
166833fe83 | ||
|
|
752854028a | ||
|
|
6197cab1ed | ||
|
|
73f2240763 | ||
|
|
3ef82aee9c | ||
|
|
e49e53e2b2 | ||
|
|
0266476aef | ||
|
|
5ed369ba69 | ||
|
|
98c278fe60 | ||
|
|
8594346488 | ||
|
|
dc91e1e8ed | ||
|
|
976dd13a31 | ||
|
|
8cca272bb9 | ||
|
|
f066b7097c | ||
|
|
71b41a9ca2 | ||
|
|
9e748552b2 | ||
|
|
743d7bf608 | ||
|
|
315b4521b6 | ||
|
|
b558ba55b4 |
@@ -16,6 +16,17 @@ POSTGRES_USER=djangodb
|
||||
POSTGRES_PASSWORD=
|
||||
POSTGRES_DB=djangodb
|
||||
|
||||
# Users can set a amount of time after which the shopping list is refreshed when they are in viewing mode
|
||||
# This is the minimum interval users can set. Setting this to low will allow users to refresh very frequently which
|
||||
# might cause high load on the server. (Technically they can obviously refresh as often as they want with their own scripts)
|
||||
SHOPPING_MIN_AUTOSYNC_INTERVAL=5
|
||||
|
||||
# If staticfiles are stored at a different location uncomment and change accordingly
|
||||
# STATIC_URL=/static/
|
||||
|
||||
# If mediafiles are stored at a different location uncomment and change accordingly
|
||||
# MEDIA_URL=/media/
|
||||
|
||||
# Serve mediafiles directly using gunicorn. Basically everyone recommends not doing this. Please use any of the examples
|
||||
# provided that include an additional nxginx container to handle media file serving.
|
||||
# If you know what you are doing turn this back on (1) to serve media files using djangos serve() method.
|
||||
|
||||
11
.github/dependabot.yml
vendored
Normal file
11
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "pip" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
||||
2
.github/workflows/docker-publish-release.yml
vendored
2
.github/workflows/docker-publish-release.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
name: Build image job
|
||||
steps:
|
||||
- name: Checkout master
|
||||
uses: actions/checkout@master#
|
||||
uses: actions/checkout@master
|
||||
- name: Get version number
|
||||
id: get_version
|
||||
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
|
||||
|
||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
1
.idea/dictionaries/vabene1111_PC.xml
generated
1
.idea/dictionaries/vabene1111_PC.xml
generated
@@ -1,6 +1,7 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="vabene1111-PC">
|
||||
<words>
|
||||
<w>autosync</w>
|
||||
<w>csrftoken</w>
|
||||
<w>gunicorn</w>
|
||||
<w>ical</w>
|
||||
|
||||
3
.idea/recipes.iml
generated
3
.idea/recipes.iml
generated
@@ -14,6 +14,8 @@
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/cookbook/tests/resources" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/staticfiles" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.8 (recipes)" jdkType="Python SDK" />
|
||||
@@ -28,7 +30,6 @@
|
||||
<option name="TEMPLATE_FOLDERS">
|
||||
<list>
|
||||
<option value="$MODULE_DIR$/cookbook/templates" />
|
||||
<option value="$MODULE_DIR$/recipes/templates" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
11
CONTRIBUTERS.md
Normal file
11
CONTRIBUTERS.md
Normal file
@@ -0,0 +1,11 @@
|
||||
Many thanks to everyone who contributed to this project!
|
||||
|
||||
|
||||
## Translations
|
||||
|
||||
### Dutch
|
||||
[D0T1X](https://www.transifex.com/user/profile/D0T1X/)
|
||||
|
||||
### French
|
||||
[jt117](https://www.transifex.com/user/profile/jt117/)
|
||||
[nerdinator](https://www.transifex.com/user/profile/nerdinator/)
|
||||
700
LICENSE.md
700
LICENSE.md
@@ -1,22 +1,690 @@
|
||||
“Commons Clause” License Condition v1.0
|
||||
|
||||
The Software is provided to you by the Licensor under the License, as defined below, subject to the following condition.
|
||||
|
||||
Without limiting other conditions in the License, the grant of rights under the License will not include, and the License does not grant to you, the right to Sell the Software.
|
||||
|
||||
For purposes of the foregoing, “Sell” means practicing any or all of the rights granted to you under the License to provide to third parties, for a fee or other consideration (including without limitation fees for hosting or consulting/ support services related to the Software), a product or service whose value derives, entirely or substantially, from the functionality of the Software. Any license notice or attribution required by the License must also include this Commons Clause License Condition notice.
|
||||
|
||||
Software: https://github.com/vabene1111/recipes
|
||||
|
||||
License: GNU AFFERO GENERAL PUBLIC LICENSE v3
|
||||
|
||||
Licensor: https://github.com/vabene1111
|
||||
|
||||
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are 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.
|
||||
|
||||
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.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
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 Affero 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. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
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 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 work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero 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 Affero 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 Affero 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 Affero 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 Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
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 AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
### Prior 0.10.0
|
||||
> All versions released before version 0.10. or 29.06.2020 were licensed under the following license
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018
|
||||
Copyright (c) 2018
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
41
README.md
41
README.md
@@ -1,16 +1,18 @@
|
||||
# Recipes 
|
||||
|
||||
Recipes is a Django application to manage, tag and search recipes using either built in models or external storage providers hosting PDF's, Images or other files.
|
||||
|
||||

|
||||
|
||||
[More Screenshots](https://imgur.com/a/V01151p)
|
||||
|
||||
### Features
|
||||
## Features
|
||||
|
||||
- :package: **Sync** files with Dropbox and Nextcloud (more can easily be added)
|
||||
- :mag: Powerful **search** with Djangos [TrigramSimilarity](https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/search/#trigram-similarity)
|
||||
- :label: Create and search for **tags**, assign them in batch to all files matching certain filters
|
||||
- :page_facing_up: **Create recipes** locally within a nice, standardized web interface
|
||||
- :page_facing_up: **Create recipes** locally within a nice, standardized web interface
|
||||
- :arrow_down: **Import recipes** from thousands of websites supporting [ld+json or microdata](https://schema.org/Recipe)
|
||||
- :iphone: Optimized for use on **mobile** devices like phones and tablets
|
||||
- :shopping_cart: Generate **shopping** lists from recipes
|
||||
- :calendar: Create a **Plan** on what to eat when
|
||||
@@ -20,30 +22,29 @@ Recipes is a Django application to manage, tag and search recipes using either b
|
||||
- :envelope: Export and import recipes from other users
|
||||
- :heavy_plus_sign: Many more like recipe scaling, image compression, cookbooks, printing views, ...
|
||||
|
||||
This application is meant for people with a collection of recipes they want to share with family and friends or simply
|
||||
This application is meant for people with a collection of recipes they want to share with family and friends or simply
|
||||
store them in a nicely organized way. A basic permission system exists but this application is not meant to be run as a public page.
|
||||
Some Documentation can be found [here](https://github.com/vabene1111/recipes/wiki)
|
||||
# Installation
|
||||
|
||||
## Installation
|
||||
|
||||
The docker image (`vabene1111/recipes`) simply exposes the application on port `8080`. You may choose any preferred installation method, the following are just examples to make it easier.
|
||||
|
||||
### Docker-Compose
|
||||
|
||||
2. Choose one of the included configurations [here](docs/docker).
|
||||
2. Download the environment (config) file template and fill it out `wget https://raw.githubusercontent.com/vabene1111/recipes/develop/.env.template -O .env `
|
||||
1. Choose one of the included configurations [here](docs/docker).
|
||||
2. Download the environment (config) file template and fill it out `wget https://raw.githubusercontent.com/vabene1111/recipes/develop/.env.template -O .env`
|
||||
3. Start the container `docker-compose up -d`
|
||||
4. Open the page to create the first user. Alternatively use `docker-compose exec web_recipes createsuperuser`
|
||||
4. Open the page to create the first user. Alternatively use `docker-compose exec web_recipes createsuperuser`
|
||||
|
||||
### Manual
|
||||
**Python >= 3.8** is required to run this!
|
||||
|
||||
Copy `.env.template` to `.env` and fill in the missing values accordingly.
|
||||
Make sure all variables are available to whatever serves your application.
|
||||
**Python >= 3.8** is required to run this!
|
||||
|
||||
Otherwise simply follow the instructions for any django based deployment
|
||||
(for example [this one](http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html)).
|
||||
Refer to [manual install](docs/manual_install) for detailled instructions.
|
||||
|
||||
## Updating
|
||||
|
||||
While intermediate updates can be skipped when updating please make sure to **read the release notes** in case some special action is required to update.
|
||||
|
||||
0. Before updating it is recommended to **create a backup!**
|
||||
@@ -56,13 +57,27 @@ While intermediate updates can be skipped when updating please make sure to **re
|
||||
You can find a basic kubernetes setup [here](docs/k8s/). Please see the README in the folder for more detail.
|
||||
|
||||
## Contributing
|
||||
|
||||
Pull Requests and ideas are welcome, feel free to contribute in any way.
|
||||
For any questions on how to work with django please refer to their excellent [documentation](https://www.djangoproject.com/start/).
|
||||
|
||||
### Translating
|
||||
|
||||
There is a [transifex project](https://www.transifex.com/django-recipes/django-cookbook/) project to enable community driven translations. If you want to contribute a new language or help maintain an already existing one feel free to create a transifex account (using the link above) and request to join the project.
|
||||
|
||||
It is also possible to provide the translations directly by creating a new language using `manage.py makemessages -l <language_code> -i venv`. Once finished simply open a PR with the changed files.
|
||||
|
||||
## License
|
||||
This project is licensed under the MIT license. Even though it is not required to publish derivatives, I highly encourage pushing changes upstream and letting people profit from any work done on this project.
|
||||
|
||||
Beginning with version 0.10.0 the code in this repository is licensed under the [GNU AGPL v3](https://www.gnu.org/licenses/agpl-3.0.de.html) license with an
|
||||
[common clause](https://commonsclause.com/) selling exception. See [LICENSE.md](https://github.com/vabene1111/recipes/blob/develop/LICENSE.md) for details.
|
||||
|
||||
**Reasoning**
|
||||
**This software and *all* its features are and will always be free for everyone to use and enjoy.**
|
||||
|
||||
The reason for the selling exception is that a significant amount of time was spend over multiple years to develop this software.
|
||||
A payed hosted version which will be identical in features and code base to the software offered in this repository will
|
||||
likely be released in the future (including all features needed to sell a hosted version as they might also be useful for personal use).
|
||||
This will not only benefit me personally but also everyone who self-hosts this software as any profits made trough selling the hosted option
|
||||
allow me to spend more time developing and improving the software for everyone. Selling exceptions are [approved by Richard Stallman](http://www.gnu.org/philosophy/selling-exceptions.en.html) and the
|
||||
common clause license is very permissive (see the [FAQ](https://commonsclause.com/)).
|
||||
|
||||
@@ -2,6 +2,13 @@ from django.contrib import admin
|
||||
from .models import *
|
||||
|
||||
|
||||
class SpaceAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'message')
|
||||
|
||||
|
||||
admin.site.register(Space, SpaceAdmin)
|
||||
|
||||
|
||||
class UserPreferenceAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'theme', 'nav_color', 'default_page', 'search_style', 'comments')
|
||||
|
||||
@@ -36,6 +43,13 @@ admin.site.register(SyncLog, SyncLogAdmin)
|
||||
admin.site.register(Keyword)
|
||||
|
||||
|
||||
class StepAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'type', 'order')
|
||||
|
||||
|
||||
admin.site.register(Step, StepAdmin)
|
||||
|
||||
|
||||
class RecipeAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'internal', 'created_by', 'storage')
|
||||
|
||||
@@ -47,14 +61,14 @@ class RecipeAdmin(admin.ModelAdmin):
|
||||
admin.site.register(Recipe, RecipeAdmin)
|
||||
|
||||
admin.site.register(Unit)
|
||||
admin.site.register(Ingredient)
|
||||
admin.site.register(Food)
|
||||
|
||||
|
||||
class RecipeIngredientAdmin(admin.ModelAdmin):
|
||||
list_display = ('recipe', 'ingredient', 'amount', 'unit')
|
||||
class IngredientAdmin(admin.ModelAdmin):
|
||||
list_display = ('food', 'amount', 'unit')
|
||||
|
||||
|
||||
admin.site.register(RecipeIngredient, RecipeIngredientAdmin)
|
||||
admin.site.register(Ingredient, IngredientAdmin)
|
||||
|
||||
|
||||
class CommentAdmin(admin.ModelAdmin):
|
||||
@@ -118,6 +132,13 @@ class ViewLogAdmin(admin.ModelAdmin):
|
||||
admin.site.register(ViewLog, ViewLogAdmin)
|
||||
|
||||
|
||||
class InviteLinkAdmin(admin.ModelAdmin):
|
||||
list_display = ('username', 'group', 'valid_until', 'created_by', 'created_at', 'used_by')
|
||||
|
||||
|
||||
admin.site.register(InviteLink, InviteLinkAdmin)
|
||||
|
||||
|
||||
class CookLogAdmin(admin.ModelAdmin):
|
||||
list_display = ('recipe', 'created_by', 'created_at', 'rating', 'servings')
|
||||
|
||||
@@ -125,6 +146,27 @@ class CookLogAdmin(admin.ModelAdmin):
|
||||
admin.site.register(CookLog, CookLogAdmin)
|
||||
|
||||
|
||||
class ShoppingListRecipeAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'recipe', 'multiplier')
|
||||
|
||||
|
||||
admin.site.register(ShoppingListRecipe, ShoppingListRecipeAdmin)
|
||||
|
||||
|
||||
class ShoppingListEntryAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'food', 'unit', 'list_recipe', 'checked')
|
||||
|
||||
|
||||
admin.site.register(ShoppingListEntry, ShoppingListEntryAdmin)
|
||||
|
||||
|
||||
class ShoppingListAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'created_by', 'created_at')
|
||||
|
||||
|
||||
admin.site.register(ShoppingList, ShoppingListAdmin)
|
||||
|
||||
|
||||
class ShareLinkAdmin(admin.ModelAdmin):
|
||||
list_display = ('recipe', 'created_by', 'uuid', 'created_at',)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import django_filters
|
||||
from django.contrib.postgres.search import TrigramSimilarity
|
||||
from django.db.models import Q
|
||||
from cookbook.forms import MultiSelectWidget
|
||||
from cookbook.models import Recipe, Keyword, Ingredient
|
||||
from cookbook.models import Recipe, Keyword, Food, ShoppingList
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
@@ -11,8 +11,8 @@ class RecipeFilter(django_filters.FilterSet):
|
||||
name = django_filters.CharFilter(method='filter_name')
|
||||
keywords = django_filters.ModelMultipleChoiceFilter(queryset=Keyword.objects.all(), widget=MultiSelectWidget,
|
||||
method='filter_keywords')
|
||||
ingredients = django_filters.ModelMultipleChoiceFilter(queryset=Ingredient.objects.all(), widget=MultiSelectWidget,
|
||||
method='filter_ingredients', label=_('Ingredients'))
|
||||
foods = django_filters.ModelMultipleChoiceFilter(queryset=Food.objects.all(), widget=MultiSelectWidget,
|
||||
method='filter_foods', label=_('Ingredients'))
|
||||
|
||||
@staticmethod
|
||||
def filter_keywords(queryset, name, value):
|
||||
@@ -23,11 +23,11 @@ class RecipeFilter(django_filters.FilterSet):
|
||||
return queryset
|
||||
|
||||
@staticmethod
|
||||
def filter_ingredients(queryset, name, value):
|
||||
if not name == 'ingredients':
|
||||
def filter_foods(queryset, name, value):
|
||||
if not name == 'foods':
|
||||
return queryset
|
||||
for x in value:
|
||||
queryset = queryset.filter(recipeingredient__ingredient=x).distinct()
|
||||
queryset = queryset.filter(steps__ingredients__food__name=x).distinct()
|
||||
return queryset
|
||||
|
||||
@staticmethod
|
||||
@@ -43,12 +43,25 @@ class RecipeFilter(django_filters.FilterSet):
|
||||
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ['name', 'keywords', 'ingredients', 'internal']
|
||||
fields = ['name', 'keywords', 'foods', 'internal']
|
||||
|
||||
|
||||
class IngredientFilter(django_filters.FilterSet):
|
||||
name = django_filters.CharFilter(lookup_expr='icontains')
|
||||
|
||||
class Meta:
|
||||
model = Ingredient
|
||||
model = Food
|
||||
fields = ['name']
|
||||
|
||||
|
||||
class ShoppingListFilter(django_filters.FilterSet):
|
||||
|
||||
def __init__(self, data=None, *args, **kwargs):
|
||||
if data is not None:
|
||||
data = data.copy()
|
||||
data.setdefault("finished", False)
|
||||
super(ShoppingListFilter, self).__init__(data, *args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
model = ShoppingList
|
||||
fields = ['finished']
|
||||
|
||||
@@ -31,7 +31,7 @@ class UserPreferenceForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = UserPreference
|
||||
fields = ('default_unit', 'theme', 'nav_color', 'default_page', 'show_recent', 'search_style', 'plan_share', 'ingredient_decimals', 'comments')
|
||||
fields = ('default_unit', 'theme', 'nav_color', 'default_page', 'show_recent', 'search_style', 'plan_share', 'ingredient_decimals', 'shopping_auto_sync', 'comments')
|
||||
|
||||
help_texts = {
|
||||
'nav_color': _('Color of the top navigation bar. Not all colors work with all themes, just try them out!'),
|
||||
@@ -39,7 +39,10 @@ class UserPreferenceForm(forms.ModelForm):
|
||||
'plan_share': _('Default user to share newly created meal plan entries with.'),
|
||||
'show_recent': _('Show recently viewed recipes on search page.'),
|
||||
'ingredient_decimals': _('Number of decimals to round ingredients.'),
|
||||
'comments': _('If you want to be able to create and see comments underneath recipes.')
|
||||
'comments': _('If you want to be able to create and see comments underneath recipes.'),
|
||||
'shopping_auto_sync': _(
|
||||
'Setting to 0 will disable auto sync. When viewing a shopping list the list is updated every set seconds to sync changes someone else might have made. Useful when shopping with multiple people but might use a little bit '
|
||||
'of mobile data. If lower than instance limit it is reset when saving.')
|
||||
}
|
||||
|
||||
widgets = {
|
||||
@@ -84,19 +87,15 @@ class InternalRecipeForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'instructions', 'image', 'working_time', 'waiting_time', 'keywords')
|
||||
fields = ('name', 'image', 'working_time', 'waiting_time', 'keywords')
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
'keywords': _('Keywords'),
|
||||
'instructions': _('Instructions'),
|
||||
'working_time': _('Preparation time in minutes'),
|
||||
'waiting_time': _('Waiting time (cooking/baking) in minutes'),
|
||||
}
|
||||
widgets = {'keywords': MultiSelectWidget}
|
||||
help_texts = {
|
||||
'instructions': _('You can use markdown to format this field. See the <a href="/docs/markdown/">docs here</a>')
|
||||
}
|
||||
|
||||
|
||||
class ShoppingForm(forms.Form):
|
||||
@@ -147,20 +146,20 @@ class UnitMergeForm(forms.Form):
|
||||
)
|
||||
|
||||
|
||||
class IngredientMergeForm(forms.Form):
|
||||
prefix = 'ingredient'
|
||||
class FoodMergeForm(forms.Form):
|
||||
prefix = 'food'
|
||||
|
||||
new_ingredient = forms.ModelChoiceField(
|
||||
queryset=Ingredient.objects.all(),
|
||||
new_food = forms.ModelChoiceField(
|
||||
queryset=Food.objects.all(),
|
||||
widget=SelectWidget,
|
||||
label=_('New Ingredient'),
|
||||
help_text=_('New ingredient that other gets replaced by.'),
|
||||
label=_('New Food'),
|
||||
help_text=_('New food that other gets replaced by.'),
|
||||
)
|
||||
old_ingredient = forms.ModelChoiceField(
|
||||
queryset=Ingredient.objects.all(),
|
||||
old_food = forms.ModelChoiceField(
|
||||
queryset=Food.objects.all(),
|
||||
widget=SelectWidget,
|
||||
label=_('Old Ingredient'),
|
||||
help_text=_('Ingredient that should be replaced.'),
|
||||
label=_('Old Food'),
|
||||
help_text=_('Food that should be replaced.'),
|
||||
)
|
||||
|
||||
|
||||
@@ -186,9 +185,9 @@ class KeywordForm(forms.ModelForm):
|
||||
widgets = {'icon': EmojiPickerTextInput}
|
||||
|
||||
|
||||
class IngredientForm(forms.ModelForm):
|
||||
class FoodForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Ingredient
|
||||
model = Food
|
||||
fields = ('name', 'recipe')
|
||||
widgets = {'recipe': SelectWidget}
|
||||
|
||||
@@ -265,17 +264,27 @@ class MealPlanForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = MealPlan
|
||||
fields = ('recipe', 'title', 'meal_type', 'note', 'date', 'shared')
|
||||
fields = ('recipe', 'title', 'meal_type', 'note', 'recipe_multiplier', 'date', 'shared')
|
||||
|
||||
help_texts = {
|
||||
'shared': _('You can list default users to share recipes with in the settings.'),
|
||||
'note': _('You can use markdown to format this field. See the <a href="/docs/markdown/">docs here</a>')
|
||||
'note': _('You can use markdown to format this field. See the <a href="/docs/markdown/">docs here</a>'),
|
||||
'recipe_multiplier': _('Scaling factor for recipe.')
|
||||
}
|
||||
|
||||
widgets = {'recipe': SelectWidget, 'date': DateWidget, 'shared': MultiSelectWidget}
|
||||
|
||||
|
||||
class SuperUserForm(forms.Form):
|
||||
name = forms.CharField()
|
||||
class InviteLinkForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = InviteLink
|
||||
fields = ('username', 'group', 'valid_until')
|
||||
help_texts = {
|
||||
'username': _('A username is not required, if left blank the new user can choose one.')
|
||||
}
|
||||
|
||||
|
||||
class UserCreateForm(forms.Form):
|
||||
name = forms.CharField(label='Username')
|
||||
password = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password', 'type': 'password'}))
|
||||
password_confirm = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password', 'type': 'password'}))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from dal import autocomplete
|
||||
|
||||
from cookbook.models import Keyword, RecipeIngredient, Recipe, Unit, Ingredient
|
||||
from cookbook.models import Keyword, Recipe, Unit, Food
|
||||
|
||||
|
||||
class KeywordAutocomplete(autocomplete.Select2QuerySetView):
|
||||
@@ -19,9 +19,9 @@ class KeywordAutocomplete(autocomplete.Select2QuerySetView):
|
||||
class IngredientsAutocomplete(autocomplete.Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
if not self.request.user.is_authenticated:
|
||||
return Ingredient.objects.none()
|
||||
return Food.objects.none()
|
||||
|
||||
qs = Ingredient.objects.all()
|
||||
qs = Food.objects.all()
|
||||
|
||||
if self.q:
|
||||
qs = qs.filter(name__icontains=self.q)
|
||||
|
||||
@@ -9,6 +9,7 @@ from django.utils.translation import gettext as _
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from rest_framework import permissions
|
||||
from rest_framework.permissions import SAFE_METHODS
|
||||
|
||||
from cookbook.models import ShareLink
|
||||
|
||||
@@ -66,9 +67,28 @@ def is_object_owner(user, obj):
|
||||
return owner == user
|
||||
if owner := getattr(obj, 'user', None):
|
||||
return owner == user
|
||||
if getattr(obj, 'get_owner', None):
|
||||
return obj.get_owner() == user
|
||||
return False
|
||||
|
||||
|
||||
def is_object_shared(user, obj):
|
||||
"""
|
||||
Tests if a given user is shared for a given object
|
||||
test performed by checking user against the objects shared table
|
||||
superusers bypass all checks, unauthenticated users cannot own anything
|
||||
:param user django auth user object
|
||||
:param obj any object that should be tested
|
||||
:return: true if user is shared for object, false otherwise
|
||||
"""
|
||||
# TODO this could be improved/cleaned up by adding share checks for relevant objects
|
||||
if not user.is_authenticated:
|
||||
return False
|
||||
if user.is_superuser:
|
||||
return True
|
||||
return user in obj.shared.all()
|
||||
|
||||
|
||||
def share_link_valid(recipe, share):
|
||||
"""
|
||||
Verifies the validity of a share uuid
|
||||
@@ -144,6 +164,20 @@ class CustomIsOwner(permissions.BasePermission):
|
||||
return is_object_owner(request.user, obj)
|
||||
|
||||
|
||||
class CustomIsShared(permissions.BasePermission): # TODO function duplicate/too similar name
|
||||
"""
|
||||
Custom permission class for django rest framework views
|
||||
verifies user is shared for the object he is trying to access
|
||||
"""
|
||||
message = _('You cannot interact with this object as its not owned by you!')
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return request.user.is_authenticated
|
||||
|
||||
def has_object_permission(self, request, view, obj):
|
||||
return is_object_shared(request.user, obj)
|
||||
|
||||
|
||||
class CustomIsGuest(permissions.BasePermission):
|
||||
"""
|
||||
Custom permission class for django rest framework views
|
||||
@@ -152,7 +186,10 @@ class CustomIsGuest(permissions.BasePermission):
|
||||
message = _('You do not have the required permissions to view this page!')
|
||||
|
||||
def has_permission(self, request, view):
|
||||
has_group_permission(request.user, ['guest'])
|
||||
return has_group_permission(request.user, ['guest'])
|
||||
|
||||
def has_object_permission(self, request, view, obj):
|
||||
return has_group_permission(request.user, ['guest'])
|
||||
|
||||
|
||||
class CustomIsUser(permissions.BasePermission):
|
||||
@@ -163,7 +200,7 @@ class CustomIsUser(permissions.BasePermission):
|
||||
message = _('You do not have the required permissions to view this page!')
|
||||
|
||||
def has_permission(self, request, view):
|
||||
has_group_permission(request.user, ['user'])
|
||||
return has_group_permission(request.user, ['user'])
|
||||
|
||||
|
||||
class CustomIsAdmin(permissions.BasePermission):
|
||||
@@ -174,5 +211,21 @@ class CustomIsAdmin(permissions.BasePermission):
|
||||
message = _('You do not have the required permissions to view this page!')
|
||||
|
||||
def has_permission(self, request, view):
|
||||
has_group_permission(request.user, ['admin'])
|
||||
return has_group_permission(request.user, ['admin'])
|
||||
|
||||
|
||||
class CustomIsShare(permissions.BasePermission):
|
||||
"""
|
||||
Custom permission class for django rest framework views
|
||||
verifies the requesting user provided a valid share link
|
||||
"""
|
||||
message = _('You do not have the required permissions to view this page!')
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return request.method in SAFE_METHODS and 'pk' in view.kwargs
|
||||
|
||||
def has_object_permission(self, request, view, obj):
|
||||
share = request.query_params.get('share', None)
|
||||
if share:
|
||||
return share_link_valid(obj, share)
|
||||
return False
|
||||
|
||||
190
cookbook/helper/recipe_url_import.py
Normal file
190
cookbook/helper/recipe_url_import.py
Normal file
@@ -0,0 +1,190 @@
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
from json import JSONDecodeError
|
||||
|
||||
import microdata
|
||||
from bs4 import BeautifulSoup
|
||||
from django.http import JsonResponse
|
||||
from django.utils.dateparse import parse_duration
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from cookbook.models import Keyword
|
||||
|
||||
|
||||
def get_from_html(html_text, url):
|
||||
soup = BeautifulSoup(html_text, "html.parser")
|
||||
|
||||
# first try finding ld+json as its most common
|
||||
for ld in soup.find_all('script', type='application/ld+json'):
|
||||
try:
|
||||
ld_json = json.loads(ld.string.replace('\n', ''))
|
||||
if type(ld_json) != list:
|
||||
ld_json = [ld_json]
|
||||
|
||||
for ld_json_item in ld_json:
|
||||
# recipes type might be wrapped in @graph type
|
||||
if '@graph' in ld_json_item:
|
||||
for x in ld_json_item['@graph']:
|
||||
if '@type' in x and x['@type'] == 'Recipe':
|
||||
ld_json_item = x
|
||||
|
||||
if '@type' in ld_json_item and ld_json_item['@type'] == 'Recipe':
|
||||
return find_recipe_json(ld_json_item, url)
|
||||
except JSONDecodeError as e:
|
||||
return JsonResponse({'error': True, 'msg': _('The requested site provided malformed data and cannot be read.')}, status=400)
|
||||
|
||||
# now try to find microdata
|
||||
items = microdata.get_items(html_text)
|
||||
for i in items:
|
||||
md_json = json.loads(i.json())
|
||||
if 'schema.org/Recipe' in str(md_json['type']):
|
||||
return find_recipe_json(md_json['properties'], url)
|
||||
|
||||
return JsonResponse({'error': True, 'msg': _('The requested site does not provide any recognized data format to import the recipe from.')}, status=400)
|
||||
|
||||
|
||||
def find_recipe_json(ld_json, url):
|
||||
if type(ld_json['name']) == list:
|
||||
try:
|
||||
ld_json['name'] = ld_json['name'][0]
|
||||
except:
|
||||
ld_json['name'] = 'ERROR'
|
||||
|
||||
# some sites use ingredients instead of recipeIngredients
|
||||
if 'recipeIngredient' not in ld_json and 'ingredients' in ld_json:
|
||||
ld_json['recipeIngredient'] = ld_json['ingredients']
|
||||
|
||||
if 'recipeIngredient' in ld_json:
|
||||
# some pages have comma separated ingredients in a single array entry
|
||||
if len(ld_json['recipeIngredient']) == 1 and len(ld_json['recipeIngredient'][0]) > 30:
|
||||
ld_json['recipeIngredient'] = ld_json['recipeIngredient'][0].split(',')
|
||||
|
||||
for x in ld_json['recipeIngredient']:
|
||||
if '\n' in x:
|
||||
ld_json['recipeIngredient'].remove(x)
|
||||
for i in x.split('\n'):
|
||||
ld_json['recipeIngredient'].insert(0, i)
|
||||
|
||||
ingredients = []
|
||||
|
||||
for x in ld_json['recipeIngredient']:
|
||||
ingredient_split = x.split()
|
||||
ingredient = None
|
||||
amount = 0
|
||||
unit = ''
|
||||
if len(ingredient_split) > 2:
|
||||
ingredient = " ".join(ingredient_split[2:])
|
||||
unit = ingredient_split[1]
|
||||
try:
|
||||
amount = float(ingredient_split[0].replace(',', '.'))
|
||||
except ValueError:
|
||||
amount = 0
|
||||
ingredient = " ".join(ingredient_split)
|
||||
if len(ingredient_split) == 2:
|
||||
ingredient = " ".join(ingredient_split[1:])
|
||||
unit = ''
|
||||
try:
|
||||
amount = float(ingredient_split[0].replace(',', '.'))
|
||||
except ValueError:
|
||||
amount = 0
|
||||
ingredient = " ".join(ingredient_split)
|
||||
if len(ingredient_split) == 1:
|
||||
ingredient = " ".join(ingredient_split)
|
||||
|
||||
if ingredient:
|
||||
ingredients.append({'amount': amount, 'unit': {'text': unit, 'id': random.randrange(10000, 99999)}, 'ingredient': {'text': ingredient, 'id': random.randrange(10000, 99999)}, 'original': x})
|
||||
|
||||
ld_json['recipeIngredient'] = ingredients
|
||||
else:
|
||||
ld_json['recipeIngredient'] = []
|
||||
|
||||
if 'keywords' in ld_json:
|
||||
keywords = []
|
||||
|
||||
# keywords as string
|
||||
if type(ld_json['keywords']) == str:
|
||||
ld_json['keywords'] = ld_json['keywords'].split(',')
|
||||
|
||||
# keywords as string in list
|
||||
if type(ld_json['keywords']) == list and len(ld_json['keywords']) == 1 and ',' in ld_json['keywords'][0]:
|
||||
ld_json['keywords'] = ld_json['keywords'][0].split(',')
|
||||
|
||||
# keywords as list
|
||||
for kw in ld_json['keywords']:
|
||||
if k := Keyword.objects.filter(name=kw).first():
|
||||
keywords.append({'id': str(k.id), 'text': str(k).strip()})
|
||||
else:
|
||||
keywords.append({'id': "null", 'text': kw.strip()})
|
||||
|
||||
ld_json['keywords'] = keywords
|
||||
else:
|
||||
ld_json['keywords'] = []
|
||||
|
||||
if 'recipeInstructions' in ld_json:
|
||||
instructions = ''
|
||||
|
||||
# flatten instructions if they are in a list
|
||||
if type(ld_json['recipeInstructions']) == list:
|
||||
for i in ld_json['recipeInstructions']:
|
||||
if type(i) == str:
|
||||
instructions += i
|
||||
else:
|
||||
if 'text' in i:
|
||||
instructions += i['text'] + '\n\n'
|
||||
elif 'itemListElement' in i:
|
||||
for ile in i['itemListElement']:
|
||||
if type(ile) == str:
|
||||
instructions += ile + '\n\n'
|
||||
elif 'text' in ile:
|
||||
instructions += ile['text'] + '\n\n'
|
||||
else:
|
||||
instructions += str(i)
|
||||
ld_json['recipeInstructions'] = instructions
|
||||
|
||||
ld_json['recipeInstructions'] = re.sub(r'\n\s*\n', '\n\n', ld_json['recipeInstructions'])
|
||||
ld_json['recipeInstructions'] = re.sub(' +', ' ', ld_json['recipeInstructions'])
|
||||
ld_json['recipeInstructions'] = ld_json['recipeInstructions'].replace('<p>', '')
|
||||
ld_json['recipeInstructions'] = ld_json['recipeInstructions'].replace('</p>', '')
|
||||
else:
|
||||
ld_json['recipeInstructions'] = ''
|
||||
|
||||
ld_json['recipeInstructions'] += '\n\n' + _('Imported from ') + url
|
||||
|
||||
if 'image' in ld_json:
|
||||
# check if list of images is returned, take first if so
|
||||
if (type(ld_json['image'])) == list:
|
||||
if type(ld_json['image'][0]) == str:
|
||||
ld_json['image'] = ld_json['image'][0]
|
||||
elif 'url' in ld_json['image'][0]:
|
||||
ld_json['image'] = ld_json['image'][0]['url']
|
||||
|
||||
# ignore relative image paths
|
||||
if 'http' not in ld_json['image']:
|
||||
ld_json['image'] = ''
|
||||
|
||||
if 'cookTime' in ld_json:
|
||||
try:
|
||||
if type(ld_json['cookTime']) == list and len(ld_json['cookTime']) > 0:
|
||||
ld_json['cookTime'] = ld_json['cookTime'][0]
|
||||
ld_json['cookTime'] = round(parse_duration(ld_json['cookTime']).seconds / 60)
|
||||
except TypeError:
|
||||
ld_json['cookTime'] = 0
|
||||
else:
|
||||
ld_json['cookTime'] = 0
|
||||
|
||||
if 'prepTime' in ld_json:
|
||||
try:
|
||||
if type(ld_json['prepTime']) == list and len(ld_json['prepTime']) > 0:
|
||||
ld_json['prepTime'] = ld_json['prepTime'][0]
|
||||
ld_json['prepTime'] = round(parse_duration(ld_json['prepTime']).seconds / 60)
|
||||
except TypeError:
|
||||
ld_json['prepTime'] = 0
|
||||
else:
|
||||
ld_json['prepTime'] = 0
|
||||
|
||||
for key in list(ld_json):
|
||||
if key not in ['prepTime', 'cookTime', 'image', 'recipeInstructions', 'keywords', 'name', 'recipeIngredient']:
|
||||
ld_json.pop(key, None)
|
||||
|
||||
return JsonResponse(ld_json)
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/fr/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/fr/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
2053
cookbook/locale/fr/LC_MESSAGES/django.po
Normal file
2053
cookbook/locale/fr/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/pt/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/pt/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1791
cookbook/locale/pt/LC_MESSAGES/django.po
Normal file
1791
cookbook/locale/pt/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/rn/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/rn/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1791
cookbook/locale/rn/LC_MESSAGES/django.po
Normal file
1791
cookbook/locale/rn/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/tr/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/tr/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1791
cookbook/locale/tr/LC_MESSAGES/django.po
Normal file
1791
cookbook/locale/tr/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
29
cookbook/migrations/0056_auto_20200625_2118.py
Normal file
29
cookbook/migrations/0056_auto_20200625_2118.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 19:18
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
atomic = False
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0055_auto_20200616_1236'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel(
|
||||
old_name='Ingredient',
|
||||
new_name='Food',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='recipe',
|
||||
name='ingredients',
|
||||
field=models.ManyToManyField(blank=True, related_name='tmp_ingredients', to='cookbook.RecipeIngredient'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sharelink',
|
||||
name='uuid',
|
||||
field=models.UUIDField(default=uuid.UUID('a5f12617-9e4b-41e3-87ee-49db96090974')),
|
||||
),
|
||||
]
|
||||
25
cookbook/migrations/0056_auto_20200625_2157.py
Normal file
25
cookbook/migrations/0056_auto_20200625_2157.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 19:57
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
def invalidate_shares(apps, schema_editor):
|
||||
ShareLink = apps.get_model('cookbook', 'ShareLink')
|
||||
|
||||
ShareLink.objects.all().delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('cookbook', '0055_auto_20200616_1236'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='sharelink',
|
||||
name='uuid',
|
||||
field=models.UUIDField(default=uuid.uuid4),
|
||||
),
|
||||
migrations.RunPython(invalidate_shares)
|
||||
]
|
||||
24
cookbook/migrations/0057_auto_20200625_2127.py
Normal file
24
cookbook/migrations/0057_auto_20200625_2127.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 19:27
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0056_auto_20200625_2118'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='recipeingredient',
|
||||
old_name='ingredient',
|
||||
new_name='food',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sharelink',
|
||||
name='uuid',
|
||||
field=models.UUIDField(default=uuid.UUID('4a604ec8-c158-4011-ab5d-ddad7604c1e3')),
|
||||
),
|
||||
]
|
||||
24
cookbook/migrations/0058_auto_20200625_2128.py
Normal file
24
cookbook/migrations/0058_auto_20200625_2128.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 19:28
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
atomic = False
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0057_auto_20200625_2127'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel(
|
||||
old_name='RecipeIngredient',
|
||||
new_name='Ingredient',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sharelink',
|
||||
name='uuid',
|
||||
field=models.UUIDField(default=uuid.UUID('27328011-54fb-46fa-8846-424d5828d858')),
|
||||
),
|
||||
]
|
||||
23
cookbook/migrations/0059_auto_20200625_2137.py
Normal file
23
cookbook/migrations/0059_auto_20200625_2137.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 19:37
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def migrate_ingredients(apps, schema_editor):
|
||||
Recipe = apps.get_model('cookbook', 'Recipe')
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
|
||||
for r in Recipe.objects.all():
|
||||
for i in Ingredient.objects.filter(recipe=r).all():
|
||||
r.ingredients.add(i)
|
||||
r.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('cookbook', '0058_auto_20200625_2128'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(migrate_ingredients),
|
||||
]
|
||||
23
cookbook/migrations/0060_auto_20200625_2144.py
Normal file
23
cookbook/migrations/0060_auto_20200625_2144.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 19:44
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0059_auto_20200625_2137'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='ingredient',
|
||||
name='recipe',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sharelink',
|
||||
name='uuid',
|
||||
field=models.UUIDField(default=uuid.UUID('a7a91b2e-ad33-4159-a35e-828a5244ede9')),
|
||||
),
|
||||
]
|
||||
14
cookbook/migrations/0061_merge_20200625_2209.py
Normal file
14
cookbook/migrations/0061_merge_20200625_2209.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 20:09
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0056_auto_20200625_2157'),
|
||||
('cookbook', '0060_auto_20200625_2144'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
||||
47
cookbook/migrations/0062_auto_20200625_2219.py
Normal file
47
cookbook/migrations/0062_auto_20200625_2219.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 20:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def create_default_step(apps, schema_editor):
|
||||
Recipe = apps.get_model('cookbook', 'Recipe')
|
||||
Step = apps.get_model('cookbook', 'Step')
|
||||
|
||||
for r in Recipe.objects.filter(internal=True).all():
|
||||
s = Step.objects.create(
|
||||
instruction=r.instructions
|
||||
)
|
||||
for i in r.ingredients.all():
|
||||
s.ingredients.add(i)
|
||||
s.save()
|
||||
r.steps.add(s)
|
||||
r.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('cookbook', '0061_merge_20200625_2209'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='ingredients',
|
||||
field=models.ManyToManyField(blank=True, to='cookbook.Ingredient'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Step',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('kind', models.CharField(choices=[('TEXT', 'Text')], default='TEXT', max_length=16)),
|
||||
('instruction', models.TextField(blank=True)),
|
||||
('ingredients', models.ManyToManyField(blank=True, to='cookbook.Ingredient')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='recipe',
|
||||
name='steps',
|
||||
field=models.ManyToManyField(blank=True, to='cookbook.Step'),
|
||||
),
|
||||
migrations.RunPython(create_default_step)
|
||||
]
|
||||
21
cookbook/migrations/0063_auto_20200625_2230.py
Normal file
21
cookbook/migrations/0063_auto_20200625_2230.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 20:30
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0062_auto_20200625_2219'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='recipe',
|
||||
name='ingredients',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='recipe',
|
||||
name='instructions',
|
||||
),
|
||||
]
|
||||
23
cookbook/migrations/0064_auto_20200625_2329.py
Normal file
23
cookbook/migrations/0064_auto_20200625_2329.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 21:29
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0063_auto_20200625_2230'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='file_path',
|
||||
field=models.CharField(blank=True, default='', max_length=512),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='recipe',
|
||||
name='file_uid',
|
||||
field=models.CharField(blank=True, default='', max_length=256),
|
||||
),
|
||||
]
|
||||
23
cookbook/migrations/0065_auto_20200626_1444.py
Normal file
23
cookbook/migrations/0065_auto_20200626_1444.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-26 12:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0064_auto_20200625_2329'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='ingredient',
|
||||
name='order',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='step',
|
||||
name='order',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
]
|
||||
26
cookbook/migrations/0066_auto_20200626_1455.py
Normal file
26
cookbook/migrations/0066_auto_20200626_1455.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-26 12:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0065_auto_20200626_1444'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='ingredient',
|
||||
options={'ordering': ['order', 'pk']},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='step',
|
||||
options={'ordering': ['order', 'pk']},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='step',
|
||||
name='name',
|
||||
field=models.CharField(blank=True, default='', max_length=128),
|
||||
),
|
||||
]
|
||||
18
cookbook/migrations/0067_auto_20200629_1508.py
Normal file
18
cookbook/migrations/0067_auto_20200629_1508.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-29 13:08
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0066_auto_20200626_1455'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='ingredient',
|
||||
name='note',
|
||||
field=models.CharField(blank=True, max_length=256, null=True),
|
||||
),
|
||||
]
|
||||
55
cookbook/migrations/0068_auto_20200629_2127.py
Normal file
55
cookbook/migrations/0068_auto_20200629_2127.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-29 19:27
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
def convert_old_specials(apps, schema_editor):
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
Food = apps.get_model('cookbook', 'Food')
|
||||
Unit = apps.get_model('cookbook', 'Unit')
|
||||
|
||||
for i in Ingredient.objects.all():
|
||||
if i.amount == 0:
|
||||
i.no_amount = True
|
||||
if i.unit.name == 'Special:Header':
|
||||
i.header = True
|
||||
i.unit = None
|
||||
i.food = None
|
||||
i.save()
|
||||
|
||||
try:
|
||||
Unit.objects.filter(name='Special:Header').delete()
|
||||
Food.objects.filter(name='Header').delete()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('cookbook', '0067_auto_20200629_1508'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='ingredient',
|
||||
name='header',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='ingredient',
|
||||
name='no_amount',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='ingredient',
|
||||
name='food',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='cookbook.Food'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='ingredient',
|
||||
name='unit',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='cookbook.Unit'),
|
||||
),
|
||||
migrations.RunPython(convert_old_specials)
|
||||
]
|
||||
18
cookbook/migrations/0069_auto_20200629_2134.py
Normal file
18
cookbook/migrations/0069_auto_20200629_2134.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-29 19:34
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0068_auto_20200629_2127'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='ingredient',
|
||||
old_name='header',
|
||||
new_name='is_header',
|
||||
),
|
||||
]
|
||||
23
cookbook/migrations/0070_auto_20200701_2007.py
Normal file
23
cookbook/migrations/0070_auto_20200701_2007.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.0.7 on 2020-07-01 18:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0069_auto_20200629_2134'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='step',
|
||||
name='time',
|
||||
field=models.IntegerField(blank=True, default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='step',
|
||||
name='kind',
|
||||
field=models.CharField(choices=[('TEXT', 'Text'), ('TIME', 'Time')], default='TEXT', max_length=16),
|
||||
),
|
||||
]
|
||||
18
cookbook/migrations/0071_auto_20200701_2048.py
Normal file
18
cookbook/migrations/0071_auto_20200701_2048.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-07-01 18:48
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0070_auto_20200701_2007'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='step',
|
||||
old_name='kind',
|
||||
new_name='type',
|
||||
),
|
||||
]
|
||||
18
cookbook/migrations/0072_step_show_as_header.py
Normal file
18
cookbook/migrations/0072_step_show_as_header.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-07-02 10:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0071_auto_20200701_2048'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='step',
|
||||
name='show_as_header',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
]
|
||||
18
cookbook/migrations/0073_auto_20200708_2311.py
Normal file
18
cookbook/migrations/0073_auto_20200708_2311.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-07-08 21:11
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0072_step_show_as_header'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='sync',
|
||||
name='last_checked',
|
||||
field=models.DateTimeField(null=True),
|
||||
),
|
||||
]
|
||||
17
cookbook/migrations/0074_remove_keyword_created_by.py
Normal file
17
cookbook/migrations/0074_remove_keyword_created_by.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 3.0.7 on 2020-07-09 19:54
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0073_auto_20200708_2311'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='keyword',
|
||||
name='created_by',
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,49 @@
|
||||
# Generated by Django 3.0.7 on 2020-08-11 10:14
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('cookbook', '0074_remove_keyword_created_by'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ShoppingListRecipe',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('multiplier', models.IntegerField(default=1)),
|
||||
('recipe', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='cookbook.Recipe')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ShoppingListEntry',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('amount', models.IntegerField(default=1)),
|
||||
('order', models.IntegerField(default=0)),
|
||||
('checked', models.BooleanField(default=False)),
|
||||
('food', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cookbook.Food')),
|
||||
('list_recipe', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='cookbook.ShoppingListRecipe')),
|
||||
('unit', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='cookbook.Unit')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ShoppingList',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('uuid', models.UUIDField(default=uuid.uuid4)),
|
||||
('note', models.TextField(blank=True, null=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
('recipes', models.ManyToManyField(blank=True, to='cookbook.ShoppingListRecipe')),
|
||||
('shared', models.ManyToManyField(blank=True, related_name='list_share', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
||||
18
cookbook/migrations/0076_shoppinglist_entries.py
Normal file
18
cookbook/migrations/0076_shoppinglist_entries.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-08-26 18:46
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0075_shoppinglist_shoppinglistentry_shoppinglistrecipe'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='shoppinglist',
|
||||
name='entries',
|
||||
field=models.ManyToManyField(blank=True, to='cookbook.ShoppingListEntry'),
|
||||
),
|
||||
]
|
||||
29
cookbook/migrations/0077_invitelink.py
Normal file
29
cookbook/migrations/0077_invitelink.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 3.0.7 on 2020-09-01 11:31
|
||||
|
||||
import datetime
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('cookbook', '0076_shoppinglist_entries'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='InviteLink',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('uuid', models.UUIDField(default=uuid.uuid4)),
|
||||
('username', models.CharField(blank=True, max_length=64)),
|
||||
('valid_until', models.DateField(default=datetime.date(2020, 9, 15))),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
||||
21
cookbook/migrations/0078_invitelink_used_by.py
Normal file
21
cookbook/migrations/0078_invitelink_used_by.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 3.0.7 on 2020-09-01 11:39
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('cookbook', '0077_invitelink'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='invitelink',
|
||||
name='used_by',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='used_by', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
21
cookbook/migrations/0079_invitelink_group.py
Normal file
21
cookbook/migrations/0079_invitelink_group.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 3.0.7 on 2020-09-01 12:54
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth', '0011_update_proxy_permissions'),
|
||||
('cookbook', '0078_invitelink_used_by'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='invitelink',
|
||||
name='group',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='auth.Group'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
24
cookbook/migrations/0080_auto_20200921_2331.py
Normal file
24
cookbook/migrations/0080_auto_20200921_2331.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 3.0.7 on 2020-09-21 21:31
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0079_invitelink_group'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='userpreference',
|
||||
name='shopping_auto_sync',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='invitelink',
|
||||
name='valid_until',
|
||||
field=models.DateField(default=datetime.date(2020, 10, 5)),
|
||||
),
|
||||
]
|
||||
18
cookbook/migrations/0081_auto_20200921_2349.py
Normal file
18
cookbook/migrations/0081_auto_20200921_2349.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-09-21 21:49
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0080_auto_20200921_2331'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='userpreference',
|
||||
name='shopping_auto_sync',
|
||||
field=models.IntegerField(default=5),
|
||||
),
|
||||
]
|
||||
24
cookbook/migrations/0082_auto_20200922_1143.py
Normal file
24
cookbook/migrations/0082_auto_20200922_1143.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 3.0.7 on 2020-09-22 09:43
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0081_auto_20200921_2349'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='invitelink',
|
||||
name='valid_until',
|
||||
field=models.DateField(default=datetime.date(2020, 10, 6)),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='shoppinglistentry',
|
||||
name='amount',
|
||||
field=models.DecimalField(decimal_places=16, default=0, max_digits=32),
|
||||
),
|
||||
]
|
||||
21
cookbook/migrations/0083_space.py
Normal file
21
cookbook/migrations/0083_space.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 3.0.7 on 2020-09-22 10:24
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0082_auto_20200922_1143'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Space',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(default='Default', max_length=128)),
|
||||
('message', models.CharField(default='', max_length=512)),
|
||||
],
|
||||
),
|
||||
]
|
||||
21
cookbook/migrations/0084_auto_20200922_1233.py
Normal file
21
cookbook/migrations/0084_auto_20200922_1233.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 3.0.7 on 2020-09-22 10:33
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def create_default_space(apps, schema_editor):
|
||||
Space = apps.get_model('cookbook', 'Space')
|
||||
Space.objects.create(
|
||||
name='Default',
|
||||
message=''
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('cookbook', '0083_space'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_default_space),
|
||||
]
|
||||
18
cookbook/migrations/0085_auto_20200922_1235.py
Normal file
18
cookbook/migrations/0085_auto_20200922_1235.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-09-22 10:35
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0084_auto_20200922_1233'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='space',
|
||||
name='message',
|
||||
field=models.CharField(blank=True, default='', max_length=512),
|
||||
),
|
||||
]
|
||||
24
cookbook/migrations/0086_auto_20200929_1143.py
Normal file
24
cookbook/migrations/0086_auto_20200929_1143.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 3.0.7 on 2020-09-29 09:43
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0085_auto_20200922_1235'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='mealplan',
|
||||
name='recipe_multiplier',
|
||||
field=models.IntegerField(default=1),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='invitelink',
|
||||
name='valid_until',
|
||||
field=models.DateField(default=datetime.date(2020, 10, 13)),
|
||||
),
|
||||
]
|
||||
23
cookbook/migrations/0087_auto_20200929_1152.py
Normal file
23
cookbook/migrations/0087_auto_20200929_1152.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.0.7 on 2020-09-29 09:52
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0086_auto_20200929_1143'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='mealplan',
|
||||
name='recipe_multiplier',
|
||||
field=models.DecimalField(decimal_places=4, default=1, max_digits=8),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='shoppinglistrecipe',
|
||||
name='multiplier',
|
||||
field=models.DecimalField(decimal_places=4, default=1, max_digits=8),
|
||||
),
|
||||
]
|
||||
18
cookbook/migrations/0088_shoppinglist_finished.py
Normal file
18
cookbook/migrations/0088_shoppinglist_finished.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.1.1 on 2020-09-29 11:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0087_auto_20200929_1152'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='shoppinglist',
|
||||
name='finished',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
||||
@@ -1,10 +1,13 @@
|
||||
import re
|
||||
import uuid
|
||||
from datetime import date, timedelta
|
||||
|
||||
from annoying.fields import AutoOneToOneField
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.utils.translation import gettext as _
|
||||
from django.db import models
|
||||
from django_random_queryset import RandomManager
|
||||
|
||||
from recipes.settings import COMMENT_PREF_DEFAULT
|
||||
|
||||
@@ -23,6 +26,11 @@ def get_model_name(model):
|
||||
return ('_'.join(re.findall('[A-Z][^A-Z]*', model.__name__))).lower()
|
||||
|
||||
|
||||
class Space(models.Model):
|
||||
name = models.CharField(max_length=128, default='Default')
|
||||
message = models.CharField(max_length=512, default='', blank=True)
|
||||
|
||||
|
||||
class UserPreference(models.Model):
|
||||
# Themes
|
||||
BOOTSTRAP = 'BOOTSTRAP'
|
||||
@@ -67,6 +75,7 @@ class UserPreference(models.Model):
|
||||
plan_share = models.ManyToManyField(User, blank=True, related_name='plan_share_default')
|
||||
ingredient_decimals = models.IntegerField(default=2)
|
||||
comments = models.BooleanField(default=COMMENT_PREF_DEFAULT)
|
||||
shopping_auto_sync = models.IntegerField(default=5)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.user)
|
||||
@@ -93,7 +102,7 @@ class Sync(models.Model):
|
||||
storage = models.ForeignKey(Storage, on_delete=models.PROTECT)
|
||||
path = models.CharField(max_length=512, default="")
|
||||
active = models.BooleanField(default=True)
|
||||
last_checked = models.DateTimeField()
|
||||
last_checked = models.DateTimeField(null=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
@@ -115,7 +124,6 @@ class Keyword(models.Model):
|
||||
name = models.CharField(max_length=64, unique=True)
|
||||
icon = models.CharField(max_length=16, blank=True, null=True)
|
||||
description = models.TextField(default="", blank=True)
|
||||
created_by = models.IntegerField(default=0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
@@ -126,27 +134,6 @@ class Keyword(models.Model):
|
||||
return f"{self.name}"
|
||||
|
||||
|
||||
class Recipe(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
instructions = models.TextField(blank=True)
|
||||
image = models.ImageField(upload_to='recipes/', blank=True, null=True)
|
||||
storage = models.ForeignKey(Storage, on_delete=models.PROTECT, blank=True, null=True)
|
||||
file_uid = models.CharField(max_length=256, default="")
|
||||
file_path = models.CharField(max_length=512, default="")
|
||||
link = models.CharField(max_length=512, null=True, blank=True)
|
||||
cors_link = models.CharField(max_length=1024, null=True, blank=True)
|
||||
keywords = models.ManyToManyField(Keyword, blank=True)
|
||||
working_time = models.IntegerField(default=0)
|
||||
waiting_time = models.IntegerField(default=0)
|
||||
internal = models.BooleanField(default=False)
|
||||
created_by = models.ForeignKey(User, on_delete=models.PROTECT)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Unit(models.Model):
|
||||
name = models.CharField(unique=True, max_length=128)
|
||||
description = models.TextField(blank=True, null=True)
|
||||
@@ -155,23 +142,67 @@ class Unit(models.Model):
|
||||
return self.name
|
||||
|
||||
|
||||
class Ingredient(models.Model):
|
||||
class Food(models.Model):
|
||||
name = models.CharField(unique=True, max_length=128)
|
||||
recipe = models.ForeignKey(Recipe, null=True, blank=True, on_delete=models.SET_NULL)
|
||||
recipe = models.ForeignKey('Recipe', null=True, blank=True, on_delete=models.SET_NULL)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class RecipeIngredient(models.Model):
|
||||
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
||||
ingredient = models.ForeignKey(Ingredient, on_delete=models.PROTECT)
|
||||
unit = models.ForeignKey(Unit, on_delete=models.PROTECT)
|
||||
class Ingredient(models.Model):
|
||||
food = models.ForeignKey(Food, on_delete=models.PROTECT, null=True, blank=True)
|
||||
unit = models.ForeignKey(Unit, on_delete=models.PROTECT, null=True, blank=True)
|
||||
amount = models.DecimalField(default=0, decimal_places=16, max_digits=32)
|
||||
note = models.CharField(max_length=64, null=True, blank=True)
|
||||
note = models.CharField(max_length=256, null=True, blank=True)
|
||||
is_header = models.BooleanField(default=False)
|
||||
no_amount = models.BooleanField(default=False)
|
||||
order = models.IntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.amount) + ' ' + str(self.unit) + ' ' + str(self.ingredient)
|
||||
return str(self.amount) + ' ' + str(self.unit) + ' ' + str(self.food)
|
||||
|
||||
class Meta:
|
||||
ordering = ['order', 'pk']
|
||||
|
||||
|
||||
class Step(models.Model):
|
||||
TEXT = 'TEXT'
|
||||
TIME = 'TIME'
|
||||
|
||||
name = models.CharField(max_length=128, default='', blank=True)
|
||||
type = models.CharField(choices=((TEXT, _('Text')), (TIME, _('Time')),), default=TEXT, max_length=16)
|
||||
instruction = models.TextField(blank=True)
|
||||
ingredients = models.ManyToManyField(Ingredient, blank=True)
|
||||
time = models.IntegerField(default=0, blank=True)
|
||||
order = models.IntegerField(default=0)
|
||||
show_as_header = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['order', 'pk']
|
||||
|
||||
|
||||
class Recipe(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
image = models.ImageField(upload_to='recipes/', blank=True, null=True)
|
||||
storage = models.ForeignKey(Storage, on_delete=models.PROTECT, blank=True, null=True)
|
||||
file_uid = models.CharField(max_length=256, default="", blank=True)
|
||||
file_path = models.CharField(max_length=512, default="", blank=True)
|
||||
link = models.CharField(max_length=512, null=True, blank=True)
|
||||
cors_link = models.CharField(max_length=1024, null=True, blank=True)
|
||||
keywords = models.ManyToManyField(Keyword, blank=True)
|
||||
steps = models.ManyToManyField(Step, blank=True)
|
||||
working_time = models.IntegerField(default=0)
|
||||
waiting_time = models.IntegerField(default=0)
|
||||
internal = models.BooleanField(default=False)
|
||||
created_by = models.ForeignKey(User, on_delete=models.PROTECT)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
objects = RandomManager()
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Comment(models.Model):
|
||||
@@ -226,6 +257,7 @@ class MealType(models.Model):
|
||||
|
||||
class MealPlan(models.Model):
|
||||
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE, blank=True, null=True)
|
||||
recipe_multiplier = models.DecimalField(default=1, max_digits=8, decimal_places=4)
|
||||
title = models.CharField(max_length=64, blank=True, default='')
|
||||
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
shared = models.ManyToManyField(User, blank=True, related_name='plan_share')
|
||||
@@ -245,12 +277,74 @@ class MealPlan(models.Model):
|
||||
return f'{self.get_label()} - {self.date} - {self.meal_type.name}'
|
||||
|
||||
|
||||
class ShareLink(models.Model):
|
||||
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
||||
uuid = models.UUIDField(default=uuid.uuid4())
|
||||
class ShoppingListRecipe(models.Model):
|
||||
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE, null=True, blank=True)
|
||||
multiplier = models.DecimalField(default=1, max_digits=8, decimal_places=4)
|
||||
|
||||
def __str__(self):
|
||||
return f'Shopping list recipe {self.id} - {self.recipe}'
|
||||
|
||||
def get_owner(self):
|
||||
try:
|
||||
return self.shoppinglist_set.first().created_by
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
|
||||
class ShoppingListEntry(models.Model):
|
||||
list_recipe = models.ForeignKey(ShoppingListRecipe, on_delete=models.CASCADE, null=True, blank=True)
|
||||
food = models.ForeignKey(Food, on_delete=models.CASCADE)
|
||||
unit = models.ForeignKey(Unit, on_delete=models.CASCADE, null=True, blank=True)
|
||||
amount = models.DecimalField(default=0, decimal_places=16, max_digits=32)
|
||||
order = models.IntegerField(default=0)
|
||||
checked = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f'Shopping list entry {self.id}'
|
||||
|
||||
def get_owner(self):
|
||||
try:
|
||||
return self.shoppinglist_set.first().created_by
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
|
||||
class ShoppingList(models.Model):
|
||||
uuid = models.UUIDField(default=uuid.uuid4)
|
||||
note = models.TextField(blank=True, null=True)
|
||||
recipes = models.ManyToManyField(ShoppingListRecipe, blank=True)
|
||||
entries = models.ManyToManyField(ShoppingListEntry, blank=True)
|
||||
shared = models.ManyToManyField(User, blank=True, related_name='list_share')
|
||||
finished = models.BooleanField(default=False)
|
||||
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'Shopping list {self.id}'
|
||||
|
||||
|
||||
class ShareLink(models.Model):
|
||||
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
||||
uuid = models.UUIDField(default=uuid.uuid4)
|
||||
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.recipe} - {self.uuid}'
|
||||
|
||||
|
||||
class InviteLink(models.Model):
|
||||
uuid = models.UUIDField(default=uuid.uuid4)
|
||||
username = models.CharField(blank=True, max_length=64)
|
||||
group = models.ForeignKey(Group, on_delete=models.CASCADE)
|
||||
valid_until = models.DateField(default=date.today() + timedelta(days=14))
|
||||
used_by = models.ForeignKey(User, null=True, on_delete=models.CASCADE, related_name='used_by')
|
||||
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.uuid}'
|
||||
|
||||
|
||||
class CookLog(models.Model):
|
||||
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
||||
|
||||
@@ -1,68 +1,164 @@
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework import serializers
|
||||
from decimal import Decimal
|
||||
|
||||
from cookbook.models import MealPlan, MealType, Recipe, ViewLog, UserPreference, Storage, Sync, SyncLog, Keyword, Ingredient, Unit, RecipeIngredient, Comment, RecipeImport, RecipeBook, RecipeBookEntry, ShareLink, CookLog
|
||||
from django.contrib.auth.models import User
|
||||
from drf_writable_nested import WritableNestedModelSerializer, UniqueFieldsMixin
|
||||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
from cookbook.models import MealPlan, MealType, Recipe, ViewLog, UserPreference, Storage, Sync, SyncLog, Keyword, Unit, Ingredient, Comment, RecipeImport, RecipeBook, RecipeBookEntry, ShareLink, CookLog, Food, Step, ShoppingList, \
|
||||
ShoppingListEntry, ShoppingListRecipe
|
||||
from cookbook.templatetags.custom_tags import markdown
|
||||
|
||||
|
||||
class UserNameSerializer(serializers.ModelSerializer):
|
||||
class CustomDecimalField(serializers.Field):
|
||||
"""
|
||||
Custom decimal field to normalize useless decimal places and allow commas as decimal separators
|
||||
"""
|
||||
|
||||
def to_representation(self, value):
|
||||
if isinstance(value, Decimal):
|
||||
return value.normalize()
|
||||
else:
|
||||
return Decimal(value).normalize()
|
||||
|
||||
def to_internal_value(self, data):
|
||||
if type(data) == int or type(data) == float:
|
||||
return data
|
||||
elif type(data) == str:
|
||||
if data == '':
|
||||
return 0
|
||||
try:
|
||||
return float(data.replace(',', ''))
|
||||
except ValueError:
|
||||
raise ValidationError('A valid number is required')
|
||||
|
||||
|
||||
class UserNameSerializer(WritableNestedModelSerializer):
|
||||
username = serializers.SerializerMethodField('get_user_label')
|
||||
|
||||
def get_user_label(self, obj):
|
||||
return obj.get_user_name()
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('id', 'username', 'first_name', 'last_name')
|
||||
fields = ('id', 'username')
|
||||
|
||||
|
||||
class UserPreferenceSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = UserPreference
|
||||
fields = '__all__'
|
||||
fields = ('user', 'theme', 'nav_color', 'default_unit', 'default_page', 'search_style', 'show_recent',
|
||||
'plan_share', 'ingredient_decimals', 'comments')
|
||||
read_only_fields = ['user']
|
||||
|
||||
|
||||
class StorageSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Storage
|
||||
fields = '__all__'
|
||||
fields = ('id', 'name', 'method', 'username', 'password', 'token', 'created_by')
|
||||
|
||||
extra_kwargs = {
|
||||
'password': {'write_only': True},
|
||||
'token': {'write_only': True},
|
||||
}
|
||||
|
||||
|
||||
class SyncSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Sync
|
||||
fields = '__all__'
|
||||
fields = ('id', 'storage', 'path', 'active', 'last_checked', 'created_at', 'updated_at')
|
||||
|
||||
|
||||
class SyncLogSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = SyncLog
|
||||
fields = '__all__'
|
||||
fields = ('id', 'sync', 'status', 'msg', 'created_at')
|
||||
|
||||
|
||||
class KeywordSerializer(serializers.ModelSerializer):
|
||||
class KeywordSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
||||
label = serializers.SerializerMethodField('get_label')
|
||||
|
||||
def get_label(self, obj):
|
||||
return str(obj)
|
||||
|
||||
def create(self, validated_data):
|
||||
# since multi select tags dont have id's duplicate names might be routed to create
|
||||
obj, created = Keyword.objects.get_or_create(**validated_data)
|
||||
return obj
|
||||
|
||||
class Meta:
|
||||
model = Keyword
|
||||
fields = '__all__'
|
||||
fields = ('id', 'name', 'icon', 'label', 'description', 'created_at', 'updated_at')
|
||||
|
||||
read_only_fields = ('id',)
|
||||
|
||||
|
||||
class RecipeSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = '__all__'
|
||||
class UnitSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
||||
|
||||
def create(self, validated_data):
|
||||
# since multi select tags dont have id's duplicate names might be routed to create
|
||||
obj, created = Unit.objects.get_or_create(**validated_data)
|
||||
return obj
|
||||
|
||||
class UnitSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Unit
|
||||
fields = '__all__'
|
||||
fields = ('id', 'name', 'description')
|
||||
read_only_fields = ('id',)
|
||||
|
||||
|
||||
class IngredientSerializer(serializers.ModelSerializer):
|
||||
class FoodSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
||||
|
||||
def create(self, validated_data):
|
||||
# since multi select tags dont have id's duplicate names might be routed to create
|
||||
obj, created = Food.objects.get_or_create(**validated_data)
|
||||
return obj
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
return super(FoodSerializer, self).update(instance, validated_data)
|
||||
|
||||
class Meta:
|
||||
model = Food
|
||||
fields = ('id', 'name', 'recipe')
|
||||
read_only_fields = ('id',)
|
||||
|
||||
|
||||
class IngredientSerializer(WritableNestedModelSerializer):
|
||||
food = FoodSerializer(allow_null=True)
|
||||
unit = UnitSerializer(allow_null=True)
|
||||
amount = CustomDecimalField()
|
||||
|
||||
class Meta:
|
||||
model = Ingredient
|
||||
fields = '__all__'
|
||||
fields = ('id', 'food', 'unit', 'amount', 'note', 'order', 'is_header', 'no_amount')
|
||||
|
||||
|
||||
class RecipeIngredientSerializer(serializers.ModelSerializer):
|
||||
class StepSerializer(WritableNestedModelSerializer):
|
||||
ingredients = IngredientSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = RecipeIngredient
|
||||
model = Step
|
||||
fields = ('id', 'name', 'type', 'instruction', 'ingredients', 'time', 'order', 'show_as_header')
|
||||
|
||||
|
||||
class RecipeSerializer(WritableNestedModelSerializer):
|
||||
steps = StepSerializer(many=True)
|
||||
keywords = KeywordSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ['id', 'name', 'image', 'keywords', 'steps', 'working_time', 'waiting_time', 'created_by', 'created_at', 'updated_at', 'internal']
|
||||
read_only_fields = ['image', 'created_by', 'created_at']
|
||||
|
||||
|
||||
class RecipeImageSerializer(WritableNestedModelSerializer):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ['image', ]
|
||||
|
||||
|
||||
class RecipeImportSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = RecipeImport
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
@@ -72,12 +168,6 @@ class CommentSerializer(serializers.ModelSerializer):
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class RecipeImportSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = RecipeImport
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class RecipeBookSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = RecipeBook
|
||||
@@ -101,13 +191,61 @@ class MealPlanSerializer(serializers.ModelSerializer):
|
||||
recipe_name = serializers.ReadOnlyField(source='recipe.name')
|
||||
meal_type_name = serializers.ReadOnlyField(source='meal_type.name')
|
||||
note_markdown = serializers.SerializerMethodField('get_note_markdown')
|
||||
recipe_multiplier = CustomDecimalField()
|
||||
|
||||
def get_note_markdown(self, obj):
|
||||
return markdown(obj.note)
|
||||
|
||||
class Meta:
|
||||
model = MealPlan
|
||||
fields = ('id', 'title', 'recipe', 'note', 'note_markdown', 'date', 'meal_type', 'created_by', 'shared', 'recipe_name', 'meal_type_name')
|
||||
fields = ('id', 'title', 'recipe', 'recipe_multiplier', 'note', 'note_markdown', 'date', 'meal_type', 'created_by', 'shared', 'recipe_name', 'meal_type_name')
|
||||
|
||||
|
||||
class ShoppingListRecipeSerializer(serializers.ModelSerializer):
|
||||
recipe_name = serializers.ReadOnlyField(source='recipe.name')
|
||||
multiplier = CustomDecimalField()
|
||||
|
||||
class Meta:
|
||||
model = ShoppingListRecipe
|
||||
fields = ('id', 'recipe', 'recipe_name', 'multiplier')
|
||||
read_only_fields = ('id',)
|
||||
|
||||
|
||||
class ShoppingListEntrySerializer(WritableNestedModelSerializer):
|
||||
food = FoodSerializer(allow_null=True)
|
||||
unit = UnitSerializer(allow_null=True)
|
||||
amount = CustomDecimalField()
|
||||
|
||||
class Meta:
|
||||
model = ShoppingListEntry
|
||||
fields = ('id', 'list_recipe', 'food', 'unit', 'amount', 'order', 'checked')
|
||||
read_only_fields = ('id',)
|
||||
|
||||
|
||||
class ShoppingListEntryCheckedSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ShoppingListEntry
|
||||
fields = ('id', 'checked')
|
||||
|
||||
|
||||
class ShoppingListSerializer(WritableNestedModelSerializer):
|
||||
recipes = ShoppingListRecipeSerializer(many=True, allow_null=True)
|
||||
entries = ShoppingListEntrySerializer(many=True, allow_null=True)
|
||||
shared = UserNameSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = ShoppingList
|
||||
fields = ('id', 'uuid', 'note', 'recipes', 'entries', 'shared', 'finished', 'created_by', 'created_at',)
|
||||
read_only_fields = ('id',)
|
||||
|
||||
|
||||
class ShoppingListAutoSyncSerializer(WritableNestedModelSerializer):
|
||||
entries = ShoppingListEntryCheckedSerializer(many=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = ShoppingList
|
||||
fields = ('id', 'entries',)
|
||||
read_only_fields = ('id',)
|
||||
|
||||
|
||||
class ShareLinkSerializer(serializers.ModelSerializer):
|
||||
|
||||
4
cookbook/static/css/bootstrap-vue.min.css
vendored
Normal file
4
cookbook/static/css/bootstrap-vue.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
cookbook/static/css/vue-multiselect-bs4.min.css
vendored
Normal file
1
cookbook/static/css/vue-multiselect-bs4.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
cookbook/static/css/vue-multiselect.min.css
vendored
Normal file
1
cookbook/static/css/vue-multiselect.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
11
cookbook/static/js/bootstrap-vue.min.js
vendored
Normal file
11
cookbook/static/js/bootstrap-vue.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
10
cookbook/static/js/portal-vue.umd.min.js
vendored
Normal file
10
cookbook/static/js/portal-vue.umd.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
cookbook/static/js/vue-multiselect.min.js
vendored
Normal file
1
cookbook/static/js/vue-multiselect.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
8
cookbook/static/js/vue-scrollto.js
Normal file
8
cookbook/static/js/vue-scrollto.js
Normal file
File diff suppressed because one or more lines are too long
@@ -45,7 +45,7 @@
|
||||
id="namedview6"
|
||||
showgrid="false"
|
||||
inkscape:zoom="0.921875"
|
||||
inkscape:cx="309.52383"
|
||||
inkscape:cx="-25.662611"
|
||||
inkscape:cy="214.71807"
|
||||
inkscape:window-x="2869"
|
||||
inkscape:window-y="54"
|
||||
@@ -59,8 +59,8 @@
|
||||
x="-602.57629"
|
||||
y="-290.16949" />
|
||||
<path
|
||||
d="m 198.99508,105.32039 c -9.4835,-0.89523 -18.30973,4.9591 -20.73342,14.20588 l -8.69126,33.14115 c 110.10488,3.23343 184.58794,76.92493 189.24752,186.70242 l 33.41527,-9.29389 c 9.22528,-2.56789 14.95881,-11.59086 13.8614,-21.1439 C 393.84116,202.45866 305.74904,115.43295 198.99508,105.32039 Z m -34.31314,65.96427 -58.59701,223.50695 a 9.5128449,9.5471493 0 0 0 11.73701,11.63209 l 222.4163,-61.9004 C 337.73239,241.51893 268.0087,172.46259 164.68194,171.30821 Z m 16.19707,178.95751 a 18.779213,18.846933 0 1 1 18.77921,-18.84693 18.779213,18.846933 0 0 1 -18.77921,18.84693 z m 28.16882,-89.52293 a 18.779213,18.846933 0 1 1 18.77921,-18.84693 18.779213,18.846933 0 0 1 -18.77921,18.84693 z m 61.03245,61.25253 a 18.779213,18.846933 0 1 1 18.77921,-18.84693 18.779213,18.846933 0 0 1 -18.77921,18.84693 z"
|
||||
d="m 235.62851,202.1526 c -3.38906,-0.31992 -6.54323,1.7722 -7.40937,5.07666 l -3.10593,11.84344 c 39.34747,1.15551 65.965,27.49017 67.63017,66.72064 l 11.9414,-3.32129 c 3.29677,-0.91767 5.34573,-4.14216 4.95356,-7.55606 -4.37894,-38.04972 -35.85985,-69.14953 -74.00983,-72.76339 z m -12.26226,23.57322 -20.94044,79.87325 a 3.3995443,3.4118034 0 0 0 4.19438,4.15688 L 286.10367,287.635 c -0.8955,-36.81001 -25.8122,-61.48823 -62.73742,-61.90076 z m 5.78824,63.9529 a 6.7110067,6.7352075 0 1 1 6.711,-6.73521 6.7110067,6.7352075 0 0 1 -6.711,6.73521 z M 239.221,257.68648 a 6.7110067,6.7352075 0 1 1 6.71101,-6.7352 6.7110067,6.7352075 0 0 1 -6.71101,6.7352 z m 21.81077,21.88943 a 6.7110067,6.7352075 0 1 1 6.71101,-6.73521 6.7110067,6.7352075 0 0 1 -6.71101,6.73521 z"
|
||||
id="path2"
|
||||
style="fill:#d9cfbe;fill-opacity:1;stroke-width:0.58790755"
|
||||
style="fill:#d9cfbe;fill-opacity:1;stroke-width:0.21009675"
|
||||
inkscape:connector-curvature="0" />
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
@@ -48,7 +48,7 @@ class KeywordTable(tables.Table):
|
||||
|
||||
|
||||
class IngredientTable(tables.Table):
|
||||
id = tables.LinkColumn('edit_ingredient', args=[A('id')])
|
||||
id = tables.LinkColumn('edit_food', args=[A('id')])
|
||||
|
||||
class Meta:
|
||||
model = Keyword
|
||||
@@ -108,6 +108,25 @@ class RecipeImportTable(tables.Table):
|
||||
fields = ('id', 'name', 'file_path')
|
||||
|
||||
|
||||
class ShoppingListTable(tables.Table):
|
||||
id = tables.LinkColumn('view_shopping', args=[A('id')])
|
||||
|
||||
class Meta:
|
||||
model = ShoppingList
|
||||
template_name = 'generic/table_template.html'
|
||||
fields = ('id', 'finished', 'created_by', 'created_at')
|
||||
|
||||
|
||||
class InviteLinkTable(tables.Table):
|
||||
link = tables.TemplateColumn("<a href='{% url 'view_signup' record.uuid %}' >" + _('Link') + "</a>")
|
||||
delete = tables.TemplateColumn("<a href='{% url 'delete_invite_link' record.id %}' >" + _('Delete') + "</a>")
|
||||
|
||||
class Meta:
|
||||
model = InviteLink
|
||||
template_name = 'generic/table_template.html'
|
||||
fields = ('username', 'group', 'valid_until', 'created_by', 'created_at')
|
||||
|
||||
|
||||
class ViewLogTable(tables.Table):
|
||||
recipe = tables.LinkColumn('view_recipe', args=[A('recipe_id')])
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
{% load theming_tags %}
|
||||
{% load custom_tags %}
|
||||
|
||||
<html>
|
||||
<head>
|
||||
@@ -54,13 +55,13 @@
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarText">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<li class="nav-item {% if request.resolver_match.url_name in 'view_search,edit_recipe,edit_internal_recipe,edit_external_recipe,view_recipe' %}active{% endif %}">
|
||||
<li class="nav-item {% if request.resolver_match.url_name in 'view_search,edit_recipe,edit_internal_recipe,edit_external_recipe,view_recipe,data_import_url' %}active{% endif %}">
|
||||
<a class="nav-link" href="{% url 'view_search' %}"><i
|
||||
class="fas fa-book"></i> {% trans 'Cookbook' %}<span
|
||||
class="sr-only">(current)</span></a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item dropdown {% if request.resolver_match.url_name in 'view_books,view_plan,view_shopping,list_ingredient,view_plan_entry' %}active{% endif %}">
|
||||
<li class="nav-item dropdown {% if request.resolver_match.url_name in 'view_books,view_plan,view_shopping,list_food,view_plan_entry' %}active{% endif %}">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
|
||||
aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fas fa-mortar-pestle"></i> {% trans 'Utensils' %}
|
||||
@@ -72,10 +73,10 @@
|
||||
<a class="dropdown-item" href="{% url 'view_plan' %}"><i
|
||||
class="fas fa-calendar fa-fw"></i> {% trans 'Meal-Plan' %}
|
||||
</a>
|
||||
<a class="dropdown-item" href="{% url 'view_shopping' %}"><i
|
||||
<a class="dropdown-item" href="{% url 'list_shopping_list' %}"><i
|
||||
class="fas fa-shopping-cart fa-fw"></i> {% trans 'Shopping' %}
|
||||
</a>
|
||||
<a class="dropdown-item" href="{% url 'list_ingredient' %}"><i
|
||||
<a class="dropdown-item" href="{% url 'list_food' %}"><i
|
||||
class="fas fa-leaf fa-fw"></i> {% trans 'Ingredients' %}
|
||||
</a>
|
||||
</div>
|
||||
@@ -92,7 +93,7 @@
|
||||
class="fas fa-edit fa-fw"></i> {% trans 'Batch Edit' %}</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown {% if request.resolver_match.url_name in 'list_storage,data_sync,list_recipe_import,list_sync_log,data_stats,edit_ingredient' %}active{% endif %}">
|
||||
<li class="nav-item dropdown {% if request.resolver_match.url_name in 'list_storage,data_sync,list_recipe_import,list_sync_log,data_stats,edit_food' %}active{% endif %}">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
|
||||
aria-haspopup="true" aria-expanded="false"><i class="fas fa-database"></i> {% trans 'Storage Data' %}
|
||||
</a>
|
||||
@@ -107,7 +108,7 @@
|
||||
class="fas fa-history fa-fw"></i> {% trans 'Discovery Log' %}</a>
|
||||
<a class="dropdown-item" href="{% url 'data_stats' %}"><i
|
||||
class="fas fa-chart-line fa-fw"></i> {% trans 'Statistics' %}</a>
|
||||
<a class="dropdown-item" href="{% url 'edit_ingredient' %}"><i
|
||||
<a class="dropdown-item" href="{% url 'edit_food' %}"><i
|
||||
class="fas fa-balance-scale fa-fw"></i> {% trans 'Units & Ingredients' %}</a>
|
||||
<a class="dropdown-item" href="{% url 'view_import' %}"><i
|
||||
class="fas fa-file-import"></i> {% trans 'Import Recipe' %}</a>
|
||||
@@ -158,30 +159,52 @@
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{% message_of_the_day as message_of_the_day %}
|
||||
{% if message_of_the_day %}
|
||||
<div class="bg-warning" style=" width: 100%; text-align: center!important; color: #ffffff; padding: 8px">
|
||||
{{ message_of_the_day }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<div class="container">
|
||||
{% for message in messages %}
|
||||
<div class="row">
|
||||
<div class="col col-md-12">
|
||||
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
|
||||
{{ message }}
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-fluid" id="id_base_container">
|
||||
<div class="row">
|
||||
<div class="col-xl-2 d-none d-xl-block">
|
||||
{% block content_xl_left %}
|
||||
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="col-xl-8 col-12">
|
||||
{% for message in messages %}
|
||||
<div class="row">
|
||||
<div class="col col-md-12">
|
||||
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
|
||||
{{ message }}
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% block content %}
|
||||
|
||||
{% endblock %}
|
||||
</div>
|
||||
<div class="col-xl-2 d-none d-xl-block">
|
||||
{% block content_xl_right %}
|
||||
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container-fluid">
|
||||
{% block content_fluid %}
|
||||
{% endblock %}
|
||||
|
||||
</div>
|
||||
|
||||
{% block script %}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
{% extends "base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% load i18n %}
|
||||
{% load custom_tags %}
|
||||
{% load theming_tags %}
|
||||
@@ -8,228 +7,649 @@
|
||||
{% block title %}{% trans 'Edit Recipe' %}{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<script src="{% static 'tabulator/tabulator.min.js' %}"></script>
|
||||
<link rel="stylesheet" href="{% tabulator_theme_url request %}"/>
|
||||
|
||||
{% include 'include/vue_base.html' %}
|
||||
|
||||
<link rel="stylesheet" href="{% static 'css/vue-multiselect-bs4.min.css' %}">
|
||||
<script src="{% static 'js/vue-multiselect.min.js' %}"></script>
|
||||
|
||||
<script src="{% static 'js/Sortable.min.js' %}"></script>
|
||||
<script src="{% static 'js/vuedraggable.umd.min.js' %}"></script>
|
||||
|
||||
<script src="{% static 'js/vue-scrollto.js' %}"></script>
|
||||
<script src="{% static 'js/portal-vue.umd.min.js' %}"></script>
|
||||
|
||||
<style>
|
||||
.small-padding {
|
||||
padding-left: 2px;
|
||||
padding-right: 2px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h3>{% trans 'Edit Recipe' %}</h3>
|
||||
|
||||
<form action="." method="post" enctype="multipart/form-data" id="id_form">
|
||||
{% csrf_token %}
|
||||
<div v-if="!recipe" class="text-center">
|
||||
<br/>
|
||||
<i class="fas fa-spinner fa-spin fa-8x"></i>
|
||||
</div>
|
||||
|
||||
{% for field in form %}
|
||||
<div class="fieldWrapper">
|
||||
{{ field|as_crispy_field }}
|
||||
<div v-if="recipe">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<label for="id_name"> {% trans 'Name' %}</label>
|
||||
<input class="form-control" id="id_name" v-model="recipe.name">
|
||||
</div>
|
||||
{% if field.name == 'name' %}
|
||||
<label>{% trans 'Ingredients' %}</label>
|
||||
{{ form.ingredients.errors }}
|
||||
<div id="ingredients-table"></div>
|
||||
<br>
|
||||
<div class="table-controls" style="text-align: center">
|
||||
<button class="btn btn-success" id="new_empty" type="button" style="min-width: 20vw"><i
|
||||
class="fas fa-plus-circle"></i></button>
|
||||
<button class="btn btn-warning" id="new_header" type="button" data-toggle="tooltip"
|
||||
data-placement="top" title="{% trans 'Insert a header between the ingredients.' %}"><i class="fas fa-heading"></i></button>
|
||||
</div>
|
||||
<br/>
|
||||
|
||||
<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover"
|
||||
data-placement="right" data-html="true" data-trigger="focus"
|
||||
data-content="{% trans 'Use <b>Ctrl</b>+<b>Space</b> to insert new Ingredient!<br/>You can also save the recipe using <b>Ctrl</b>+<b>Shift</b>+<b>S</b>.' %}">
|
||||
<i class="fas fa-question"></i>
|
||||
</button>
|
||||
<br/>
|
||||
<br/>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<img src="{% if recipe.image %}{{ recipe.image.url }}{% endif %}" id="id_image"
|
||||
class="img img-fluid img-responsive"
|
||||
style="max-height: 20vh">
|
||||
<input type="file" @change="imageChanged">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="id_name"> {% trans 'Preparation Time' %}</label>
|
||||
<input class="form-control" id="id_prep_time" v-model="recipe.working_time">
|
||||
<br/>
|
||||
<label for="id_name"> {% trans 'Waiting Time' %}</label>
|
||||
<input class="form-control" id="id_wait_time" v-model="recipe.waiting_time">
|
||||
<br/>
|
||||
<label for="id_name"> {% trans 'Keywords' %}</label>
|
||||
<multiselect
|
||||
v-model="recipe.keywords"
|
||||
:options="keywords"
|
||||
:close-on-select="false"
|
||||
:clear-on-select="true"
|
||||
:hide-selected="true"
|
||||
:preserve-search="true"
|
||||
placeholder="{% trans 'Select Keywords' %}"
|
||||
label="label"
|
||||
track-by="id"
|
||||
id="id_keywords"
|
||||
:multiple="true"
|
||||
:loading="keywords_loading"
|
||||
@search-change="searchKeywords">
|
||||
</multiselect>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<draggable :list="recipe.steps" group="steps"
|
||||
:empty-insert-threshold="10" handle=".handle" @sort="sortSteps()">
|
||||
|
||||
<div v-for="step, step_index in recipe.steps" style="margin-top: 1vh" class="card">
|
||||
|
||||
<div class="card-body" :id="`id_card_step_${step_index}`">
|
||||
<div class="row">
|
||||
<div class="col-11">
|
||||
<h4 class="handle" :id="'id_step_' + step_index">
|
||||
<i class="fas fa-paragraph" v-if="step.type == 'TEXT'"></i>
|
||||
<i class="fas fa-clock" v-if="step.type == 'TIME'"></i>
|
||||
<template v-if="step.name !== ''">[[step.name]]</template>
|
||||
<template v-else>{% trans 'Step' %} [[step_index+1]]</template>
|
||||
|
||||
</h4>
|
||||
</div>
|
||||
<div class="col-1" style="text-align: right">
|
||||
<a class="btn shadow-none btn-lg" href="#" role="button"
|
||||
id="dropdownMenuLink"
|
||||
data-toggle="dropdown" aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
<i class="fas fa-ellipsis-v text-muted"></i>
|
||||
</a>
|
||||
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right"
|
||||
aria-labelledby="dropdownMenuLink">
|
||||
<button class="dropdown-item" @click="removeStep(step)"><i
|
||||
class="fa fa-trash fa-fw"></i> {% trans 'Delete Step' %}</button>
|
||||
|
||||
<button type="button" class="dropdown-item"
|
||||
v-if="!step.show_as_header"
|
||||
@click="step.show_as_header = true"><i
|
||||
class="fas fa-eye fa-fw"></i> {% trans 'Show as header' %}
|
||||
</button>
|
||||
|
||||
<button type="button" class="dropdown-item"
|
||||
v-if="step.show_as_header"
|
||||
@click="step.show_as_header = false"><i
|
||||
class="fas fa-eye-slash fa-fw"></i> {% trans 'Hide as header' %}
|
||||
</button>
|
||||
|
||||
<button class="dropdown-item" @click="moveStep(step, (step_index - 1))"
|
||||
v-if="step_index > 0">
|
||||
<i class="fa fa-arrow-up fa-fw"></i> {% trans 'Move Up' %}
|
||||
</button>
|
||||
<button class="dropdown-item"
|
||||
@click="moveStep(step, (step_index + 1))"
|
||||
v-if="step_index != (recipe.steps.length - 1)">
|
||||
<i class="fa fa-arrow-down fa-fw"></i> {% trans 'Move Down' %}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<label :for="'id_step_' + step.id + 'name'">{% trans 'Step Name' %}</label>
|
||||
<input class="form-control" v-model="step.name" :id="'id_step_' + step.id + 'name'">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label for="id_type"> {% trans 'Step Type' %}</label>
|
||||
<select class="form-control" id="id_type" v-model="step.type">
|
||||
<option value="TEXT">{% trans 'Text' %}</option>
|
||||
<option value="TIME">{% trans 'Time' %}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row" style="margin-top: 12px">
|
||||
<div class="col-md-12">
|
||||
<label :for="'id_step_' + step.id + '_time'">{% trans 'Step time in Minutes' %}</label>
|
||||
<input class="form-control" v-model="step.time"
|
||||
:id="'id_step_' + step.id + '_time'">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-if="step.type == 'TEXT'">
|
||||
<div class="row" style="margin-top: 12px">
|
||||
<div class="col-md-12">
|
||||
<div class="jumbotron" style="padding: 16px">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h4>{% trans 'Ingredients' %}</h4>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12" style="margin-top: 8px">
|
||||
<draggable :list="step.ingredients" group="ingredients"
|
||||
:empty-insert-threshold="10" handle=".handle"
|
||||
@sort="sortIngredients(step)">
|
||||
<div v-for="ingredient, index in step.ingredients"
|
||||
:key="ingredient.id">
|
||||
|
||||
<hr class="d-md-none"/>
|
||||
<div class="d-flex">
|
||||
<div class="flex-grow-0 handle align-self-start">
|
||||
<button type="button" class="btn btn-lg shadow-none"><i
|
||||
class="fas fa-arrows-alt-v "></i></button>
|
||||
</div>
|
||||
|
||||
<div class="flex-fill row"
|
||||
style="margin-left: 4px; margin-right: 4px">
|
||||
<div class="col-lg-2 col-md-6 small-padding"
|
||||
v-if="!ingredient.is_header">
|
||||
<input class="form-control"
|
||||
v-model="ingredient.amount"
|
||||
type="number" step="any"
|
||||
v-if="!ingredient.no_amount"
|
||||
:id="`amount_${step_index}_${index}`">
|
||||
</div>
|
||||
|
||||
<div class="col-lg-2 col-md-6 small-padding"
|
||||
v-if="!ingredient.is_header">
|
||||
<multiselect
|
||||
v-if="!ingredient.no_amount"
|
||||
v-tabindex
|
||||
ref="unit"
|
||||
v-model="ingredient.unit"
|
||||
:options="units"
|
||||
:close-on-select="true"
|
||||
:clear-on-select="true"
|
||||
:allow-empty="true"
|
||||
:preserve-search="true"
|
||||
placeholder="{% trans 'Select Unit' %}"
|
||||
tag-placeholder="{% trans 'Create' %}"
|
||||
select-label="{% trans 'Select' %}"
|
||||
:taggable="true"
|
||||
@tag="addUnitType"
|
||||
:id="`unit_${step_index}_${index}`"
|
||||
label="name"
|
||||
track-by="name"
|
||||
:multiple="false"
|
||||
:loading="units_loading"
|
||||
@search-change="searchUnits">
|
||||
</multiselect>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 small-padding"
|
||||
v-if="!ingredient.is_header">
|
||||
<multiselect
|
||||
v-tabindex
|
||||
ref="food"
|
||||
v-model="ingredient.food"
|
||||
:options="foods"
|
||||
:close-on-select="true"
|
||||
:clear-on-select="true"
|
||||
:allow-empty="true"
|
||||
:preserve-search="true"
|
||||
placeholder="{% trans 'Select Food' %}"
|
||||
tag-placeholder="{% trans 'Create' %}"
|
||||
select-label="{% trans 'Select' %}"
|
||||
:taggable="true"
|
||||
@tag="addFoodType"
|
||||
:id="`ingredient_${step_index}_${index}`"
|
||||
label="name"
|
||||
track-by="name"
|
||||
:multiple="false"
|
||||
:loading="foods_loading"
|
||||
@search-change="searchFoods">
|
||||
</multiselect>
|
||||
</div>
|
||||
<div class="small-padding"
|
||||
v-bind:class="{ 'col-lg-4 col-md-6': !ingredient.is_header, 'col-lg-12 col-md-12': ingredient.is_header }">
|
||||
<input class="form-control"
|
||||
v-model="ingredient.note"
|
||||
placeholder="{% trans 'Note' %}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-grow-0 small-padding">
|
||||
<a class="btn shadow-none btn-lg" href="#" role="button"
|
||||
id="dropdownMenuLink"
|
||||
data-toggle="dropdown" aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
<i class="fas fa-ellipsis-v text-muted"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right"
|
||||
aria-labelledby="dropdownMenuLink">
|
||||
<button type="button" class="dropdown-item"
|
||||
@click="removeIngredient(step, ingredient)">
|
||||
<i
|
||||
class="fa fa-trash fa-fw"></i> {% trans 'Delete Ingredient' %}
|
||||
</button>
|
||||
|
||||
<button type="button" class="dropdown-item"
|
||||
v-if="!ingredient.is_header "
|
||||
@click="ingredient.is_header = true"><i
|
||||
class="fas fa-heading fa-fw"></i> {% trans 'Make Header' %}
|
||||
</button>
|
||||
|
||||
<button type="button" class="dropdown-item"
|
||||
v-if="ingredient.is_header "
|
||||
@click="ingredient.is_header = false"><i
|
||||
class="fas fa-leaf fa-fw"></i> {% trans 'Make Ingredient' %}
|
||||
</button>
|
||||
|
||||
<button type="button" class="dropdown-item"
|
||||
v-if="!ingredient.no_amount "
|
||||
@click="ingredient.no_amount = true"><i
|
||||
class="fas fa-balance-scale-right fa-fw"></i> {% trans 'Disable Amount' %}
|
||||
</button>
|
||||
|
||||
<button type="button" class="dropdown-item"
|
||||
v-if="ingredient.no_amount "
|
||||
@click="ingredient.no_amount = false"><i
|
||||
class="fas fa-balance-scale-right fa-fw"></i> {% trans 'Enable Amount' %}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</draggable>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-2 offset-md-5"
|
||||
style="text-align: center; margin-top: 8px;">
|
||||
<button class="btn btn-dark btn-block" @click="addIngredient(step)"><i
|
||||
class="fa fa-plus"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<label :for="'id_instruction_' + step.id">{% trans 'Instructions' %}</label>
|
||||
<b-form-textarea class="form-control" rows="2" max-rows="20" v-model="step.instruction"
|
||||
:id="'id_instruction_' + step.id"></b-form-textarea>
|
||||
<small class="text-muted">{% trans 'You can use markdown to format this field. See the <a href="/docs/markdown/">docs here</a>' %}</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</draggable>
|
||||
|
||||
<hr>
|
||||
<button class="btn btn-success" type="submit"><i class="fas fa-save"></i> {% trans 'Save' %}</button>
|
||||
<a href="{% delete_url form.instance|get_class form.instance.pk %}"
|
||||
class="btn btn-danger"><i class="fas fa-trash-alt"></i> {% trans 'Delete' %}</a>
|
||||
{% if view_url %}
|
||||
<a href="{{ view_url }}" class="btn btn-info"><i class="far fa-eye"></i> {% trans 'View' %}</a>
|
||||
{% endif %}
|
||||
{% if form.instance.storage %}
|
||||
<a href="{% url 'delete_recipe_source' form.instance.pk %}" class="btn btn-warning"><i
|
||||
class="fas fa-exclamation-triangle"></i> {% trans 'Delete original file' %}</a>
|
||||
{% endif %}
|
||||
</form>
|
||||
<div class="row" style="margin-top: 1vh; margin-bottom: 8vh">
|
||||
<div class="col-12">
|
||||
<button type="button" @click="updateRecipe(true)"
|
||||
class="btn btn-success shadow-none">{% trans 'Save & View' %}</button>
|
||||
<button type="button" @click="updateRecipe(false)"
|
||||
class="btn btn-info shadow-none">{% trans 'Save' %}</button>
|
||||
<button type="button" @click="addStep()"
|
||||
class="btn btn-primary shadow-none">{% trans 'Add Step' %}</button>
|
||||
<a href="{% url 'view_recipe' recipe.pk %}" @click="addStep()"
|
||||
class="btn btn-secondary shadow-none">{% trans 'View Recipe' %}</a>
|
||||
<a href="{% url 'delete_recipe' recipe.pk %}"
|
||||
class="btn btn-danger shadow-none">{% trans 'Delete Recipe' %}</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content_xl_right %}
|
||||
<div class="sticky-top" style="top: 2vh; z-index: 100;">
|
||||
<div class="row">
|
||||
<div class="col-md-11">
|
||||
<button type="button" @click="updateRecipe(true)"
|
||||
class="btn btn-success btn-block shadow-none">{% trans 'Save & View' %}</button>
|
||||
|
||||
<button type="button" @click="updateRecipe(false)"
|
||||
class="btn btn-info btn-block shadow-none">{% trans 'Save' %}</button>
|
||||
|
||||
<button type="button" @click="addStep()"
|
||||
class="btn btn-primary btn-block shadow-none">{% trans 'Add Step' %}</button>
|
||||
|
||||
<a href="{% url 'view_recipe' recipe.pk %}"
|
||||
class="btn btn-secondary btn-block shadow-none">{% trans 'View Recipe' %}</a>
|
||||
<a href="{% url 'delete_recipe' recipe.pk %}"
|
||||
class="btn btn-danger btn-block shadow-none">{% trans 'Delete Recipe' %}</a>
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="row" v-if="recipe !== undefined">
|
||||
<div class="col-md-11">
|
||||
<h5><i class="fas fa-sort-amount-down-alt"></i> {% trans 'Steps' %}</h5>
|
||||
<draggable :list="recipe.steps" group="steps_sorter"
|
||||
:empty-insert-threshold="10" handle=".handle" @sort="sortSteps()" class="list-group"
|
||||
style="margin-top: 1vh">
|
||||
<div v-for="step, step_index in recipe.steps" class="list-group-item">
|
||||
<div class="d-flex justify-content-center align-items-center">
|
||||
<div class="flex-grow-0 text-muted">
|
||||
<i class="fas fa-paragraph fa-fw" v-if="step.type == 'TEXT'"></i>
|
||||
<i class="fas fa-clock fa-fw" v-if="step.type == 'TIME'"></i>
|
||||
</div>
|
||||
<div class="flex-fill" style="padding-left: 4px">
|
||||
<a href="#" v-scroll-to="'#id_step_' + step_index">
|
||||
<template v-if="step.name">[[step.name]]</template>
|
||||
<template v-else>{% trans 'Step' %} [[step_index + 1]]</template>
|
||||
</a>
|
||||
</div>
|
||||
<div class="handle flex-grow-0 align-content-end">
|
||||
<i class="fas fa-sort "></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</draggable>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="application/javascript">
|
||||
let csrftoken = Cookies.get('csrftoken');
|
||||
Vue.http.headers.common['X-CSRFToken'] = csrftoken;
|
||||
|
||||
$(function () {
|
||||
$('[data-toggle="popover"]').popover()
|
||||
});
|
||||
Vue.component('vue-multiselect', window.VueMultiselect.default)
|
||||
|
||||
$('.popover-dismiss').popover({
|
||||
trigger: 'focus'
|
||||
});
|
||||
|
||||
let select2UnitEditor = function (cell, onRendered, success, cancel, editorParams) {
|
||||
return select2Editor(cell, onRendered, success, cancel, editorParams, '{% url 'dal_unit' %}')
|
||||
};
|
||||
|
||||
let select2IngredientEditor = function (cell, onRendered, success, cancel, editorParams) {
|
||||
return select2Editor(cell, onRendered, success, cancel, editorParams, '{% url 'dal_ingredient' %}')
|
||||
};
|
||||
|
||||
let select2Editor = function (cell, onRendered, success, cancel, editorParams, url) {
|
||||
|
||||
let editor = document.createElement("select");
|
||||
editor.setAttribute("class", "form-control");
|
||||
editor.setAttribute("style", "height: 100%; color: #00ff00");
|
||||
|
||||
onRendered(function () {
|
||||
let select_2 = $(editor);
|
||||
|
||||
select_2.select2({
|
||||
tags: true,
|
||||
ajax: {
|
||||
url: url,
|
||||
dataType: 'json'
|
||||
}
|
||||
});
|
||||
|
||||
select_2.select2('open');
|
||||
|
||||
select_2.on('select2:select', function (e) {
|
||||
success(e.params.data.text);
|
||||
});
|
||||
|
||||
select_2.on('select2:close', function (e) {
|
||||
if (e.target.textContent === "") {
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//add editor to cell
|
||||
return editor;
|
||||
};
|
||||
|
||||
//converts multiselct in recipe edit to searchable multiselect
|
||||
//shitty solution that needs to be redone at some point
|
||||
$(document).ready(function () {
|
||||
$('#id_keywords').select2();
|
||||
|
||||
let ingredients = {{ ingredients|safe }}
|
||||
|
||||
ingredients.forEach(function (cur, i) {
|
||||
cur.delete = false
|
||||
});
|
||||
|
||||
let data = ingredients;
|
||||
|
||||
let table = new Tabulator("#ingredients-table", {
|
||||
index: "id",
|
||||
layout: "fitColumns",
|
||||
reactiveData: true,
|
||||
data: data,
|
||||
movableRows: true,
|
||||
headerSort: false,
|
||||
columns: [
|
||||
{
|
||||
title: "<i class='fas fa-sort'></i>",
|
||||
rowHandle: true,
|
||||
formatter: "handle",
|
||||
headerSort: false,
|
||||
frozen: true,
|
||||
width: 36,
|
||||
minWidth: 36
|
||||
},
|
||||
{
|
||||
title: "{% trans 'Ingredient' %}",
|
||||
field: "ingredient__name",
|
||||
validator: "required",
|
||||
editor: select2IngredientEditor
|
||||
},
|
||||
{title: "{% trans 'Amount' %}", field: "amount", validator: "required", editor: "number"},
|
||||
{
|
||||
title: "{% trans 'Unit' %}",
|
||||
field: "unit__name",
|
||||
validator: "required",
|
||||
editor: select2UnitEditor
|
||||
},
|
||||
{title: "{% trans 'Note' %}", field: "note", editor: "input"},
|
||||
{
|
||||
formatter: function (cell, formatterParams) {
|
||||
return "<span style='color:red'><i class=\"fas fa-trash-alt\"></i></span>"
|
||||
},
|
||||
align: "center",
|
||||
title: "{% trans 'Delete' %}",
|
||||
headerSort: false,
|
||||
cellClick: function (e, cell) {
|
||||
if (confirm('{% trans 'Are you sure that you want to delete this ingredient?' %}'))
|
||||
cell.getRow().delete();
|
||||
}
|
||||
},
|
||||
{title: "id", field: "id", visible: false}
|
||||
],
|
||||
cellClick: function (e, cell) {
|
||||
if (cell._cell.column.definition.editor === "input") {
|
||||
input = cell.getElement().childNodes[0];
|
||||
input.focus();
|
||||
input.select();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// save ingredient data before submitting form
|
||||
$('#id_form').submit(function () {
|
||||
$('#id_ingredients').val(JSON.stringify(table.getData()));
|
||||
return true;
|
||||
});
|
||||
|
||||
// load initial value
|
||||
$('#id_ingredients').val(JSON.stringify(data));
|
||||
|
||||
function addIngredientRow() {
|
||||
data.push({
|
||||
ingredient__name: "{% trans 'Ingredient' %}",
|
||||
amount: "100",
|
||||
unit__name: "{{ request.user.userpreference.default_unit }}",
|
||||
note: "",
|
||||
id: Math.floor(Math.random() * 10000000),
|
||||
delete: false,
|
||||
});
|
||||
input = table.rowManager.rows[((table.rowManager.rows).length) - 1].cells[1].getElement()
|
||||
input.focus();
|
||||
input.select();
|
||||
}
|
||||
|
||||
function addHeaderRow(type) {
|
||||
data.push({
|
||||
ingredient__name: '{% trans 'Header' %}',
|
||||
amount: "0",
|
||||
unit__name: "Special:Header",
|
||||
note: "{% trans 'write header here' %}",
|
||||
id: Math.floor(Math.random() * 10000000),
|
||||
delete: false,
|
||||
});
|
||||
input = table.rowManager.rows[((table.rowManager.rows).length) - 1].cells[4].getElement()
|
||||
input.focus();
|
||||
input.select();
|
||||
}
|
||||
|
||||
document.onkeyup = function (e) {
|
||||
if (e.shiftKey && e.ctrlKey && (e.which === 83 || e.keyCode === 83)) {
|
||||
$('#id_form').submit()
|
||||
} else if (e.ctrlKey && (e.which === 83 || e.keyCode === 32)) {
|
||||
addIngredientRow();
|
||||
}
|
||||
};
|
||||
|
||||
document.getElementById("new_empty").addEventListener("click", addIngredientRow);
|
||||
document.getElementById("new_header").addEventListener("click", addHeaderRow);
|
||||
});
|
||||
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip()
|
||||
VueScrollTo.setDefaults({
|
||||
offset: -40,
|
||||
})
|
||||
|
||||
let app = new Vue({
|
||||
components: {
|
||||
Multiselect: window.VueMultiselect.default
|
||||
},
|
||||
delimiters: ['[[', ']]'],
|
||||
el: '#id_base_container',
|
||||
data: {
|
||||
recipe: undefined,
|
||||
recipe_changed: undefined,
|
||||
keywords: [],
|
||||
keywords_loading: false,
|
||||
foods: [],
|
||||
foods_loading: false,
|
||||
units: [],
|
||||
units_loading: false,
|
||||
message: '',
|
||||
},
|
||||
directives: {
|
||||
tabindex: {
|
||||
inserted(el) {
|
||||
el.setAttribute('tabindex', 0);
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
recipe: {
|
||||
deep: true,
|
||||
handler() {
|
||||
this.recipe_changed = this.recipe_changed !== undefined;
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
window.addEventListener('beforeunload', this.warnPageLeave)
|
||||
},
|
||||
mounted: function () {
|
||||
this.loadRecipe()
|
||||
this.searchUnits('')
|
||||
this.searchFoods('')
|
||||
this.searchKeywords('')
|
||||
|
||||
this._keyListener = function (e) {
|
||||
if (e.code === "Space" && e.ctrlKey) {
|
||||
e.preventDefault(); // present "Save Page" from getting triggered.
|
||||
|
||||
for (el of e.path) {
|
||||
if(el.id !== undefined && el.id.includes('id_card_step_')) {
|
||||
let step = this.recipe.steps[el.id.replace('id_card_step_','')]
|
||||
this.addIngredient(step)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('keydown', this._keyListener.bind(this));
|
||||
},
|
||||
beforeDestroy() {
|
||||
document.removeEventListener('keydown', this._keyListener);
|
||||
},
|
||||
methods: {
|
||||
makeToast: function (title, message, variant = null) {
|
||||
//TODO remove duplicate function in favor of central one
|
||||
this.$bvToast.toast(message, {
|
||||
title: title,
|
||||
variant: variant,
|
||||
toaster: 'b-toaster-top-center',
|
||||
solid: true
|
||||
})
|
||||
},
|
||||
warnPageLeave: function (event) {
|
||||
if (this.recipe_changed) {
|
||||
event.returnValue = ''
|
||||
return ''
|
||||
}
|
||||
},
|
||||
loadRecipe: function () {
|
||||
this.$http.get("{% url 'api:recipe-detail' recipe.pk %}").then((response) => {
|
||||
this.recipe = response.data;
|
||||
this.loading = false
|
||||
}).catch((err) => {
|
||||
this.loading = false
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading the recipe!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
updateRecipe: function (view_after) {
|
||||
this.sortSteps()
|
||||
for (let s of this.recipe.steps) {
|
||||
this.sortIngredients(s)
|
||||
}
|
||||
this.$http.put("{% url 'api:recipe-detail' recipe.pk %}", this.recipe,
|
||||
{}).then((response) => {
|
||||
console.log(response)
|
||||
this.makeToast('{% trans 'Updated' %}', '{% trans 'Changes saved successfully!' %}', 'success')
|
||||
this.recipe_changed = false
|
||||
if (view_after) {
|
||||
location.href = "{% url 'view_recipe' 12345 %}".replace(/12345/, this.recipe.id);
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error updating the recipe!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
imageChanged: function (event) {
|
||||
if (event.target.files && event.target.files[0]) {
|
||||
let fd = new FormData()
|
||||
fd.append('image', event.target.files[0])
|
||||
this.$http.put("{% url 'api:recipe-detail' recipe.pk %}" + 'image/', fd,
|
||||
{headers: {'Content-Type': 'multipart/form-data'}}).then((response) => {
|
||||
console.log(response)
|
||||
this.makeToast('{% trans 'Updated' %}', '{% trans 'Changes saved successfully!' %}', 'success')
|
||||
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error updating the recipe!' %}' + err.body.image, 'danger')
|
||||
})
|
||||
|
||||
let reader = new FileReader();
|
||||
reader.onload = function (e) {
|
||||
$('#id_image').attr('src', e.target.result);
|
||||
}
|
||||
reader.readAsDataURL(event.target.files[0]);
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
addStep: function () { //TODO see if default can be generated from options request
|
||||
this.recipe.steps.push(
|
||||
{'instruction': '', ingredients: [], type: 'TEXT', show_as_header: true}
|
||||
)
|
||||
},
|
||||
sortSteps: function () {
|
||||
this.recipe.steps.forEach(function (element, index) {
|
||||
element.order = index
|
||||
});
|
||||
},
|
||||
sortIngredients: function (step) {
|
||||
step.ingredients.forEach(function (element, index) {
|
||||
element.order = index
|
||||
});
|
||||
},
|
||||
addIngredient: function (step) { //TODO see if default can be generated from options request
|
||||
step.ingredients.push({
|
||||
'food': null,
|
||||
'unit': {
|
||||
'name': '{{request.user.userpreference.default_unit}}'
|
||||
},
|
||||
'amount': 0,
|
||||
'note': '',
|
||||
'order': 0,
|
||||
'is_header': false,
|
||||
'no_amount': false
|
||||
})
|
||||
this.sortIngredients(step)
|
||||
this.$nextTick(() => document.getElementById(`amount_${this.recipe.steps.indexOf(step)}_${step.ingredients.length - 1}`).focus())
|
||||
|
||||
},
|
||||
removeIngredient: function (step, ingredient) {
|
||||
if (confirm('{% trans 'Are you sure that you want to delete this ingredient?' %}')) {
|
||||
step.ingredients = step.ingredients.filter(item => item !== ingredient)
|
||||
}
|
||||
},
|
||||
removeStep: function (step) {
|
||||
if (confirm('{% trans 'Are you sure that you want to delete this step?' %}')) {
|
||||
this.recipe.steps = this.recipe.steps.filter(item => item !== step)
|
||||
}
|
||||
},
|
||||
moveStep: function (step, new_index) {
|
||||
this.recipe.steps.splice(this.recipe.steps.indexOf(step), 1);
|
||||
this.recipe.steps.splice((new_index < 0 ? 0 : new_index), 0, step);
|
||||
this.sortSteps()
|
||||
},
|
||||
addFoodType: function (tag, index) {
|
||||
let [tmp, step, id] = index.split('_')
|
||||
|
||||
let new_food = this.recipe.steps[step].ingredients[id]
|
||||
new_food.food = {'name': tag}
|
||||
this.foods.push(new_food.food)
|
||||
this.recipe.steps[step].ingredients[id] = new_food
|
||||
},
|
||||
addUnitType: function (tag, index) {
|
||||
let [tmp, step, id] = index.split('_')
|
||||
|
||||
let new_unit = this.recipe.steps[step].ingredients[id]
|
||||
new_unit.unit = {'name': tag}
|
||||
this.units.push(new_unit.unit)
|
||||
this.recipe.steps[step].ingredients[id] = new_unit
|
||||
},
|
||||
searchKeywords: function (query) {
|
||||
this.keywords_loading = true
|
||||
this.$http.get("{% url 'api:keyword-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||
this.keywords = response.data;
|
||||
this.keywords_loading = false
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
searchUnits: function (query) {
|
||||
this.units_loading = true
|
||||
this.$http.get("{% url 'api:unit-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||
this.units = response.data;
|
||||
|
||||
if (this.recipe !== undefined) {
|
||||
for (let s of this.recipe.steps) {
|
||||
for (let i of s.ingredients) {
|
||||
if (i.unit !== null && i.unit.id === undefined) {
|
||||
this.units.push(i.unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.units_loading = false
|
||||
}).catch((err) => {
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
searchFoods: function (query) {
|
||||
this.foods_loading = true
|
||||
this.$http.get("{% url 'api:food-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||
this.foods = response.data
|
||||
|
||||
if (this.recipe !== undefined) {
|
||||
for (let s of this.recipe.steps) {
|
||||
for (let i of s.ingredients) {
|
||||
if (i.food !== null && i.food.id === undefined) {
|
||||
this.foods.push(i.food)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.foods_loading = false
|
||||
}).catch((err) => {
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
scrollToStep: function (step_index) {
|
||||
document.getElementById('id_step_' + step_index).scrollIntoView({behavior: 'smooth'});
|
||||
},
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -22,7 +22,7 @@
|
||||
<br/>
|
||||
|
||||
<h4>{% trans 'Units' %}</h4>
|
||||
<form action="{% url 'edit_ingredient' %}" method="post"
|
||||
<form action="{% url 'edit_food' %}" method="post"
|
||||
onsubmit="return confirm('{% trans 'Are you sure that you want to merge these two units ?' %}')">
|
||||
{% csrf_token %}
|
||||
{{ units_form|crispy }}
|
||||
@@ -32,10 +32,10 @@
|
||||
</form>
|
||||
|
||||
<h4>{% trans 'Ingredients' %}</h4>
|
||||
<form action="{% url 'edit_ingredient' %}" method="post"
|
||||
<form action="{% url 'edit_food' %}" method="post"
|
||||
onsubmit="return confirm('{% trans 'Are you sure that you want to merge these two ingredients ?' %}')">
|
||||
{% csrf_token %}
|
||||
{{ ingredients_form|crispy }}
|
||||
{{ food_form|crispy }}
|
||||
<button class="btn btn-danger" type="submit">
|
||||
<i class="fas fa-sync-alt"></i> {% trans 'Merge' %}</button>
|
||||
</form>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
{% block content %}
|
||||
|
||||
<div class="table-container">
|
||||
<h3>{{ title }} {% trans 'List' %}
|
||||
<h3 style="margin-bottom: 2vh">{{ title }} {% trans 'List' %}
|
||||
{% if create_url %}
|
||||
<a href="{% url create_url %}"> <i class="fas fa-plus-circle"></i>
|
||||
</a>
|
||||
|
||||
@@ -32,16 +32,17 @@
|
||||
</div>
|
||||
|
||||
<script type="application/javascript">
|
||||
let modal = $('#id_modal_cook_log')
|
||||
let rating = $('#id_log_rating')
|
||||
|
||||
function openCookLogModal(id) {
|
||||
let modal = $('#id_modal_cook_log')
|
||||
modal.data('recipe_id', id)
|
||||
modal.modal('show')
|
||||
}
|
||||
|
||||
//TODO there is definitely a nicer way to do this than this ugly shit
|
||||
function logCook() {
|
||||
let modal = $('#id_modal_cook_log')
|
||||
let rating = $('#id_log_rating')
|
||||
let id = modal.data('recipe_id');
|
||||
|
||||
let url = "{% url 'api_log_cooking' recipe_id=12345 %}".replace(/12345/, id);
|
||||
@@ -53,11 +54,11 @@
|
||||
|
||||
let val_rating = rating.val()
|
||||
if (val_rating !== '' && val_rating !== 0) {
|
||||
if (val_servings !== '' && val_servings !== 0) {
|
||||
url += '&'
|
||||
}else {
|
||||
url += '?'
|
||||
}
|
||||
if (val_servings !== '' && val_servings !== 0) {
|
||||
url += '&'
|
||||
} else {
|
||||
url += '?'
|
||||
}
|
||||
url += 'r=' + val_rating
|
||||
}
|
||||
|
||||
@@ -71,7 +72,7 @@
|
||||
modal.modal('hide')
|
||||
}
|
||||
|
||||
rating.on("input", () => {
|
||||
$('#id_log_rating').on("input", () => {
|
||||
$('#id_rating_show').html(rating.val() + '/5')
|
||||
});
|
||||
|
||||
|
||||
@@ -1,26 +1,5 @@
|
||||
{% load i18n %}
|
||||
|
||||
<style>
|
||||
.loader {
|
||||
border: 16px solid #f3f3f3; /* Light grey */
|
||||
border-top: 16px solid #3498db; /* Blue */
|
||||
border-radius: 50%;
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
animation: spin 2s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<div class="modal" tabindex="-1" role="dialog" id="modal_recipe">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
@@ -31,7 +10,7 @@
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body" style="text-align: center">
|
||||
<div class="loader" id="div_loader"></div>
|
||||
<i class="fas fa-spinner fa-spin fa-8x" id="id_spinner"></i>
|
||||
<a href="" id="a_recipe_open" target="_blank" onclick="afterClick()" style="font-size: 250%"></a>
|
||||
|
||||
</div>
|
||||
@@ -42,11 +21,11 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
<script type="application/javascript">
|
||||
function openRecipe(id) {
|
||||
var link = $('#a_recipe_open');
|
||||
link.hide();
|
||||
$('#div_loader').show();
|
||||
$('#id_spinner').show();
|
||||
|
||||
var url = "{% url 'api_get_external_file_link' recipe_id=12345 %}".replace(/12345/, id);
|
||||
|
||||
@@ -64,7 +43,7 @@
|
||||
$('#modal_recipe').modal('hide');
|
||||
}
|
||||
|
||||
$('#div_loader').hide();
|
||||
$('#id_spinner').hide();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
16
cookbook/templates/include/vue_base.html
Normal file
16
cookbook/templates/include/vue_base.html
Normal file
@@ -0,0 +1,16 @@
|
||||
{% load static %}
|
||||
{% load custom_tags %}
|
||||
|
||||
{% is_debug as DEBUG %}
|
||||
{% if DEBUG %}
|
||||
<script src="{% static 'js/vue.js' %}"></script>
|
||||
{% else %}
|
||||
<script src="{% static 'js/vue.min.js' %}"></script>
|
||||
{% endif %}
|
||||
|
||||
<script src="{% static 'js/vue-resource.js' %}"></script>
|
||||
|
||||
<script src="{% static 'js/js.cookie.min.js' %}"></script>
|
||||
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap-vue.min.css' %}">
|
||||
<script src="{% static 'js/bootstrap-vue.min.js' %}"></script>
|
||||
@@ -42,6 +42,10 @@
|
||||
<button class="dropdown-item" type="button"
|
||||
onclick="location.href='{% url 'new_recipe' %}'"><i
|
||||
class="fas fa-plus-circle fa-fw"></i> {% trans 'New Recipe' %}</button>
|
||||
<button class="dropdown-item" type="button"
|
||||
onclick="location.href='{% url 'data_import_url' %}'"><i
|
||||
class="fas fa-cloud-download-alt fa-fw"></i> {% trans 'Website Import' %}
|
||||
</button>
|
||||
<button data-toggle="collapse" href="#collapse_adv_search"
|
||||
role="button" class="dropdown-item"
|
||||
aria-expanded="false" type="button"
|
||||
@@ -63,7 +67,7 @@
|
||||
{{ filter.form.keywords | as_crispy_field }}
|
||||
</div>
|
||||
<div>
|
||||
{{ filter.form.ingredients | as_crispy_field }}
|
||||
{{ filter.form.foods | as_crispy_field }}
|
||||
</div>
|
||||
<div>
|
||||
{{ filter.form.internal | as_crispy_field }}
|
||||
@@ -87,7 +91,7 @@
|
||||
{% render_table recipes %}
|
||||
{% else %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{% trans "Log in to view Recipies" %}
|
||||
{% trans "Log in to view Recipes" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
@@ -6,13 +6,8 @@
|
||||
|
||||
{% block extra_head %}
|
||||
|
||||
{% if DEBUG %}
|
||||
<script src="{% static 'js/vue.js' %}"></script>
|
||||
{% else %}
|
||||
<script src="{% static 'js/vue.min.js' %}"></script>
|
||||
{% endif %}
|
||||
{% include 'include/vue_base.html' %}
|
||||
|
||||
<script src="{% static 'js/vue-resource.js' %}"></script>
|
||||
<script src="{% static 'js/moment-with-locales.min.js' %}"></script>
|
||||
|
||||
<script src="{% static 'js/Sortable.min.js' %}"></script>
|
||||
@@ -108,8 +103,15 @@
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<input type="text" class="form-control" v-model="recipe_query" @keyup="getRecipes"
|
||||
placeholder="{% trans 'Search Recipe' %}" style="margin-bottom: 8px">
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control" v-model="recipe_query" @keyup="getRecipes"
|
||||
placeholder="{% trans 'Search Recipe' %}">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-secondary" type="button" @click="getRandomRecipes">
|
||||
<i class="fas fa-dice"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<draggable class="list-group" :list="recipes"
|
||||
@@ -131,6 +133,9 @@
|
||||
class="text-muted">{% trans 'You can use markdown to format this field. See the <a href="/docs/markdown/" target="_blank" rel="noopener noreferrer">docs here</a>' %}</span></small>
|
||||
<br/>
|
||||
<br/>
|
||||
<input type="number" class="form-control" v-model="new_note_multiplier"
|
||||
placeholder="{% trans 'Recipe Multiplier' %}" style="margin-bottom: 8px">
|
||||
<br/>
|
||||
<draggable :list="pseudo_note_list"
|
||||
:group="{ name: 'plan', pull: 'clone', put: false }" :clone="cloneNote">
|
||||
<div class="list-group-item" v-for="(element, index) in pseudo_note_list"
|
||||
@@ -354,6 +359,7 @@
|
||||
],
|
||||
new_note_title: '',
|
||||
new_note_text: '',
|
||||
new_note_multiplier: '',
|
||||
default_shared_users: [],
|
||||
user_id_update: [],
|
||||
user_names: {},
|
||||
@@ -372,6 +378,15 @@
|
||||
this.getRecipes();
|
||||
},
|
||||
methods: {
|
||||
makeToast: function (title, message, variant = null) {
|
||||
//TODO remove duplicate function in favor of central one
|
||||
this.$bvToast.toast(message, {
|
||||
title: title,
|
||||
variant: variant,
|
||||
toaster: 'b-toaster-top-center',
|
||||
solid: true
|
||||
})
|
||||
},
|
||||
updatePlan: function () {
|
||||
let planEntryPromise = this.getPlanEntries();
|
||||
let planTypePromise = this.getPlanTypes();
|
||||
@@ -385,6 +400,7 @@
|
||||
this.plan_entries = response.data;
|
||||
}).catch((err) => {
|
||||
console.log("getPlanEntries error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
getPlanTypes: function () {
|
||||
@@ -396,6 +412,7 @@
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log("getPlanTypes error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
buildGrid: function () {
|
||||
@@ -435,16 +452,23 @@
|
||||
|
||||
this.updateUserNames()
|
||||
},
|
||||
getRandomRecipes: function () {
|
||||
this.$set(this, 'recipe_query', '');
|
||||
this.getRecipes();
|
||||
},
|
||||
getRecipes: function () {
|
||||
let url = "{% url 'api:recipe-list' %}?limit=5"
|
||||
if (this.recipe_query !== '') {
|
||||
url += '&query=' + this.recipe_query;
|
||||
} else {
|
||||
url += '&random=True'
|
||||
}
|
||||
|
||||
this.$http.get(url).then((response) => {
|
||||
this.recipes = response.data;
|
||||
}).catch((err) => {
|
||||
console.log("getRecipes error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
getMdNote: function () {
|
||||
@@ -457,20 +481,18 @@
|
||||
this.recipes = response.data;
|
||||
}).catch((err) => {
|
||||
console.log("getRecipes error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
updateUserNames: function () {
|
||||
return this.$http.get("{% url 'api:username-list' %}?filter_list=[" + this.user_id_update + ']').then((response) => {
|
||||
for (let u of response.data) {
|
||||
let name = u.username
|
||||
if (`${u.first_name} ${u.last_name}` !== ' ') {
|
||||
name = `${u.first_name} ${u.last_name}`
|
||||
}
|
||||
this.$set(this.user_names, u.id, name);
|
||||
this.$set(this.user_names, u.id, u.username);
|
||||
}
|
||||
|
||||
}).catch((err) => {
|
||||
console.log("updateUserNames error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
dragChanged: function (date, meal_type, evt) {
|
||||
@@ -496,6 +518,7 @@
|
||||
this.$http.put(`{% url 'api:mealplan-list' %}${plan_entry.id}/`, plan_entry).then((response) => {
|
||||
}).catch((err) => {
|
||||
console.log("dragChanged update error", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -506,6 +529,7 @@
|
||||
this.meal_plan[entry.meal_type_name].days[entry.date].items = this.meal_plan[entry.meal_type_name].days[entry.date].items.filter(item => item !== entry)
|
||||
}).catch((err) => {
|
||||
console.log("deleteEntry error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
updatePlanTypes: function () {
|
||||
@@ -519,12 +543,14 @@
|
||||
promise_list.push(this.$http.post("{% url 'api:mealtype-list' %}", x).then((response) => {
|
||||
}).catch((err) => {
|
||||
console.log("updatePlanTypes create error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
}))
|
||||
} else if (x.delete) {
|
||||
if (x.id !== undefined) {
|
||||
promise_list.push(this.$http.delete(`{% url 'api:mealtype-list' %}${x.id}/`, x).then((response) => {
|
||||
}).catch((err) => {
|
||||
console.log("updatePlanTypes delete error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
}))
|
||||
}
|
||||
} else {
|
||||
@@ -532,6 +558,7 @@
|
||||
|
||||
}).catch((err) => {
|
||||
console.log("updatePlanTypes update error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -546,20 +573,28 @@
|
||||
}
|
||||
},
|
||||
cloneRecipe: function (recipe) {
|
||||
return {
|
||||
let r = {
|
||||
id: Math.round(Math.random() * 1000) + 10000,
|
||||
recipe: recipe.id,
|
||||
recipe_name: recipe.name,
|
||||
recipe_multiplier: (this.new_note_multiplier > 1) ? this.new_note_multiplier : 1,
|
||||
title: this.new_note_title,
|
||||
note: this.new_note_text,
|
||||
is_new: true
|
||||
}
|
||||
|
||||
this.new_note_title = ''
|
||||
this.new_note_text = ''
|
||||
this.new_note_multiplier = ''
|
||||
|
||||
return r
|
||||
},
|
||||
cloneNote: function () {
|
||||
let new_entry = {
|
||||
id: Math.round(Math.random() * 1000) + 10000,
|
||||
title: this.new_note_title,
|
||||
note: this.new_note_text,
|
||||
recipe_multiplier: 1,
|
||||
is_new: true,
|
||||
}
|
||||
|
||||
@@ -569,6 +604,7 @@
|
||||
|
||||
this.new_note_title = ''
|
||||
this.new_note_text = ''
|
||||
this.new_note_multiplier = ''
|
||||
return new_entry
|
||||
},
|
||||
planElementName: function (element) {
|
||||
@@ -608,10 +644,10 @@
|
||||
let first = true
|
||||
for (let se of this.shopping_list) {
|
||||
if (first) {
|
||||
url += `?r=${se.recipe}`
|
||||
url += `?r=[${se.recipe},${se.recipe_multiplier}]`
|
||||
first = false
|
||||
} else {
|
||||
url += `&r=${se.recipe}`
|
||||
url += `&r=[${se.recipe},${se.recipe_multiplier}]`
|
||||
}
|
||||
}
|
||||
return url
|
||||
|
||||
@@ -8,28 +8,20 @@
|
||||
{% block title %}{{ recipe.name }}{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
|
||||
{% include 'include/vue_base.html' %}
|
||||
<script src="{% static 'js/moment-with-locales.min.js' %}"></script>
|
||||
|
||||
<link rel="stylesheet" href="{% static 'css/pretty-checkbox.min.css' %}">
|
||||
|
||||
<link rel="stylesheet" href="{% static 'custom/css/markdown_blockquote.css' %}">
|
||||
|
||||
<style>
|
||||
/* fixes print layout being disturbed by print button tooltip */
|
||||
@media print {
|
||||
.tooltip {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col col-md-8">
|
||||
{% recipe_rating recipe request.user as rating %}
|
||||
<h3>{{ recipe.name }} {{ rating|safe }} <a href="{% url 'edit_recipe' recipe.pk %}" class="d-print-none"><i
|
||||
class="fas fa-pencil-alt"></i></a></h3>
|
||||
<h3>{{ recipe.name }} {{ rating|safe }}</h3>
|
||||
</div>
|
||||
{% if request.user.is_authenticated %}
|
||||
<div class="col col-md-4 d-print-none" style="text-align: right">
|
||||
@@ -39,13 +31,15 @@
|
||||
<i class="fas fa-ellipsis-v"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
|
||||
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
|
||||
<a class="dropdown-item" href="{% url 'edit_recipe' recipe.pk %}"><i
|
||||
class="fas fa-pencil-alt fa-fw"></i> {% trans 'Edit' %}</a>
|
||||
<button class="dropdown-item" onclick="$('#bookmarkModal').modal({'show':true})">
|
||||
<i class="fas fa-bookmark fa-fw"></i> {% trans 'Add to Book' %}</button>
|
||||
{% if ingredients %}
|
||||
<a class="dropdown-item" href="{% url 'view_shopping' %}?r={{ recipe.pk }}">
|
||||
<i class="fas fa-shopping-cart fa-fw"></i> {% trans 'Add to Shopping' %}</a>
|
||||
{% endif %}
|
||||
|
||||
<a class="dropdown-item" v-bind:href="getShoppingUrl()" v-if="has_ingredients">
|
||||
<i class="fas fa-shopping-cart fa-fw"></i> {% trans 'Add to Shopping' %}</a>
|
||||
|
||||
<a class="dropdown-item" href="{% url 'new_meal_plan' %}?recipe={{ recipe.pk }}"><i
|
||||
class="fas fa-calendar fa-fw"></i> {% trans 'Add to Plan' %}</a>
|
||||
<button class="dropdown-item" onclick="openCookLogModal({{ recipe.pk }})"><i
|
||||
@@ -102,97 +96,108 @@
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
{% if ingredients %}
|
||||
<div class="col-md-6 order-md-1 col-sm-12 order-sm-2 col-12 order-2">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col col-md-9">
|
||||
<h4 class="card-title">{% trans 'Ingredients' %}</h4>
|
||||
</div>
|
||||
<div class="col col-md-3">
|
||||
<div class="col-md-6 order-md-1 col-sm-12 order-sm-2 col-12 order-2" v-if="recipe && has_ingredients">
|
||||
<!-- TODO duplicate code remove -->
|
||||
<div class="card border-primary">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col col-md-9">
|
||||
<h4 class="card-title">{% trans 'Ingredients' %}</h4>
|
||||
</div>
|
||||
<div class="col col-md-3">
|
||||
|
||||
<div class="input-group d-print-none">
|
||||
<input type="number" value="1" maxlength="3" class="form-control" id="in_factor"
|
||||
onchange="reloadIngredients()"/>
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text"><i class="fas fa-calculator"></i></span>
|
||||
</div>
|
||||
<div class="input-group d-print-none">
|
||||
<input type="number" value="1" maxlength="3" class="form-control"
|
||||
v-model="ingredient_factor"/>
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text"><i class="fas fa-calculator"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<table class="table table-sm">
|
||||
{% for i in ingredients %}
|
||||
{% if i.unit.name == 'Special:Header' %}
|
||||
<tr>
|
||||
<td style="padding-top: 8px!important; ">
|
||||
<b>{{ i.note }}</b>
|
||||
</td>
|
||||
<td>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<table class="table table-sm">
|
||||
<template v-for="s in recipe.steps">
|
||||
<template v-if="s.name != '' && s.show_as_header && s.ingredients.length > 0">
|
||||
<tr>
|
||||
<td style="padding-top: 8px!important; ">
|
||||
<b>[[s.name]]</b>
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</template>
|
||||
<template v-for="i in s.ingredients">
|
||||
<template v-if="i.is_header">
|
||||
<tr>
|
||||
<td style="padding-top: 8px!important; ">
|
||||
<b>[[i.note]]</b>
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</template>
|
||||
<template v-else>
|
||||
<tr>
|
||||
<td style="vertical-align: middle!important;">
|
||||
<div class="pretty p-default p-curve">
|
||||
<input type="checkbox" v-model="i.checked"/>
|
||||
<div class="state p-success">
|
||||
<label>
|
||||
<template v-if="i.no_amount">
|
||||
<span>⁣</span>
|
||||
</template>
|
||||
<template v-if="!i.no_amount">
|
||||
<span>[[roundDecimals(i.amount * ingredient_factor)]]</span>
|
||||
{# Allow for amounts without units, such as "2 eggs" #}
|
||||
<template v-if="i.unit">
|
||||
[[i.unit.name]]
|
||||
</template>
|
||||
</template>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td style="vertical-align: middle!important;">
|
||||
<div class="pretty p-default p-curve">
|
||||
<input type="checkbox"/>
|
||||
<div class="state p-success">
|
||||
<label>
|
||||
{% if i.amount != 0 %}
|
||||
<span id="ing_{{ i.pk }}">{{ i.amount.normalize }}</span>
|
||||
{{ i.unit }}
|
||||
{% else %}
|
||||
<span>⁣</span>
|
||||
{% endif %}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
<td style="vertical-align: middle!important;">
|
||||
{% if i.ingredient.recipe %}
|
||||
<a href="{% url 'view_recipe' i.ingredient.recipe.pk %}"
|
||||
target="_blank" rel="noopener noreferrer">
|
||||
{% endif %}
|
||||
{{ i.ingredient.name }}
|
||||
{% if i.ingredient.recipe %}
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
</td>
|
||||
<td style="vertical-align: middle!important;">
|
||||
{% if i.note %}
|
||||
<a class="btn btn-light btn-sm d-print-none" tabindex="-1"
|
||||
data-toggle="popover"
|
||||
data-placement="right" data-html="true" data-trigger="focus"
|
||||
data-content="{{ i.note }}">
|
||||
<i class="fas fa-info"></i>
|
||||
</a>
|
||||
<div class="d-none d-print-block">
|
||||
<i class="far fa-comment-alt"></i> {{ i.note }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<!-- Bottom border -->
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td style="vertical-align: middle!important;">
|
||||
<template v-if="i.food && i.food.recipe">
|
||||
<a v-bind:href='"{% url 'view_recipe' 12345 %}".replace(/12345/, i.food.recipe)'
|
||||
target="_blank" rel="noopener noreferrer">[[i.food.name]]</a>
|
||||
</template>
|
||||
<template v-else-if="i.food">
|
||||
[[i.food.name]]
|
||||
</template>
|
||||
</td>
|
||||
<td style="vertical-align: middle!important;">
|
||||
<template v-if="i.note">
|
||||
<b-button v-b-popover.hover="i.note"
|
||||
class="btn btn-sm d-print-none"><i
|
||||
class="fas fa-info"></i></b-button>
|
||||
|
||||
<div class="d-none d-print-block">
|
||||
<i class="far fa-comment-alt"></i> [[i.note]]
|
||||
</div>
|
||||
</template>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<!-- Bottom border -->
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if recipe.image %}
|
||||
<div class="col-12 order-1 col-sm-12 order-sm-1 col-md-6 order-md-2" style="text-align: center">
|
||||
<img class="img img-fluid rounded" src="{{ recipe.image.url }}" style="max-height: 30vh;"
|
||||
@@ -202,15 +207,126 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if ingredients or recipe.image %}
|
||||
<br/>
|
||||
<br/>
|
||||
{% endif %}
|
||||
|
||||
<div style="font-size: large">
|
||||
{% if recipe.instructions %}
|
||||
{{ recipe.instructions | markdown | safe }}
|
||||
{% endif %}
|
||||
<div v-if="recipe !== undefined && recipe.steps.length > 0">
|
||||
<hr>
|
||||
<h3>{% trans 'Instructions' %}</h3>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<div style="font-size: large;" v-if="recipe">
|
||||
{% for s in recipe.steps.all %}
|
||||
<div style="margin-top: 1vh" class="card">
|
||||
<div class="card-body">
|
||||
{% if recipe.steps.all|length > 1 %}
|
||||
<div class="card-title">
|
||||
|
||||
<div class="row d-flex">
|
||||
<div class="col-md-8 text-muted ">
|
||||
{% if s.type == 'TEXT' %}
|
||||
<i class="fas fa-paragraph fa-fw"></i>
|
||||
{% elif s.type == 'TIME' %}
|
||||
<i class="fas fa-clock fa-fw"></i>
|
||||
{% endif %}
|
||||
{% if s.name %}{{ s.name }}{% else %}{% trans 'Step' %}
|
||||
{{ forloop.counter }}{% endif %}
|
||||
{% if s.time != 0 %}
|
||||
- {{ s.time }} {% trans 'Minutes' %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-md-4 col-12 justify-content-end" v-if="has_times">
|
||||
<input type="datetime-local" class="form-control"
|
||||
@change="updateTimes(recipe.steps[{{ forloop.counter0 }}])"
|
||||
v-model="recipe.steps[{{ forloop.counter0 }}].time_finished">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" v-if="recipe.steps[{{ forloop.counter0 }}].ingredients.length > 0"
|
||||
style="margin-top: 1vh">
|
||||
<div class="col-md-6">
|
||||
<table class="table table-sm">
|
||||
<template v-for="i in recipe.steps[{{ forloop.counter0 }}].ingredients">
|
||||
<!-- TODO duplicate code remove -->
|
||||
|
||||
<template v-if="i.is_header">
|
||||
<tr>
|
||||
<td style="padding-top: 8px!important; ">
|
||||
<b>[[i.note]]</b>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</template>
|
||||
<template v-else>
|
||||
<tr>
|
||||
<td style="vertical-align: middle!important;">
|
||||
<div class="pretty p-default p-curve">
|
||||
<input type="checkbox" v-model="i.checked"/>
|
||||
<div class="state p-success">
|
||||
<label>
|
||||
<template v-if="i.no_amount">
|
||||
<span>⁣</span>
|
||||
</template>
|
||||
<template v-if="!i.no_amount">
|
||||
<span>[[roundDecimals(i.amount * ingredient_factor)]]</span>
|
||||
{# Allow for amounts without units, such as "2 eggs" #}
|
||||
<template v-if="i.unit">
|
||||
[[i.unit.name]]
|
||||
</template>
|
||||
</template>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
<td style="vertical-align: middle!important;">
|
||||
<template v-if="i.food && i.food.recipe">
|
||||
<a v-bind:href='"{% url 'view_recipe' 12345 %}".replace(/12345/, i.food.recipe)'
|
||||
target="_blank" rel="noopener noreferrer">[[i.food.name]]</a>
|
||||
</template>
|
||||
<template v-else-if="i.food">
|
||||
[[i.food.name]]
|
||||
</template>
|
||||
</td>
|
||||
<td style="vertical-align: middle!important;">
|
||||
<template v-if="i.note">
|
||||
<b-button v-b-popover.hover="i.note"
|
||||
class="btn btn-sm d-print-none"><i
|
||||
class="fas fa-info"></i></b-button>
|
||||
<div class="d-none d-print-block">
|
||||
<i class="far fa-comment-alt"></i> [[i.note]]
|
||||
</div>
|
||||
</template>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
|
||||
</template>
|
||||
<!-- Bottom border -->
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
<div class="row" style="margin-top: 8px">
|
||||
<div class="col-md-12">
|
||||
{% if s.instruction %}
|
||||
{{ s.instruction | markdown | safe }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if recipe.storage %}
|
||||
@@ -228,7 +344,6 @@
|
||||
width="100%"
|
||||
height="700px"
|
||||
style="border: none;"></iframe>
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if '.jpg' in recipe.file_path or '.png' in recipe.file_path or '.jpeg' in recipe.file_path %}
|
||||
@@ -337,45 +452,79 @@
|
||||
|
||||
{% include 'include/log_cooking.html' %}
|
||||
|
||||
<script type="text/javascript">
|
||||
{% endblock %}
|
||||
|
||||
reloadIngredients()
|
||||
{% block script %}
|
||||
<script type="application/javascript">
|
||||
|
||||
$(function () {
|
||||
$('[data-toggle="popover"]').popover()
|
||||
});
|
||||
let csrftoken = Cookies.get('csrftoken');
|
||||
Vue.http.headers.common['X-CSRFToken'] = csrftoken;
|
||||
|
||||
$('.popover-dismiss').popover({
|
||||
trigger: 'focus'
|
||||
});
|
||||
let app = new Vue({
|
||||
delimiters: ['[[', ']]'],
|
||||
el: '#id_base_container',
|
||||
data: {
|
||||
recipe: undefined,
|
||||
has_ingredients: false,
|
||||
has_times: false,
|
||||
ingredient_factor: 1,
|
||||
},
|
||||
|
||||
function roundDecimals(num) {
|
||||
let decimals = {% if request.user.userpreference.ingredient_decimals %}
|
||||
{{ request.user.userpreference.ingredient_decimals }} {% else %} 2 {% endif %}
|
||||
return +(Math.round(num + `e+${decimals}`) + `e-${decimals}`);
|
||||
}
|
||||
mounted: function () {
|
||||
this.loadRecipe()
|
||||
},
|
||||
methods: {
|
||||
loadRecipe: function () {
|
||||
this.$http.get("{% url 'api:recipe-detail' recipe.pk %}" {% if share %}
|
||||
+ "?share={{ share }}"{% endif %}).then((response) => {
|
||||
this.recipe = response.data;
|
||||
this.loading = false
|
||||
|
||||
function reloadIngredients() {
|
||||
let factor = Number($('#in_factor').val());
|
||||
let ingredients = {
|
||||
{% for i in ingredients %}
|
||||
{{ i.pk }}: {{ i.amount|unlocalize }},
|
||||
{% endfor %}
|
||||
}
|
||||
for (let step of this.recipe.steps) {
|
||||
if (step.ingredients.length > 0) {
|
||||
this.has_ingredients = true
|
||||
}
|
||||
if (step.time !== 0) {
|
||||
this.has_times = true
|
||||
}
|
||||
this.$set(step, 'time_finished', undefined)
|
||||
for (let i of step.ingredients) {
|
||||
this.$set(i, 'checked', false)
|
||||
}
|
||||
}
|
||||
|
||||
for (let key in ingredients) {
|
||||
let val = ''
|
||||
if (Math.abs(ingredients[key] * factor - roundDecimals(ingredients[key] * factor)) > 0) {
|
||||
val += '~'
|
||||
}).catch((err) => {
|
||||
this.error = err.data
|
||||
this.loading = false
|
||||
console.log(err)
|
||||
})
|
||||
},
|
||||
roundDecimals: function (num) {
|
||||
let decimals = {% if request.user.userpreference.ingredient_decimals %}
|
||||
{{ request.user.userpreference.ingredient_decimals }} {% else %} 2 {% endif %}
|
||||
return +(Math.round(num + `e+${decimals}`) + `e-${decimals}`);
|
||||
},
|
||||
updateTimes: function (step) {
|
||||
let time_diff_first = 0
|
||||
for (let s of this.recipe.steps) {
|
||||
if (this.recipe.steps.indexOf(s) < this.recipe.steps.indexOf(step)) {
|
||||
time_diff_first += s.time
|
||||
}
|
||||
}
|
||||
|
||||
this.recipe.steps[0].time_finished = moment(step.time_finished).subtract(time_diff_first, 'minutes').format(moment.HTML5_FMT.DATETIME_LOCAL);
|
||||
|
||||
let time_diff = 0
|
||||
for (let s of this.recipe.steps) {
|
||||
s.time_finished = moment(this.recipe.steps[0].time_finished).add(time_diff, 'minutes').format(moment.HTML5_FMT.DATETIME_LOCAL);
|
||||
time_diff += s.time
|
||||
}
|
||||
|
||||
},
|
||||
getShoppingUrl: function () {
|
||||
return `{% url 'view_shopping' %}?r=[${this.recipe.id},${this.ingredient_factor}]`
|
||||
}
|
||||
|
||||
$('#ing_' + key).html(val + roundDecimals(ingredients[key] * factor))
|
||||
}
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip()
|
||||
})
|
||||
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -21,45 +21,71 @@
|
||||
{% else %}
|
||||
<img src="{% static 'recipe_no_image.svg' %}"
|
||||
alt="{% trans 'Recipe Image' %}"
|
||||
class="card-img d-none d-lg-block"
|
||||
style="object-fit: inherit; height: 130px">
|
||||
class="card-img d-none d-md-block"
|
||||
style="object-fit: cover; height: 130px">
|
||||
|
||||
{% endif %}
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ row.cells.name }}
|
||||
{% recipe_rating row.record request.user as rating %}
|
||||
{{ rating|safe }}
|
||||
</h5>
|
||||
<p class="card-text{% if not row.record.keywords %} d-none d-lg-block{% endif %}">
|
||||
{% for x in row.record.keywords.all %}
|
||||
<span class="badge badge-pill badge-light">{{ x }}</span>
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p class="card-text"><small class="text-muted">
|
||||
{% if row.cells.working_time != 0 %}
|
||||
<span class="badge badge-secondary"><i
|
||||
class="fas fa-user-clock"></i> {% trans 'Preparation time ca.' %} {{ row.cells.working_time }} min </span>
|
||||
{% endif %}
|
||||
<div class="d-flex">
|
||||
<div class="flex-fill">
|
||||
<h5 class="card-title">{{ row.cells.name }}
|
||||
{% recipe_rating row.record request.user as rating %}
|
||||
{{ rating|safe }}
|
||||
</h5>
|
||||
<p class="card-text{% if not row.record.keywords %} d-none d-lg-block{% endif %}">
|
||||
{% for x in row.record.keywords.all %}
|
||||
<span class="badge badge-pill badge-light">{{ x }}</span>
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p class="card-text"><small class="text-muted">
|
||||
{% if row.cells.working_time != 0 %}
|
||||
<span class="badge badge-secondary"><i
|
||||
class="fas fa-user-clock"></i> {% trans 'Preparation time ca.' %} {{ row.cells.working_time }} min </span>
|
||||
{% endif %}
|
||||
|
||||
{% if row.cells.waiting_time != 0 %}
|
||||
<span
|
||||
class="badge badge-secondary"><i
|
||||
class="far fa-clock"></i> {% trans 'Waiting time ca.' %} {{ row.cells.waiting_time }} min </span>
|
||||
{% endif %}
|
||||
{% if not row.record.internal %}
|
||||
<span class="badge badge-info">{% trans 'External' %} </span>
|
||||
{% endif %}
|
||||
{% recipe_last row.record request.user as last_cooked %}
|
||||
{% if last_cooked %}
|
||||
<span class="badge badge-primary">{% trans 'Last cooked' %} {{ last_cooked|date }}</span>
|
||||
{% endif %}
|
||||
</small></p>
|
||||
</div>
|
||||
<div>
|
||||
<div class="dropdown">
|
||||
<a class="btn shadow-none" href="#" role="button"
|
||||
id="dropdownMenuLink"
|
||||
data-toggle="dropdown" aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
<i class="fas fa-ellipsis-v text-muted"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right"
|
||||
aria-labelledby="dropdownMenuLink">
|
||||
|
||||
<a class="dropdown-item"
|
||||
href="{% url 'edit_recipe' row.record.pk %}"><i
|
||||
class="fas fa-pencil-alt fa-fw"></i> {% trans 'Edit' %}
|
||||
</a>
|
||||
<button class="dropdown-item"
|
||||
onclick="openCookLogModal({{ row.record.pk }})"><i
|
||||
class="fas fa-clipboard-list fa-fw"></i> {% trans 'Log Cooking' %}
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if row.cells.waiting_time != 0 %}
|
||||
<span
|
||||
class="badge badge-secondary"><i
|
||||
class="far fa-clock"></i> {% trans 'Waiting time ca.' %} {{ row.cells.waiting_time }} min </span>
|
||||
{% endif %}
|
||||
{% if not row.record.internal %}
|
||||
<span class="badge badge-info">{% trans 'External' %} </span>
|
||||
{% endif %}
|
||||
{% recipe_last row.record request.user as last_cooked %}
|
||||
{% if last_cooked %}
|
||||
<span class="badge badge-primary">{% trans 'Last cooked' %} {{ last_cooked|date }}</span>
|
||||
{% endif %}
|
||||
<span class="badge badge-light">{{ row.cells.edit }}</span>
|
||||
<span class="badge badge-warning"><a href="#" style="color: inherit"
|
||||
onclick="openCookLogModal({{ row.record.pk }})">{% trans 'Log' %}</a></span>
|
||||
</small></p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans 'Login' %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if form.errors %}
|
||||
|
||||
18
cookbook/templates/registration/signup.html
Normal file
18
cookbook/templates/registration/signup.html
Normal file
@@ -0,0 +1,18 @@
|
||||
{% extends "base.html" %}
|
||||
{% load crispy_forms_filters %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans 'Register' %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h3>{% trans 'Create your Account' %}</h3>
|
||||
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<button class="btn btn-success" type="submit"><i class="fas fa-save"></i> {% trans 'Create User' %}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
@@ -4,61 +4,700 @@
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans "Cookbook" %}{% endblock %}
|
||||
{% block title %}{% trans "Shopping List" %}{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
{{ form.media }}
|
||||
{% include 'include/vue_base.html' %}
|
||||
|
||||
<link rel="stylesheet" href="{% static 'css/vue-multiselect-bs4.min.css' %}">
|
||||
<script src="{% static 'js/vue-multiselect.min.js' %}"></script>
|
||||
|
||||
<script src="{% static 'js/Sortable.min.js' %}"></script>
|
||||
<script src="{% static 'js/vuedraggable.umd.min.js' %}"></script>
|
||||
|
||||
<link rel="stylesheet" href="{% static 'css/pretty-checkbox.min.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2><i class="fas fa-shopping-cart"></i> {% trans 'Shopping List' %}</h2>
|
||||
|
||||
<form action="{% url 'view_shopping' %}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<button class="btn btn-success" type="submit"><i class="fas fa-sync-alt"></i> {% trans 'Load' %}</button>
|
||||
</form>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<div class="row">
|
||||
<div class="col col-md-12">
|
||||
<!--// @formatter:off-->
|
||||
<textarea id="id_list" class="form-control" rows="{{ ingredients|length|add:1 }}">{% for i in ingredients %}{% if markdown_format %}- [ ] {% endif %}{{ i.amount.normalize }} {{ i.unit }} {{ i.ingredient.name }} {% endfor %}</textarea>
|
||||
<!--// @formatter:on-->
|
||||
<div class="col col-md-9">
|
||||
<h2>{% trans 'Shopping List' %}</h2>
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="row">
|
||||
<div class="col col-md-12 text-center">
|
||||
<button class="btn btn-success" onclick="copy()" style="width: 15vw" data-toggle="tooltip"
|
||||
data-placement="right" title="{% trans 'Copy list to clipboard' %}" id="id_btn_copy" onmouseout="resetTooltip()"><i
|
||||
class="far fa-copy"></i></button>
|
||||
<div class="col col-mdd-3 text-right">
|
||||
<b-form-checkbox switch size="lg" v-model="edit_mode"
|
||||
@change="$forceUpdate()">{% trans 'Edit' %}</b-form-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function copy() {
|
||||
let list = $('#id_list');
|
||||
<template v-if="shopping_list !== undefined">
|
||||
|
||||
list.select();
|
||||
<div class="text-center" v-if="loading">
|
||||
<i class="fas fa-spinner fa-spin fa-8x"></i>
|
||||
</div>
|
||||
<div v-else-if="edit_mode">
|
||||
<div class="row">
|
||||
<div class="col col-md-6">
|
||||
|
||||
$('#id_btn_copy').attr('data-original-title','{% trans 'Copied!' %}').tooltip('show');
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<i class="fa fa-search"></i> {% trans 'Search' %}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<input type="text" class="form-control" v-model="recipe_query" @keyup="getRecipes"
|
||||
placeholder="{% trans 'Search Recipe' %}">
|
||||
<ul class="list-group" style="margin-top: 8px">
|
||||
<li class="list-group-item" v-for="x in recipes">
|
||||
<div class="row flex-row" style="padding-left: 0.5vw; padding-right: 0.5vw">
|
||||
<div class="flex-column flex-fill my-auto"><a v-bind:href="getRecipeUrl(x.id)"
|
||||
target="_blank"
|
||||
rel="nofollow norefferer">[[x.name]]</a>
|
||||
</div>
|
||||
<div class="flex-column align-self-end">
|
||||
<button class="btn btn-outline-primary shadow-none"
|
||||
@click="addRecipeToList(x)"><i
|
||||
class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
document.execCommand("copy");
|
||||
}
|
||||
<div class="col col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<i class="fa fa-shopping-cart"></i> {% trans 'Shopping Recipes' %}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<template v-if="shopping_list.recipes.length < 1">
|
||||
{% trans 'No recipes selected' %}
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="row flex-row my-auto" v-for="x in shopping_list.recipes"
|
||||
style="margin-top: 1vh!important;">
|
||||
<div class="flex-column align-self-start " style="margin-right: 0.4vw">
|
||||
<button class="btn btn-outline-danger" @click="removeRecipeFromList(x)"><i
|
||||
class="fa fa-trash"></i></button>
|
||||
</div>
|
||||
<div class="flex-grow-1 flex-column my-auto"><a v-bind:href="getRecipeUrl(x.recipe)"
|
||||
target="_blank"
|
||||
rel="nofollow norefferer">[[x.recipe_name]]</a>
|
||||
</div>
|
||||
<div class="flex-column align-self-end ">
|
||||
<div class="input-group input-group-sm my-auto">
|
||||
<div class="input-group-prepend">
|
||||
<button class="text-muted btn btn-outline-primary shadow-none"
|
||||
@click="((x.multiplier - 1) > 0) ? x.multiplier -= 1 : 1">-
|
||||
</button>
|
||||
</div>
|
||||
<input class="form-control" type="number" v-model="x.multiplier">
|
||||
<div class="input-group-append">
|
||||
<button class="text-muted btn btn-outline-primary shadow-none"
|
||||
@click="x.multiplier += 1">
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
function resetTooltip() {
|
||||
setTimeout(function () {
|
||||
$('#id_btn_copy').attr('data-original-title','{% trans 'Copy list to clipboard' %}');
|
||||
}, 300);
|
||||
}
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip()
|
||||
})
|
||||
<table class="table table-sm table-striped" style="margin-top: 1vh">
|
||||
|
||||
<tbody is="draggable" group="people" :list="display_entries" tag="tbody" :empty-insert-threshold="10"
|
||||
handle=".handle" @sort="sortEntries()">
|
||||
|
||||
<tr v-for="(element, index) in display_entries" :key="element.id">
|
||||
<!--<td class="handle"><i class="fas fa-sort"></i></td>-->
|
||||
<td>[[element.amount]]</td>
|
||||
<td>[[element.unit.name]]</td>
|
||||
<td>[[element.food.name]]</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-outline-danger" v-if="element.list_recipe === null"
|
||||
@click="shopping_list.entries = shopping_list.entries.filter(item => item.id !== element.id)">
|
||||
<i class="fa fa-trash"></i></button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col col-md-3">
|
||||
<input class="form-control" type="number" placeholder="{% trans 'Amount' %}"
|
||||
v-model="new_entry.amount" ref="new_entry_amount">
|
||||
</div>
|
||||
<div class="col col-md-4">
|
||||
<multiselect
|
||||
v-tabindex
|
||||
ref="unit"
|
||||
v-model="new_entry.unit"
|
||||
:options="units"
|
||||
:close-on-select="true"
|
||||
:clear-on-select="true"
|
||||
:allow-empty="true"
|
||||
:preserve-search="true"
|
||||
placeholder="{% trans 'Select Unit' %}"
|
||||
tag-placeholder="{% trans 'Create' %}"
|
||||
select-label="{% trans 'Select' %}"
|
||||
:taggable="true"
|
||||
@tag="addUnitType"
|
||||
label="name"
|
||||
track-by="name"
|
||||
:multiple="false"
|
||||
:loading="units_loading"
|
||||
@search-change="searchUnits">
|
||||
</multiselect>
|
||||
</div>
|
||||
<div class="col col-md-4">
|
||||
<multiselect
|
||||
v-tabindex
|
||||
ref="food"
|
||||
v-model="new_entry.food"
|
||||
:options="foods"
|
||||
:close-on-select="true"
|
||||
:clear-on-select="true"
|
||||
:allow-empty="true"
|
||||
:preserve-search="true"
|
||||
placeholder="{% trans 'Select Food' %}"
|
||||
tag-placeholder="{% trans 'Create' %}"
|
||||
select-label="{% trans 'Select' %}"
|
||||
:taggable="true"
|
||||
@tag="addFoodType"
|
||||
label="name"
|
||||
track-by="name"
|
||||
:multiple="false"
|
||||
:loading="foods_loading"
|
||||
@search-change="searchFoods">
|
||||
</multiselect>
|
||||
</div>
|
||||
|
||||
<div class="col col-md-1 my-auto text-right">
|
||||
<button class="btn btn-success btn-lg" @click="addEntry()"><i class="fa fa-plus"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col" style="text-align: right; margin-top: 1vh">
|
||||
|
||||
<div class="form-group form-check form-group-lg">
|
||||
<input class="form-check-input" style="zoom:1.3;" type="checkbox"
|
||||
v-model="shopping_list.finished" id="id_finished">
|
||||
<label class="form-check-label" style="zoom:1.3;"
|
||||
for="id_finished"> {% trans 'Finished' %}</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col" style="margin-top: 1vh">
|
||||
<multiselect
|
||||
v-tabindex
|
||||
|
||||
v-model="shopping_list.shared"
|
||||
:options="users"
|
||||
:close-on-select="true"
|
||||
:clear-on-select="true"
|
||||
:allow-empty="true"
|
||||
:preserve-search="true"
|
||||
placeholder="{% trans 'Select User' %}"
|
||||
select-label="{% trans 'Select' %}"
|
||||
label="username"
|
||||
track-by="id"
|
||||
:multiple="true"
|
||||
:loading="users_loading"
|
||||
@search-change="searchUsers">
|
||||
</multiselect>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div v-else>
|
||||
|
||||
{% if request.user.userpreference.shopping_auto_sync > 0 %}
|
||||
<div class="row" v-if="!onLine">
|
||||
<div class="col col-md-12">
|
||||
<div class="alert alert-warning" role="alert">
|
||||
{% trans 'You are offline, shopping list might not sync.' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="row" style="margin-top: 8px">
|
||||
<div class="col col-md-12">
|
||||
<table class="table">
|
||||
<tr v-for="x in display_entries">
|
||||
<template v-if="!x.checked">
|
||||
<td><input type="checkbox" style="zoom:1.4;" v-model="x.checked"
|
||||
@change="entryChecked(x)">
|
||||
</td>
|
||||
<td>[[x.amount]]</td>
|
||||
<td>[[x.unit.name]]</td>
|
||||
<td>[[x.food.name]]</td>
|
||||
</template>
|
||||
</tr>
|
||||
|
||||
<tr v-for="x in display_entries" class="text-muted">
|
||||
<template v-if="x.checked">
|
||||
<td><input type="checkbox" style="zoom:1.4;" v-model="x.checked"
|
||||
@change="entryChecked(x)">
|
||||
</td>
|
||||
<td>[[x.amount]]</td>
|
||||
<td>[[x.unit.name]]</td>
|
||||
<td>[[x.food.name]]</td>
|
||||
</template>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row" style="margin-top: 2vh">
|
||||
<div class="col" style="text-align: right">
|
||||
<b-button class="btn btn-info" v-b-modal.id_modal_export><i
|
||||
class="fas fa-file-export"></i> {% trans 'Export' %}</b-button>
|
||||
<button class="btn btn-success" @click="updateShoppingList()" v-if="edit_mode"><i
|
||||
class="fas fa-save"></i> {% trans 'Save' %}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<b-modal id="id_modal_export" title="{% trans 'Copy/Export' %}">
|
||||
<div class="row">
|
||||
<div class="col col-12">
|
||||
<label>
|
||||
{% trans 'List Prefix' %}
|
||||
<input class="form-control" v-model="export_text_prefix">
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col col-12">
|
||||
<b-form-textarea class="form-control" max-rows="8" v-model="export_text">
|
||||
|
||||
</b-form-textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</b-modal>
|
||||
|
||||
|
||||
</template>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
{% block script %}
|
||||
<script type="application/javascript">
|
||||
let csrftoken = Cookies.get('csrftoken');
|
||||
Vue.http.headers.common['X-CSRFToken'] = csrftoken;
|
||||
|
||||
Vue.component('vue-multiselect', window.VueMultiselect.default)
|
||||
|
||||
let app = new Vue({
|
||||
components: {
|
||||
Multiselect: window.VueMultiselect.default
|
||||
},
|
||||
delimiters: ['[[', ']]'],
|
||||
el: '#id_base_container',
|
||||
data: {
|
||||
shopping_list_id: {% if shopping_list_id %}{{ shopping_list_id }}{% else %}null{% endif %},
|
||||
loading: true,
|
||||
edit_mode: false,
|
||||
export_text_prefix: '', //TODO add userpreference
|
||||
recipe_query: '',
|
||||
recipes: [],
|
||||
shopping_list: undefined,
|
||||
new_entry: {
|
||||
unit: undefined,
|
||||
amount: undefined,
|
||||
food: undefined,
|
||||
},
|
||||
foods: [],
|
||||
foods_loading: false,
|
||||
units: [],
|
||||
units_loading: false,
|
||||
users: [],
|
||||
users_loading: false,
|
||||
onLine: navigator.onLine,
|
||||
},
|
||||
directives: {
|
||||
tabindex: {
|
||||
inserted(el) {
|
||||
el.setAttribute('tabindex', 0);
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
multiplier_cache() {
|
||||
let cache = {}
|
||||
this.shopping_list.recipes.forEach((r) => {
|
||||
cache[r.id] = !(Number.isNaN(r.multiplier)) ? parseFloat(r.multiplier) : 1
|
||||
})
|
||||
return cache
|
||||
},
|
||||
display_entries() {
|
||||
let entries = []
|
||||
|
||||
//TODO merge multiple ingredients of same unit
|
||||
|
||||
this.shopping_list.entries.forEach(element => {
|
||||
let item = {}
|
||||
Object.assign(item, element);
|
||||
if (item.list_recipe !== null) {
|
||||
item.amount = item.amount * this.multiplier_cache[item.list_recipe]
|
||||
}
|
||||
item.unit = ((element.unit !== undefined && element.unit !== null) ? element.unit : {'name': ''})
|
||||
entries.push(item)
|
||||
});
|
||||
|
||||
return entries
|
||||
},
|
||||
export_text() {
|
||||
let text = ''
|
||||
for (let e of this.display_entries.filter(item => item.checked === false)) {
|
||||
text += `${this.export_text_prefix}${e.amount} ${e.unit.name} ${e.food.name} \n`
|
||||
}
|
||||
return text
|
||||
}
|
||||
},
|
||||
/*
|
||||
watch: {
|
||||
recipe: {
|
||||
deep: true,
|
||||
handler() {
|
||||
this.recipe_changed = this.recipe_changed !== undefined;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
created() {
|
||||
window.addEventListener('beforeunload', this.warnPageLeave)
|
||||
},
|
||||
*/
|
||||
mounted: function () {
|
||||
this.loadShoppingList()
|
||||
|
||||
{% if recipes %}
|
||||
this.loading = true
|
||||
this.edit_mode = true
|
||||
let loadingRecipes = []
|
||||
{% for r in recipes %}
|
||||
loadingRecipes.push(this.loadInitialRecipe({{ r.recipe }}, {{ r.multiplier }}))
|
||||
{% endfor %}
|
||||
|
||||
Promise.allSettled(loadingRecipes).then(() => {
|
||||
this.loading = false
|
||||
})
|
||||
{% endif %}
|
||||
|
||||
{% if request.user.userpreference.shopping_auto_sync > 0 %}
|
||||
setInterval(() => {
|
||||
if ((this.shopping_list_id !== null) && !this.edit_mode && window.navigator.onLine) {
|
||||
this.loadShoppingList(true)
|
||||
}
|
||||
}, {% widthratio request.user.userpreference.shopping_auto_sync 1 1000 %})
|
||||
|
||||
window.addEventListener('online', this.updateOnlineStatus);
|
||||
window.addEventListener('offline', this.updateOnlineStatus);
|
||||
{% endif %}
|
||||
|
||||
this.searchUsers('')
|
||||
},
|
||||
methods: {
|
||||
updateOnlineStatus(e) {
|
||||
const {
|
||||
type
|
||||
} = e;
|
||||
this.onLine = type === 'online';
|
||||
},
|
||||
/*
|
||||
warnPageLeave: function (event) {
|
||||
if (this.recipe_changed) {
|
||||
event.returnValue = ''
|
||||
return ''
|
||||
}
|
||||
},
|
||||
*/
|
||||
makeToast: function (title, message, variant = null) {
|
||||
//TODO remove duplicate function in favor of central one
|
||||
this.$bvToast.toast(message, {
|
||||
title: title,
|
||||
variant: variant,
|
||||
toaster: 'b-toaster-top-center',
|
||||
solid: true
|
||||
})
|
||||
},
|
||||
loadInitialRecipe: function (recipe, multiplier) {
|
||||
return this.$http.get('{% url 'api:recipe-detail' 123456 %}'.replace('123456', recipe)).then((response) => {
|
||||
this.addRecipeToList(response.data, multiplier)
|
||||
}).catch((err) => {
|
||||
console.log("getRecipes error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
loadShoppingList: function (autosync = false) {
|
||||
|
||||
if (this.shopping_list_id) {
|
||||
this.$http.get("{% url 'api:shoppinglist-detail' 123456 %}".replace('123456', this.shopping_list_id) + ((autosync) ? '?autosync=true' : '')).then((response) => {
|
||||
if (!autosync) {
|
||||
this.shopping_list = response.body
|
||||
this.loading = false
|
||||
} else {
|
||||
let check_map = {}
|
||||
for (let e of response.body.entries) {
|
||||
check_map[e.id] = {checked: e.checked}
|
||||
}
|
||||
|
||||
for (let se of this.shopping_list.entries) {
|
||||
if (check_map[se.id] !== undefined) {
|
||||
se.checked = check_map[se.id].checked
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.shopping_list.entries.length === 0) {
|
||||
this.edit_mode = true
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
} else {
|
||||
this.shopping_list = {
|
||||
"recipes": [],
|
||||
"entries": [],
|
||||
"entries_display": [],
|
||||
"shared": [{% for u in request.user.userpreference.plan_share.all %}
|
||||
{'id': {{ u.pk }}, 'username': '{{ u.get_user_name }}'},
|
||||
{% endfor %}],
|
||||
"created_by": 1
|
||||
}
|
||||
this.loading = false
|
||||
|
||||
if (this.shopping_list.entries.length === 0) {
|
||||
this.edit_mode = true
|
||||
}
|
||||
}
|
||||
},
|
||||
updateShoppingList: function () {
|
||||
this.loading = true
|
||||
let recipe_promises = []
|
||||
|
||||
for (let i in this.shopping_list.recipes) {
|
||||
if (this.shopping_list.recipes[i].created) {
|
||||
console.log('updating recipe', this.shopping_list.recipes[i])
|
||||
recipe_promises.push(this.$http.post("{% url 'api:shoppinglistrecipe-list' %}", this.shopping_list.recipes[i], {}).then((response) => {
|
||||
let old_id = this.shopping_list.recipes[i].id
|
||||
console.log("list recipe create respose ", response.body)
|
||||
this.$set(this.shopping_list.recipes, i, response.body)
|
||||
for (let e of this.shopping_list.entries.filter(item => item.list_recipe === old_id)) {
|
||||
console.log("found recipe updating ID")
|
||||
e.list_recipe = this.shopping_list.recipes[i].id
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error updating a resource!' %}' + err.bodyText, 'danger')
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Promise.allSettled(recipe_promises).then(() => {
|
||||
console.log("proceeding to update shopping list", this.shopping_list)
|
||||
|
||||
if (this.shopping_list_id === null) {
|
||||
return this.$http.post("{% url 'api:shoppinglist-list' %}", this.shopping_list, {}).then((response) => {
|
||||
console.log(response)
|
||||
this.makeToast('{% trans 'Updated' %}', '{% trans 'Object created successfully!' %}', 'success')
|
||||
this.loading = false
|
||||
|
||||
this.shopping_list = response.body
|
||||
this.shopping_list_id = this.shopping_list.id
|
||||
|
||||
window.history.pushState('shopping_list', '{% trans 'Shopping List' %}', "{% url 'view_shopping' 123456 %}".replace('123456', this.shopping_list_id));
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error creating a resource!' %}' + err.bodyText, 'danger')
|
||||
this.loading = false
|
||||
})
|
||||
} else {
|
||||
return this.$http.put("{% url 'api:shoppinglist-detail' shopping_list_id %}", this.shopping_list, {}).then((response) => {
|
||||
console.log(response)
|
||||
this.shopping_list = response.body
|
||||
this.makeToast('{% trans 'Updated' %}', '{% trans 'Changes saved successfully!' %}', 'success')
|
||||
this.loading = false
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error updating a resource!' %}' + err.bodyText, 'danger')
|
||||
this.loading = false
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
},
|
||||
sortEntries: function () {
|
||||
this.display_entries.forEach((item, index) => {
|
||||
|
||||
})
|
||||
console.log("IMPLEMENT ME", this.display_entries)
|
||||
},
|
||||
entryChecked: function (entry) {
|
||||
console.log("checked entry: ", entry)
|
||||
this.shopping_list.entries.forEach((item) => {
|
||||
if (item.id === entry.id) { //TODO unwrap once same entries are merged
|
||||
item.checked = entry.checked
|
||||
this.$http.put("{% url 'api:shoppinglistentry-detail' 123456 %}".replace('123456', item.id), item, {}).then((response) => {
|
||||
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error updating a resource!' %}' + err.bodyText, 'danger')
|
||||
this.loading = false
|
||||
})
|
||||
|
||||
}
|
||||
})
|
||||
},
|
||||
addEntry: function () {
|
||||
if (this.new_entry.food !== undefined) {
|
||||
this.shopping_list.entries.push({
|
||||
'list_recipe': null,
|
||||
'food': this.new_entry.food,
|
||||
'unit': this.new_entry.unit,
|
||||
'amount': parseFloat(this.new_entry.amount),
|
||||
'order': 0,
|
||||
'checked': false
|
||||
})
|
||||
|
||||
this.new_entry = {
|
||||
unit: undefined,
|
||||
amount: undefined,
|
||||
food: undefined,
|
||||
}
|
||||
|
||||
this.$refs.new_entry_amount.focus();
|
||||
} else {
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'Please enter a valid food' %}', 'danger')
|
||||
}
|
||||
},
|
||||
getRecipes: function () {
|
||||
let url = "{% url 'api:recipe-list' %}?limit=5&internal=true"
|
||||
if (this.recipe_query !== '') {
|
||||
url += '&query=' + this.recipe_query;
|
||||
} else {
|
||||
this.recipes = []
|
||||
return
|
||||
}
|
||||
|
||||
this.$http.get(url).then((response) => {
|
||||
this.recipes = response.data;
|
||||
}).catch((err) => {
|
||||
console.log("getRecipes error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
getRecipeUrl: function (id) { //TODO generic function that can be reused else were
|
||||
return '{% url 'view_recipe' 123456 %}'.replace('123456', id)
|
||||
},
|
||||
addRecipeToList: function (recipe, multiplier = 1) {
|
||||
let slr = {
|
||||
"created": true,
|
||||
"id": Math.random() * 1000,
|
||||
"recipe": recipe.id,
|
||||
"recipe_name": recipe.name,
|
||||
"multiplier": multiplier
|
||||
}
|
||||
|
||||
this.shopping_list.recipes.push(slr)
|
||||
|
||||
for (let s of recipe.steps) {
|
||||
for (let i of s.ingredients) {
|
||||
if (!i.is_header && i.food !== null) {
|
||||
this.shopping_list.entries.push({
|
||||
'list_recipe': slr.id,
|
||||
'food': i.food,
|
||||
'unit': i.unit,
|
||||
'amount': i.amount,
|
||||
'order': 0
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
removeRecipeFromList: function (slr) {
|
||||
this.shopping_list.entries = this.shopping_list.entries.filter(item => item.list_recipe !== slr.id)
|
||||
this.shopping_list.recipes = this.shopping_list.recipes.filter(item => item !== slr)
|
||||
},
|
||||
searchKeywords: function (query) {
|
||||
this.keywords_loading = true
|
||||
this.$http.get("{% url 'api:keyword-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||
this.keywords = response.data;
|
||||
this.keywords_loading = false
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
|
||||
searchUnits: function (query) { //TODO move to central component
|
||||
this.units_loading = true
|
||||
this.$http.get("{% url 'api:unit-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||
this.units = response.data;
|
||||
this.units_loading = false
|
||||
}).catch((err) => {
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
searchFoods: function (query) { //TODO move to central component
|
||||
this.foods_loading = true
|
||||
this.$http.get("{% url 'api:food-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||
this.foods = response.data
|
||||
this.foods_loading = false
|
||||
}).catch((err) => {
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
addFoodType: function (tag, index) { //TODO move to central component
|
||||
let new_food = {'name': tag}
|
||||
this.foods.push(new_food)
|
||||
this.new_entry.food = new_food
|
||||
},
|
||||
addUnitType: function (tag, index) { //TODO move to central component
|
||||
let new_unit = {'name': tag}
|
||||
this.units.push(new_unit)
|
||||
this.new_entry.unit = new_unit
|
||||
},
|
||||
searchUsers: function (query) { //TODO move to central component
|
||||
this.users_loading = true
|
||||
this.$http.get("{% url 'api:username-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||
this.users = response.data
|
||||
this.users_loading = false
|
||||
}).catch((err) => {
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
},
|
||||
beforeDestroy() {
|
||||
window.removeEventListener('online', this.updateOnlineStatus);
|
||||
window.removeEventListener('offline', this.updateOnlineStatus);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
@@ -10,7 +10,31 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>{% trans 'System Information' %}</h1>
|
||||
<h1>{% trans 'System' %}</h1>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<h3>{% trans 'Invite Links' %}</h3>
|
||||
<a href="{% url 'list_invite_link' %}" class="btn btn-success">{% trans 'Show Links' %}</a>
|
||||
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h3>{% trans 'Backup & Restore' %}</h3>
|
||||
<a href="{% url 'api_backup' %}" class="btn btn-success">{% trans 'Download Backup' %}</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<h3>{% trans 'System Information' %}</h3>
|
||||
|
||||
{% blocktrans %}
|
||||
Django Recipes is an open source free software application. It can be found on
|
||||
@@ -45,7 +69,8 @@
|
||||
{% trans 'Warning' %}{% else %}{% trans 'Ok' %}{% endif %}</span></h4>
|
||||
{% if secret_key %}
|
||||
{% blocktrans %}
|
||||
You do not have a <code>SECRET_KEY</code> configured in your <code>.env</code> file. Django defaulted to the standard key
|
||||
You do not have a <code>SECRET_KEY</code> configured in your <code>.env</code> file. Django defaulted to the
|
||||
standard key
|
||||
provided with the installation which is publicly know and insecure! Please set
|
||||
<code>SECRET_KEY</code> int the <code>.env</code> configuration file.
|
||||
{% endblocktrans %}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{{ test }}
|
||||
410
cookbook/templates/url_import.html
Normal file
410
cookbook/templates/url_import.html
Normal file
@@ -0,0 +1,410 @@
|
||||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}{% trans 'URL Import' %}{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
|
||||
{% include 'include/vue_base.html' %}
|
||||
|
||||
<script src="{% static 'js/vue-multiselect.min.js' %}"></script>
|
||||
<link rel="stylesheet" href="{% static 'css/vue-multiselect.min.css' %}">
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div id="app">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="input-group mb-3">
|
||||
<input class="form-control" v-model="remote_url" placeholder="{% trans 'Enter website URL' %}">
|
||||
<div class="input-group-append">
|
||||
<button @click="loadRecipe()" class="btn btn-primary shadow-none" type="button"
|
||||
id="id_btn_search"><i class="fas fa-search"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
||||
<div v-if="loading" class="text-center">
|
||||
<br/>
|
||||
<i class="fas fa-spinner fa-spin fa-8x"></i>
|
||||
</div>
|
||||
|
||||
<template v-if="recipe_data !== undefined">
|
||||
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="id_name">{% trans 'Recipe Name' %}</label>
|
||||
<input id="id_name" class="form-control" v-model="recipe_data.name">
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col col-md-6" v-if="recipe_data.image !== ''">
|
||||
<img v-bind:src="recipe_data.image" alt="{% trans 'Recipe Image' %}"
|
||||
class="img-fluid img-responsive img-rounded">
|
||||
</div>
|
||||
<div class="col col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="id_prep_time">{% trans 'Preparation time ca.' %}</label>
|
||||
<input id="id_prep_time" class="form-control" v-model="recipe_data.prepTime">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="id_waiting_time">{% trans 'Waiting time ca.' %}</label>
|
||||
<input id="id_waiting_time" class="form-control" v-model="recipe_data.cookTime">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<br/>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<template v-for="(i, index) in recipe_data.recipeIngredient">
|
||||
|
||||
<div class="card" style="margin-top: 4px">
|
||||
<div class="card-body">
|
||||
<div class="row" v-if="i.original">
|
||||
<div class="col-md-12" style="margin-bottom: 4px">
|
||||
<span class="text-muted"><i class="fas fa-globe"></i> [[i.original]]</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-1">
|
||||
<input class="form-control" v-model="i.amount">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
|
||||
<table class="table-layout:fixed">
|
||||
<col width="95%"/>
|
||||
<col width="5%"/>
|
||||
<tr>
|
||||
<td>
|
||||
<multiselect v-tabindex
|
||||
ref="unit"
|
||||
style="width: 100%!important;"
|
||||
v-model="i.unit"
|
||||
:options="units"
|
||||
:close-on-select="true"
|
||||
:clear-on-select="true"
|
||||
:allow-empty="true"
|
||||
:preserve-search="true"
|
||||
placeholder="{% trans 'Select one' %}"
|
||||
tag-placeholder="{% trans 'Select' %}"
|
||||
label="text"
|
||||
:taggable="true"
|
||||
@tag="addUnitType"
|
||||
:id="'unit_' + index"
|
||||
@open="openUnitSelect"
|
||||
track-by="id"
|
||||
:multiple="false"
|
||||
:loading="units_loading"
|
||||
@search-change="searchUnits">
|
||||
</multiselect>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-outline-success btn-lg" type="button"
|
||||
@click="i.unit = ''" tabindex="-1">
|
||||
<i class="fas fa-eraser"></i></button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
|
||||
<multiselect v-tabindex
|
||||
ref="ingredient"
|
||||
v-model="i.ingredient"
|
||||
:options="ingredients"
|
||||
:taggable="true"
|
||||
@tag="addIngredientType"
|
||||
:id="'ingredient_' + index"
|
||||
placeholder="{% trans 'Select one' %}"
|
||||
tag-placeholder="{% trans 'Select' %}"
|
||||
:close-on-select="true"
|
||||
:clear-on-select="true"
|
||||
:allow-empty="false"
|
||||
:preserve-search="true"
|
||||
label="text"
|
||||
track-by="id"
|
||||
:multiple="false"
|
||||
:loading="ingredients_loading"
|
||||
@search-change="searchIngredients"
|
||||
@open="openIngredientSelect">
|
||||
|
||||
</multiselect>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<input type="text" placeholder="{% trans 'Note' %}" class="form-control" v-model="i.note">
|
||||
</div>
|
||||
<div class="col-md-1">
|
||||
<button class="btn btn-outline-danger btn-lg" type="button"
|
||||
@click="deleteIngredient(i)" tabindex="-1"><i
|
||||
class="fas fa-trash-alt"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</template>
|
||||
|
||||
<div style="text-align: center; margin-top: 16px">
|
||||
<button class="btn btn-success" type="button" @click="addIngredient()"><i
|
||||
class="fas fa-plus"></i></button>
|
||||
<br/><br/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="id_instructions">{% trans 'Instructions' %}</label>
|
||||
<textarea id="id_instructions" class="form-control" v-model="recipe_data.recipeInstructions"
|
||||
rows="8"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="id_keywords">{% trans 'Keywords' %}</label>
|
||||
|
||||
<multiselect
|
||||
v-model="recipe_data.keywords"
|
||||
:options="keywords"
|
||||
:close-on-select="false"
|
||||
:clear-on-select="true"
|
||||
:hide-selected="true"
|
||||
:preserve-search="true"
|
||||
placeholder="{% trans 'Select one' %}"
|
||||
label="text"
|
||||
track-by="id"
|
||||
id="id_keywords"
|
||||
:multiple="true"
|
||||
:loading="keywords_loading"
|
||||
@search-change="searchKeywords">
|
||||
</multiselect>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="id_all_keywords">{% trans 'All Keywords' %}</label><br/>
|
||||
<input id="id_all_keywords" type="checkbox"
|
||||
v-model="all_keywords"> {% trans 'Import all Keywords not only the ones already existing.' %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="button" class="btn btn-success" @click="importRecipe()" :disabled="importing_recipe">{% trans 'Import' %}</button>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<template v-if="error !== undefined">
|
||||
<div>
|
||||
|
||||
<div style="text-align: center">
|
||||
<i class="fas fa-robot fa-8x"></i><br/><br/>
|
||||
[[error.msg]]
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="row">
|
||||
<div class="col-md-8 offset-md-2">
|
||||
<div class="card border-info mb-6">
|
||||
<div class="card-body text-info">
|
||||
<h5 class="card-title">{% trans 'Information' %}</h5>
|
||||
<p class="card-text">
|
||||
{% blocktrans %} Only websites containing ld+json or microdata information can currently
|
||||
be imported. Most big recipe pages support this. If you site cannot be imported but
|
||||
you think
|
||||
it probably has some kind of structured data feel free to post an example in the
|
||||
github issues.{% endblocktrans %}
|
||||
</p>
|
||||
<a href="https://developers.google.com/search/docs/data-types/recipe" target="_blank"
|
||||
rel="noreferrer nofollow"
|
||||
class="card-link">{% trans 'Google ld+json Info' %}</a>
|
||||
<a href="https://github.com/vabene1111/recipes/issues" target="_blank"
|
||||
rel="noreferrer nofollow"
|
||||
class="card-link">{% trans 'GitHub Issues' %}</a>
|
||||
<a href="https://schema.org/Recipe" target="_blank" rel="noreferrer nofollow"
|
||||
class="card-link">{% trans 'Recipe Markup Specification' %}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
</div>
|
||||
|
||||
<script type="application/javascript">
|
||||
let csrftoken = Cookies.get('csrftoken');
|
||||
Vue.http.headers.common['X-CSRFToken'] = csrftoken;
|
||||
|
||||
Vue.component('vue-multiselect', window.VueMultiselect.default)
|
||||
|
||||
let app = new Vue({
|
||||
components: {
|
||||
Multiselect: window.VueMultiselect.default
|
||||
},
|
||||
delimiters: ['[[', ']]'],
|
||||
el: '#app',
|
||||
data: {
|
||||
remote_url: '',
|
||||
keywords: [],
|
||||
keywords_loading: false,
|
||||
units: [],
|
||||
units_loading: false,
|
||||
ingredients: [],
|
||||
ingredients_loading: false,
|
||||
recipe_data: undefined,
|
||||
error: undefined,
|
||||
loading: false,
|
||||
all_keywords: false,
|
||||
importing_recipe: false,
|
||||
},
|
||||
directives: {
|
||||
tabindex: {
|
||||
inserted(el) {
|
||||
el.setAttribute('tabindex', 0);
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
this.searchKeywords('')
|
||||
this.searchUnits('')
|
||||
this.searchIngredients('')
|
||||
},
|
||||
methods: {
|
||||
makeToast: function (title, message, variant = null) {
|
||||
//TODO remove duplicate function in favor of central one
|
||||
this.$bvToast.toast(message, {
|
||||
title: title,
|
||||
variant: variant,
|
||||
toaster: 'b-toaster-top-center',
|
||||
solid: true
|
||||
})
|
||||
},
|
||||
loadRecipe: function () {
|
||||
this.recipe_data = undefined
|
||||
this.error = undefined
|
||||
this.loading = true
|
||||
this.$http.post("{% url 'api_recipe_from_url' %}", {'url' : this.remote_url}, {emulateJSON: true}).then((response) => {
|
||||
this.recipe_data = response.data;
|
||||
this.loading = false
|
||||
}).catch((err) => {
|
||||
this.error = err.data
|
||||
this.loading = false
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
importRecipe: function () {
|
||||
if (this.importing_recipe) {
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'Already importing the selected recipe, please wait!' %}', 'danger')
|
||||
return;
|
||||
}
|
||||
this.importing_recipe = true
|
||||
this.$set(this.recipe_data, 'all_keywords', this.all_keywords)
|
||||
this.$http.post(`{% url 'data_import_url' %}`, this.recipe_data).then((response) => {
|
||||
window.location.href = response.data
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'An error occurred while trying to import this recipe!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
deleteIngredient: function (i) {
|
||||
this.recipe_data.recipeIngredient = this.recipe_data.recipeIngredient.filter(item => item !== i)
|
||||
},
|
||||
addIngredient: function (i) {
|
||||
this.recipe_data.recipeIngredient.push({
|
||||
unit: {id: Math.random() * 1000, text: '{{ request.user.userpreference.default_unit }}'},
|
||||
amount: 0,
|
||||
ingredient: {id: Math.random() * 1000, text: ''}
|
||||
})
|
||||
},
|
||||
addIngredientType: function (tag, index) {
|
||||
index = index.replace('ingredient_', '')
|
||||
let new_ingredient = this.recipe_data.recipeIngredient[index]
|
||||
new_ingredient.ingredient = {'id': Math.random() * 1000, 'text': tag}
|
||||
this.ingredients.push(new_ingredient.ingredient)
|
||||
this.recipe_data.recipeIngredient[index] = new_ingredient
|
||||
},
|
||||
addUnitType: function (tag, index) {
|
||||
index = index.replace('unit_', '')
|
||||
let new_unit = this.recipe_data.recipeIngredient[index]
|
||||
new_unit.unit = {'id': Math.random() * 1000, 'text': tag}
|
||||
this.units.push(new_unit.unit)
|
||||
this.recipe_data.recipeIngredient[index] = new_unit
|
||||
},
|
||||
openUnitSelect: function (id) {
|
||||
let index = id.replace('unit_', '')
|
||||
if (this.recipe_data.recipeIngredient[index].unit !== null) {
|
||||
this.$set(app.$refs.unit[index].$data, 'search', this.recipe_data.recipeIngredient[index].unit.text)
|
||||
}
|
||||
},
|
||||
openIngredientSelect: function (id) {
|
||||
let index = id.replace('ingredient_', '')
|
||||
this.$set(this.$refs.ingredient[index].$data, 'search', this.recipe_data.recipeIngredient[index].ingredient.text)
|
||||
},
|
||||
searchKeywords: function (query) {
|
||||
this.keywords_loading = true
|
||||
this.$http.get("{% url 'dal_keyword' %}" + '?q=' + query).then((response) => {
|
||||
this.keywords = response.data.results;
|
||||
this.keywords_loading = false
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
searchUnits: function (query) {
|
||||
this.units_loading = true
|
||||
this.$http.get("{% url 'dal_unit' %}" + '?q=' + query).then((response) => {
|
||||
this.units = response.data.results;
|
||||
if (this.recipe_data !== undefined) {
|
||||
for (let x of Array.from(this.recipe_data.recipeIngredient)) {
|
||||
if (x.unit !== null && x.unit.text !== '') {
|
||||
this.units = this.units.filter(item => item.text !== x.unit.text)
|
||||
this.units.push(x.unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
this.units_loading = false
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
searchIngredients: function (query) {
|
||||
this.ingredients_loading = true
|
||||
this.$http.get("{% url 'dal_food' %}" + '?q=' + query).then((response) => {
|
||||
this.ingredients = response.data.results
|
||||
if (this.recipe_data !== undefined) {
|
||||
for (let x of Array.from(this.recipe_data.recipeIngredient)) {
|
||||
if (x.ingredient.text !== '') {
|
||||
this.ingredients = this.ingredients.filter(item => item.text !== x.ingredient.text)
|
||||
this.ingredients.push(x.ingredient)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.ingredients_loading = false
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
@@ -7,7 +7,8 @@ from django.urls import reverse, NoReverseMatch
|
||||
|
||||
from cookbook.helper.mdx_attributes import MarkdownFormatExtension
|
||||
from cookbook.helper.mdx_urlize import UrlizeExtension
|
||||
from cookbook.models import get_model_name, CookLog
|
||||
from cookbook.models import get_model_name, Space
|
||||
from recipes import settings
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@@ -66,3 +67,13 @@ def recipe_last(recipe, user):
|
||||
return last.created_at
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def message_of_the_day():
|
||||
return Space.objects.first().message
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def is_debug():
|
||||
return settings.DEBUG
|
||||
|
||||
53
cookbook/tests/api/test_api_food.py
Normal file
53
cookbook/tests/api/test_api_food.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import json
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
from cookbook.models import Food
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
|
||||
|
||||
class TestApiUnit(TestViews):
|
||||
|
||||
def setUp(self):
|
||||
super(TestApiUnit, self).setUp()
|
||||
self.food_1 = Food.objects.create(
|
||||
name='Beef'
|
||||
)
|
||||
self.food_2 = Food.objects.create(
|
||||
name='Chicken'
|
||||
)
|
||||
|
||||
def test_keyword_list(self):
|
||||
# verify view permissions are applied accordingly
|
||||
self.batch_requests([(self.anonymous_client, 403), (self.guest_client_1, 403), (self.user_client_1, 200), (self.admin_client_1, 200), (self.superuser_client, 200)],
|
||||
reverse('api:food-list'))
|
||||
|
||||
# verify storage is returned
|
||||
r = self.user_client_1.get(reverse('api:food-list'))
|
||||
self.assertEqual(r.status_code, 200)
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 2)
|
||||
self.assertEqual(response[0]['name'], self.food_1.name)
|
||||
|
||||
r = self.user_client_1.get(f'{reverse("api:food-list")}?limit=1')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 1)
|
||||
|
||||
r = self.user_client_1.get(f'{reverse("api:food-list")}?query=Pork')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 0)
|
||||
|
||||
r = self.user_client_1.get(f'{reverse("api:food-list")}?query=Beef')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 1)
|
||||
|
||||
def test_keyword_update(self):
|
||||
r = self.user_client_1.patch(reverse('api:food-detail', args={self.food_1.id}), {'name': 'new'}, content_type='application/json')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(response['name'], 'new')
|
||||
|
||||
def test_keyword_delete(self):
|
||||
r = self.user_client_1.delete(reverse('api:food-detail', args={self.food_1.id}))
|
||||
self.assertEqual(r.status_code, 204)
|
||||
self.assertEqual(Food.objects.count(), 1)
|
||||
55
cookbook/tests/api/test_api_keyword.py
Normal file
55
cookbook/tests/api/test_api_keyword.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import json
|
||||
|
||||
from django.contrib import auth
|
||||
from django.db.models import ProtectedError
|
||||
from django.urls import reverse
|
||||
|
||||
from cookbook.models import Storage, Sync, Keyword
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
|
||||
|
||||
class TestApiKeyword(TestViews):
|
||||
|
||||
def setUp(self):
|
||||
super(TestApiKeyword, self).setUp()
|
||||
self.keyword_1 = Keyword.objects.create(
|
||||
name='meat'
|
||||
)
|
||||
self.keyword_2 = Keyword.objects.create(
|
||||
name='veggies'
|
||||
)
|
||||
|
||||
def test_keyword_list(self):
|
||||
# verify view permissions are applied accordingly
|
||||
self.batch_requests([(self.anonymous_client, 403), (self.guest_client_1, 403), (self.user_client_1, 200), (self.admin_client_1, 200), (self.superuser_client, 200)],
|
||||
reverse('api:keyword-list'))
|
||||
|
||||
# verify storage is returned
|
||||
r = self.user_client_1.get(reverse('api:keyword-list'))
|
||||
self.assertEqual(r.status_code, 200)
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 2)
|
||||
self.assertEqual(response[0]['name'], self.keyword_1.name)
|
||||
|
||||
r = self.user_client_1.get(f'{reverse("api:keyword-list")}?limit=1')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 1)
|
||||
|
||||
r = self.user_client_1.get(f'{reverse("api:keyword-list")}?query=chicken')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 0)
|
||||
|
||||
r = self.user_client_1.get(f'{reverse("api:keyword-list")}?query=MEAT')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 1)
|
||||
|
||||
def test_keyword_update(self):
|
||||
r = self.user_client_1.patch(reverse('api:keyword-detail', args={self.keyword_1.id}), {'name': 'new'}, content_type='application/json')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(response['name'], 'new')
|
||||
|
||||
def test_keyword_delete(self):
|
||||
r = self.user_client_1.delete(reverse('api:keyword-detail', args={self.keyword_1.id}))
|
||||
self.assertEqual(r.status_code, 204)
|
||||
self.assertEqual(Keyword.objects.count(), 1)
|
||||
27
cookbook/tests/api/test_api_shopping.py
Normal file
27
cookbook/tests/api/test_api_shopping.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import json
|
||||
|
||||
from django.contrib import auth
|
||||
from django.db.models import ProtectedError
|
||||
from django.urls import reverse
|
||||
|
||||
from cookbook.models import Storage, Sync, Keyword, ShoppingList
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
|
||||
|
||||
class TestApiShopping(TestViews):
|
||||
|
||||
def setUp(self):
|
||||
super(TestApiShopping, self).setUp()
|
||||
self.list_1 = ShoppingList.objects.create(created_by=auth.get_user(self.user_client_1))
|
||||
self.list_2 = ShoppingList.objects.create(created_by=auth.get_user(self.user_client_2))
|
||||
|
||||
def test_shopping_view_permissions(self):
|
||||
self.batch_requests([(self.anonymous_client, 403), (self.guest_client_1, 404), (self.user_client_1, 200), (self.user_client_2, 404), (self.admin_client_1, 404), (self.superuser_client, 200)],
|
||||
reverse('api:shoppinglist-detail', args={self.list_1.id}))
|
||||
|
||||
self.list_1.shared.add(auth.get_user(self.user_client_2))
|
||||
|
||||
self.batch_requests([(self.anonymous_client, 403), (self.guest_client_1, 404), (self.user_client_1, 200), (self.user_client_2, 200), (self.admin_client_1, 404), (self.superuser_client, 200)],
|
||||
reverse('api:shoppinglist-detail', args={self.list_1.id}))
|
||||
|
||||
# TODO add tests for editing
|
||||
61
cookbook/tests/api/test_api_storage.py
Normal file
61
cookbook/tests/api/test_api_storage.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import json
|
||||
|
||||
from django.contrib import auth
|
||||
from django.db.models import ProtectedError
|
||||
from django.urls import reverse
|
||||
|
||||
from cookbook.models import Storage, Sync
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
|
||||
|
||||
class TestApiStorage(TestViews):
|
||||
|
||||
def setUp(self):
|
||||
super(TestApiStorage, self).setUp()
|
||||
self.storage = Storage.objects.create(
|
||||
name='Test Storage',
|
||||
username='test',
|
||||
password='password',
|
||||
token='token',
|
||||
url='url',
|
||||
created_by=auth.get_user(self.admin_client_1)
|
||||
)
|
||||
|
||||
def test_storage_list(self):
|
||||
# verify view permissions are applied accordingly
|
||||
self.batch_requests([(self.anonymous_client, 403), (self.guest_client_1, 403), (self.user_client_1, 403), (self.admin_client_1, 200), (self.superuser_client, 200)],
|
||||
reverse('api:storage-list'))
|
||||
|
||||
# verify storage is returned
|
||||
r = self.admin_client_1.get(reverse('api:storage-list'))
|
||||
self.assertEqual(r.status_code, 200)
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 1)
|
||||
storage_response = response[0]
|
||||
self.assertEqual(storage_response['name'], self.storage.name)
|
||||
self.assertFalse('password' in storage_response)
|
||||
self.assertFalse('token' in storage_response)
|
||||
|
||||
def test_storage_update(self):
|
||||
# can update storage as admin
|
||||
r = self.admin_client_1.patch(reverse('api:storage-detail', args={self.storage.id}), {'name': 'new', 'password': 'new_password'}, content_type='application/json')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(response['name'], 'new')
|
||||
|
||||
# verify password was updated (write only field)
|
||||
self.storage.refresh_from_db()
|
||||
self.assertEqual(self.storage.password, 'new_password')
|
||||
|
||||
def test_storage_delete(self):
|
||||
# can delete storage as admin
|
||||
r = self.admin_client_1.delete(reverse('api:storage-detail', args={self.storage.id}))
|
||||
self.assertEqual(r.status_code, 204)
|
||||
self.assertEqual(Storage.objects.count(), 0)
|
||||
|
||||
self.storage = Storage.objects.create(created_by=auth.get_user(self.admin_client_1), name='test protect')
|
||||
Sync.objects.create(storage=self.storage, )
|
||||
|
||||
# test if deleting a storage with existing sync fails (as sync protects storage)
|
||||
with self.assertRaises(ProtectedError):
|
||||
self.admin_client_1.delete(reverse('api:storage-detail', args={self.storage.id}))
|
||||
51
cookbook/tests/api/test_api_syn_log.py
Normal file
51
cookbook/tests/api/test_api_syn_log.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import json
|
||||
|
||||
from django.contrib import auth
|
||||
from django.db.models import ProtectedError
|
||||
from django.urls import reverse
|
||||
|
||||
from cookbook.models import Storage, Sync, SyncLog
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
|
||||
|
||||
class TestApiSyncLog(TestViews):
|
||||
|
||||
def setUp(self):
|
||||
super(TestApiSyncLog, self).setUp()
|
||||
self.storage = Storage.objects.create(
|
||||
name='Test Storage',
|
||||
username='test',
|
||||
password='password',
|
||||
token='token',
|
||||
url='url',
|
||||
created_by=auth.get_user(self.admin_client_1)
|
||||
)
|
||||
|
||||
self.sync = Sync.objects.create(
|
||||
storage=self.storage,
|
||||
path='path'
|
||||
)
|
||||
|
||||
self.sync_log = SyncLog.objects.create(sync=self.sync, status='success')
|
||||
|
||||
def test_sync_log_list(self):
|
||||
# verify view permissions are applied accordingly
|
||||
self.batch_requests([(self.anonymous_client, 403), (self.guest_client_1, 403), (self.user_client_1, 403), (self.admin_client_1, 200), (self.superuser_client, 200)],
|
||||
reverse('api:synclog-list'))
|
||||
|
||||
# verify log entry is returned
|
||||
r = self.admin_client_1.get(reverse('api:synclog-list'))
|
||||
self.assertEqual(r.status_code, 200)
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 1)
|
||||
self.assertEqual(response[0]['status'], self.sync_log.status)
|
||||
|
||||
def test_sync_log_update(self):
|
||||
# read only view
|
||||
r = self.admin_client_1.patch(reverse('api:synclog-detail', args={self.sync.id}), {'path': 'new'}, content_type='application/json')
|
||||
self.assertEqual(r.status_code, 405)
|
||||
|
||||
def test_sync_log_delete(self):
|
||||
# read only view
|
||||
r = self.admin_client_1.delete(reverse('api:synclog-detail', args={self.sync.id}))
|
||||
self.assertEqual(r.status_code, 405)
|
||||
53
cookbook/tests/api/test_api_sync.py
Normal file
53
cookbook/tests/api/test_api_sync.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import json
|
||||
|
||||
from django.contrib import auth
|
||||
from django.db.models import ProtectedError
|
||||
from django.urls import reverse
|
||||
|
||||
from cookbook.models import Storage, Sync
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
|
||||
|
||||
class TestApiSync(TestViews):
|
||||
|
||||
def setUp(self):
|
||||
super(TestApiSync, self).setUp()
|
||||
self.storage = Storage.objects.create(
|
||||
name='Test Storage',
|
||||
username='test',
|
||||
password='password',
|
||||
token='token',
|
||||
url='url',
|
||||
created_by=auth.get_user(self.admin_client_1)
|
||||
)
|
||||
|
||||
self.sync = Sync.objects.create(
|
||||
storage=self.storage,
|
||||
path='path'
|
||||
)
|
||||
|
||||
def test_sync_list(self):
|
||||
# verify view permissions are applied accordingly
|
||||
self.batch_requests([(self.anonymous_client, 403), (self.guest_client_1, 403), (self.user_client_1, 403), (self.admin_client_1, 200), (self.superuser_client, 200)],
|
||||
reverse('api:sync-list'))
|
||||
|
||||
# verify sync is returned
|
||||
r = self.admin_client_1.get(reverse('api:sync-list'))
|
||||
self.assertEqual(r.status_code, 200)
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 1)
|
||||
storage_response = response[0]
|
||||
self.assertEqual(storage_response['path'], self.sync.path)
|
||||
|
||||
def test_sync_update(self):
|
||||
# can update sync as admin
|
||||
r = self.admin_client_1.patch(reverse('api:sync-detail', args={self.sync.id}), {'path': 'new'}, content_type='application/json')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(response['path'], 'new')
|
||||
|
||||
def test_sync_delete(self):
|
||||
# can delete sync as admin
|
||||
r = self.admin_client_1.delete(reverse('api:sync-detail', args={self.sync.id}))
|
||||
self.assertEqual(r.status_code, 204)
|
||||
self.assertEqual(Sync.objects.count(), 0)
|
||||
53
cookbook/tests/api/test_api_unit.py
Normal file
53
cookbook/tests/api/test_api_unit.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import json
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
from cookbook.models import Unit
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
|
||||
|
||||
class TestApiUnit(TestViews):
|
||||
|
||||
def setUp(self):
|
||||
super(TestApiUnit, self).setUp()
|
||||
self.unit_1 = Unit.objects.create(
|
||||
name='kg'
|
||||
)
|
||||
self.unit_2 = Unit.objects.create(
|
||||
name='g'
|
||||
)
|
||||
|
||||
def test_keyword_list(self):
|
||||
# verify view permissions are applied accordingly
|
||||
self.batch_requests([(self.anonymous_client, 403), (self.guest_client_1, 403), (self.user_client_1, 200), (self.admin_client_1, 200), (self.superuser_client, 200)],
|
||||
reverse('api:unit-list'))
|
||||
|
||||
# verify storage is returned
|
||||
r = self.user_client_1.get(reverse('api:unit-list'))
|
||||
self.assertEqual(r.status_code, 200)
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 2)
|
||||
self.assertEqual(response[0]['name'], self.unit_1.name)
|
||||
|
||||
r = self.user_client_1.get(f'{reverse("api:unit-list")}?limit=1')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 1)
|
||||
|
||||
r = self.user_client_1.get(f'{reverse("api:unit-list")}?query=m')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 0)
|
||||
|
||||
r = self.user_client_1.get(f'{reverse("api:unit-list")}?query=kg')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(len(response), 1)
|
||||
|
||||
def test_keyword_update(self):
|
||||
r = self.user_client_1.patch(reverse('api:unit-detail', args={self.unit_1.id}), {'name': 'new'}, content_type='application/json')
|
||||
response = json.loads(r.content)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(response['name'], 'new')
|
||||
|
||||
def test_keyword_delete(self):
|
||||
r = self.user_client_1.delete(reverse('api:unit-detail', args={self.unit_1.id}))
|
||||
self.assertEqual(r.status_code, 204)
|
||||
self.assertEqual(Unit.objects.count(), 1)
|
||||
27
cookbook/tests/api/test_api_username.py
Normal file
27
cookbook/tests/api/test_api_username.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import json
|
||||
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
|
||||
from cookbook.models import UserPreference
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
|
||||
|
||||
class TestApiUsername(TestViews):
|
||||
|
||||
def setUp(self):
|
||||
super(TestApiUsername, self).setUp()
|
||||
|
||||
def test_forbidden_methods(self):
|
||||
r = self.user_client_1.post(reverse('api:username-list'))
|
||||
self.assertEqual(r.status_code, 405)
|
||||
|
||||
r = self.user_client_1.put(reverse('api:username-detail', args=[auth.get_user(self.user_client_1).pk]))
|
||||
self.assertEqual(r.status_code, 405)
|
||||
|
||||
r = self.user_client_1.delete(reverse('api:username-detail', args=[auth.get_user(self.user_client_1).pk]))
|
||||
self.assertEqual(r.status_code, 405)
|
||||
|
||||
def test_username_list(self):
|
||||
self.batch_requests([(self.anonymous_client, 403), (self.guest_client_1, 200), (self.user_client_1, 200), (self.admin_client_1, 200), (self.superuser_client, 200)],
|
||||
reverse('api:username-list'))
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user