Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Jul 8, 2024
2 parents fb821ba + af9a956 commit cc839a1
Show file tree
Hide file tree
Showing 124 changed files with 4,217 additions and 3,462 deletions.
3 changes: 3 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# random secret key, use for example `base64 /dev/urandom | head -c50` to generate one
SECRET_KEY=

# allowed hosts (see documentation), should be set to your hostname(s) but might be * (default) for some proxies/providers
# ALLOWED_HOSTS=recipes.mydomain.com

# add only a database password if you want to run with the default postgres, otherwise change settings accordingly
DB_ENGINE=django.db.backends.postgresql
POSTGRES_HOST=db_recipes
Expand Down
22 changes: 22 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[flake8]
extend-ignore =
# Whitespace before ':' - Required for black compatibility
E203,
# Line break occurred before a binary operator - Required for black compatibility
W503,
# Comparison to False should be 'if cond is False:' or 'if not cond:'
E712
exclude =
.git,
**/__pycache__,
**/.git,
**/.svn,
**/.hg,
**/CVS,
**/.DS_Store,
.vscode,
**/*.pyc
per-file-ignores=
cookbook/apps.py:F401
max-line-length = 179

28 changes: 12 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ docs/reports/**

# Django stuff:
*.log
mediafiles/
*.sqlite3*
staticfiles/
postgresql/
data/

# Sphinx documentation
docs/_build/
Expand All @@ -59,32 +64,23 @@ target/

\.idea/dataSources\.local\.xml

venv/

mediafiles/

*.sqlite3*

\.idea/workspace\.xml

\.idea/misc\.xml

# Deployment

\.env
staticfiles/
postgresql/
data/


cookbook/static/vue
vue/webpack-stats.json
/docker-compose.override.yml
vue/node_modules
plugins
vetur.config.js
cookbook/static/vue
vue/webpack-stats.json
vue3/node_modules
cookbook/templates/sw.js
.prettierignore
vue/.yarn
vue3/.vite
vue3/node_modules

# Configs
vetur.config.js
venv/
31 changes: 31 additions & 0 deletions .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# generated files
api.ts
vue/src/apps/*.js
vue/node_modules
staticfiles/
docs/reports/
/vue3/src/openapi/

# ignored files - prettier interferes with django templates and github actions
*.html
*.yml
*.yaml

7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 179,
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"experimentalTernaries": true
}
11 changes: 9 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
"cookbook/tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
"python.testing.pytestEnabled": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[python]": {
"editor.defaultFormatter": "eeyore.yapf",
},
"yapf.args": [],
"isort.args": []
}
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ RUN apk add --no-cache postgresql-libs postgresql-client gettext zlib libjpeg li
#Print all logs without buffering it.
ENV PYTHONUNBUFFERED 1

ENV DOCKER true

#This port will be used by gunicorn.
EXPOSE 8080

Expand Down
2 changes: 1 addition & 1 deletion boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ echo "Migrating database"

python manage.py migrate

echo "Generating static files"
echo "Collecting static files, this may take a while..."

python manage.py collectstatic_js_reverse
python manage.py collectstatic --noinput
Expand Down
11 changes: 9 additions & 2 deletions cookbook/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class StepAdmin(admin.ModelAdmin):
@admin.display(description="Name")
def recipe_and_name(obj):
if not obj.recipe_set.exists():
return f"Orphaned Step{'':s if not obj.name else f': {obj.name}'}"
return "Orphaned Step" + ('' if not obj.name else f': {obj.name}')
return f"{obj.recipe_set.first().name}: {obj.name}" if obj.name else obj.recipe_set.first().name


Expand Down Expand Up @@ -376,10 +376,17 @@ class ShareLinkAdmin(admin.ModelAdmin):
admin.site.register(ShareLink, ShareLinkAdmin)


@admin.action(description='Delete all properties with type')
def delete_properties_with_type(modeladmin, request, queryset):
for pt in queryset:
Property.objects.filter(property_type=pt).delete()


class PropertyTypeAdmin(admin.ModelAdmin):
search_fields = ('space',)
search_fields = ('name',)

list_display = ('id', 'space', 'name', 'fdc_id')
actions = [delete_properties_with_type]


admin.site.register(PropertyType, PropertyTypeAdmin)
Expand Down
67 changes: 35 additions & 32 deletions cookbook/helper/recipe_url_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@


def get_from_scraper(scrape, request):
# converting the scrape_me object to the existing json format based on ld+json
# converting the scrape_html object to the existing json format based on ld+json

recipe_json = {
'steps': [],
'internal': True
}
recipe_json = {'steps': [], 'internal': True}
keywords = []

# assign source URL
Expand Down Expand Up @@ -157,11 +154,18 @@ def get_from_scraper(scrape, request):
# assign steps
try:
for i in parse_instructions(scrape.instructions()):
recipe_json['steps'].append({'instruction': i, 'ingredients': [], 'show_ingredients_table': request.user.userpreference.show_step_ingredients, })
recipe_json['steps'].append({
'instruction': i,
'ingredients': [],
'show_ingredients_table': request.user.userpreference.show_step_ingredients,
})
except Exception:
pass
if len(recipe_json['steps']) == 0:
recipe_json['steps'].append({'instruction': '', 'ingredients': [], })
recipe_json['steps'].append({
'instruction': '',
'ingredients': [],
})

recipe_json['description'] = recipe_json['description'][:512]
if len(recipe_json['description']) > 256: # split at 256 as long descriptions don't look good on recipe cards
Expand All @@ -182,20 +186,20 @@ def get_from_scraper(scrape, request):
'original_text': x
}
if unit:
ingredient['unit'] = {'name': unit, }
ingredient['unit'] = {
'name': unit,
}
recipe_json['steps'][0]['ingredients'].append(ingredient)
except Exception:
recipe_json['steps'][0]['ingredients'].append(
{
'amount': 0,
'unit': None,
'food': {
'name': x,
},
'note': '',
'original_text': x
}
)
recipe_json['steps'][0]['ingredients'].append({
'amount': 0,
'unit': None,
'food': {
'name': x,
},
'note': '',
'original_text': x
})
except Exception:
pass

Expand Down Expand Up @@ -248,14 +252,16 @@ def get_from_youtube_scraper(url, request):
'working_time': 0,
'waiting_time': 0,
'image': "",
'keywords': [{'name': kw.name, 'label': kw.name, 'id': kw.pk}],
'keywords': [{
'name': kw.name,
'label': kw.name,
'id': kw.pk
}],
'source_url': url,
'steps': [
{
'ingredients': [],
'instruction': ''
}
]
'steps': [{
'ingredients': [],
'instruction': ''
}]
}

try:
Expand Down Expand Up @@ -367,8 +373,8 @@ def parse_servings(servings):
servings = 1
elif isinstance(servings, list):
try:
servings = int(re.findall(r'\b\d+\b', servings[0])[0])
except KeyError:
servings = int(re.findall(r'\b\d+\b', str(servings[0]))[0])
except (KeyError, IndexError):
servings = 1
return servings

Expand Down Expand Up @@ -452,10 +458,7 @@ def normalize_string(string):


def iso_duration_to_minutes(string):
match = re.match(
r'P((?P<years>\d+)Y)?((?P<months>\d+)M)?((?P<weeks>\d+)W)?((?P<days>\d+)D)?T((?P<hours>\d+)H)?((?P<minutes>\d+)M)?((?P<seconds>\d+)S)?',
string
).groupdict()
match = re.match(r'P((?P<years>\d+)Y)?((?P<months>\d+)M)?((?P<weeks>\d+)W)?((?P<days>\d+)D)?T((?P<hours>\d+)H)?((?P<minutes>\d+)M)?((?P<seconds>\d+)S)?', string).groupdict()
return int(match['days'] or 0) * 24 * 60 + int(match['hours'] or 0) * 60 + int(match['minutes'] or 0)


Expand Down
2 changes: 1 addition & 1 deletion cookbook/helper/scrapers/scrapers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(
html=None,
url=None,
):
self.wild_mode = False
self.supported_only = False
self.meta_http_equiv = False
self.soup = BeautifulSoup(html, "html.parser")
self.url = url
Expand Down
24 changes: 12 additions & 12 deletions cookbook/integration/nextcloud_cookbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ def get_recipe_from_file(self, file):
step = Step.objects.create(
instruction=s, space=self.request.space, show_ingredients_table=self.request.user.userpreference.show_step_ingredients,
)
if not ingredients_added:
if len(recipe_json['description'].strip()) > 500:
step.instruction = recipe_json['description'].strip() + '\n\n' + step.instruction

ingredients_added = True

ingredient_parser = IngredientParser(self.request, True)
ingredient_parser = IngredientParser(self.request, True)
if ingredients_added == False:
for ingredient in recipe_json['recipeIngredient']:
amount, unit, food, note = ingredient_parser.parse(ingredient)
f = ingredient_parser.get_food(food)
u = ingredient_parser.get_unit(unit)
step.ingredients.add(Ingredient.objects.create(
food=f, unit=u, amount=amount, note=note, original_text=ingredient, space=self.request.space,
))
ingredients_added = True
if ingredient.startswith('##'):
subheader = ingredient.replace('##', '', 1)
step.ingredients.add(Ingredient.objects.create(note=subheader, is_header=True, no_amount=True, space=self.request.space))
else:
amount, unit, food, note = ingredient_parser.parse(ingredient)
f = ingredient_parser.get_food(food)
u = ingredient_parser.get_unit(unit)
step.ingredients.add(Ingredient.objects.create(
food=f, unit=u, amount=amount, note=note, original_text=ingredient, space=self.request.space,))
recipe.steps.add(step)

if 'nutrition' in recipe_json:
Expand Down
Loading

0 comments on commit cc839a1

Please sign in to comment.