mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-28 12:39:36 -05:00
Compare commits
170 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b90c70b2a3 | ||
|
|
bcf50f30bc | ||
|
|
065ed6c437 | ||
|
|
285e09f40a | ||
|
|
0398f36949 | ||
|
|
ea30eb96cd | ||
|
|
b787ae49bb | ||
|
|
f8e2283a69 | ||
|
|
13d51a7b46 | ||
|
|
e74ae06b64 | ||
|
|
aa495250c9 | ||
|
|
f8ee48c23b | ||
|
|
320246b18b | ||
|
|
00992da998 | ||
|
|
2b9ad2feed | ||
|
|
257127bd4e | ||
|
|
b1df118140 | ||
|
|
da6b437b20 | ||
|
|
6fe4c79b0d | ||
|
|
1793753cb4 | ||
|
|
9ed1aff0d2 | ||
|
|
51c3ec5762 | ||
|
|
5feeabb498 | ||
|
|
c4aa3eb019 | ||
|
|
e8b9f473a6 | ||
|
|
279b4dc025 | ||
|
|
6a1226ca26 | ||
|
|
b9ee7d53fa | ||
|
|
ace7ee4274 | ||
|
|
16968db1cf | ||
|
|
2b24155dd2 | ||
|
|
5a7c914fe7 | ||
|
|
f822e03be0 | ||
|
|
1bdf14dbf9 | ||
|
|
6ef173d82d | ||
|
|
1e471ad40d | ||
|
|
4ff1a6bc93 | ||
|
|
7d1f47edc5 | ||
|
|
f69d7898d5 | ||
|
|
9692e2386b | ||
|
|
93b2e2d7e4 | ||
|
|
8b2833f353 | ||
|
|
643dbbc294 | ||
|
|
c4273a4c3f | ||
|
|
95461316a5 | ||
|
|
1775b64ba4 | ||
|
|
5a9270373f | ||
|
|
37f98ce9fe | ||
|
|
fa556c9a7f | ||
|
|
29e1d1286c | ||
|
|
f489043077 | ||
|
|
bdd004518c | ||
|
|
840f5ec60d | ||
|
|
566eea1d75 | ||
|
|
bb48655acb | ||
|
|
d723165b1c | ||
|
|
592bd4f11e | ||
|
|
0aec23fcdd | ||
|
|
a23dc717aa | ||
|
|
d364994ed7 | ||
|
|
a38ed28512 | ||
|
|
1f5c02bcc3 | ||
|
|
f4afdfbc07 | ||
|
|
f753b63b13 | ||
|
|
6f3068a28c | ||
|
|
aa57b47d18 | ||
|
|
113e9ef1e3 | ||
|
|
5899527621 | ||
|
|
0a40de0f14 | ||
|
|
bc31f013c0 | ||
|
|
e7fc15dc72 | ||
|
|
79396cec9e | ||
|
|
5e07c6130f | ||
|
|
94e1fdfbff | ||
|
|
a0d414c83f | ||
|
|
1441368465 | ||
|
|
6f301c4771 | ||
|
|
ec31d251ea | ||
|
|
289625923f | ||
|
|
a42a76a2cf | ||
|
|
fd1216cd22 | ||
|
|
3f6a342026 | ||
|
|
f72fc699f8 | ||
|
|
cdcca80196 | ||
|
|
400cd2f6a0 | ||
|
|
37a4821d01 | ||
|
|
d165075a96 | ||
|
|
a062173ebd | ||
|
|
806963c396 | ||
|
|
851853740d | ||
|
|
7ca88f3c0a | ||
|
|
ac2e9dd6cb | ||
|
|
b2a34ce59a | ||
|
|
6124501f5a | ||
|
|
4ec313f752 | ||
|
|
dd07c56ede | ||
|
|
77fae46aee | ||
|
|
ff573b0358 | ||
|
|
247eab2a4f | ||
|
|
dc46502667 | ||
|
|
ac58f1959d | ||
|
|
f4543f8d65 | ||
|
|
d0ef5e27df | ||
|
|
9ea90f1c87 | ||
|
|
e7922a7e47 | ||
|
|
d3bc440c83 | ||
|
|
910b28fe2d | ||
|
|
89cd8bc2d2 | ||
|
|
d2e9ad2ae6 | ||
|
|
56c9edd328 | ||
|
|
7732aa7646 | ||
|
|
9863447bac | ||
|
|
53b00cc4c8 | ||
|
|
4f34ec1be8 | ||
|
|
e444ba91f0 | ||
|
|
fa3513eb65 | ||
|
|
d323778f1d | ||
|
|
53cb5afef6 | ||
|
|
0349301919 | ||
|
|
a5d2bd75d6 | ||
|
|
26499ad431 | ||
|
|
2eb72953f0 | ||
|
|
6fd9cf0d8c | ||
|
|
1e800889e4 | ||
|
|
422113a745 | ||
|
|
e687d0e569 | ||
|
|
76c1529ec1 | ||
|
|
d30b2b7ec8 | ||
|
|
c4fbad614e | ||
|
|
4c92a4b39c | ||
|
|
3dad5132bb | ||
|
|
7d7890445e | ||
|
|
cea015f23d | ||
|
|
3e8610912e | ||
|
|
ba80ca42e6 | ||
|
|
c413db5460 | ||
|
|
0e319ff293 | ||
|
|
88e3b22dcd | ||
|
|
19e2094ecd | ||
|
|
215989682b | ||
|
|
2f038edf8c | ||
|
|
a754002f4e | ||
|
|
1af2211010 | ||
|
|
724d57ecd7 | ||
|
|
4b04fada51 | ||
|
|
4ad7043f91 | ||
|
|
4dfda4439c | ||
|
|
591d185b9d | ||
|
|
8d582548bd | ||
|
|
209924e5b3 | ||
|
|
7e3e2aadaf | ||
|
|
0930e615f0 | ||
|
|
21c759b127 | ||
|
|
7d1a83440d | ||
|
|
2d75b303fd | ||
|
|
a1b15d46b8 | ||
|
|
69a6edee99 | ||
|
|
0ac23b4e3a | ||
|
|
085e777ee0 | ||
|
|
c31df3f7a6 | ||
|
|
98e2c0acaf | ||
|
|
1509b8243b | ||
|
|
31dabd4757 | ||
|
|
7a89015ac5 | ||
|
|
2b1cde2efc | ||
|
|
368d631602 | ||
|
|
24ced66c69 | ||
|
|
6c1982cccb | ||
|
|
3bae7283d1 | ||
|
|
652b4bf2af |
@@ -14,5 +14,4 @@ LICENSE
|
||||
.idea
|
||||
LICENSE.md
|
||||
docs
|
||||
nginx
|
||||
update.sh
|
||||
@@ -8,14 +8,25 @@ ALLOWED_HOSTS=*
|
||||
# random secret key, use for example base64 /dev/urandom | head -c50 to generate one
|
||||
SECRET_KEY=
|
||||
|
||||
# your default timezone
|
||||
TIMEZONE=Europe/Berlin
|
||||
|
||||
# add only a database password if you want to run with the default postgres, otherwise change settings accordingly
|
||||
DB_ENGINE=django.db.backends.postgresql_psycopg2
|
||||
DB_ENGINE=django.db.backends.postgresql
|
||||
POSTGRES_HOST=db_recipes
|
||||
POSTGRES_PORT=5432
|
||||
POSTGRES_USER=djangodb
|
||||
POSTGRES_PASSWORD=
|
||||
POSTGRES_DB=djangodb
|
||||
|
||||
# the default value for the user preference 'fractions' (enable/disable fraction support)
|
||||
# when unset: 0 (disabled)
|
||||
FRACTION_PREF_DEFAULT=0
|
||||
|
||||
# the default value for the user preference 'comments' (enable/disable commenting system)
|
||||
# when unset: 1 (true)
|
||||
COMMENT_PREF_DEFAULT=1
|
||||
|
||||
# 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)
|
||||
@@ -33,14 +44,9 @@ SHOPPING_MIN_AUTOSYNC_INTERVAL=5
|
||||
# when unset: 1 (true) - this is temporary until an appropriate amount of time has passed for everyone to migrate
|
||||
GUNICORN_MEDIA=0
|
||||
|
||||
|
||||
# allow authentication via reverse proxy (e.g. authelia), leave of if you dont know what you are doing
|
||||
# docs: https://github.com/vabene1111/recipes/tree/develop/docs/docker/nginx-proxy%20with%20proxy%20authentication
|
||||
# when unset: 0 (false)
|
||||
REVERSE_PROXY_AUTH=0
|
||||
|
||||
|
||||
# the default value for the user preference 'comments' (enable/disable commenting system)
|
||||
# when unset: 1 (true)
|
||||
COMMENT_PREF_DEFAULT=1
|
||||
|
||||
|
||||
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\//}
|
||||
|
||||
17
.github/workflows/docs.yml
vendored
Normal file
17
.github/workflows/docs.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
name: Make Docs
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.x
|
||||
- run: pip install mkdocs-material
|
||||
- run: mkdocs gh-deploy --force
|
||||
@@ -1,11 +1,63 @@
|
||||
Many thanks to everyone who contributed to this project!
|
||||
Many thanks to everyone who contributed to this project! If you add something or help out feel free to add yourself
|
||||
to this list.
|
||||
|
||||
## Code/Features
|
||||
Please have a look at the [list of pull requests](https://github.com/vabene1111/recipes/pulls) for
|
||||
a complete list of contributions.
|
||||
Below are some of the larger contributions made yet.
|
||||
|
||||
|
||||
- @tourn provided the serving feature and **several** other improvements!
|
||||
- @l0c4lh057 provided a much improved ingredient text parser in [#277](https://github.com/vabene1111/recipes/pull/277)
|
||||
- @sebimarkgraf added nutritional information [#199](https://github.com/vabene1111/recipes/pull/199)
|
||||
- @cazier added reverse proxy authentication [#88](https://github.com/vabene1111/recipes/pull/88)
|
||||
|
||||
## Translations
|
||||
|
||||
### Catalan
|
||||
[Rubenix](https://www.transifex.com/user/profile/rubenix/)
|
||||
|
||||
### Dutch
|
||||
[D0T1X](https://www.transifex.com/user/profile/D0T1X/)
|
||||
[D0T1X](https://www.transifex.com/user/profile/D0T1X/)
|
||||
[ikbenfrank](https://www.transifex.com/user/profile/ikbenfrank/)
|
||||
[kampsj](https://www.transifex.com/user/profile/kampsj/)
|
||||
|
||||
### French
|
||||
[jt117](https://www.transifex.com/user/profile/jt117/)
|
||||
[nerdinator](https://www.transifex.com/user/profile/nerdinator/)
|
||||
[nerdinator](https://www.transifex.com/user/profile/nerdinator/)
|
||||
[agaume](https://www.transifex.com/user/profile/agaume/)
|
||||
|
||||
### German
|
||||
[eTaurus](https://www.transifex.com/user/profile/eTaurus/)
|
||||
[l0c4lh057](https://www.transifex.com/user/profile/l0c4lh057/)
|
||||
|
||||
### Hungarian
|
||||
[igazka](https://www.transifex.com/user/profile/igazka/)
|
||||
|
||||
### Italian
|
||||
[SK3LA](https://www.transifex.com/user/profile/SK3LA/)
|
||||
[auanasgheps](https://www.transifex.com/user/profile/auanasgheps/)
|
||||
|
||||
### Latvian
|
||||
[melkypie](https://github.com/melkypie)
|
||||
|
||||
### Portuguese
|
||||
|
||||
[hds](https://www.transifex.com/user/profile/hds/)
|
||||
[mlopezifu](https://www.transifex.com/user/profile/mlopezifu/)
|
||||
[stormsz](https://www.transifex.com/user/profile/stormsz/)
|
||||
|
||||
### Spanish
|
||||
|
||||
[albertocp](https://www.transifex.com/user/profile/albertocp/)
|
||||
[alfa5](https://www.transifex.com/user/profile/alfa5/)
|
||||
[mlopezifu](https://www.transifex.com/user/profile/mlopezifu/)
|
||||
[sergio.laya](https://www.transifex.com/user/profile/sergio.laya/)
|
||||
|
||||
### Turkish
|
||||
|
||||
[batmanisnaked](https://www.transifex.com/user/profile/batmanisnaked/)
|
||||
|
||||
### Vietnamese
|
||||
|
||||
[vuongtrunghieu](https://www.transifex.com/user/profile/vuongtrunghieu/)
|
||||
63
README.md
63
README.md
@@ -1,6 +1,11 @@
|
||||
# Recipes 
|
||||
# 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.
|
||||
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.
|
||||
|
||||

|
||||
|
||||
@@ -17,49 +22,43 @@ Recipes is a Django application to manage, tag and search recipes using either b
|
||||
- :shopping_cart: Generate **shopping** lists from recipes
|
||||
- :calendar: Create a **Plan** on what to eat when
|
||||
- :family: **Share** recipes with friends and comment on them to suggest or remember changes you made
|
||||
- :heavy_division_sign: automatically convert decimal units to **fractions** for those who like this
|
||||
- :whale: Easy setup with **Docker**
|
||||
- :art: Customize your interface with **themes**
|
||||
- :envelope: Export and import recipes from other users
|
||||
- :earth_africa: localized in many languages thanks to the awesome community
|
||||
- :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
|
||||
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.
|
||||
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)
|
||||
|
||||
While this application has been around for a while and is actively used by many (including myself) it is still considered
|
||||
**beta** software that has a lot of rough edges and unpolished parts.
|
||||
|
||||
## 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
|
||||
|
||||
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`
|
||||
|
||||
### Manual
|
||||
|
||||
**Python >= 3.8** is required to run this!
|
||||
|
||||
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!**
|
||||
1. Stop the container using `docker-compose down`
|
||||
2. Pull the latest image using `docker-compose pull`
|
||||
3. Start the container again using `docker-compose up -d`
|
||||
|
||||
## Kubernetes
|
||||
|
||||
You can find a basic kubernetes setup [here](docs/k8s/). Please see the README in the folder for more detail.
|
||||
Please refer to the Installation section of the [Documentation](https://vabene1111.github.io/recipes/).
|
||||
|
||||
## 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/).
|
||||
|
||||
**If you want feel free to open an issue or pull request to add yourself to the list of awesome contributors.**
|
||||
|
||||
### Getting Started
|
||||
This application is developed using the django framework for Python. They have excellent
|
||||
[documentation](https://www.djangoproject.com/start/) on how to get started, so I will only give you the basics here
|
||||
|
||||
1. Clone this repository wherever you like and install the Python language for your OS (at least version 3.8)
|
||||
2. Open it in your favorite editor/IDE (e.g. PyCharm)
|
||||
1. if you want, create a virutal environment for all your packages.
|
||||
3. Install all required packages by running `pip install -r requirements.txt`
|
||||
4. Run the migrations `python manage.py migrate`
|
||||
5. Start the development server `python manage.py runserver`
|
||||
|
||||
There is **no** need to set any environment variables. By default, a simple sqlite database is used and all settings are
|
||||
populated from default values.
|
||||
|
||||
### Translating
|
||||
|
||||
|
||||
10
SECURITY.md
Normal file
10
SECURITY.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Since this software is still considered beta/WIP support is always only given for the latest version. There are no backports of security or any other fixes.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please open a normal public issue if you have any security related concerns. If you feel like the issue should not be discussed in
|
||||
public just open a generic issue and we will discuss further communitcation there (since GitHub does not allow everyone to create a security advisory :/).
|
||||
@@ -147,7 +147,7 @@ admin.site.register(CookLog, CookLogAdmin)
|
||||
|
||||
|
||||
class ShoppingListRecipeAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'recipe', 'multiplier')
|
||||
list_display = ('id', 'recipe', 'servings')
|
||||
|
||||
|
||||
admin.site.register(ShoppingListRecipe, ShoppingListRecipeAdmin)
|
||||
@@ -172,3 +172,10 @@ class ShareLinkAdmin(admin.ModelAdmin):
|
||||
|
||||
|
||||
admin.site.register(ShareLink, ShareLinkAdmin)
|
||||
|
||||
|
||||
class NutritionInformationAdmin(admin.ModelAdmin):
|
||||
list_display = ('id',)
|
||||
|
||||
|
||||
admin.site.register(NutritionInformation, NutritionInformationAdmin)
|
||||
|
||||
@@ -31,12 +31,13 @@ class UserPreferenceForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = UserPreference
|
||||
fields = ('default_unit', 'theme', 'nav_color', 'default_page', 'show_recent', 'search_style', 'plan_share', 'ingredient_decimals', 'shopping_auto_sync', 'comments')
|
||||
fields = ('default_unit', 'use_fractions', '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!'),
|
||||
'default_unit': _('Default Unit to be used when inserting a new ingredient into a recipe.'),
|
||||
'plan_share': _('Default user to share newly created meal plan entries with.'),
|
||||
'use_fractions': _('Enables support for fractions in ingredient amounts (e.g. convert decimals to fractions automatically)'),
|
||||
'plan_share': _('Users with whom newly created meal plan/shopping list entries should be shared by default.'),
|
||||
'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.'),
|
||||
@@ -87,13 +88,14 @@ class InternalRecipeForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'image', 'working_time', 'waiting_time', 'keywords')
|
||||
fields = ('name', 'image', 'working_time', 'waiting_time', 'servings', 'keywords')
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
'keywords': _('Keywords'),
|
||||
'working_time': _('Preparation time in minutes'),
|
||||
'waiting_time': _('Waiting time (cooking/baking) in minutes'),
|
||||
'servings': _('Number of servings'),
|
||||
}
|
||||
widgets = {'keywords': MultiSelectWidget}
|
||||
|
||||
@@ -264,12 +266,11 @@ class MealPlanForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = MealPlan
|
||||
fields = ('recipe', 'title', 'meal_type', 'note', 'recipe_multiplier', 'date', 'shared')
|
||||
fields = ('recipe', 'title', 'meal_type', 'note', 'servings', '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>'),
|
||||
'recipe_multiplier': _('Scaling factor for recipe.')
|
||||
'note': _('You can use markdown to format this field. See the <a href="/docs/markdown/">docs here</a>')
|
||||
}
|
||||
|
||||
widgets = {'recipe': SelectWidget, 'date': DateWidget, 'shared': MultiSelectWidget}
|
||||
@@ -285,6 +286,6 @@ class InviteLinkForm(forms.ModelForm):
|
||||
|
||||
|
||||
class UserCreateForm(forms.Form):
|
||||
name = forms.CharField()
|
||||
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'}))
|
||||
|
||||
131
cookbook/helper/ingredient_parser.py
Normal file
131
cookbook/helper/ingredient_parser.py
Normal file
@@ -0,0 +1,131 @@
|
||||
import unicodedata
|
||||
import string
|
||||
|
||||
def parse_fraction(x):
|
||||
if len(x) == 1 and 'fraction' in unicodedata.decomposition(x):
|
||||
frac_split = unicodedata.decomposition(x[-1:]).split()
|
||||
return float((frac_split[1]).replace('003', '')) / float((frac_split[3]).replace('003', ''))
|
||||
else:
|
||||
frac_split = x.split('/')
|
||||
if not len(frac_split) == 2:
|
||||
raise ValueError
|
||||
try:
|
||||
return int(frac_split[0]) / int(frac_split[1])
|
||||
except ZeroDivisionError:
|
||||
raise ValueError
|
||||
|
||||
def parse_amount(x):
|
||||
amount = 0
|
||||
unit = ''
|
||||
|
||||
did_check_frac = False
|
||||
end = 0
|
||||
while end < len(x) and (x[end] in string.digits or ((x[end] == '.' or x[end] == ',') and end + 1 < len(x) and x[end+1] in string.digits)):
|
||||
end += 1
|
||||
if end > 0:
|
||||
amount = float(x[:end].replace(',', '.'))
|
||||
else:
|
||||
amount = parse_fraction(x[0])
|
||||
end += 1
|
||||
did_check_frac = True
|
||||
if end < len(x):
|
||||
if did_check_frac:
|
||||
unit = x[end:]
|
||||
else:
|
||||
try:
|
||||
amount += parse_fraction(x[end])
|
||||
unit = x[end+1:]
|
||||
except ValueError:
|
||||
unit = x[end:]
|
||||
return amount, unit
|
||||
|
||||
def parse_ingredient_with_comma(tokens):
|
||||
ingredient = ''
|
||||
note = ''
|
||||
start = 0
|
||||
# search for first occurence of an argument ending in a comma
|
||||
while start < len(tokens) and not tokens[start].endswith(','):
|
||||
start += 1
|
||||
if start == len(tokens):
|
||||
# no token ending in a comma found -> use everything as ingredient
|
||||
ingredient = ' '.join(tokens)
|
||||
else:
|
||||
ingredient = ' '.join(tokens[:start+1])[:-1]
|
||||
note = ' '.join(tokens[start+1:])
|
||||
return ingredient, note
|
||||
|
||||
def parse_ingredient(tokens):
|
||||
ingredient = ''
|
||||
note = ''
|
||||
if tokens[-1].endswith(')'):
|
||||
# last argument ends with closing bracket -> look for opening bracket
|
||||
start = len(tokens) - 1
|
||||
while not tokens[start].startswith('(') and not start == 0:
|
||||
start -= 1
|
||||
if start == 0:
|
||||
# the whole list is wrapped in brackets -> assume it is an error (e.g. assumed first argument was the unit)
|
||||
raise ValueError
|
||||
elif start < 0:
|
||||
# no opening bracket anywhere -> just ignore the last bracket
|
||||
ingredient, note = parse_ingredient_with_comma(tokens)
|
||||
else:
|
||||
# opening bracket found -> split in ingredient and note, remove brackets from note
|
||||
note = ' '.join(tokens[start:])[1:-1]
|
||||
ingredient = ' '.join(tokens[:start])
|
||||
else:
|
||||
ingredient, note = parse_ingredient_with_comma(tokens)
|
||||
return ingredient, note
|
||||
|
||||
def parse(x):
|
||||
# initialize default values
|
||||
amount = 0
|
||||
unit = ''
|
||||
ingredient = ''
|
||||
note = ''
|
||||
|
||||
tokens = x.split()
|
||||
if len(tokens) == 1:
|
||||
# there only is one argument, that must be the ingredient
|
||||
ingredient = tokens[0]
|
||||
else:
|
||||
try:
|
||||
# try to parse first argument as amount
|
||||
amount, unit = parse_amount(tokens[0])
|
||||
# only try to parse second argument as amount if there are at least three arguments
|
||||
# if it already has a unit there can't be a fraction for the amount
|
||||
if len(tokens) > 2:
|
||||
try:
|
||||
if not unit == '':
|
||||
# a unit is already found, no need to try the second argument for a fraction
|
||||
# probably not the best method to do it, but I didn't want to make an if check and paste the exact same thing in the else as already is in the except
|
||||
raise ValueError
|
||||
# try to parse second argument as amount and add that, in case of '2 1/2' or '2 ½'
|
||||
amount += parse_fraction(tokens[1])
|
||||
# assume that units can't end with a comma
|
||||
if len(tokens) > 3 and not tokens[2].endswith(','):
|
||||
# try to use third argument as unit and everything else as ingredient, use everything as ingredient if it fails
|
||||
try:
|
||||
ingredient, note = parse_ingredient(tokens[3:])
|
||||
unit = tokens[2]
|
||||
except ValueError:
|
||||
ingredient, note = parse_ingredient(tokens[2:])
|
||||
else:
|
||||
ingredient, note = parse_ingredient(tokens[2:])
|
||||
except ValueError:
|
||||
# assume that units can't end with a comma
|
||||
if not tokens[1].endswith(','):
|
||||
# try to use second argument as unit and everything else as ingredient, use everything as ingredient if it fails
|
||||
try:
|
||||
ingredient, note = parse_ingredient(tokens[2:])
|
||||
unit = tokens[1]
|
||||
except ValueError:
|
||||
ingredient, note = parse_ingredient(tokens[1:])
|
||||
else:
|
||||
ingredient, note = parse_ingredient(tokens[1:])
|
||||
else:
|
||||
# only two arguments, first one is the amount which means this is the ingredient
|
||||
ingredient = tokens[1]
|
||||
except ValueError:
|
||||
# can't parse first argument as amount -> no unit -> parse everything as ingredient
|
||||
ingredient, note = parse_ingredient(tokens)
|
||||
return amount, unit.strip(), ingredient.strip(), note.strip()
|
||||
@@ -141,7 +141,7 @@ class OwnerRequiredMixin(object):
|
||||
return HttpResponseRedirect(reverse_lazy('login'))
|
||||
else:
|
||||
if not is_object_owner(request.user, self.get_object()):
|
||||
messages.add_message(request, messages.ERROR, _('You cannot interact with this object as its not owned by you!'))
|
||||
messages.add_message(request, messages.ERROR, _('You cannot interact with this object as it is not owned by you!'))
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
return super(OwnerRequiredMixin, self).dispatch(request, *args, **kwargs)
|
||||
@@ -155,7 +155,7 @@ class CustomIsOwner(permissions.BasePermission):
|
||||
verifies user has ownership over object
|
||||
(either user or created_by or user is request user)
|
||||
"""
|
||||
message = _('You cannot interact with this object as its not owned by you!')
|
||||
message = _('You cannot interact with this object as it is not owned by you!')
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return request.user.is_authenticated
|
||||
@@ -169,7 +169,7 @@ class CustomIsShared(permissions.BasePermission): # TODO function duplicate/too
|
||||
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!')
|
||||
message = _('You cannot interact with this object as it is not owned by you!')
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return request.user.is_authenticated
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
import unicodedata
|
||||
from json import JSONDecodeError
|
||||
|
||||
import microdata
|
||||
@@ -10,6 +11,7 @@ from django.utils.dateparse import parse_duration
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from cookbook.models import Keyword
|
||||
from cookbook.helper.ingredient_parser import parse as parse_ingredient
|
||||
|
||||
|
||||
def get_from_html(html_text, url):
|
||||
@@ -69,31 +71,12 @@ def find_recipe_json(ld_json, url):
|
||||
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})
|
||||
try:
|
||||
amount, unit, ingredient, note = parse_ingredient(x)
|
||||
if ingredient:
|
||||
ingredients.append({'amount': amount, 'unit': {'text': unit, 'id': random.randrange(10000, 99999)}, 'ingredient': {'text': ingredient, 'id': random.randrange(10000, 99999)}, "note": note, 'original': x})
|
||||
except:
|
||||
pass
|
||||
|
||||
ld_json['recipeIngredient'] = ingredients
|
||||
else:
|
||||
@@ -149,7 +132,7 @@ def find_recipe_json(ld_json, url):
|
||||
else:
|
||||
ld_json['recipeInstructions'] = ''
|
||||
|
||||
ld_json['recipeInstructions'] += '\n\n' + _('Imported from ') + url
|
||||
ld_json['recipeInstructions'] += '\n\n' + _('Imported from') + ' ' + url
|
||||
|
||||
if 'image' in ld_json:
|
||||
# check if list of images is returned, take first if so
|
||||
|
||||
BIN
cookbook/locale/ca/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/ca/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
2027
cookbook/locale/ca/LC_MESSAGES/django.po
Normal file
2027
cookbook/locale/ca/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
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/es/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/es/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1969
cookbook/locale/es/LC_MESSAGES/django.po
Normal file
1969
cookbook/locale/es/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/hu_HU/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/hu_HU/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1841
cookbook/locale/hu_HU/LC_MESSAGES/django.po
Normal file
1841
cookbook/locale/hu_HU/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/it/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/it/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1949
cookbook/locale/it/LC_MESSAGES/django.po
Normal file
1949
cookbook/locale/it/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/lv/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/lv/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1927
cookbook/locale/lv/LC_MESSAGES/django.po
Normal file
1927
cookbook/locale/lv/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
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
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
cookbook/locale/zh_CN/LC_MESSAGES/django.mo
Normal file
BIN
cookbook/locale/zh_CN/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
1841
cookbook/locale/zh_CN/LC_MESSAGES/django.po
Normal file
1841
cookbook/locale/zh_CN/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
36
cookbook/migrations/0089_auto_20201117_2222.py
Normal file
36
cookbook/migrations/0089_auto_20201117_2222.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Generated by Django 3.1.1 on 2020-11-17 21:22
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0088_shoppinglist_finished'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='NutritionInformation',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('fats', models.DecimalField(decimal_places=16, default=0, max_digits=32)),
|
||||
('carbohydrates', models.DecimalField(decimal_places=16, default=0, max_digits=32)),
|
||||
('proteins', models.DecimalField(decimal_places=16, default=0, max_digits=32)),
|
||||
('calories', models.DecimalField(decimal_places=16, default=0, max_digits=32)),
|
||||
('source', models.CharField(blank=True, default='', max_length=512, null=True)),
|
||||
],
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='invitelink',
|
||||
name='valid_until',
|
||||
field=models.DateField(default=datetime.date(2020, 12, 1)),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='recipe',
|
||||
name='nutrition',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='cookbook.nutritioninformation'),
|
||||
),
|
||||
]
|
||||
24
cookbook/migrations/0090_auto_20201214_1359.py
Normal file
24
cookbook/migrations/0090_auto_20201214_1359.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 3.1.3 on 2020-12-14 12:59
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0089_auto_20201117_2222'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='userpreference',
|
||||
name='use_fractions',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='invitelink',
|
||||
name='valid_until',
|
||||
field=models.DateField(default=datetime.date(2020, 12, 28)),
|
||||
),
|
||||
]
|
||||
26
cookbook/migrations/0091_auto_20201226_1551.py
Normal file
26
cookbook/migrations/0091_auto_20201226_1551.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Generated by Django 3.1.4 on 2020-12-26 14:51
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def migrate_empty_units(apps, schema_editor):
|
||||
Unit = apps.get_model('cookbook', 'Unit')
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
|
||||
empty_units = Unit.objects.filter(name='').all()
|
||||
for x in empty_units:
|
||||
for i in Ingredient.objects.all():
|
||||
if i.unit == x:
|
||||
i.unit = None
|
||||
i.save()
|
||||
x.delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('cookbook', '0090_auto_20201214_1359'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(migrate_empty_units),
|
||||
]
|
||||
18
cookbook/migrations/0092_recipe_servings.py
Normal file
18
cookbook/migrations/0092_recipe_servings.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-08-30 13:32
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0091_auto_20201226_1551'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='recipe',
|
||||
name='servings',
|
||||
field=models.IntegerField(default=1),
|
||||
),
|
||||
]
|
||||
30
cookbook/migrations/0093_auto_20201231_1236.py
Normal file
30
cookbook/migrations/0093_auto_20201231_1236.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# Generated by Django 3.1.4 on 2020-12-31 11:36
|
||||
|
||||
import datetime
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0092_recipe_servings'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='mealplan',
|
||||
old_name='recipe_multiplier',
|
||||
new_name='servings',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='invitelink',
|
||||
name='valid_until',
|
||||
field=models.DateField(default=datetime.date(2021, 1, 14)),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='unit',
|
||||
name='name',
|
||||
field=models.CharField(max_length=128, unique=True, validators=[django.core.validators.MinLengthValidator(1)]),
|
||||
),
|
||||
]
|
||||
18
cookbook/migrations/0094_auto_20201231_1238.py
Normal file
18
cookbook/migrations/0094_auto_20201231_1238.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.1.4 on 2020-12-31 11:38
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0093_auto_20201231_1236'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='shoppinglistrecipe',
|
||||
old_name='multiplier',
|
||||
new_name='servings',
|
||||
),
|
||||
]
|
||||
@@ -5,10 +5,12 @@ from datetime import date, timedelta
|
||||
from annoying.fields import AutoOneToOneField
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.core.validators import MinLengthValidator
|
||||
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
|
||||
from recipes.settings import COMMENT_PREF_DEFAULT, FRACTION_PREF_DEFAULT
|
||||
|
||||
|
||||
def get_user_name(self):
|
||||
@@ -68,6 +70,7 @@ class UserPreference(models.Model):
|
||||
theme = models.CharField(choices=THEMES, max_length=128, default=FLATLY)
|
||||
nav_color = models.CharField(choices=COLORS, max_length=128, default=PRIMARY)
|
||||
default_unit = models.CharField(max_length=32, default='g')
|
||||
use_fractions = models.BooleanField(default=FRACTION_PREF_DEFAULT)
|
||||
default_page = models.CharField(choices=PAGES, max_length=64, default=SEARCH)
|
||||
search_style = models.CharField(choices=SEARCH_STYLE, max_length=64, default=LARGE)
|
||||
show_recent = models.BooleanField(default=True)
|
||||
@@ -134,7 +137,7 @@ class Keyword(models.Model):
|
||||
|
||||
|
||||
class Unit(models.Model):
|
||||
name = models.CharField(unique=True, max_length=128)
|
||||
name = models.CharField(unique=True, max_length=128, validators=[MinLengthValidator(1)])
|
||||
description = models.TextField(blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
@@ -181,8 +184,20 @@ class Step(models.Model):
|
||||
ordering = ['order', 'pk']
|
||||
|
||||
|
||||
class NutritionInformation(models.Model):
|
||||
fats = models.DecimalField(default=0, decimal_places=16, max_digits=32)
|
||||
carbohydrates = models.DecimalField(default=0, decimal_places=16, max_digits=32)
|
||||
proteins = models.DecimalField(default=0, decimal_places=16, max_digits=32)
|
||||
calories = models.DecimalField(default=0, decimal_places=16, max_digits=32)
|
||||
source = models.CharField(max_length=512, default="", null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'Nutrition'
|
||||
|
||||
|
||||
class Recipe(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
servings = models.IntegerField(default=1)
|
||||
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)
|
||||
@@ -194,10 +209,13 @@ class Recipe(models.Model):
|
||||
working_time = models.IntegerField(default=0)
|
||||
waiting_time = models.IntegerField(default=0)
|
||||
internal = models.BooleanField(default=False)
|
||||
nutrition = models.ForeignKey(NutritionInformation, blank=True, null=True, on_delete=models.CASCADE)
|
||||
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
|
||||
|
||||
@@ -254,7 +272,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)
|
||||
servings = 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')
|
||||
@@ -276,7 +294,7 @@ class MealPlan(models.Model):
|
||||
|
||||
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)
|
||||
servings = models.DecimalField(default=1, max_digits=8, decimal_places=4)
|
||||
|
||||
def __str__(self):
|
||||
return f'Shopping list recipe {self.id} - {self.recipe}'
|
||||
|
||||
@@ -6,7 +6,7 @@ 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
|
||||
ShoppingListEntry, ShoppingListRecipe, NutritionInformation
|
||||
from cookbook.templatetags.custom_tags import markdown
|
||||
|
||||
|
||||
@@ -140,15 +140,26 @@ class StepSerializer(WritableNestedModelSerializer):
|
||||
fields = ('id', 'name', 'type', 'instruction', 'ingredients', 'time', 'order', 'show_as_header')
|
||||
|
||||
|
||||
class NutritionInformationSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = NutritionInformation
|
||||
fields = ('carbohydrates', 'fats', 'proteins', 'calories', 'source')
|
||||
|
||||
|
||||
class RecipeSerializer(WritableNestedModelSerializer):
|
||||
nutrition = NutritionInformationSerializer(allow_null=True, required=False)
|
||||
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']
|
||||
fields = ['id', 'name', 'image', 'keywords', 'steps', 'working_time', 'waiting_time', 'created_by', 'created_at', 'updated_at', 'internal', 'nutrition', 'servings']
|
||||
read_only_fields = ['image', 'created_by', 'created_at']
|
||||
|
||||
def create(self, validated_data):
|
||||
validated_data['created_by'] = self.context['request']._user
|
||||
return super().create(validated_data)
|
||||
|
||||
|
||||
class RecipeImageSerializer(WritableNestedModelSerializer):
|
||||
class Meta:
|
||||
@@ -191,23 +202,23 @@ 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()
|
||||
servings = CustomDecimalField()
|
||||
|
||||
def get_note_markdown(self, obj):
|
||||
return markdown(obj.note)
|
||||
|
||||
class Meta:
|
||||
model = MealPlan
|
||||
fields = ('id', 'title', 'recipe', 'recipe_multiplier', 'note', 'note_markdown', 'date', 'meal_type', 'created_by', 'shared', 'recipe_name', 'meal_type_name')
|
||||
fields = ('id', 'title', 'recipe', 'servings', '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()
|
||||
servings = CustomDecimalField()
|
||||
|
||||
class Meta:
|
||||
model = ShoppingListRecipe
|
||||
fields = ('id', 'recipe', 'recipe_name', 'multiplier')
|
||||
fields = ('id', 'recipe', 'recipe_name', 'servings')
|
||||
read_only_fields = ('id',)
|
||||
|
||||
|
||||
|
||||
43
cookbook/static/js/frac.js
Normal file
43
cookbook/static/js/frac.js
Normal file
@@ -0,0 +1,43 @@
|
||||
/* frac.js (C) 2012-present SheetJS -- http://sheetjs.com */
|
||||
/*https://developer.aliyun.com/mirror/npm/package/frac/v/0.3.0 Apache license*/
|
||||
var frac = function frac(x, D, mixed) {
|
||||
var n1 = Math.floor(x), d1 = 1;
|
||||
var n2 = n1+1, d2 = 1;
|
||||
if(x !== n1) while(d1 <= D && d2 <= D) {
|
||||
var m = (n1 + n2) / (d1 + d2);
|
||||
if(x === m) {
|
||||
if(d1 + d2 <= D) { d1+=d2; n1+=n2; d2=D+1; }
|
||||
else if(d1 > d2) d2=D+1;
|
||||
else d1=D+1;
|
||||
break;
|
||||
}
|
||||
else if(x < m) { n2 = n1+n2; d2 = d1+d2; }
|
||||
else { n1 = n1+n2; d1 = d1+d2; }
|
||||
}
|
||||
if(d1 > D) { d1 = d2; n1 = n2; }
|
||||
if(!mixed) return [0, n1, d1];
|
||||
var q = Math.floor(n1/d1);
|
||||
return [q, n1 - q*d1, d1];
|
||||
};
|
||||
frac.cont = function cont(x, D, mixed) {
|
||||
var sgn = x < 0 ? -1 : 1;
|
||||
var B = x * sgn;
|
||||
var P_2 = 0, P_1 = 1, P = 0;
|
||||
var Q_2 = 1, Q_1 = 0, Q = 0;
|
||||
var A = Math.floor(B);
|
||||
while(Q_1 < D) {
|
||||
A = Math.floor(B);
|
||||
P = A * P_1 + P_2;
|
||||
Q = A * Q_1 + Q_2;
|
||||
if((B - A) < 0.00000005) break;
|
||||
B = 1 / (B - A);
|
||||
P_2 = P_1; P_1 = P;
|
||||
Q_2 = Q_1; Q_1 = Q;
|
||||
}
|
||||
if(Q > D) { if(Q_1 > D) { Q = Q_2; P = P_2; } else { Q = Q_1; P = P_1; } }
|
||||
if(!mixed) return [0, sgn * P, Q];
|
||||
var q = Math.floor(sgn * P/Q);
|
||||
return [q, sgn*P - q*Q, Q];
|
||||
};
|
||||
// eslint-disable-next-line no-undef
|
||||
if(typeof module !== 'undefined' && typeof DO_NOT_EXPORT_FRAC === 'undefined') module.exports = frac;
|
||||
146
cookbook/static/js/vue-cookies.js
Normal file
146
cookbook/static/js/vue-cookies.js
Normal file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Vue Cookies v1.7.4
|
||||
* https://github.com/cmp-cc/vue-cookies
|
||||
*
|
||||
* Copyright 2016, cmp-cc
|
||||
* Released under the MIT license
|
||||
*/
|
||||
|
||||
(function () {
|
||||
|
||||
var defaultConfig = {
|
||||
expires: '1d',
|
||||
path: '; path=/',
|
||||
domain: '',
|
||||
secure: '',
|
||||
sameSite: '; SameSite=Lax'
|
||||
};
|
||||
|
||||
var VueCookies = {
|
||||
// install of Vue
|
||||
install: function (Vue) {
|
||||
Vue.prototype.$cookies = this;
|
||||
Vue.$cookies = this;
|
||||
},
|
||||
config: function (expireTimes, path, domain, secure, sameSite) {
|
||||
defaultConfig.expires = expireTimes ? expireTimes : '1d';
|
||||
defaultConfig.path = path ? '; path=' + path : '; path=/';
|
||||
defaultConfig.domain = domain ? '; domain=' + domain : '';
|
||||
defaultConfig.secure = secure ? '; Secure' : '';
|
||||
defaultConfig.sameSite = sameSite ? '; SameSite=' + sameSite : '; SameSite=Lax';
|
||||
},
|
||||
get: function (key) {
|
||||
var value = decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(key).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
|
||||
|
||||
if (value && value.substring(0, 1) === '{' && value.substring(value.length - 1, value.length) === '}') {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (e) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
},
|
||||
set: function (key, value, expireTimes, path, domain, secure, sameSite) {
|
||||
if (!key) {
|
||||
throw new Error('Cookie name is not find in first argument.');
|
||||
} else if (/^(?:expires|max\-age|path|domain|secure|SameSite)$/i.test(key)) {
|
||||
throw new Error('Cookie key name illegality, Cannot be set to ["expires","max-age","path","domain","secure","SameSite"]\t current key name: ' + key);
|
||||
}
|
||||
// support json object
|
||||
if (value && value.constructor === Object) {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
var _expires = '';
|
||||
expireTimes = expireTimes == undefined ? defaultConfig.expires : expireTimes;
|
||||
if (expireTimes && expireTimes != 0) {
|
||||
switch (expireTimes.constructor) {
|
||||
case Number:
|
||||
if (expireTimes === Infinity || expireTimes === -1) _expires = '; expires=Fri, 31 Dec 9999 23:59:59 GMT';
|
||||
else _expires = '; max-age=' + expireTimes;
|
||||
break;
|
||||
case String:
|
||||
if (/^(?:\d+(y|m|d|h|min|s))$/i.test(expireTimes)) {
|
||||
// get capture number group
|
||||
var _expireTime = expireTimes.replace(/^(\d+)(?:y|m|d|h|min|s)$/i, '$1');
|
||||
// get capture type group , to lower case
|
||||
switch (expireTimes.replace(/^(?:\d+)(y|m|d|h|min|s)$/i, '$1').toLowerCase()) {
|
||||
// Frequency sorting
|
||||
case 'm':
|
||||
_expires = '; max-age=' + +_expireTime * 2592000;
|
||||
break; // 60 * 60 * 24 * 30
|
||||
case 'd':
|
||||
_expires = '; max-age=' + +_expireTime * 86400;
|
||||
break; // 60 * 60 * 24
|
||||
case 'h':
|
||||
_expires = '; max-age=' + +_expireTime * 3600;
|
||||
break; // 60 * 60
|
||||
case 'min':
|
||||
_expires = '; max-age=' + +_expireTime * 60;
|
||||
break; // 60
|
||||
case 's':
|
||||
_expires = '; max-age=' + _expireTime;
|
||||
break;
|
||||
case 'y':
|
||||
_expires = '; max-age=' + +_expireTime * 31104000;
|
||||
break; // 60 * 60 * 24 * 30 * 12
|
||||
default:
|
||||
new Error('unknown exception of "set operation"');
|
||||
}
|
||||
} else {
|
||||
_expires = '; expires=' + expireTimes;
|
||||
}
|
||||
break;
|
||||
case Date:
|
||||
_expires = '; expires=' + expireTimes.toUTCString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
document.cookie =
|
||||
encodeURIComponent(key) + '=' + encodeURIComponent(value) +
|
||||
_expires +
|
||||
(domain ? '; domain=' + domain : defaultConfig.domain) +
|
||||
(path ? '; path=' + path : defaultConfig.path) +
|
||||
(secure == undefined ? defaultConfig.secure : secure ? '; Secure' : '') +
|
||||
(sameSite == undefined ? defaultConfig.sameSite : (sameSite ? '; SameSite=' + sameSite : ''));
|
||||
return this;
|
||||
},
|
||||
remove: function (key, path, domain) {
|
||||
if (!key || !this.isKey(key)) {
|
||||
return false;
|
||||
}
|
||||
document.cookie = encodeURIComponent(key) +
|
||||
'=; expires=Thu, 01 Jan 1970 00:00:00 GMT' +
|
||||
(domain ? '; domain=' + domain : defaultConfig.domain) +
|
||||
(path ? '; path=' + path : defaultConfig.path) +
|
||||
'; SameSite=Lax';
|
||||
return this;
|
||||
},
|
||||
isKey: function (key) {
|
||||
return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(key).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=')).test(document.cookie);
|
||||
},
|
||||
keys: function () {
|
||||
if (!document.cookie) return [];
|
||||
var _keys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, '').split(/\s*(?:\=[^;]*)?;\s*/);
|
||||
for (var _index = 0; _index < _keys.length; _index++) {
|
||||
_keys[_index] = decodeURIComponent(_keys[_index]);
|
||||
}
|
||||
return _keys;
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof exports == 'object') {
|
||||
module.exports = VueCookies;
|
||||
} else if (typeof define == 'function' && define.amd) {
|
||||
define([], function () {
|
||||
return VueCookies;
|
||||
});
|
||||
} else if (window.Vue) {
|
||||
Vue.use(VueCookies);
|
||||
}
|
||||
// vue-cookies can exist independently,no dependencies library
|
||||
if (typeof window !== 'undefined') {
|
||||
window.$cookies = VueCookies;
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -84,7 +84,7 @@
|
||||
<li class="nav-item dropdown {% if request.resolver_match.url_name in 'list_keyword,data_batch_edit' %}active{% endif %}">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
|
||||
aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fas fa-tags"></i> {% trans 'Tags' %}
|
||||
<i class="fas fa-tags"></i> {% trans 'Keywords' %}
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||
<a class="dropdown-item" href="{% url 'list_keyword' %}"><i
|
||||
@@ -139,7 +139,7 @@
|
||||
{% endif %}
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="{% url 'docs_markdown' %}"><i
|
||||
class="fab fa-markdown fa-fw"></i> {% trans 'Markdown Help' %}</a>
|
||||
class="fab fa-markdown fa-fw"></i> {% trans 'Markdown Guide' %}</a>
|
||||
<a class="dropdown-item" href="https://github.com/vabene1111/recipes"><i
|
||||
class="fab fa-github fa-fw"></i> {% trans 'GitHub' %}</a>
|
||||
<a class="dropdown-item" href="{% url 'docs_api' %}"><i
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
<div class="card border-info">
|
||||
<div class="card-body text-info">
|
||||
<p class="card-text">
|
||||
{% trans 'On this Page you can manage all storage folder locations that should be monitored and synced' %}
|
||||
{% trans 'On this Page you can manage all storage folder locations that should be monitored and synced.' %}
|
||||
<br/>
|
||||
{% trans 'The path must be in the following format' %} <code>/Folder/RecipesFolder</code>
|
||||
{% trans 'The path must be in the following format' %}: <code>/Folder/RecipesFolder</code>
|
||||
</p>
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
|
||||
@@ -56,12 +56,15 @@
|
||||
<input type="file" @change="imageChanged">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="id_name"> {% trans 'Preperation Time' %}</label>
|
||||
<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 'Servings' %}</label>
|
||||
<input class="form-control" id="id_servings" v-model="recipe.servings">
|
||||
<br/>
|
||||
<label for="id_name"> {% trans 'Keywords' %}</label>
|
||||
<multiselect
|
||||
v-model="recipe.keywords"
|
||||
@@ -80,6 +83,35 @@
|
||||
</multiselect>
|
||||
</div>
|
||||
</div>
|
||||
<template v-if="recipe !== undefined">
|
||||
<div class="row" v-if="recipe.nutrition" style="margin-top: 1vh">
|
||||
<div class="col-md-12">
|
||||
<div class="card border-grey">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">{% trans 'Nutrition' %}</h4>
|
||||
<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>
|
||||
|
||||
</div>
|
||||
|
||||
<label for="id_name"> {% trans 'Calories' %}</label>
|
||||
<input class="form-control" id="id_calories" v-model="recipe.nutrition.calories">
|
||||
|
||||
<label for="id_name"> {% trans 'Carbohydrates' %}</label>
|
||||
<input class="form-control" id="id_carbohydrates" v-model="recipe.nutrition.carbohydrates">
|
||||
|
||||
<label for="id_name"> {% trans 'Fats' %}</label>
|
||||
<input class="form-control" id="id_fats" v-model="recipe.nutrition.fats">
|
||||
<label for="id_name"> {% trans 'Proteins' %}</label>
|
||||
<input class="form-control" id="id_proteins" v-model="recipe.nutrition.proteins">
|
||||
<br/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<draggable :list="recipe.steps" group="steps"
|
||||
@@ -319,7 +351,7 @@
|
||||
<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>
|
||||
: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>
|
||||
@@ -327,7 +359,7 @@
|
||||
</div>
|
||||
</draggable>
|
||||
|
||||
<div class="row" style="margin-top: 1vh; margin-bottom: 8vh">
|
||||
<div class="row" style="margin-top: 1vh; margin-bottom: 8vh" v-if="recipe !== undefined">
|
||||
<div class="col-12">
|
||||
<button type="button" @click="updateRecipe(true)"
|
||||
class="btn btn-success shadow-none">{% trans 'Save & View' %}</button>
|
||||
@@ -335,6 +367,11 @@
|
||||
class="btn btn-info shadow-none">{% trans 'Save' %}</button>
|
||||
<button type="button" @click="addStep()"
|
||||
class="btn btn-primary shadow-none">{% trans 'Add Step' %}</button>
|
||||
<button type="button" @click="addNutrition()"
|
||||
class="btn btn-primary shadow-none"
|
||||
v-if="recipe.nutrition === null">{% trans 'Add Nutrition' %}</button>
|
||||
<button type="button" @click="removeNutrition()" v-if="recipe.nutrition !== null"
|
||||
class="btn btn-warning shadow-none">{% trans 'Remove Nutrition' %}</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 %}"
|
||||
@@ -349,7 +386,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content_xl_right %}
|
||||
<div class="sticky-top" style="top: 2vh; z-index: 100;">
|
||||
<div class="sticky-top" style="top: 2vh; z-index: 100;" v-if="recipe !== undefined">
|
||||
<div class="row">
|
||||
<div class="col-md-11">
|
||||
<button type="button" @click="updateRecipe(true)"
|
||||
@@ -361,6 +398,12 @@
|
||||
<button type="button" @click="addStep()"
|
||||
class="btn btn-primary btn-block shadow-none">{% trans 'Add Step' %}</button>
|
||||
|
||||
<button type="button" @click="addNutrition()"
|
||||
class="btn btn-primary btn-block shadow-none"
|
||||
v-if="recipe.nutrition === null">{% trans 'Add Nutrition' %}</button>
|
||||
<button type="button" @click="removeNutrition()" v-if="recipe.nutrition !== null"
|
||||
class="btn btn-warning btn-block shadow-none">{% trans 'Remove Nutrition' %}</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 %}"
|
||||
@@ -399,6 +442,8 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
|
||||
<script src="{% url 'javascript-catalog' %}"></script>
|
||||
<script type="application/javascript">
|
||||
let csrftoken = Cookies.get('csrftoken');
|
||||
Vue.http.headers.common['X-CSRFToken'] = csrftoken;
|
||||
@@ -455,8 +500,8 @@
|
||||
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_','')]
|
||||
if (el.id !== undefined && el.id.includes('id_card_step_')) {
|
||||
let step = this.recipe.steps[el.id.replace('id_card_step_', '')]
|
||||
this.addIngredient(step)
|
||||
}
|
||||
}
|
||||
@@ -491,7 +536,7 @@
|
||||
}).catch((err) => {
|
||||
this.loading = false
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading the recipe!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading the recipe!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
updateRecipe: function (view_after) {
|
||||
@@ -502,14 +547,14 @@
|
||||
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.makeToast(gettext('Updated'), gettext('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')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error updating the recipe!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
imageChanged: function (event) {
|
||||
@@ -519,11 +564,11 @@
|
||||
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')
|
||||
this.makeToast(gettext('Updated'), gettext('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')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error updating the recipe!') + err.body.image, 'danger')
|
||||
})
|
||||
|
||||
let reader = new FileReader();
|
||||
@@ -567,12 +612,12 @@
|
||||
|
||||
},
|
||||
removeIngredient: function (step, ingredient) {
|
||||
if (confirm('{% trans 'Are you sure that you want to delete this ingredient?' %}')) {
|
||||
if (confirm(gettext('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?' %}')) {
|
||||
if (confirm(gettext('Are you sure that you want to delete this step?'))) {
|
||||
this.recipe.steps = this.recipe.steps.filter(item => item !== step)
|
||||
}
|
||||
},
|
||||
@@ -604,7 +649,7 @@
|
||||
this.keywords_loading = false
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
searchUnits: function (query) {
|
||||
@@ -623,7 +668,7 @@
|
||||
}
|
||||
this.units_loading = false
|
||||
}).catch((err) => {
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
searchFoods: function (query) {
|
||||
@@ -643,12 +688,18 @@
|
||||
|
||||
this.foods_loading = false
|
||||
}).catch((err) => {
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
scrollToStep: function (step_index) {
|
||||
document.getElementById('id_step_' + step_index).scrollIntoView({behavior: 'smooth'});
|
||||
},
|
||||
addNutrition: function () {
|
||||
this.recipe.nutrition = {}
|
||||
},
|
||||
removeNutrition: function () {
|
||||
this.recipe.nutrition = null
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
<h4>{% trans 'Units' %}</h4>
|
||||
<form action="{% url 'edit_food' %}" method="post"
|
||||
onsubmit="return confirm('{% trans 'Are you sure that you want to merge these two units ?' %}')">
|
||||
onsubmit="return confirm('{% trans 'Are you sure that you want to merge these two units?' %}')">
|
||||
{% csrf_token %}
|
||||
{{ units_form|crispy }}
|
||||
<button class="btn btn-danger" type="submit"
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
<h4>{% trans 'Ingredients' %}</h4>
|
||||
<form action="{% url 'edit_food' %}" method="post"
|
||||
onsubmit="return confirm('{% trans 'Are you sure that you want to merge these two ingredients ?' %}')">
|
||||
onsubmit="return confirm('{% trans 'Are you sure that you want to merge these two ingredients?' %}')">
|
||||
{% csrf_token %}
|
||||
{{ food_form|crispy }}
|
||||
<button class="btn btn-danger" type="submit">
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="collapse col-md-12" id="collapse_adv_search">
|
||||
<div class="collapse col-md-12{% if filter.data.keywords or filter.data.foods or filter.data.internal and not filter.data.internal == "unknown" %} show{% endif %}" id="collapse_adv_search">
|
||||
<div style="margin-top: 1vh">
|
||||
{{ filter.form.keywords | as_crispy_field }}
|
||||
</div>
|
||||
@@ -91,7 +91,7 @@
|
||||
{% render_table recipes %}
|
||||
{% else %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{% trans "Log in to view Recipes" %}
|
||||
{% trans "Log in to view recipes" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
{% blocktrans %}
|
||||
Markdown is lightweight markup language that can be used to format plain text easily.
|
||||
This site uses the <a href="https://python-markdown.github.io/" target="_blank">Python Markdown</a> library to
|
||||
convert your text into nice looking html. Its full markdown documentation can be found
|
||||
convert your text into nice looking HTML. Its full markdown documentation can be found
|
||||
<a href="https://daringfireball.net/projects/markdown/syntax" target="_blank">here</a>.
|
||||
An incomplete but most likely sufficient documentation can be found below.
|
||||
{% endblocktrans %}
|
||||
@@ -57,7 +57,7 @@
|
||||
{% trans 'or by leaving a blank line inbetween.' %}
|
||||
|
||||
**{% trans 'This text is bold' %}**
|
||||
*{% trans 'This text is in italics' %}*
|
||||
*{% trans 'This text is italic' %}*
|
||||
> {% trans 'Blockquotes are also possible' %}
|
||||
</code></pre>
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
{% trans 'Line breaks are inserted by adding two spaces after the end of a line' %}<br/>
|
||||
{% trans 'or by leaving a blank line inbetween.' %}<br/><br/>
|
||||
<b>{% trans 'This text is bold' %}</b><br/>
|
||||
<i>{% trans 'This text is in italics' %}</i>
|
||||
<i>{% trans 'This text is italic' %}</i>
|
||||
<blockquote>
|
||||
<p>{% trans 'Blockquotes are also possible' %}</p>
|
||||
</blockquote>
|
||||
@@ -123,13 +123,13 @@
|
||||
|
||||
<br/>
|
||||
<h2>{% trans 'Images & Links' %}</h2>
|
||||
{% trans 'Links can be formatted with Markdown. This applicaiton also allows to paste links directly into markdown fields without any formatting.' %}
|
||||
{% trans 'Links can be formatted with Markdown. This application also allows to paste links directly into markdown fields without any formatting.' %}
|
||||
<pre class="intro-code code-block"><code>
|
||||
https://github.com/vabene1111/recipes
|
||||
[](https://github.com/vabene1111/recipes)
|
||||
[GitHub](https://github.com/vabene1111/recipes)
|
||||
|
||||

|
||||

|
||||
</code></pre>
|
||||
|
||||
<div style="text-align: center">
|
||||
@@ -142,7 +142,7 @@
|
||||
<div class="card-body">
|
||||
<a href="https://github.com/vabene1111/recipes">https://github.com/vabene1111/recipes</a> <br/>
|
||||
<a href="https://github.com/vabene1111/recipes">GitHub</a> <br/>
|
||||
<img src="{% static 'favicon.png' %}" class="img-fluid" alt="{% trans 'This will become and Image' %}"
|
||||
<img src="{% static 'favicon.png' %}" class="img-fluid" alt="{% trans 'This will become and image' %}"
|
||||
style="height: 3vw">
|
||||
</div>
|
||||
|
||||
@@ -150,7 +150,7 @@
|
||||
|
||||
<br/>
|
||||
<h2>{% trans 'Tables' %}</h2>
|
||||
{% trans 'Markdown tables are hard to create by hand. It is recommended to use a table editor like <a href="https://www.tablesgenerator.com/markdown_tables" target="_blank">this</a> one.' %}
|
||||
{% trans 'Markdown tables are hard to create by hand. It is recommended to use a table editor like <a href="https://www.tablesgenerator.com/markdown_tables" rel="noreferrer noopener" target="_blank">this one.</a>' %}
|
||||
<pre class="intro-code code-block"><code>
|
||||
| {% trans 'Table' %} | {% trans 'Header' %} |
|
||||
|--------|---------|
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
<script src="{% static 'js/Sortable.min.js' %}"></script>
|
||||
<script src="{% static 'js/vuedraggable.umd.min.js' %}"></script>
|
||||
<script src="{% static 'js/vue-cookies.js' %}"></script>
|
||||
|
||||
<script src="{% static 'js/js.cookie.min.js' %}"></script>
|
||||
|
||||
@@ -24,14 +25,15 @@
|
||||
<div class="col-md-4 offset-md-4">
|
||||
<div class="input-group" style="margin-top: 8px; margin-bottom: 8px">
|
||||
<div class="input-group-prepend">
|
||||
<button class="btn btn-outline-secondary shadow-none" @click="changeWeek(-1)">
|
||||
<button class="btn btn-outline-secondary shadow-none"
|
||||
@click="changeStartDate(number_of_days * -1)">
|
||||
<i class="fas fa-arrow-left"></i>
|
||||
</button>
|
||||
</div>
|
||||
<input name="week" id="id_week" class="form-control" type="week" v-model="week"
|
||||
<input name="date" id="id_date" class="form-control" type="date" v-model="start_date"
|
||||
@change="updatePlan()">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-secondary shadow-none" @click="changeWeek(1)">
|
||||
<button class="btn btn-outline-secondary shadow-none" @click="changeStartDate(number_of_days)">
|
||||
<i class="fas fa-arrow-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
@@ -41,10 +43,10 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<table class="table table-sm table-striped table-responsive-sm">
|
||||
<table class="table table-sm table-striped table-responsive-sm" style=" table-layout:fixed;">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th v-for="d in days" style="width: 14.2%; text-align: center">[[d]]<br/>[[formatDateDay(d)]].
|
||||
<th v-for="d in dates" style="width: 14.2%; text-align: center">[[formatDateDayname(d)]]<br/>[[formatDateDay(d)]].
|
||||
<button class="btn btn-sm btn-outline-secondary shadow-none" @click="addDayToShopping(d)"><i
|
||||
class="fas fa-cart-plus fa-sm"></i></button>
|
||||
</th>
|
||||
@@ -52,7 +54,7 @@
|
||||
</thead>
|
||||
<tbody v-for="t in meal_types">
|
||||
<tr v-if="meal_plan[t.name] !== undefined">
|
||||
<td colspan="7" style="text-align: center">
|
||||
<td :colspan="number_of_days" style="text-align: center">
|
||||
[[ meal_plan[t.name].name]]
|
||||
<template
|
||||
v-if="t.created_by !== {{ request.user.pk }} && user_names[t.created_by] !== undefined">
|
||||
@@ -66,18 +68,21 @@
|
||||
@change="dragChanged(d.date, t, $event)"
|
||||
:empty-insert-threshold="10" handle=".handle">
|
||||
<div class="" v-for="(element, index) in d.items" :key="element.id">
|
||||
<!-- small layout with handle -->
|
||||
<div class="d-block d-md-none">
|
||||
<div class="col-">
|
||||
<i class="fas fa-arrows-alt handle input-group-text"
|
||||
style="width: 100%"></i>
|
||||
</div>
|
||||
<div class="list-group-item">
|
||||
<div class="list-group-item" style="word-wrap: break-word;">
|
||||
<a href="#" @click="plan_detail = element" data-toggle="modal"
|
||||
data-target="#id_plan_detail_modal">[[ planElementName(element)]]</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="list-group-item handle d-md-block d-none">
|
||||
<div class="col-md-12">
|
||||
<!-- big layout -->
|
||||
<div class="list-group-item handle d-md-block d-none"
|
||||
style="word-wrap: break-word; padding: 2;margin-bottom: 4">
|
||||
<div class="col-md-12" style="padding: 0">
|
||||
<a href="#" @click="plan_detail = element" data-toggle="modal"
|
||||
data-target="#id_plan_detail_modal">[[ planElementName(element)]]</a>
|
||||
</div>
|
||||
@@ -103,14 +108,25 @@
|
||||
<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"
|
||||
:group="{ name: 'plan', pull: 'clone', put: false }" :clone="cloneRecipe">
|
||||
<div class="list-group-item" v-for="(element, index) in recipes" :key="element.id">
|
||||
<i class="fas fa-arrows-alt"></i> [[element.name]]
|
||||
<div class="list-group-item d-flex align-items-center justify-content-between" v-for="(element, index) in recipes" :key="element.id">
|
||||
<span>
|
||||
<i class="fas fa-arrows-alt"></i> [[element.name]]
|
||||
</span>
|
||||
<span class="badge badge-light badge-pill">[[element.servings]]</span>
|
||||
</div>
|
||||
</draggable>
|
||||
</div>
|
||||
@@ -126,8 +142,8 @@
|
||||
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">
|
||||
<input type="number" class="form-control" v-model="new_note_servings"
|
||||
placeholder="{% trans 'Serving Count' %}" style="margin-bottom: 8px">
|
||||
<br/>
|
||||
<draggable :list="pseudo_note_list"
|
||||
:group="{ name: 'plan', pull: 'clone', put: false }" :clone="cloneNote">
|
||||
@@ -152,7 +168,7 @@
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<template v-if="shopping_list.length < 1">{% trans 'Shopping List currently empty' %}</template>
|
||||
<template v-if="shopping_list.length < 1">{% trans 'Shopping list currently empty' %}</template>
|
||||
<template v-else>
|
||||
<a v-bind:href="getShoppingUrl()" class="btn btn-success"
|
||||
target="_blank">{% trans 'Open Shopping List' %}</a>
|
||||
@@ -173,6 +189,29 @@
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<label>
|
||||
{% trans 'Number of Days' %}
|
||||
<input class="form-control" type="number" v-model="number_of_days"
|
||||
@change="updatePlan(); $cookies.set('number_of_days',number_of_days)">
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<label>
|
||||
{% trans 'Weekday offset' %}
|
||||
<input class="form-control" type="number" v-model="start_offset"
|
||||
@change="updatePlan(); $cookies.set('start_offset',start_offset)">
|
||||
<small class="text-muted">{% trans 'Number of days starting from the first day of the week to offset the default view.' %}</small>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<a href="#" data-toggle="modal"
|
||||
data-target="#id_plan_types_modal">{% trans 'Edit plan types' %}</a> <br/>
|
||||
<a href="#" data-toggle="modal"
|
||||
@@ -207,6 +246,9 @@
|
||||
<small class="text-muted">{% trans 'Recipe' %}</small><br/>
|
||||
<a v-bind:href="planDetailRecipeUrl()" target="_blank">[[ plan_detail.recipe_name ]]</a>
|
||||
<br/>
|
||||
<br/>
|
||||
<small class="text-muted">{% trans 'Serving Count' %}</small><br/>
|
||||
<span>[[ plan_detail.servings ]]</span>
|
||||
</template>
|
||||
|
||||
<template v-if="plan_detail.note !== ''">
|
||||
@@ -299,12 +341,12 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
{% blocktrans %}
|
||||
<p>The meal plan module allows planning of meals both with recipes or just notes.</p>
|
||||
<p>The meal plan module allows planning of meals both with recipes and notes.</p>
|
||||
<p>Simply select a recipe from the list of recently viewed recipes or search the one you
|
||||
want and drag it to the desired plan position. You can also add a note and a title and
|
||||
then drag the recipe to create a plan entry with a custom title and note. Creating only
|
||||
Notes is possible by dragging the create note box into the plan.</p>
|
||||
<p>Click on a recipe in order to open the detail view. Here you can also add it to the
|
||||
<p>Click on a recipe in order to open the detailed view. There you can also add it to the
|
||||
shopping list. You can also add all recipes of a day to the shopping list by
|
||||
clicking the shopping cart at the top of the table.</p>
|
||||
<p>Since a common use case is to plan meals together you can define
|
||||
@@ -327,7 +369,8 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<script src="{% url 'javascript-catalog' %}"></script>
|
||||
<script type="application/javascript">
|
||||
moment.locale('{{request.LANGUAGE_CODE}}');
|
||||
|
||||
@@ -338,8 +381,10 @@
|
||||
delimiters: ['[[', ']]'],
|
||||
el: '#app',
|
||||
data: {
|
||||
week: moment().format('YYYY-[W]WW'),
|
||||
days: moment.weekdays(true),
|
||||
start_date: undefined,
|
||||
start_offset: 0,
|
||||
dates: [],
|
||||
number_of_days: $cookies.isKey('number_of_days') ? $cookies.get('number_of_days') : 7,
|
||||
plan_entries: [],
|
||||
meal_types: [],
|
||||
meal_types_edit: [],
|
||||
@@ -352,7 +397,7 @@
|
||||
],
|
||||
new_note_title: '',
|
||||
new_note_text: '',
|
||||
new_note_multiplier: '',
|
||||
new_note_servings: '',
|
||||
default_shared_users: [],
|
||||
user_id_update: [],
|
||||
user_names: {},
|
||||
@@ -367,6 +412,9 @@
|
||||
this.$set(this.user_names, {{ request.user.pk }}, '{{ request.user.get_user_name }}')
|
||||
this.user_id_update = Array.from(this.default_shared_users)
|
||||
|
||||
this.start_offset = $cookies.isKey('start_offset') ? $cookies.get('start_offset') : 0;
|
||||
this.start_date = moment().weekday(0).add(this.start_offset, 'days').format('YYYY-MM-DD')
|
||||
|
||||
this.updatePlan();
|
||||
this.getRecipes();
|
||||
},
|
||||
@@ -381,6 +429,11 @@
|
||||
})
|
||||
},
|
||||
updatePlan: function () {
|
||||
this.dates = [];
|
||||
for (var i = 0; i <= (this.number_of_days - 1); i++) {
|
||||
this.dates.push(moment(this.start_date).add(i, 'days'));
|
||||
}
|
||||
|
||||
let planEntryPromise = this.getPlanEntries();
|
||||
let planTypePromise = this.getPlanTypes();
|
||||
|
||||
@@ -389,11 +442,11 @@
|
||||
})
|
||||
},
|
||||
getPlanEntries: function () {
|
||||
return this.$http.get("{% url 'api:mealplan-list' %}?html_week=" + this.week).then((response) => {
|
||||
return this.$http.get("{% url 'api:mealplan-list' %}?from_date=" + this.dates[0].format('YYYY-MM-DD') + "&to_date=" + this.dates[this.dates.length - 1].format('YYYY-MM-DD')).then((response) => {
|
||||
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')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
getPlanTypes: function () {
|
||||
@@ -405,7 +458,7 @@
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log("getPlanTypes error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
buildGrid: function () {
|
||||
@@ -424,11 +477,10 @@
|
||||
meal_type: t.id,
|
||||
days: {}
|
||||
})
|
||||
for (let d of this.days) {
|
||||
let date = moment(this.week).weekday(this.days.indexOf(d)).format('YYYY-MM-DD')
|
||||
this.$set(this.meal_plan[t.name].days, date, {
|
||||
name: d,
|
||||
date: date,
|
||||
for (let d of this.dates) {
|
||||
this.$set(this.meal_plan[t.name].days, d.format('YYYY-MM-DD'), {
|
||||
name: this.formatDateDayname(d),
|
||||
date: d.format('YYYY-MM-DD'),
|
||||
items: []
|
||||
})
|
||||
}
|
||||
@@ -445,17 +497,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')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
getMdNote: function () {
|
||||
@@ -468,7 +526,7 @@
|
||||
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')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
updateUserNames: function () {
|
||||
@@ -479,7 +537,7 @@
|
||||
|
||||
}).catch((err) => {
|
||||
console.log("updateUserNames error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
dragChanged: function (date, meal_type, evt) {
|
||||
@@ -505,7 +563,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')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -516,7 +574,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')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
updatePlanTypes: function () {
|
||||
@@ -530,14 +588,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')
|
||||
this.makeToast(gettext('Error'), gettext('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')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
}))
|
||||
}
|
||||
} else {
|
||||
@@ -545,7 +603,7 @@
|
||||
|
||||
}).catch((err) => {
|
||||
console.log("updatePlanTypes update error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -555,7 +613,7 @@
|
||||
})
|
||||
},
|
||||
markTypeDelete: function (element) {
|
||||
if (confirm('{% trans 'When deleting a meal type all entries using that type will be deleted as well. Deletion will apply when configuration is saved. Do you want to proceed?' %}')) {
|
||||
if (confirm(gettext('When deleting a meal type all entries using that type will be deleted as well. Deletion will apply when configuration is saved. Do you want to proceed?'))) {
|
||||
element.delete = true
|
||||
}
|
||||
},
|
||||
@@ -564,7 +622,7 @@
|
||||
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,
|
||||
servings: (this.new_note_servings > 1) ? this.new_note_servings : recipe.servings,
|
||||
title: this.new_note_title,
|
||||
note: this.new_note_text,
|
||||
is_new: true
|
||||
@@ -572,7 +630,7 @@
|
||||
|
||||
this.new_note_title = ''
|
||||
this.new_note_text = ''
|
||||
this.new_note_multiplier = ''
|
||||
this.new_note_servings = ''
|
||||
|
||||
return r
|
||||
},
|
||||
@@ -581,16 +639,17 @@
|
||||
id: Math.round(Math.random() * 1000) + 10000,
|
||||
title: this.new_note_title,
|
||||
note: this.new_note_text,
|
||||
servings: 1,
|
||||
is_new: true,
|
||||
}
|
||||
|
||||
if (new_entry.title === '') {
|
||||
new_entry.title = '{% trans 'Title' %}'
|
||||
new_entry.title = gettext('Title')
|
||||
}
|
||||
|
||||
this.new_note_title = ''
|
||||
this.new_note_text = ''
|
||||
this.new_note_multiplier = ''
|
||||
this.new_note_servings = ''
|
||||
return new_entry
|
||||
},
|
||||
planElementName: function (element) {
|
||||
@@ -618,11 +677,14 @@
|
||||
formatLocalDate: function (date) {
|
||||
return moment(date).format('LL')
|
||||
},
|
||||
formatDateDay: function (day) {
|
||||
return moment(this.week).weekday(this.days.indexOf(day)).format('D')
|
||||
formatDateDay: function (date) {
|
||||
return moment(date).format('D')
|
||||
},
|
||||
changeWeek: function (change) {
|
||||
this.week = moment(this.week).add(change, 'w').format('YYYY-[W]WW')
|
||||
formatDateDayname: function (date) {
|
||||
return moment(date).format('dddd')
|
||||
},
|
||||
changeStartDate: function (change) {
|
||||
this.start_date = moment(this.start_date).add(change, 'days').format('YYYY-MM-DD')
|
||||
this.updatePlan();
|
||||
},
|
||||
getShoppingUrl: function () {
|
||||
@@ -630,22 +692,23 @@
|
||||
let first = true
|
||||
for (let se of this.shopping_list) {
|
||||
if (first) {
|
||||
url += `?r=[${se.recipe},${se.recipe_multiplier}]`
|
||||
url += `?r=[${se.recipe},${se.servings}]`
|
||||
first = false
|
||||
} else {
|
||||
url += `&r=[${se.recipe},${se.recipe_multiplier}]`
|
||||
url += `&r=[${se.recipe},${se.servings}]`
|
||||
}
|
||||
}
|
||||
return url
|
||||
},
|
||||
getIcalUrl: function () {
|
||||
return "{% url 'api_get_plan_ical' 12345 %}".replace(/12345/, this.week);
|
||||
if (this.dates.length === 0) {
|
||||
return ""
|
||||
}
|
||||
return "{% url 'api_get_plan_ical' 12345 6789 %}".replace(/12345/, this.dates[0].format('YYYY-MM-DD')).replace(/6789/, this.dates[this.dates.length - 1].format('YYYY-MM-DD'));
|
||||
},
|
||||
addDayToShopping: function (day) {
|
||||
let date = moment(this.week).weekday(this.days.indexOf(day)).format('YYYY-MM-DD')
|
||||
|
||||
addDayToShopping: function (date) {
|
||||
for (let t of this.meal_types) {
|
||||
for (let i of this.meal_plan[t.name].days[date].items) {
|
||||
for (let i of this.meal_plan[t.name].days[date.format('YYYY-MM-DD')].items) {
|
||||
if (!this.shopping_list.includes(i)) {
|
||||
this.shopping_list.push(i)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
{% include 'include/vue_base.html' %}
|
||||
<script src="{% static 'js/moment-with-locales.min.js' %}"></script>
|
||||
|
||||
<script src="{% static 'js/frac.js' %}"></script>
|
||||
|
||||
<link rel="stylesheet" href="{% static 'css/pretty-checkbox.min.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'custom/css/markdown_blockquote.css' %}">
|
||||
|
||||
@@ -37,7 +39,7 @@
|
||||
<button class="dropdown-item" onclick="$('#bookmarkModal').modal({'show':true})">
|
||||
<i class="fas fa-bookmark fa-fw"></i> {% trans 'Add to Book' %}</button>
|
||||
|
||||
<a class="dropdown-item" v-bind:href="getShoppingUrl()" v-if="has_ingredients">
|
||||
<a class="dropdown-item" v-bind:href="shopping_url" 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
|
||||
@@ -77,13 +79,13 @@
|
||||
|
||||
{% if recipe.working_time and recipe.working_time != 0 %}
|
||||
<span class="badge badge-secondary"><i
|
||||
class="fas fa-user-clock"></i> {% trans 'Preparation time ca.' %} {{ recipe.working_time }} min </span>
|
||||
class="fas fa-user-clock"></i> {% trans 'Preparation time ~' %} {{ recipe.working_time }} min </span>
|
||||
{% endif %}
|
||||
|
||||
{% if recipe.waiting_time and recipe.waiting_time != 0 %}
|
||||
<span
|
||||
class="badge badge-secondary"><i
|
||||
class="far fa-clock"></i> {% trans 'Waiting time ca.' %} {{ recipe.waiting_time }} min </span>
|
||||
class="far fa-clock"></i> {% trans 'Waiting time ~' %} {{ recipe.waiting_time }} min </span>
|
||||
{% endif %}
|
||||
{% recipe_last recipe request.user as last_cooked %}
|
||||
{% if last_cooked %}
|
||||
@@ -107,8 +109,8 @@
|
||||
<div class="col col-md-3">
|
||||
|
||||
<div class="input-group d-print-none">
|
||||
<input type="number" value="1" maxlength="3" class="form-control"
|
||||
v-model="ingredient_factor"/>
|
||||
<input type="number" value="1" maxlength="3" class="form-control" style="min-width: 2vw"
|
||||
v-model="servings"/>
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text"><i class="fas fa-calculator"></i></span>
|
||||
</div>
|
||||
@@ -150,7 +152,7 @@
|
||||
<span>⁣</span>
|
||||
</template>
|
||||
<template v-if="!i.no_amount">
|
||||
<span>[[roundDecimals(i.amount * ingredient_factor)]]</span>
|
||||
<span v-html="calculateAmount(i.amount)"></span>
|
||||
{# Allow for amounts without units, such as "2 eggs" #}
|
||||
<template v-if="i.unit">
|
||||
[[i.unit.name]]
|
||||
@@ -208,6 +210,60 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if recipe.nutrition %}
|
||||
<div class="row mt-5">
|
||||
<div class="col-md-6 order-md-1 col-sm-12 order-sm-2 col-12 order-2">
|
||||
<div class="card border-primary">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">{% trans 'Nutrition' %}</h4>
|
||||
<table class="table table-sm">
|
||||
<tr>
|
||||
<td style="padding-top: 8px!important; ">
|
||||
<b>{% trans 'Calories' %}</b>
|
||||
</td>
|
||||
<td style="text-align: right">{{ recipe.nutrition.calories|floatformat:2 }}</td>
|
||||
<td>kcal</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr>
|
||||
<td style="padding-top: 8px!important; ">
|
||||
<b>{% trans 'Carbohydrates' %}</b>
|
||||
</td>
|
||||
<td style="text-align: right">{{ recipe.nutrition.carbohydrates|floatformat:2 }}</td>
|
||||
<td>g</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr>
|
||||
<td style="padding-top: 8px!important; ">
|
||||
<b>{% trans 'Fats' %}</b>
|
||||
</td>
|
||||
<td style="text-align: right">{{ recipe.nutrition.fats|floatformat:2 }}</td>
|
||||
<td>g</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr>
|
||||
<td style="padding-top: 8px!important; ">
|
||||
<b>{% trans 'Proteins' %}</b>
|
||||
</td>
|
||||
<td style="text-align: right">{{ recipe.nutrition.proteins|floatformat:2 }}</td>
|
||||
<td>g</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
{% if recipe.nutrition.source %}
|
||||
Source: {{ recipe.nutrition.source }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div v-if="recipe !== undefined && recipe.steps.length > 0">
|
||||
<hr>
|
||||
<h3>{% trans 'Instructions' %}</h3>
|
||||
@@ -271,7 +327,7 @@
|
||||
<span>⁣</span>
|
||||
</template>
|
||||
<template v-if="!i.no_amount">
|
||||
<span>[[roundDecimals(i.amount * ingredient_factor)]]</span>
|
||||
<span v-html="calculateAmount(i.amount)"></span>
|
||||
{# Allow for amounts without units, such as "2 eggs" #}
|
||||
<template v-if="i.unit">
|
||||
[[i.unit.name]]
|
||||
@@ -460,6 +516,13 @@
|
||||
let csrftoken = Cookies.get('csrftoken');
|
||||
Vue.http.headers.common['X-CSRFToken'] = csrftoken;
|
||||
|
||||
{% if user_servings %}
|
||||
const recipe_servings = {{ user_servings|floatformat:0 }}
|
||||
{% else %}
|
||||
const recipe_servings = {{ recipe.servings }}
|
||||
{% endif %}
|
||||
|
||||
|
||||
let app = new Vue({
|
||||
delimiters: ['[[', ']]'],
|
||||
el: '#id_base_container',
|
||||
@@ -467,9 +530,16 @@
|
||||
recipe: undefined,
|
||||
has_ingredients: false,
|
||||
has_times: false,
|
||||
ingredient_factor: 1,
|
||||
servings: recipe_servings,
|
||||
},
|
||||
computed: {
|
||||
ingredient_factor: function () {
|
||||
return this.servings / recipe_servings
|
||||
},
|
||||
shopping_url: function () {
|
||||
return `{% url 'view_shopping' %}?r=[${this.recipe.id},${this.servings}]`
|
||||
},
|
||||
},
|
||||
|
||||
mounted: function () {
|
||||
this.loadRecipe()
|
||||
},
|
||||
@@ -478,7 +548,7 @@
|
||||
this.$http.get("{% url 'api:recipe-detail' recipe.pk %}" {% if share %}
|
||||
+ "?share={{ share }}"{% endif %}).then((response) => {
|
||||
this.recipe = response.data;
|
||||
this.loading = false
|
||||
this.loading = false;
|
||||
|
||||
for (let step of this.recipe.steps) {
|
||||
if (step.ingredients.length > 0) {
|
||||
@@ -487,25 +557,25 @@
|
||||
if (step.time !== 0) {
|
||||
this.has_times = true
|
||||
}
|
||||
this.$set(step, 'time_finished', undefined)
|
||||
this.$set(step, 'time_finished', undefined);
|
||||
for (let i of step.ingredients) {
|
||||
this.$set(i, 'checked', false)
|
||||
}
|
||||
}
|
||||
|
||||
}).catch((err) => {
|
||||
this.error = err.data
|
||||
this.loading = false
|
||||
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 %}
|
||||
{{ request.user.userpreference.ingredient_decimals }} {% else %} 2; {% endif %}
|
||||
return +(Math.round(num + `e+${decimals}`) + `e-${decimals}`);
|
||||
},
|
||||
updateTimes: function (step) {
|
||||
let time_diff_first = 0
|
||||
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
|
||||
@@ -514,17 +584,34 @@
|
||||
|
||||
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
|
||||
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}]`
|
||||
}
|
||||
calculateAmount: function (amount) {
|
||||
{% if request.user.userpreference.use_fractions %}
|
||||
let return_string = ''
|
||||
let fraction = frac.cont((amount * this.ingredient_factor), 9, true)
|
||||
|
||||
if (fraction[0] > 0) {
|
||||
return_string += fraction[0]
|
||||
}
|
||||
|
||||
if (fraction[1] > 0) {
|
||||
return_string += ` <sup>${(fraction[1])}</sup>⁄<sub>${(fraction[2])}</sub>`
|
||||
}
|
||||
|
||||
return return_string
|
||||
{% else %}
|
||||
return this.roundDecimals(amount * this.ingredient_factor)
|
||||
{% endif %}
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -12,12 +12,12 @@
|
||||
{% block content %}
|
||||
|
||||
<h1>{% trans 'Setup' %}</h1>
|
||||
<p>{% blocktrans %}To start using this application you must first create a superuser.{% endblocktrans %}</p>
|
||||
<p>{% blocktrans %}To start using this application you must first create a superuser account.{% endblocktrans %}</p>
|
||||
|
||||
<form action="." method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<button class="btn btn-success" type="submit"><i class="fas fa-save"></i> {% trans 'Create Superuser' %}</button>
|
||||
<button class="btn btn-success" type="submit"><i class="fas fa-save"></i> {% trans 'Create Superuser account' %}</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
@@ -89,13 +89,13 @@
|
||||
<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">-
|
||||
@click="((x.servings - 1) > 0) ? x.servings -= 1 : 1">-
|
||||
</button>
|
||||
</div>
|
||||
<input class="form-control" type="number" v-model="x.multiplier">
|
||||
<input class="form-control" type="number" v-model="x.servings">
|
||||
<div class="input-group-append">
|
||||
<button class="text-muted btn btn-outline-primary shadow-none"
|
||||
@click="x.multiplier += 1">
|
||||
@click="x.servings += 1">
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
@@ -229,7 +229,7 @@
|
||||
<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.' %}
|
||||
{% trans 'You are offline, shopping list might not syncronize.' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -305,6 +305,8 @@
|
||||
|
||||
{% endblock %}
|
||||
{% block script %}
|
||||
|
||||
<script src="{% url 'javascript-catalog' %}"></script>
|
||||
<script type="application/javascript">
|
||||
let csrftoken = Cookies.get('csrftoken');
|
||||
Vue.http.headers.common['X-CSRFToken'] = csrftoken;
|
||||
@@ -346,10 +348,10 @@
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
multiplier_cache() {
|
||||
servings_cache() {
|
||||
let cache = {}
|
||||
this.shopping_list.recipes.forEach((r) => {
|
||||
cache[r.id] = !(Number.isNaN(r.multiplier)) ? parseFloat(r.multiplier) : 1
|
||||
cache[r.id] = r.servings;
|
||||
})
|
||||
return cache
|
||||
},
|
||||
@@ -362,7 +364,7 @@
|
||||
let item = {}
|
||||
Object.assign(item, element);
|
||||
if (item.list_recipe !== null) {
|
||||
item.amount = item.amount * this.multiplier_cache[item.list_recipe]
|
||||
item.amount = item.amount * this.servings_cache[item.list_recipe]
|
||||
}
|
||||
item.unit = ((element.unit !== undefined && element.unit !== null) ? element.unit : {'name': ''})
|
||||
entries.push(item)
|
||||
@@ -400,7 +402,7 @@
|
||||
this.edit_mode = true
|
||||
let loadingRecipes = []
|
||||
{% for r in recipes %}
|
||||
loadingRecipes.push(this.loadInitialRecipe({{ r.recipe }}, {{ r.multiplier }}))
|
||||
loadingRecipes.push(this.loadInitialRecipe({{ r.recipe }}, {{ r.servings }}))
|
||||
{% endfor %}
|
||||
|
||||
Promise.allSettled(loadingRecipes).then(() => {
|
||||
@@ -445,12 +447,12 @@
|
||||
solid: true
|
||||
})
|
||||
},
|
||||
loadInitialRecipe: function (recipe, multiplier) {
|
||||
loadInitialRecipe: function (recipe, servings) {
|
||||
return this.$http.get('{% url 'api:recipe-detail' 123456 %}'.replace('123456', recipe)).then((response) => {
|
||||
this.addRecipeToList(response.data, multiplier)
|
||||
this.addRecipeToList(response.data, servings)
|
||||
}).catch((err) => {
|
||||
console.log("getRecipes error: ", err);
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
loadShoppingList: function (autosync = false) {
|
||||
@@ -477,7 +479,7 @@
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
} else {
|
||||
this.shopping_list = {
|
||||
@@ -513,7 +515,7 @@
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error updating a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error updating a resource!') + err.bodyText, 'danger')
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -524,7 +526,7 @@
|
||||
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.makeToast(gettext('Updated'), gettext('Object created successfully!'), 'success')
|
||||
this.loading = false
|
||||
|
||||
this.shopping_list = response.body
|
||||
@@ -533,18 +535,18 @@
|
||||
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.makeToast(gettext('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.makeToast(gettext('Updated'), gettext('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.makeToast(gettext('Error'), gettext('There was an error updating a resource!') + err.bodyText, 'danger')
|
||||
this.loading = false
|
||||
})
|
||||
}
|
||||
@@ -567,7 +569,7 @@
|
||||
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error updating a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error updating a resource!') + err.bodyText, 'danger')
|
||||
this.loading = false
|
||||
})
|
||||
|
||||
@@ -593,7 +595,7 @@
|
||||
|
||||
this.$refs.new_entry_amount.focus();
|
||||
} else {
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'Please enter a valid food' %}', 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('Please enter a valid food'), 'danger')
|
||||
}
|
||||
},
|
||||
getRecipes: function () {
|
||||
@@ -609,19 +611,19 @@
|
||||
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')
|
||||
this.makeToast(gettext('Error'), gettext('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) {
|
||||
addRecipeToList: function (recipe, servings = 1) {
|
||||
let slr = {
|
||||
"created": true,
|
||||
"id": Math.random() * 1000,
|
||||
"recipe": recipe.id,
|
||||
"recipe_name": recipe.name,
|
||||
"multiplier": multiplier
|
||||
"servings": servings,
|
||||
}
|
||||
|
||||
this.shopping_list.recipes.push(slr)
|
||||
@@ -651,7 +653,7 @@
|
||||
this.keywords_loading = false
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
|
||||
@@ -661,7 +663,7 @@
|
||||
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')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
searchFoods: function (query) { //TODO move to central component
|
||||
@@ -670,7 +672,7 @@
|
||||
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')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
addFoodType: function (tag, index) { //TODO move to central component
|
||||
@@ -689,7 +691,7 @@
|
||||
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')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
},
|
||||
|
||||
@@ -22,11 +22,23 @@
|
||||
<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>
|
||||
|
||||
<br/> <br/>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
⚠️ Backups simply create a so called fixture. Fixtures are json files containing all your data (WITHOUT
|
||||
MEDIA FILES) <br>
|
||||
They can be imported into django by running <code style="color: white">manage.py loaddata [fixture-name]</code> <br>
|
||||
It is planned to provide a better way of backing up and restoring data but it is not yet implemented.<br><br>
|
||||
⚠️<b>Please make sure to setup a solid backup strategy on your server to save the Database and the <code style="color: white">mediafiles</code>
|
||||
directory</b>⚠️
|
||||
</div>
|
||||
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
||||
@@ -144,7 +144,8 @@
|
||||
</multiselect>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<input type="text" placeholder="{% trans 'Note' %}" class="form-control" v-model="i.note">
|
||||
<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"
|
||||
@@ -194,13 +195,15 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="id_all_keywords">{% trans 'All Keywords' %}</label><br/>
|
||||
{% trans 'All Keywords' %}<br/>
|
||||
<input id="id_all_keywords" type="checkbox"
|
||||
v-model="all_keywords"> {% trans 'Import all Keywords not only the ones already existing.' %}
|
||||
v-model="all_keywords"> <label
|
||||
for="id_all_keywords">{% trans 'Import all keywords, not only the ones already existing.' %}</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="button" class="btn btn-success" @click="importRecipe()" :disabled="importing_recipe">{% trans 'Import' %}</button>
|
||||
<button type="button" class="btn btn-success" @click="importRecipe()"
|
||||
:disabled="importing_recipe">{% trans 'Import' %}</button>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
@@ -246,6 +249,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<script src="{% url 'javascript-catalog' %}"></script>
|
||||
<script type="application/javascript">
|
||||
let csrftoken = Cookies.get('csrftoken');
|
||||
Vue.http.headers.common['X-CSRFToken'] = csrftoken;
|
||||
@@ -283,6 +287,7 @@
|
||||
this.searchKeywords('')
|
||||
this.searchUnits('')
|
||||
this.searchIngredients('')
|
||||
|
||||
},
|
||||
methods: {
|
||||
makeToast: function (title, message, variant = null) {
|
||||
@@ -298,19 +303,19 @@
|
||||
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.$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')
|
||||
this.makeToast(gettext('Error'), gettext('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')
|
||||
this.makeToast(gettext('Error'), gettext('Already importing the selected recipe, please wait!'), 'danger')
|
||||
return;
|
||||
}
|
||||
this.importing_recipe = true
|
||||
@@ -319,7 +324,7 @@
|
||||
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')
|
||||
this.makeToast(gettext('Error'), gettext('An error occurred while trying to import this recipe!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
deleteIngredient: function (i) {
|
||||
@@ -363,7 +368,7 @@
|
||||
this.keywords_loading = false
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
searchUnits: function (query) {
|
||||
@@ -381,7 +386,7 @@
|
||||
this.units_loading = false
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
searchIngredients: function (query) {
|
||||
@@ -400,7 +405,7 @@
|
||||
this.ingredients_loading = false
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
@@ -46,13 +46,15 @@ def recipe_rating(recipe, user):
|
||||
rating = recipe.cooklog_set.filter(created_by=user).aggregate(Avg('rating'))
|
||||
if rating['rating__avg']:
|
||||
|
||||
rating_stars = ''
|
||||
rating_stars = '<span style="display: inline-block;">'
|
||||
for i in range(int(rating['rating__avg'])):
|
||||
rating_stars = rating_stars + '<i class="fas fa-star fa-xs"></i>'
|
||||
|
||||
if rating['rating__avg'] % 1 >= 0.5:
|
||||
rating_stars = rating_stars + '<i class="fas fa-star-half-alt fa-xs"></i>'
|
||||
|
||||
rating_stars += '</span>'
|
||||
|
||||
return rating_stars
|
||||
else:
|
||||
return ''
|
||||
|
||||
26
cookbook/tests/api/test_api_recipe.py
Normal file
26
cookbook/tests/api/test_api_recipe.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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, Recipe
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
|
||||
|
||||
class TestApiShopping(TestViews):
|
||||
|
||||
def setUp(self):
|
||||
super(TestApiShopping, self).setUp()
|
||||
self.internal_recipe = Recipe.objects.create(
|
||||
name='Test',
|
||||
internal=True,
|
||||
created_by=auth.get_user(self.user_client_1)
|
||||
)
|
||||
|
||||
def test_shopping_view_permissions(self):
|
||||
self.batch_requests([(self.anonymous_client, 403), (self.guest_client_1, 200), (self.user_client_1, 200),
|
||||
(self.user_client_2, 200), (self.admin_client_1, 200), (self.superuser_client, 200)],
|
||||
reverse('api:recipe-detail', args={self.internal_recipe.id}))
|
||||
|
||||
# TODO add tests for editing
|
||||
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse_ingredient
|
||||
from cookbook.helper.recipe_url_import import get_from_html
|
||||
from cookbook.tests.test_setup import TestBase
|
||||
|
||||
@@ -8,16 +9,16 @@ class TestEditsRecipe(TestBase):
|
||||
|
||||
def test_ld_json(self):
|
||||
test_list = [
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_1.html', 'result_length': 3128},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_2.html', 'result_length': 1450},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_3.html', 'result_length': 1545},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_4.html', 'result_length': 1657},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_itemList.html', 'result_length': 3131},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_multiple.html', 'result_length': 1546},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_1.html', 'result_length': 1022},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_2.html', 'result_length': 1384},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_3.html', 'result_length': 1100},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_4.html', 'result_length': 4231},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_1.html', 'result_length': 3218},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_2.html', 'result_length': 1510},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_3.html', 'result_length': 1629},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_4.html', 'result_length': 1729},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_itemList.html', 'result_length': 3200},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_multiple.html', 'result_length': 1606},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_1.html', 'result_length': 1079},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_2.html', 'result_length': 1429},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_3.html', 'result_length': 1148},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_4.html', 'result_length': 4396},
|
||||
]
|
||||
|
||||
for test in test_list:
|
||||
@@ -26,3 +27,61 @@ class TestEditsRecipe(TestBase):
|
||||
parsed_content = json.loads(get_from_html(file.read(), 'test_url').content)
|
||||
self.assertEqual(len(str(parsed_content)), test['result_length'])
|
||||
file.close()
|
||||
|
||||
def test_ingredient_parser(self):
|
||||
expectations = {
|
||||
"2¼ l Wasser": (2.25, "l", "Wasser", ""),
|
||||
"2¼l Wasser": (2.25, "l", "Wasser", ""),
|
||||
"3l Wasser": (3, "l", "Wasser", ""),
|
||||
"4 l Wasser": (4, "l", "Wasser", ""),
|
||||
"½l Wasser": (0.5, "l", "Wasser", ""),
|
||||
"⅛ Liter Sauerrahm": (0.125, "Liter", "Sauerrahm", ""),
|
||||
"5 Zwiebeln": (5, "", "Zwiebeln", ""),
|
||||
"3 Zwiebeln, gehackt": (3, "", "Zwiebeln", "gehackt"),
|
||||
"5 Zwiebeln (gehackt)": (5, "", "Zwiebeln", "gehackt"),
|
||||
"1 Zwiebel(n)": (1, "", "Zwiebel(n)", ""),
|
||||
"4 1/2 Zwiebeln": (4.5, "", "Zwiebeln", ""),
|
||||
"4 ½ Zwiebeln": (4.5, "", "Zwiebeln", ""),
|
||||
"etwas Mehl": (0, "", "etwas Mehl", ""),
|
||||
"Öl zum Anbraten": (0, "", "Öl zum Anbraten", ""),
|
||||
"n. B. Knoblauch, zerdrückt": (0, "", "n. B. Knoblauch", "zerdrückt"),
|
||||
"Kräuter, mediterrane (Oregano, Rosmarin, Basilikum)": (
|
||||
0, "", "Kräuter, mediterrane", "Oregano, Rosmarin, Basilikum"),
|
||||
"600 g Kürbisfleisch (Hokkaido), geschält, entkernt und geraspelt": (
|
||||
600, "g", "Kürbisfleisch (Hokkaido)", "geschält, entkernt und geraspelt"),
|
||||
"Muskat": (0, "", "Muskat", ""),
|
||||
"200 g Mehl, glattes": (200, "g", "Mehl", "glattes"),
|
||||
"1 Ei(er)": (1, "", "Ei(er)", ""),
|
||||
"1 Prise(n) Salz": (1, "Prise(n)", "Salz", ""),
|
||||
"etwas Wasser, lauwarmes": (0, "", "etwas Wasser", "lauwarmes"),
|
||||
"Strudelblätter, fertige, für zwei Strudel": (0, "", "Strudelblätter", "fertige, für zwei Strudel"),
|
||||
"barrel-aged Bourbon": (0, "", "barrel-aged Bourbon", ""),
|
||||
"golden syrup": (0, "", "golden syrup", ""),
|
||||
"unsalted butter, for greasing": (0, "", "unsalted butter", "for greasing"),
|
||||
"unsalted butter , for greasing": (0, "", "unsalted butter", "for greasing"), # trim
|
||||
"1 small sprig of fresh rosemary": (1, "small", "sprig of fresh rosemary", ""),
|
||||
# does not always work perfectly!
|
||||
"75 g fresh breadcrumbs": (75, "g", "fresh breadcrumbs", ""),
|
||||
"4 acorn squash , or onion squash (600-800g)": (4, "acorn", "squash , or onion squash", "600-800g"),
|
||||
"1 x 250 g packet of cooked mixed grains , such as spelt and wild rice": (
|
||||
1, "x", "250 g packet of cooked mixed grains", "such as spelt and wild rice"),
|
||||
"1 big bunch of fresh mint , (60g)": (1, "big", "bunch of fresh mint ,", "60g"),
|
||||
"1 large red onion": (1, "large", "red onion", ""),
|
||||
# "2-3 TL Curry": (), # idk what it should use here either
|
||||
"1 Zwiebel gehackt": (1, "Zwiebel", "gehackt", ""),
|
||||
"1 EL Kokosöl": (1, "EL", "Kokosöl", ""),
|
||||
"0.5 paket jäst (à 50 g)": (0.5, "paket", "jäst", "à 50 g"),
|
||||
"ägg": (0, "", "ägg", ""),
|
||||
"50 g smör eller margarin": (50, "g", "smör eller margarin", ""),
|
||||
"3,5 l Wasser": (3.5, "l", "Wasser", ""),
|
||||
"3.5 l Wasser": (3.5, "l", "Wasser", "")
|
||||
}
|
||||
# for German you could say that if an ingredient does not have an amount and it starts with a lowercase letter, then that is a unit ("etwas", "evtl.")
|
||||
# does not apply to English tho
|
||||
|
||||
errors = 0
|
||||
count = 0
|
||||
for key, val in expectations.items():
|
||||
count += 1
|
||||
parsed = parse_ingredient(key)
|
||||
self.assertNotEqual(val, parsed)
|
||||
|
||||
@@ -73,7 +73,7 @@ urlpatterns = [
|
||||
path('api/get_recipe_file/<int:recipe_id>/', api.get_recipe_file, name='api_get_recipe_file'),
|
||||
path('api/sync_all/', api.sync_all, name='api_sync'),
|
||||
path('api/log_cooking/<int:recipe_id>/', api.log_cooking, name='api_log_cooking'),
|
||||
path('api/plan-ical/<slug:html_week>/', api.get_plan_ical, name='api_get_plan_ical'),
|
||||
path('api/plan-ical/<slug:from_date>/<slug:to_date>/', api.get_plan_ical, name='api_get_plan_ical'),
|
||||
path('api/recipe-from-url/', api.recipe_from_url, name='api_recipe_from_url'),
|
||||
path('api/backup/', api.get_backup, name='api_backup'),
|
||||
|
||||
|
||||
@@ -104,8 +104,12 @@ class StandardFilterMixin(ViewSetMixin):
|
||||
queryset = queryset.filter(name__icontains=query)
|
||||
|
||||
limit = self.request.query_params.get('limit', None)
|
||||
random = self.request.query_params.get('random', False)
|
||||
if limit is not None:
|
||||
queryset = queryset[:int(limit)]
|
||||
if random:
|
||||
queryset = queryset.random(int(limit))
|
||||
else:
|
||||
queryset = queryset[:int(limit)]
|
||||
return queryset
|
||||
|
||||
|
||||
@@ -150,7 +154,8 @@ class MealPlanViewSet(viewsets.ModelViewSet):
|
||||
list:
|
||||
optional parameters
|
||||
|
||||
- **html_week**: filter for a calendar week (format 2020-W24 as html input type week)
|
||||
- **from_date**: filter from (inclusive) a certain date onward
|
||||
- **to_date**: filter upward to (inclusive) certain date
|
||||
|
||||
"""
|
||||
queryset = MealPlan.objects.all()
|
||||
@@ -159,10 +164,14 @@ class MealPlanViewSet(viewsets.ModelViewSet):
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = MealPlan.objects.filter(Q(created_by=self.request.user) | Q(shared=self.request.user)).distinct().all()
|
||||
week = self.request.query_params.get('html_week', None)
|
||||
if week is not None:
|
||||
y, w = week.replace('-W', ' ').split()
|
||||
queryset = queryset.filter(date__week=w, date__year=y)
|
||||
|
||||
from_date = self.request.query_params.get('from_date', None)
|
||||
if from_date is not None:
|
||||
queryset = queryset.filter(date__gte=from_date)
|
||||
|
||||
to_date = self.request.query_params.get('to_date', None)
|
||||
if to_date is not None:
|
||||
queryset = queryset.filter(date__lte=to_date)
|
||||
return queryset
|
||||
|
||||
|
||||
@@ -205,11 +214,12 @@ class RecipeViewSet(viewsets.ModelViewSet, StandardFilterMixin):
|
||||
permission_classes = [CustomIsShare | CustomIsGuest] # TODO split read and write permission for meal plan guest
|
||||
|
||||
def get_queryset(self):
|
||||
|
||||
internal = self.request.query_params.get('internal', None)
|
||||
if internal:
|
||||
self.queryset = self.queryset.filter(internal=True)
|
||||
|
||||
return super(RecipeViewSet, self).get_queryset()
|
||||
return super().get_queryset()
|
||||
|
||||
# TODO write extensive tests for permissions
|
||||
|
||||
@@ -363,11 +373,14 @@ def log_cooking(request, recipe_id):
|
||||
|
||||
|
||||
@group_required('user')
|
||||
def get_plan_ical(request, html_week):
|
||||
def get_plan_ical(request, from_date, to_date):
|
||||
queryset = MealPlan.objects.filter(Q(created_by=request.user) | Q(shared=request.user)).distinct().all()
|
||||
|
||||
y, w = html_week.replace('-W', ' ').split()
|
||||
queryset = queryset.filter(date__week=w, date__year=y)
|
||||
if from_date is not None:
|
||||
queryset = queryset.filter(date__gte=from_date)
|
||||
|
||||
if to_date is not None:
|
||||
queryset = queryset.filter(date__lte=to_date)
|
||||
|
||||
cal = Calendar()
|
||||
|
||||
@@ -381,7 +394,7 @@ def get_plan_ical(request, html_week):
|
||||
cal.add_component(event)
|
||||
|
||||
response = FileResponse(io.BytesIO(cal.to_ical()))
|
||||
response["Content-Disposition"] = f'attachment; filename=meal_plan_{html_week}.ics'
|
||||
response["Content-Disposition"] = f'attachment; filename=meal_plan_{from_date}-{to_date}.ics'
|
||||
|
||||
return response
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from datetime import datetime
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
from PIL import Image
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
from django.contrib import messages
|
||||
from django.core.files import File
|
||||
from django.db.transaction import atomic
|
||||
@@ -125,7 +125,7 @@ def import_url(request):
|
||||
ingredient = Ingredient()
|
||||
|
||||
ingredient.food, f_created = Food.objects.get_or_create(name=ing['ingredient']['text'])
|
||||
if ing['unit']:
|
||||
if ing['unit'] and ing['unit']['text'] != '':
|
||||
ingredient.unit, u_created = Unit.objects.get_or_create(name=ing['unit']['text'])
|
||||
|
||||
# TODO properly handle no_amount recipes
|
||||
@@ -143,20 +143,23 @@ def import_url(request):
|
||||
step.ingredients.add(ingredient)
|
||||
print(ingredient)
|
||||
|
||||
if data['image'] != '':
|
||||
response = requests.get(data['image'])
|
||||
img = Image.open(BytesIO(response.content))
|
||||
if 'image' in data and data['image'] != '':
|
||||
try:
|
||||
response = requests.get(data['image'])
|
||||
img = Image.open(BytesIO(response.content))
|
||||
|
||||
# todo move image processing to dedicated function
|
||||
basewidth = 720
|
||||
wpercent = (basewidth / float(img.size[0]))
|
||||
hsize = int((float(img.size[1]) * float(wpercent)))
|
||||
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
|
||||
# todo move image processing to dedicated function
|
||||
basewidth = 720
|
||||
wpercent = (basewidth / float(img.size[0]))
|
||||
hsize = int((float(img.size[1]) * float(wpercent)))
|
||||
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
|
||||
|
||||
im_io = BytesIO()
|
||||
img.save(im_io, 'PNG', quality=70)
|
||||
recipe.image = File(im_io, name=f'{uuid.uuid4()}_{recipe.pk}.png')
|
||||
recipe.save()
|
||||
im_io = BytesIO()
|
||||
img.save(im_io, 'PNG', quality=70)
|
||||
recipe.image = File(im_io, name=f'{uuid.uuid4()}_{recipe.pk}.png')
|
||||
recipe.save()
|
||||
except UnidentifiedImageError:
|
||||
pass
|
||||
|
||||
return HttpResponse(reverse('view_recipe', args=[recipe.pk]))
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ class RecipeBookEntryDelete(GroupRequiredMixin, DeleteView):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
if not (obj.book.created_by == request.user or request.user.is_superuser):
|
||||
messages.add_message(request, messages.ERROR, _('You cannot interact with this object as its not owned by you!'))
|
||||
messages.add_message(request, messages.ERROR, _('You cannot interact with this object as it is not owned by you!'))
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
return super(RecipeBookEntryDelete, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@@ -239,27 +239,33 @@ def edit_ingredients(request):
|
||||
if units_form.is_valid():
|
||||
new_unit = units_form.cleaned_data['new_unit']
|
||||
old_unit = units_form.cleaned_data['old_unit']
|
||||
recipe_ingredients = Ingredient.objects.filter(unit=old_unit).all()
|
||||
for i in recipe_ingredients:
|
||||
i.unit = new_unit
|
||||
i.save()
|
||||
if new_unit != old_unit:
|
||||
recipe_ingredients = Ingredient.objects.filter(unit=old_unit).all()
|
||||
for i in recipe_ingredients:
|
||||
i.unit = new_unit
|
||||
i.save()
|
||||
|
||||
old_unit.delete()
|
||||
success = True
|
||||
messages.add_message(request, messages.SUCCESS, _('Units merged!'))
|
||||
old_unit.delete()
|
||||
success = True
|
||||
messages.add_message(request, messages.SUCCESS, _('Units merged!'))
|
||||
else:
|
||||
messages.add_message(request, messages.ERROR, _('Cannot merge with the same object!'))
|
||||
|
||||
food_form = FoodMergeForm(request.POST, prefix=FoodMergeForm.prefix)
|
||||
if food_form.is_valid():
|
||||
new_food = food_form.cleaned_data['new_food']
|
||||
old_food = food_form.cleaned_data['old_food']
|
||||
ingredients = Ingredient.objects.filter(food=old_food).all()
|
||||
for i in ingredients:
|
||||
i.food = new_food
|
||||
i.save()
|
||||
if new_food != old_food:
|
||||
ingredients = Ingredient.objects.filter(food=old_food).all()
|
||||
for i in ingredients:
|
||||
i.food = new_food
|
||||
i.save()
|
||||
|
||||
old_food.delete()
|
||||
success = True
|
||||
messages.add_message(request, messages.SUCCESS, _('Foods merged!'))
|
||||
old_food.delete()
|
||||
success = True
|
||||
messages.add_message(request, messages.SUCCESS, _('Foods merged!'))
|
||||
else:
|
||||
messages.add_message(request, messages.ERROR, _('Cannot merge with the same object!'))
|
||||
|
||||
if success:
|
||||
units_form = UnitMergeForm()
|
||||
|
||||
@@ -7,7 +7,7 @@ from django.contrib.auth import update_session_auth_hash, authenticate
|
||||
from django.contrib.auth.forms import PasswordChangeForm
|
||||
from django.contrib.auth.password_validation import validate_password
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db.models import Q
|
||||
from django.db.models import Q, Avg
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.utils import timezone
|
||||
@@ -83,7 +83,8 @@ def recipe_view(request, pk, share=None):
|
||||
|
||||
if request.method == "POST":
|
||||
if not request.user.is_authenticated:
|
||||
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to perform this action!'))
|
||||
messages.add_message(request, messages.ERROR,
|
||||
_('You do not have the required permissions to perform this action!'))
|
||||
return HttpResponseRedirect(reverse('view_recipe', kwargs={'pk': recipe.pk, 'share': share}))
|
||||
|
||||
comment_form = CommentForm(request.POST, prefix='comment')
|
||||
@@ -110,13 +111,19 @@ def recipe_view(request, pk, share=None):
|
||||
comment_form = CommentForm()
|
||||
bookmark_form = RecipeBookEntryForm()
|
||||
|
||||
user_servings = None
|
||||
if request.user.is_authenticated:
|
||||
if not ViewLog.objects.filter(recipe=recipe).filter(created_by=request.user).filter(created_at__gt=(timezone.now() - timezone.timedelta(minutes=5))).exists():
|
||||
user_servings = CookLog.objects.filter(recipe=recipe, created_by=request.user,
|
||||
servings__gt=0).all().aggregate(Avg('servings'))['servings__avg']
|
||||
|
||||
if request.user.is_authenticated:
|
||||
if not ViewLog.objects.filter(recipe=recipe).filter(created_by=request.user).filter(
|
||||
created_at__gt=(timezone.now() - timezone.timedelta(minutes=5))).exists():
|
||||
ViewLog.objects.create(recipe=recipe, created_by=request.user)
|
||||
|
||||
return render(request, 'recipe_view.html',
|
||||
{'recipe': recipe, 'comments': comments, 'comment_form': comment_form,
|
||||
'bookmark_form': bookmark_form, 'share': share})
|
||||
'bookmark_form': bookmark_form, 'share': share, 'user_servings': user_servings})
|
||||
|
||||
|
||||
@group_required('user')
|
||||
@@ -158,7 +165,8 @@ def meal_plan_entry(request, pk):
|
||||
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))
|
||||
return HttpResponseRedirect(reverse_lazy('index'))
|
||||
|
||||
same_day_plan = MealPlan.objects.filter(date=plan.date).exclude(pk=plan.pk).filter(Q(created_by=request.user) | Q(shared=request.user)).order_by('meal_type').all()
|
||||
same_day_plan = MealPlan.objects.filter(date=plan.date).exclude(pk=plan.pk).filter(
|
||||
Q(created_by=request.user) | Q(shared=request.user)).order_by('meal_type').all()
|
||||
|
||||
return render(request, 'meal_plan_entry.html', {'plan': plan, 'same_day_plan': same_day_plan})
|
||||
|
||||
@@ -202,6 +210,7 @@ def user_settings(request):
|
||||
up.plan_share.set(form.cleaned_data['plan_share'])
|
||||
up.ingredient_decimals = form.cleaned_data['ingredient_decimals']
|
||||
up.comments = form.cleaned_data['comments']
|
||||
up.use_fractions = form.cleaned_data['use_fractions']
|
||||
|
||||
up.shopping_auto_sync = form.cleaned_data['shopping_auto_sync']
|
||||
if up.shopping_auto_sync < settings.SHOPPING_MIN_AUTOSYNC_INTERVAL:
|
||||
@@ -230,7 +239,9 @@ def user_settings(request):
|
||||
if (api_token := Token.objects.filter(user=request.user).first()) is None:
|
||||
api_token = Token.objects.create(user=request.user)
|
||||
|
||||
return render(request, 'settings.html', {'preference_form': preference_form, 'user_name_form': user_name_form, 'password_form': password_form, 'api_token': api_token})
|
||||
return render(request, 'settings.html',
|
||||
{'preference_form': preference_form, 'user_name_form': user_name_form, 'password_form': password_form,
|
||||
'api_token': api_token})
|
||||
|
||||
|
||||
@group_required('guest')
|
||||
@@ -242,16 +253,20 @@ def history(request):
|
||||
|
||||
@group_required('admin')
|
||||
def system(request):
|
||||
postgres = False if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql_psycopg2' else True
|
||||
postgres = False if (settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql_psycopg2' or
|
||||
settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql') else True
|
||||
|
||||
secret_key = False if os.getenv('SECRET_KEY') else True
|
||||
|
||||
return render(request, 'system.html', {'gunicorn_media': settings.GUNICORN_MEDIA, 'debug': settings.DEBUG, 'postgres': postgres, 'version': VERSION_NUMBER, 'ref': BUILD_REF, 'secret_key': secret_key})
|
||||
return render(request, 'system.html',
|
||||
{'gunicorn_media': settings.GUNICORN_MEDIA, 'debug': settings.DEBUG, 'postgres': postgres,
|
||||
'version': VERSION_NUMBER, 'ref': BUILD_REF, 'secret_key': secret_key})
|
||||
|
||||
|
||||
def setup(request):
|
||||
if User.objects.count() > 0 or 'django.contrib.auth.backends.RemoteUserBackend' in settings.AUTHENTICATION_BACKENDS:
|
||||
messages.add_message(request, messages.ERROR, _('The setup page can only be used to create the first user! If you have forgotten your superuser credentials please consult the django documentation on how to reset passwords.'))
|
||||
messages.add_message(request, messages.ERROR, _(
|
||||
'The setup page can only be used to create the first user! If you have forgotten your superuser credentials please consult the django documentation on how to reset passwords.'))
|
||||
return HttpResponseRedirect(reverse('login'))
|
||||
|
||||
if request.method == 'POST':
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
This is a further example combining the power of nginx with the reverse proxy authentication service, [Authelia](https://github.com/authelia/authelia).
|
||||
|
||||
Please refer to the appropriate documentation on how to setup the reverse proxy, authentication, and networks.
|
||||
|
||||
Ensure users have been configured for Authelia, and that the endpoint that recipes is pointed to is protected, but available.
|
||||
|
||||
There is a good guide to the other additional files that need to be added to your Nginx set up at the [Authelia Docs](https://docs.authelia.com/deployment/supported-proxies/nginx.html).
|
||||
|
||||
Remember to add the appropriate environment variables to `.env` file:
|
||||
```
|
||||
VIRTUAL_HOST=
|
||||
LETSENCRYPT_HOST=
|
||||
LETSENCRYPT_EMAIL=
|
||||
PROXY_HEADER=
|
||||
```
|
||||
@@ -1,43 +0,0 @@
|
||||
version: "3"
|
||||
services:
|
||||
db_recipes:
|
||||
restart: always
|
||||
image: postgres:11-alpine
|
||||
volumes:
|
||||
- ./postgresql:/var/lib/postgresql/data
|
||||
env_file:
|
||||
- ./.env
|
||||
networks:
|
||||
- default
|
||||
|
||||
web_recipes:
|
||||
image: vabene1111/recipes
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- ./staticfiles:/opt/recipes/staticfiles
|
||||
- ./mediafiles:/opt/recipes/mediafiles
|
||||
depends_on:
|
||||
- db_recipes
|
||||
networks:
|
||||
- default
|
||||
|
||||
nginx_recipes:
|
||||
image: nginx:mainline-alpine
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- ./nginx/conf.d:/etc/nginx/conf.d
|
||||
- ./staticfiles:/static
|
||||
- ./mediafiles:/media
|
||||
networks:
|
||||
- default
|
||||
- nginx-proxy
|
||||
|
||||
networks:
|
||||
default:
|
||||
nginx-proxy:
|
||||
external:
|
||||
name: nginx-proxy
|
||||
@@ -1,37 +0,0 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
client_max_body_size 16M;
|
||||
|
||||
# serve static files
|
||||
location /static/ {
|
||||
alias /static/;
|
||||
}
|
||||
# serve media files
|
||||
location /media/ {
|
||||
alias /media/;
|
||||
}
|
||||
|
||||
# Authelia endpoint for authentication requests
|
||||
include /config/nginx/auth.conf;
|
||||
|
||||
# pass requests for dynamic content to gunicorn
|
||||
location / {
|
||||
proxy_set_header Host $host;
|
||||
proxy_pass http://web_recipes:8080;
|
||||
|
||||
# Ensure Authelia is specifically required for this endpoint
|
||||
# This line is important as it will return a 401 error if the user doesn't have access
|
||||
include /config/nginx/authelia.conf;
|
||||
|
||||
auth_request_set $user $upstream_http_remote_user;
|
||||
proxy_set_header REMOTE-USER $user;
|
||||
}
|
||||
|
||||
# Required to allow user to logout of authentication from within Recipes
|
||||
# Ensure the <auth_endpoint> below is changed to actual the authentication url
|
||||
location /accounts/logout/ {
|
||||
return 301 http://<auth_endpoint>/logout
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
This is a docker compose example when using [jwilder's nginx reverse proxy](https://github.com/jwilder/docker-gen)
|
||||
in combination with [jrcs's letsencrypt companion](https://hub.docker.com/r/jrcs/letsencrypt-nginx-proxy-companion/).
|
||||
|
||||
Please refer to the appropriate documentation on how to setup the reverse proxy and networks.
|
||||
|
||||
Remember to add the appropriate environment variables to `.env` file:
|
||||
```
|
||||
VIRTUAL_HOST=
|
||||
LETSENCRYPT_HOST=
|
||||
LETSENCRYPT_EMAIL=
|
||||
```
|
||||
@@ -1,43 +0,0 @@
|
||||
version: "3"
|
||||
services:
|
||||
db_recipes:
|
||||
restart: always
|
||||
image: postgres:11-alpine
|
||||
volumes:
|
||||
- ./postgresql:/var/lib/postgresql/data
|
||||
env_file:
|
||||
- ./.env
|
||||
networks:
|
||||
- default
|
||||
|
||||
web_recipes:
|
||||
image: vabene1111/recipes
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- ./staticfiles:/opt/recipes/staticfiles
|
||||
- ./mediafiles:/opt/recipes/mediafiles
|
||||
depends_on:
|
||||
- db_recipes
|
||||
networks:
|
||||
- default
|
||||
|
||||
nginx_recipes:
|
||||
image: nginx:mainline-alpine
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- ./nginx/conf.d:/etc/nginx/conf.d
|
||||
- ./staticfiles:/static
|
||||
- ./mediafiles:/media
|
||||
networks:
|
||||
- default
|
||||
- nginx-proxy
|
||||
|
||||
networks:
|
||||
default:
|
||||
nginx-proxy:
|
||||
external:
|
||||
name: nginx-proxy
|
||||
@@ -1 +0,0 @@
|
||||
This is the most basic configuration to run this image with docker compose.
|
||||
@@ -1,16 +0,0 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
client_max_body_size 16M;
|
||||
|
||||
# serve media files
|
||||
location /media/ {
|
||||
alias /media/;
|
||||
}
|
||||
# pass requests for dynamic content to gunicorn
|
||||
location / {
|
||||
proxy_set_header Host $host;
|
||||
proxy_pass http://web_recipes:8080;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
client_max_body_size 16M;
|
||||
|
||||
# serve media files
|
||||
location /media/ {
|
||||
alias /media/;
|
||||
}
|
||||
# pass requests for dynamic content to gunicorn
|
||||
location / {
|
||||
proxy_set_header Host $host;
|
||||
proxy_pass http://web_recipes:8080;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
# Important Information
|
||||
Although this application allows running without any webserver in front of gunicorn it is heavily recommended by almost
|
||||
everyone **not** to do this. It is hard to find exact explanations and appears not to be a security but only
|
||||
a performance risk but that is just my personal interpretation.
|
||||
|
||||
**If you dont know what you are doing please choose the traefik-nginx config**
|
||||
|
||||
----
|
||||
|
||||
Please refer to the traefik documentation on how to setup a docker service in traefik. Since treafik can be a little
|
||||
confusing at times, the following are examples of my traefik configuration.
|
||||
|
||||
|
||||
You need to create a network called `traefik` using `docker network create traefik`.
|
||||
## docker-compose.yml
|
||||
|
||||
```
|
||||
version: "3.3"
|
||||
|
||||
services:
|
||||
|
||||
traefik:
|
||||
image: "traefik:v2.1"
|
||||
container_name: "traefik"
|
||||
ports:
|
||||
- "443:443"
|
||||
- "80:80"
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- "./letsencrypt:/letsencrypt"
|
||||
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
||||
- "./config:/etc/traefik/"
|
||||
|
||||
|
||||
networks:
|
||||
default:
|
||||
external:
|
||||
name: traefik
|
||||
```
|
||||
|
||||
## traefik.toml
|
||||
Place this in a directory called `config` as this is mounted into the traefik container (see docer compose).
|
||||
**Change the email address accordingly**.
|
||||
```
|
||||
[api]
|
||||
insecure=true
|
||||
|
||||
[providers.docker]
|
||||
endpoint = "unix:///var/run/docker.sock"
|
||||
exposedByDefault = false
|
||||
network = "traefik"
|
||||
|
||||
#[log]
|
||||
# level = "DEBUG"
|
||||
|
||||
[entryPoints]
|
||||
[entryPoints.web]
|
||||
address = ":80"
|
||||
|
||||
[entryPoints.web_secure]
|
||||
address = ":443"
|
||||
|
||||
[certificatesResolvers.le_resolver.acme]
|
||||
|
||||
email = "you_email@mail.com"
|
||||
storage = "/letsencrypt/acme.json"
|
||||
|
||||
tlsChallenge=true
|
||||
```
|
||||
@@ -1,35 +0,0 @@
|
||||
version: "3"
|
||||
services:
|
||||
db_recipes:
|
||||
restart: always
|
||||
image: postgres:11-alpine
|
||||
volumes:
|
||||
- ./postgresql:/var/lib/postgresql/data
|
||||
env_file:
|
||||
- ./.env
|
||||
networks:
|
||||
- default
|
||||
|
||||
web_recipes:
|
||||
image: vabene1111/recipes
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- ./staticfiles:/opt/recipes/staticfiles
|
||||
- ./mediafiles:/opt/recipes/mediafiles
|
||||
depends_on:
|
||||
- db_recipes
|
||||
labels: # This lables are only examples!
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.recipes.rule=Host(`recipes.mydomain.com`, `recipes.myotherdomain.com`)"
|
||||
- "traefik.http.routers.recipes.entrypoints=web_secure"
|
||||
- "traefik.http.routers.recipes.tls.certresolver=le_resolver"
|
||||
networks:
|
||||
- default
|
||||
- traefik
|
||||
|
||||
networks:
|
||||
default:
|
||||
traefik: # This is you external traefic network
|
||||
external: true
|
||||
28
docs/index.md
Normal file
28
docs/index.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Welcome to Recipes Documentation
|
||||
|
||||
The recipe manager that allows you to manage your ever growing collection of digital recipes.
|
||||
|
||||

|
||||
|
||||
!!! info "WIP"
|
||||
The documentation is work in progress. New information will be added over time.
|
||||
Feel free to open pull requests to enhance the documentation.
|
||||
|
||||
## Features
|
||||
|
||||
- 📦 **Sync** files with Dropbox and Nextcloud (more can easily be added)
|
||||
- 🔍 Powerful **search** with Djangos [TrigramSimilarity](https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/search/#trigram-similarity)
|
||||
- 🏷️ Create and search for **tags**, assign them in batch to all files matching certain filters
|
||||
- 📄 **Create recipes** locally within a nice, standardized web interface
|
||||
- ⬇️ **Import recipes** from thousands of websites supporting [ld+json or microdata](https://schema.org/Recipe)
|
||||
- 📱 Optimized for use on **mobile** devices like phones and tablets
|
||||
- 🛒 Generate **shopping** lists from recipes
|
||||
- 📆 Create a **Plan** on what to eat when
|
||||
- 👪 **Share** recipes with friends and comment on them to suggest or remember changes you made
|
||||
- ➗ automatically convert decimal units to **fractions** for those who like this
|
||||
- 🐳 Easy setup with **Docker**
|
||||
- 🎨 Customize your interface with **themes**
|
||||
- ✉️ Export and import recipes from other users
|
||||
- 🌍 localized in many languages thanks to the awesome community
|
||||
- ➕ Many more like recipe scaling, image compression, cookbooks, printing views, ...
|
||||
|
||||
366
docs/install/docker.md
Normal file
366
docs/install/docker.md
Normal file
@@ -0,0 +1,366 @@
|
||||
!!! success "Recommended Installation"
|
||||
Setting up this application using Docker is recommended. This does not mean that other options are bad, just that
|
||||
support is much easier for this setup.
|
||||
|
||||
It is possible to install this application using many docker configurations.
|
||||
|
||||
Please read the instructions/notes on each example carefully and decide if this is the way for you.
|
||||
|
||||
## Docker
|
||||
|
||||
The docker image (`vabene1111/recipes`) simply exposes the application on port `8080`.
|
||||
|
||||
It can be run using
|
||||
|
||||
```shell
|
||||
docker run -d \
|
||||
-v ./staticfiles:/opt/recipes/staticfiles \
|
||||
-v ./mediafiles:/opt/recipes/mediafiles \
|
||||
-p 80:8080 \
|
||||
-e SECRET_KEY=
|
||||
-e DB_ENGINE=django.db.backends.postgresql
|
||||
-e POSTGRES_HOST=db_recipes
|
||||
-e POSTGRES_PORT=5432
|
||||
-e POSTGRES_USER=djangodb
|
||||
-e POSTGRES_PASSWORD=
|
||||
-e POSTGRES_DB=djangodb
|
||||
vabene1111/recipes
|
||||
```
|
||||
|
||||
Please make sure, if you run your image this way, to consult
|
||||
the [.env.template](https://raw.githubusercontent.com/vabene1111/recipes/master/.env.template)
|
||||
file in the GitHub repository to verify if additional environment variables are required for your setup.
|
||||
|
||||
## Docker Compose
|
||||
|
||||
The main and also recommended installation option is to install this application using docker compose.
|
||||
|
||||
1. Choose your `docker-compose.yml` from the examples below
|
||||
2. Download the `.env` configuration file and **edit it accordingly**.
|
||||
```shell
|
||||
wget https://raw.githubusercontent.com/vabene1111/recipes/develop/.env.template -O .env
|
||||
```
|
||||
3. Start your container using `docker-compose up -d`
|
||||
|
||||
### Plain
|
||||
|
||||
This configuration exposes the application trough a nginx web server on port 80 of you machine.
|
||||
|
||||
```yaml
|
||||
version: "3"
|
||||
services:
|
||||
db_recipes:
|
||||
restart: always
|
||||
image: postgres:11-alpine
|
||||
volumes:
|
||||
- ./postgresql:/var/lib/postgresql/data
|
||||
env_file:
|
||||
- ./.env
|
||||
|
||||
web_recipes:
|
||||
image: vabene1111/recipes
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- staticfiles:/opt/recipes/staticfiles
|
||||
- mediafiles:/opt/recipes/mediafiles
|
||||
- nginx_config:/opt/recipes/nginx/conf.d
|
||||
depends_on:
|
||||
- db_recipes
|
||||
|
||||
nginx_recipes:
|
||||
image: nginx:mainline-alpine
|
||||
restart: always
|
||||
ports:
|
||||
- 80:80
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- nginx_config:/etc/nginx/conf.d:ro
|
||||
- staticfiles:/static
|
||||
- mediafiles:/media
|
||||
|
||||
volumes:
|
||||
nginx
|
||||
staticfiles
|
||||
mediafiles:
|
||||
driver: local
|
||||
driver_opts:
|
||||
type: 'none'
|
||||
o: 'bind'
|
||||
device: './mediafiles'
|
||||
```
|
||||
|
||||
### Reverse Proxy
|
||||
|
||||
Most deployments will likely use a reverse proxy.
|
||||
|
||||
#### Traefik
|
||||
If you use traefik this configuration is the one for you.
|
||||
|
||||
!!! info
|
||||
Traefik can be a little confusing to setup.
|
||||
Please refer to [their excellent documentation](https://doc.traefik.io/traefik/). If that does not help
|
||||
[this little example](traefik.md) might be for you.
|
||||
|
||||
```yaml
|
||||
version: "3"
|
||||
services:
|
||||
db_recipes:
|
||||
restart: always
|
||||
image: postgres:11-alpine
|
||||
volumes:
|
||||
- ./postgresql:/var/lib/postgresql/data
|
||||
env_file:
|
||||
- ./.env
|
||||
networks:
|
||||
- default
|
||||
|
||||
web_recipes:
|
||||
image: vabene1111/recipes
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- staticfiles:/opt/recipes/staticfiles
|
||||
- mediafiles:/opt/recipes/mediafiles
|
||||
- nginx_config:/opt/recipes/nginx/conf.d
|
||||
depends_on:
|
||||
- db_recipes
|
||||
networks:
|
||||
- default
|
||||
|
||||
nginx_recipes:
|
||||
image: nginx:mainline-alpine
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- nginx_config:/etc/nginx/conf.d:ro
|
||||
- staticfiles:/static
|
||||
- mediafiles:/media
|
||||
labels: # traefik example labels
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.recipes.rule=Host(`recipes.mydomain.com`, `recipes.myotherdomain.com`)"
|
||||
- "traefik.http.routers.recipes.entrypoints=web_secure" # your https endpoint
|
||||
- "traefik.http.routers.recipes.tls.certresolver=le_resolver" # your cert resolver
|
||||
networks:
|
||||
- default
|
||||
- traefik
|
||||
|
||||
networks:
|
||||
default:
|
||||
traefik: # This is you external traefik network
|
||||
external: true
|
||||
|
||||
volumes:
|
||||
nginx
|
||||
staticfiles
|
||||
mediafiles:
|
||||
driver: local
|
||||
driver_opts:
|
||||
type: 'none'
|
||||
o: 'bind'
|
||||
device: './mediafiles'
|
||||
```
|
||||
|
||||
#### nginx-proxy
|
||||
|
||||
This is a docker compose example when using [jwilder's nginx reverse proxy](https://github.com/jwilder/docker-gen)
|
||||
in combination with [jrcs's letsencrypt companion](https://hub.docker.com/r/jrcs/letsencrypt-nginx-proxy-companion/).
|
||||
|
||||
Please refer to the appropriate documentation on how to setup the reverse proxy and networks.
|
||||
|
||||
Remember to add the appropriate environment variables to `.env` file:
|
||||
```
|
||||
VIRTUAL_HOST=
|
||||
LETSENCRYPT_HOST=
|
||||
LETSENCRYPT_EMAIL=
|
||||
```
|
||||
|
||||
```yaml
|
||||
version: "3"
|
||||
services:
|
||||
db_recipes:
|
||||
restart: always
|
||||
image: postgres:11-alpine
|
||||
volumes:
|
||||
- ./postgresql:/var/lib/postgresql/data
|
||||
env_file:
|
||||
- ./.env
|
||||
networks:
|
||||
- default
|
||||
|
||||
web_recipes:
|
||||
image: vabene1111/recipes
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- staticfiles:/opt/recipes/staticfiles
|
||||
- mediafiles:/opt/recipes/mediafiles
|
||||
- nginx_config:/opt/recipes/nginx/conf.d
|
||||
depends_on:
|
||||
- db_recipes
|
||||
networks:
|
||||
- default
|
||||
|
||||
nginx_recipes:
|
||||
image: nginx:mainline-alpine
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- nginx_config:/etc/nginx/conf.d:ro
|
||||
- staticfiles:/static
|
||||
- mediafiles:/media
|
||||
networks:
|
||||
- default
|
||||
- nginx-proxy
|
||||
|
||||
networks:
|
||||
default:
|
||||
nginx-proxy:
|
||||
external:
|
||||
name: nginx-proxy
|
||||
|
||||
volumes:
|
||||
nginx
|
||||
staticfiles
|
||||
mediafiles:
|
||||
driver: local
|
||||
driver_opts:
|
||||
type: 'none'
|
||||
o: 'bind'
|
||||
device: './mediafiles'
|
||||
```
|
||||
|
||||
## Additional Information
|
||||
|
||||
### Nginx vs Gunicorn
|
||||
All examples use an additional `nginx` container to serve mediafiles and act as the forward facing webserver.
|
||||
This is **technically not required** but **very much recommended**.
|
||||
|
||||
I do not 100% understand the deep technical details but the [developers of gunicorn](https://serverfault.com/questions/331256/why-do-i-need-nginx-and-something-like-gunicorn/331263#331263),
|
||||
the WSGi server that handles the python execution, explicitly state that it is not recommended to deploy without nginx.
|
||||
You will also likely not see any decrease in performance or a lot of space used as nginx is a very light container.
|
||||
|
||||
!!! info
|
||||
Even if you run behind a reverse proxy as described above, using an additional nginx container is the recommended option.
|
||||
|
||||
If you run a small private deployment and dont care about performance, security and whatever else feel free to run
|
||||
without a ngix container.
|
||||
|
||||
!!! warning
|
||||
When running without nginx make sure to enable `GUNICORN_MEDIA` in the `.env`. Without it media files will be uploaded
|
||||
but not shown on the page.
|
||||
|
||||
For additional information please refer to the [0.9.0 Release](https://github.com/vabene1111/recipes/releases?after=0.9.0)
|
||||
and [Issue 201](https://github.com/vabene1111/recipes/issues/201) where these topics have been discussed.
|
||||
See also refer to the [official gunicorn docs](https://docs.gunicorn.org/en/stable/deploy.html).
|
||||
|
||||
### Nginx Config
|
||||
|
||||
In order to give the user (you) the greatest amount of freedom when choosing how to deploy this application the
|
||||
webserver is not directly bundled with the docker image.
|
||||
|
||||
This has the downside that it is difficult to supply the configuration to the webserver (e.g. nginx). Up until
|
||||
Version `0.13.0` this had to be done manually by downloading the nginx config file and placing it in a directory that
|
||||
was then mounted into the nginx container.
|
||||
|
||||
From version `0.13.0` the config file is supplied using the application image (`vabene1111/recipes`). It is then mounted
|
||||
to the host system and from there into the nginx container.
|
||||
|
||||
This is not really a clean solution, but I could not find any better alternative that provided the same amount of
|
||||
usability. If you know of any better way feel free to open an issue.
|
||||
|
||||
### Using Proxy Authentication
|
||||
|
||||
!!! Info "Community Contributed Tutorial"
|
||||
This tutorial was provided by a community member. Since i do not use reverse proxy authentication i cannot provide any
|
||||
assistance should you choose to use this authentication method.
|
||||
|
||||
In order use proxy authentication you will need to:
|
||||
|
||||
1. set `REVERSE_PROXY_AUTH=1` in the `.env` file
|
||||
2. update your nginx configuration file
|
||||
|
||||
Using any of the examples above will automatically generate a configuration file inside a docker volume.
|
||||
Use `docker volume inspect recipes_nginx` to find out where your volume is stored.
|
||||
|
||||
!!! warning "Configuration File Volume"
|
||||
The nginx config volume is generated when the container is first run. You can change the volume to a bind mount in the
|
||||
warning `docker-compose.yml` but then you will need to manually create it. See Section `Volumes vs Bind Mounts` below
|
||||
for more information.
|
||||
|
||||
The following example shows a configuration for Authelia
|
||||
|
||||
```
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
client_max_body_size 16M;
|
||||
|
||||
# serve static files
|
||||
location /static/ {
|
||||
alias /static/;
|
||||
}
|
||||
# serve media files
|
||||
location /media/ {
|
||||
alias /media/;
|
||||
}
|
||||
|
||||
# Authelia endpoint for authentication requests
|
||||
include /config/nginx/auth.conf;
|
||||
|
||||
# pass requests for dynamic content to gunicorn
|
||||
location / {
|
||||
proxy_set_header Host $host;
|
||||
proxy_pass http://web_recipes:8080;
|
||||
|
||||
# Ensure Authelia is specifically required for this endpoint
|
||||
# This line is important as it will return a 401 error if the user doesn't have access
|
||||
include /config/nginx/authelia.conf;
|
||||
|
||||
auth_request_set $user $upstream_http_remote_user;
|
||||
proxy_set_header REMOTE-USER $user;
|
||||
}
|
||||
|
||||
# Required to allow user to logout of authentication from within Recipes
|
||||
# Ensure the <auth_endpoint> below is changed to actual the authentication url
|
||||
location /accounts/logout/ {
|
||||
return 301 http://<auth_endpoint>/logout
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Please refer to the appropriate documentation on how to setup the reverse proxy, authentication, and networks.
|
||||
|
||||
Ensure users have been configured for Authelia, and that the endpoint that recipes is pointed to is protected, but
|
||||
available.
|
||||
|
||||
There is a good guide to the other additional files that need to be added to your Nginx set up at
|
||||
the [Authelia Docs](https://docs.authelia.com/deployment/supported-proxies/nginx.html).
|
||||
|
||||
Remember to add the appropriate environment variables to `.env` file (example for nginx proxy):
|
||||
|
||||
```
|
||||
VIRTUAL_HOST=
|
||||
LETSENCRYPT_HOST=
|
||||
LETSENCRYPT_EMAIL=
|
||||
PROXY_HEADER=
|
||||
```
|
||||
|
||||
### Volumes vs Bind Mounts
|
||||
|
||||
Since I personally prefer to have my data where my `docker-compose.yml` resides, bind mounts are used in the example
|
||||
configuration files for all user generated data (e.g. Postgresql and media files).
|
||||
|
||||
Please note that [there is a difference in functionality](https://docs.docker.com/storage/volumes/)
|
||||
between the two and you cannot always simply interchange them.
|
||||
|
||||
You can move everything to volumes if you prefer it this way, **but you cannot convert the nginx config file to a bind
|
||||
mount.**
|
||||
If you do so you will have to manually create the nginx config file and restart the container once after creating it.
|
||||
54
docs/install/docker/nginx-proxy/docker-compose.yml
Normal file
54
docs/install/docker/nginx-proxy/docker-compose.yml
Normal file
@@ -0,0 +1,54 @@
|
||||
version: "3"
|
||||
services:
|
||||
db_recipes:
|
||||
restart: always
|
||||
image: postgres:11-alpine
|
||||
volumes:
|
||||
- ./postgresql:/var/lib/postgresql/data
|
||||
env_file:
|
||||
- ./.env
|
||||
networks:
|
||||
- default
|
||||
|
||||
web_recipes:
|
||||
image: vabene1111/recipes
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- staticfiles:/opt/recipes/staticfiles
|
||||
- mediafiles:/opt/recipes/mediafiles
|
||||
- nginx_config:/opt/recipes/nginx/conf.d
|
||||
depends_on:
|
||||
- db_recipes
|
||||
networks:
|
||||
- default
|
||||
|
||||
nginx_recipes:
|
||||
image: nginx:mainline-alpine
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- nginx_config:/etc/nginx/conf.d:ro
|
||||
- staticfiles:/static
|
||||
- mediafiles:/media
|
||||
networks:
|
||||
- default
|
||||
- nginx-proxy
|
||||
|
||||
networks:
|
||||
default:
|
||||
nginx-proxy:
|
||||
external:
|
||||
name: nginx-proxy
|
||||
|
||||
volumes:
|
||||
nginx
|
||||
staticfiles
|
||||
mediafiles:
|
||||
driver: local
|
||||
driver_opts:
|
||||
type: 'none'
|
||||
o: 'bind'
|
||||
device: './mediafiles'
|
||||
@@ -14,8 +14,9 @@ services:
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- ./staticfiles:/opt/recipes/staticfiles
|
||||
- ./mediafiles:/opt/recipes/mediafiles
|
||||
- staticfiles:/opt/recipes/staticfiles
|
||||
- mediafiles:/opt/recipes/mediafiles
|
||||
- nginx_config:/opt/recipes/nginx/conf.d
|
||||
depends_on:
|
||||
- db_recipes
|
||||
|
||||
@@ -27,6 +28,16 @@ services:
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- ./nginx/conf.d:/etc/nginx/conf.d
|
||||
- ./staticfiles:/static
|
||||
- ./mediafiles:/media
|
||||
- nginx_config:/etc/nginx/conf.d:ro
|
||||
- staticfiles:/static
|
||||
- mediafiles:/media
|
||||
|
||||
volumes:
|
||||
nginx
|
||||
staticfiles
|
||||
mediafiles:
|
||||
driver: local
|
||||
driver_opts:
|
||||
type: 'none'
|
||||
o: 'bind'
|
||||
device: './mediafiles'
|
||||
@@ -16,8 +16,9 @@ services:
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- ./staticfiles:/opt/recipes/staticfiles
|
||||
- ./mediafiles:/opt/recipes/mediafiles
|
||||
- staticfiles:/opt/recipes/staticfiles
|
||||
- mediafiles:/opt/recipes/mediafiles
|
||||
- nginx_config:/opt/recipes/nginx/conf.d
|
||||
depends_on:
|
||||
- db_recipes
|
||||
networks:
|
||||
@@ -29,13 +30,14 @@ services:
|
||||
env_file:
|
||||
- ./.env
|
||||
volumes:
|
||||
- ./nginx/conf.d:/etc/nginx/conf.d
|
||||
- ./mediafiles:/media
|
||||
- nginx_config:/etc/nginx/conf.d:ro
|
||||
- staticfiles:/static
|
||||
- mediafiles:/media
|
||||
labels: # traefik example labels
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.recipes.rule=Host(`recipes.mydomain.com`, `recipes.myotherdomain.com`)"
|
||||
- "traefik.http.routers.recipes.entrypoints=web_secure"
|
||||
- "traefik.http.routers.recipes.tls.certresolver=le_resolver"
|
||||
- "traefik.http.routers.recipes.entrypoints=web_secure" # your https endpoint
|
||||
- "traefik.http.routers.recipes.tls.certresolver=le_resolver" # your cert resolver
|
||||
networks:
|
||||
- default
|
||||
- traefik
|
||||
@@ -43,4 +45,14 @@ services:
|
||||
networks:
|
||||
default:
|
||||
traefik: # This is you external traefik network
|
||||
external: true
|
||||
external: true
|
||||
|
||||
volumes:
|
||||
nginx
|
||||
staticfiles
|
||||
mediafiles:
|
||||
driver: local
|
||||
driver_opts:
|
||||
type: 'none'
|
||||
o: 'bind'
|
||||
device: './mediafiles'
|
||||
@@ -1,6 +1,15 @@
|
||||
!!! info "Community Contributed"
|
||||
This guide was contributed by the community and is neither officially supported, nor updated or tested.
|
||||
|
||||
|
||||
# Kubernetes
|
||||
|
||||
This is a basic kubernetes setup. Please note that this does not necessarily follow Kubernetes best practices and should only used as a basis to build your own setup from!
|
||||
This is a basic kubernetes setup.
|
||||
Please note that this does not necessarily follow Kubernetes best practices and should only used as a
|
||||
basis to build your own setup from!
|
||||
|
||||
All files con be found here in the Github Repo:
|
||||
[docs/install/k8s](https://github.com/vabene1111/recipes/tree/develop/docs/install/k8s)
|
||||
|
||||
## Important notes
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
These intructions are inspired from a standard django/gunicorn/postgresql instructions ([for example](https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04))
|
||||
|
||||
**Important note:** Be sure to use pyton3.8 and pip related to python 3.8. Depending on your distribution calling `python` or `pip` will use python2 instead of pyton 3.8.
|
||||
!!! warning
|
||||
Be sure to use pyton3.8 and pip related to python 3.8. Depending on your distribution calling `python` or `pip` will use python2 instead of pyton 3.8.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
@@ -34,43 +35,9 @@ ALTER ROLE djangouser SET timezone TO 'UTC';
|
||||
ALTER USER djangouser WITH SUPERUSER;
|
||||
```
|
||||
|
||||
Move or copy `.env.template` to `.env` and update it with relevent values. For example:
|
||||
|
||||
```env
|
||||
# only set this to true when testing/debugging
|
||||
# when unset: 1 (true) - dont unset this, just for development
|
||||
DEBUG=0
|
||||
|
||||
# hosts the application can run under e.g. recipes.mydomain.com,cooking.mydomain.com,...
|
||||
#ALLOWED_HOSTS=*
|
||||
|
||||
# random secret key, use for example base64 /dev/urandom | head -c50 to generate one
|
||||
SECRET_KEY=TOGENERATE
|
||||
|
||||
# add only a database password if you want to run with the default postgres, otherwise change settings accordingly
|
||||
DB_ENGINE=django.db.backends.postgresql_psycopg2
|
||||
POSTGRES_HOST=localhost
|
||||
POSTGRES_PORT=5432
|
||||
POSTGRES_USER=djangouser
|
||||
POSTGRES_PASSWORD=password
|
||||
POSTGRES_DB=djangodb
|
||||
|
||||
# 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.
|
||||
# when unset: 1 (true) - this is temporary until an appropriate amount of time has passed for everyone to migrate
|
||||
GUNICORN_MEDIA=0
|
||||
|
||||
|
||||
# allow authentication via reverse proxy (e.g. authelia), leave of if you dont know what you are doing
|
||||
# docs: https://github.com/vabene1111/recipes/tree/develop/docs/docker/nginx-proxy%20with%20proxy%20authentication
|
||||
# when unset: 0 (false)
|
||||
REVERSE_PROXY_AUTH=0
|
||||
|
||||
|
||||
# the default value for the user preference 'comments' (enable/disable commenting system)
|
||||
# when unset: 1 (true)
|
||||
COMMENT_PREF_DEFAULT=1
|
||||
Download the `.env` configuration file and **edit it accordingly**.
|
||||
```shell
|
||||
wget https://raw.githubusercontent.com/vabene1111/recipes/develop/.env.template -O .env
|
||||
```
|
||||
|
||||
## Initialize the application
|
||||
@@ -79,7 +46,7 @@ Execute `export $(cat .env |grep "^[^#]" | xargs)` to load variables from `.env`
|
||||
|
||||
Execute `/python3.8 manage.py migrate`
|
||||
|
||||
And revert superuser from postgres: `sudo -u postgres psql` and `ALTER USER djangouser WITH NOSUPERUSER;`
|
||||
and revert superuser from postgres: `sudo -u postgres psql` and `ALTER USER djangouser WITH NOSUPERUSER;`
|
||||
|
||||
Generate static files: `python3.8 manage.py collectstatic` and remember the folder where files have been copied.
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
!!! info "Community Contributed"
|
||||
This guide was contributed by the community and is neither officially supported, nor updated or tested.
|
||||
|
||||
Many people appear to host this application on their Synology NAS. The following documentation was provided by
|
||||
@therealschimmi in [this issue discussion](https://github.com/vabene1111/recipes/issues/98#issuecomment-643062907).
|
||||
|
||||
@@ -6,7 +9,7 @@ setup. Since i cannot test it myself feedback and improvements are always very w
|
||||
|
||||
## Instructions
|
||||
|
||||
Basic guide to setup vabenee1111/recipes docker container on Synology NAS
|
||||
Basic guide to setup `vabenee1111/recipes docker` container on Synology NAS
|
||||
|
||||
1. Login to Synology DSM through your browser
|
||||
|
||||
@@ -19,12 +22,13 @@ Basic guide to setup vabenee1111/recipes docker container on Synology NAS
|
||||
|
||||
2. Download templates
|
||||
- vabene1111 gives you a few samples for various setups to work with. I chose to use the plain setup for now.
|
||||
- Open https://github.com/vabene1111/recipes/tree/develop/docs/docker
|
||||
- Open https://github.com/vabene1111/recipes/tree/develop/docs/install/docker
|
||||
- Download docker-compose.yml to your recipes folder
|
||||
- Open https://github.com/vabene1111/recipes/tree/develop/docs/docker/plain/nginx/conf.d
|
||||
- Open https://github.com/vabene1111/recipes/tree/develop/nginx/conf.d
|
||||
- Download Recipes.conf to your conf.d folder
|
||||
- Open https://github.com/vabene1111/recipes/blob/develop/.env.template
|
||||
- Copy the text and save it as 'env' to your recipes folder (no filename extension!)
|
||||
- Copy the text and save it as '.env' to your recipes folder (no filename extension!)
|
||||
- Add a POSTGRES_PASSWORD
|
||||
- Once done, it should look like this:
|
||||
|
||||

|
||||
@@ -49,4 +53,25 @@ Creating recipes_db_recipes_1 ... done
|
||||
Creating recipes_web_recipes_1 ... done
|
||||
```
|
||||
- Browse to 192.168.1.1:2000 or whatever your IP and port are
|
||||
- While the containers are starting and doing whatever they need to do, you might still get HTTP errors e.g. 500 or 502. Just be patient and try again in a moment
|
||||
- While the containers are starting and doing whatever they need to do, you might still get HTTP errors e.g. 500 or 502. Just be patient and try again in a moment
|
||||
|
||||
5. Additional SSL Setup
|
||||
- create foler `ssl` inside `nginx` folder
|
||||
- download your ssl certificate from `security` tab in dsm `control panel`
|
||||
- or create a task in `task manager` because Synology will update the certificate every few months
|
||||
- set task to repeat every day
|
||||
- in the script write:
|
||||
```
|
||||
SRC="/usr/syno/etc/certificate/system/default"
|
||||
DEST="/volume1/docker/recipes/nginx/ssl/"
|
||||
if [ ! -f "$DEST/fullchain.pem" ] || [ "$SRC/fullchain.pem" -nt "$DEST/fullchain.pem" ]; then
|
||||
cp "$SRC/fullchain.pem" "$DEST/"
|
||||
cp "$SRC/privkey.pem" "$DEST/"
|
||||
chown root:root "$DEST/fullchain.pem" "$DEST/privkey.pem"
|
||||
chmod 600 "$DEST/fullchain.pem" "$DEST/privkey.pem"
|
||||
/usr/syno/bin/synowebapi --exec api=SYNO.Docker.Container version=1 method=restart name=recipes_nginx_recipes_1
|
||||
fi
|
||||
```
|
||||
- change `docker-compose.yml`
|
||||
add `- ./nginx/ssl:/etc/nginx/certs` to the `volumes` of `nginx_recipes`
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
This is the recommended setup to run django recipes with traefik.
|
||||
|
||||
----
|
||||
|
||||
Please refer to the traefik documentation on how to setup a docker service in traefik. Since treafik can be a little
|
||||
confusing at times, the following are examples of my traefik configuration.
|
||||
|
||||
!!! danger
|
||||
Please refer to [the offical documentation](https://doc.traefik.io/traefik/).
|
||||
This example just shows something similar to my setup in case you dont understand the offical documentation.
|
||||
|
||||
You need to create a network called `traefik` using `docker network create traefik`.
|
||||
## docker-compose.yml
|
||||
BIN
docs/preview.png
BIN
docs/preview.png
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.4 MiB |
BIN
docs/preview.xcf
BIN
docs/preview.xcf
Binary file not shown.
28
docs/system/backup.md
Normal file
28
docs/system/backup.md
Normal file
@@ -0,0 +1,28 @@
|
||||
There is currently no "good" way of backing up your data implemented in the application itself.
|
||||
This mean that you will be responsible for backing up your data.
|
||||
|
||||
It is planned to add a "real" backup feature similar to applications like homeassistant where a snapshot can be
|
||||
downloaded and restored trough the web interface.
|
||||
|
||||
!!! warning
|
||||
When developing a new backup strategy, make sure to also test the restore process!
|
||||
|
||||
## Database
|
||||
Please use any standard way of backing up your database. For most systems this can be achieved by using a dump
|
||||
command that will create an SQL file with all the required data.
|
||||
|
||||
Please refer to your Database System documentation.
|
||||
|
||||
I personally use a [little script](https://github.com/vabene1111/DockerPostgresBackups) that I have created to automatically pull SQL dumps from a postgresql database.
|
||||
It is **neither** well tested nor documented so use at your own risk.
|
||||
I would recommend using it only as a starting place for your own backup strategy.
|
||||
|
||||
## Mediafiles
|
||||
The only Data this application stores apart from the database are the media files (e.g. images) used in your
|
||||
recipes.
|
||||
|
||||
They can be found in the mediafiles mounted directory (depending on your installation).
|
||||
|
||||
To create a backup of those files simply copy them elsewhere. Do it the other way around for restoring.
|
||||
|
||||
The filenames consist of `<random uuid4>_<recipe_id>`. In case you screw up really badly this can help restore data.
|
||||
23
docs/system/updating.md
Normal file
23
docs/system/updating.md
Normal file
@@ -0,0 +1,23 @@
|
||||
The Updating process depends on your chosen method of [installation](/install/docker)
|
||||
|
||||
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.
|
||||
|
||||
## Docker
|
||||
For all setups using Docker the updating process look something like this
|
||||
|
||||
0. Before updating it is recommended to **create a [backup](/system/backup)!**
|
||||
1. Stop the container using `docker-compose down`
|
||||
2. Pull the latest image using `docker-compose pull`
|
||||
3. Start the container again using `docker-compose up -d`
|
||||
|
||||
|
||||
## Manual
|
||||
|
||||
For all setups using a manual installation updates usually involve downloading the latest source code from GitHub.
|
||||
After that make sure to run:
|
||||
|
||||
1. `manage.py collectstatic`
|
||||
2. `manage.py migrate`
|
||||
|
||||
To apply all new migrations and collect new static files.
|
||||
@@ -1,2 +1,3 @@
|
||||
CALL venv\Scripts\activate.bat
|
||||
python manage.py makemessages -i venv -l de -l nl -l rn -l fr -l tr -l pt -l en
|
||||
python manage.py makemessages -i venv -a
|
||||
python manage.py makemessages -i venv -a -l de -d djangojs
|
||||
31
mkdocs.yml
Normal file
31
mkdocs.yml
Normal file
@@ -0,0 +1,31 @@
|
||||
site_name: Recipes
|
||||
site_description: Documentation for Recipes
|
||||
site_author: vabene1111
|
||||
repo_url: https://github.com/vabene1111/recipes
|
||||
edit_uri: https://github.com/vabene1111/recipes/tree/develop/docs
|
||||
theme:
|
||||
name: material
|
||||
palette:
|
||||
scheme: slate
|
||||
primary: green
|
||||
accent: deep orange
|
||||
logo: cookbook/static/favicon.png
|
||||
favicon: cookbook/static/favicon.ico
|
||||
icon:
|
||||
repo: fontawesome/brands/github
|
||||
|
||||
markdown_extensions:
|
||||
- admonition
|
||||
- pymdownx.highlight
|
||||
- pymdownx.superfences
|
||||
|
||||
nav:
|
||||
- Home: 'index.md'
|
||||
- Installation:
|
||||
- Docker: install/docker.md
|
||||
- Synology: install/synology.md
|
||||
- Kubernetes: install/kubernetes.md
|
||||
- Manual: install/manual.md
|
||||
- System:
|
||||
- Updating: system/updating.md
|
||||
- Backup: system/backup.md
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user