remove unused imports, variables and commented code

from integrations and templatetags
This commit is contained in:
smilerz 2023-09-13 09:35:22 -05:00
parent aba7f8db5c
commit 78b1386a1c
No known key found for this signature in database
GPG Key ID: 39444C7606D47126
6 changed files with 29 additions and 24 deletions

View File

@ -20,7 +20,6 @@ class CookBookApp(Integration):
def get_recipe_from_file(self, file):
recipe_html = file.getvalue().decode("utf-8")
# recipe_json, recipe_tree, html_data, images = get_recipe_from_source(recipe_html, 'CookBookApp', self.request)
scrape = text_scraper(text=recipe_html)
recipe_json = get_from_scraper(scrape, self.request)
images = list(dict.fromkeys(get_images_from_soup(scrape.soup, None)))
@ -32,7 +31,7 @@ class CookBookApp(Integration):
try:
recipe.servings = re.findall('([0-9])+', recipe_json['recipeYield'])[0]
except Exception as e:
except Exception:
pass
try:

View File

@ -1,17 +1,12 @@
import base64
import json
from io import BytesIO
from gettext import gettext as _
import requests
import validators
from lxml import etree
from cookbook.helper.ingredient_parser import IngredientParser
from cookbook.helper.recipe_url_import import parse_servings, parse_time, parse_servings_text
from cookbook.helper.recipe_url_import import parse_servings, parse_servings_text, parse_time
from cookbook.integration.integration import Integration
from cookbook.models import Ingredient, Keyword, Recipe, Step
from cookbook.models import Ingredient, Recipe, Step
class Cookmate(Integration):

View File

@ -1,4 +1,3 @@
import re
from io import BytesIO
from zipfile import ZipFile
@ -26,12 +25,13 @@ class CopyMeThat(Integration):
except AttributeError:
source = None
recipe = Recipe.objects.create(name=file.find("div", {"id": "name"}).text.strip()[:128], source_url=source, created_by=self.request.user, internal=True, space=self.request.space, )
recipe = Recipe.objects.create(name=file.find("div", {"id": "name"}).text.strip(
)[:128], source_url=source, created_by=self.request.user, internal=True, space=self.request.space, )
for category in file.find_all("span", {"class": "recipeCategory"}):
keyword, created = Keyword.objects.get_or_create(name=category.text, space=self.request.space)
recipe.keywords.add(keyword)
try:
recipe.servings = parse_servings(file.find("a", {"id": "recipeYield"}).text.strip())
recipe.working_time = iso_duration_to_minutes(file.find("span", {"meta": "prepTime"}).text.strip())
@ -61,7 +61,14 @@ class CopyMeThat(Integration):
if not isinstance(ingredient, Tag) or not ingredient.text.strip() or "recipeIngredient_spacer" in ingredient['class']:
continue
if any(x in ingredient['class'] for x in ["recipeIngredient_subheader", "recipeIngredient_note"]):
step.ingredients.add(Ingredient.objects.create(is_header=True, note=ingredient.text.strip()[:256], original_text=ingredient.text.strip(), space=self.request.space, ))
step.ingredients.add(
Ingredient.objects.create(
is_header=True,
note=ingredient.text.strip()[
:256],
original_text=ingredient.text.strip(),
space=self.request.space,
))
else:
amount, unit, food, note = ingredient_parser.parse(ingredient.text.strip())
f = ingredient_parser.get_food(food)
@ -78,7 +85,7 @@ class CopyMeThat(Integration):
step.save()
recipe.steps.add(step)
step = Step.objects.create(instruction='', space=self.request.space, )
step.name = instruction.text.strip()[:128]
else:
step.instruction += instruction.text.strip() + ' \n\n'

View File

@ -22,7 +22,7 @@ class Default(Integration):
if images:
try:
self.import_recipe_image(recipe, BytesIO(recipe_zip.read(images[0])), filetype=get_filetype(images[0]))
except AttributeError as e:
except AttributeError:
traceback.print_exc()
return recipe

View File

@ -3,19 +3,19 @@ from gettext import gettext as _
import bleach
import markdown as md
from django_scopes import ScopeError
from markdown.extensions.tables import TableExtension
from django import template
from django.db.models import Avg
from django.templatetags.static import static
from django.urls import NoReverseMatch, reverse
from django_scopes import ScopeError
from markdown.extensions.tables import TableExtension
from rest_framework.authtoken.models import Token
from cookbook.helper.mdx_attributes import MarkdownFormatExtension
from cookbook.helper.mdx_urlize import UrlizeExtension
from cookbook.models import Space, get_model_name
from cookbook.models import get_model_name
from recipes import settings
from recipes.settings import STATIC_URL, PLUGINS
from recipes.settings import PLUGINS, STATIC_URL
register = template.Library()
@ -69,8 +69,8 @@ def markdown(value):
"a": ["href", "alt", "title"],
}
parsed_md = parsed_md[3:] # remove outer paragraph
parsed_md = parsed_md[:len(parsed_md)-4]
parsed_md = parsed_md[3:] # remove outer paragraph
parsed_md = parsed_md[:len(parsed_md) - 4]
return bleach.clean(parsed_md, tags, markdown_attrs)
@ -144,6 +144,7 @@ def is_debug():
def markdown_link():
return f"{_('You can use markdown to format this field. See the ')}<a target='_blank' href='{reverse('docs_markdown')}'>{_('docs here')}</a>"
@register.simple_tag
def plugin_dropdown_nav_templates():
templates = []
@ -152,6 +153,7 @@ def plugin_dropdown_nav_templates():
templates.append(p['nav_dropdown'])
return templates
@register.simple_tag
def plugin_main_nav_templates():
templates = []
@ -199,7 +201,8 @@ def base_path(request, path_type):
@register.simple_tag
def user_prefs(request):
from cookbook.serializer import UserPreferenceSerializer # putting it with imports caused circular execution
from cookbook.serializer import \
UserPreferenceSerializer # putting it with imports caused circular execution
try:
return UserPreferenceSerializer(request.user.userpreference, context={'request': request}).data
except AttributeError:

View File

@ -1,6 +1,7 @@
from cookbook.models import UserPreference
from django import template
from django.templatetags.static import static
from cookbook.models import UserPreference
from recipes.settings import STICKY_NAV_PREF_DEFAULT
register = template.Library()
@ -41,4 +42,4 @@ def sticky_nav(request):
(request.user.is_authenticated and request.user.userpreference.sticky_navbar): # noqa: E501
return 'position: sticky; top: 0; left: 0; z-index: 1000;'
else:
return ''
return ''