remove unused imports, variables and commented code in helpers
This commit is contained in:
parent
6dacd44f1f
commit
aba7f8db5c
@ -1,11 +1,10 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
from gettext import gettext as _
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
from allauth.account.adapter import DefaultAccountAdapter
|
from allauth.account.adapter import DefaultAccountAdapter
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.core.cache import caches
|
from django.core.cache import caches
|
||||||
from gettext import gettext as _
|
|
||||||
|
|
||||||
from cookbook.models import InviteLink
|
from cookbook.models import InviteLink
|
||||||
|
|
||||||
@ -17,7 +16,8 @@ class AllAuthCustomAdapter(DefaultAccountAdapter):
|
|||||||
Whether to allow sign-ups.
|
Whether to allow sign-ups.
|
||||||
"""
|
"""
|
||||||
signup_token = False
|
signup_token = False
|
||||||
if 'signup_token' in request.session and InviteLink.objects.filter(valid_until__gte=datetime.datetime.today(), used_by=None, uuid=request.session['signup_token']).exists():
|
if 'signup_token' in request.session and InviteLink.objects.filter(
|
||||||
|
valid_until__gte=datetime.datetime.today(), used_by=None, uuid=request.session['signup_token']).exists():
|
||||||
signup_token = True
|
signup_token = True
|
||||||
|
|
||||||
if request.resolver_match.view_name == 'account_signup' and not settings.ENABLE_SIGNUP and not signup_token:
|
if request.resolver_match.view_name == 'account_signup' and not settings.ENABLE_SIGNUP and not signup_token:
|
||||||
@ -35,7 +35,7 @@ class AllAuthCustomAdapter(DefaultAccountAdapter):
|
|||||||
if c == default:
|
if c == default:
|
||||||
try:
|
try:
|
||||||
super(AllAuthCustomAdapter, self).send_mail(template_prefix, email, context)
|
super(AllAuthCustomAdapter, self).send_mail(template_prefix, email, context)
|
||||||
except Exception: # dont fail signup just because confirmation mail could not be send
|
except Exception: # dont fail signup just because confirmation mail could not be send
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
messages.add_message(self.request, messages.ERROR, _('In order to prevent spam, the requested email was not send. Please wait a few minutes and try again.'))
|
messages.add_message(self.request, messages.ERROR, _('In order to prevent spam, the requested email was not send. Please wait a few minutes and try again.'))
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
import cookbook.helper.dal
|
|
||||||
from cookbook.helper.AllAuthCustomAdapter import AllAuthCustomAdapter
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'dal',
|
'dal',
|
||||||
]
|
]
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from django.db.models import Q
|
from cookbook.models import (Food, FoodProperty, Property, PropertyType, Supermarket,
|
||||||
|
SupermarketCategory, SupermarketCategoryRelation, Unit, UnitConversion)
|
||||||
from cookbook.models import Unit, SupermarketCategory, Property, PropertyType, Supermarket, SupermarketCategoryRelation, Food, Automation, UnitConversion, FoodProperty
|
|
||||||
|
|
||||||
|
|
||||||
class OpenDataImporter:
|
class OpenDataImporter:
|
||||||
@ -33,7 +32,8 @@ class OpenDataImporter:
|
|||||||
))
|
))
|
||||||
|
|
||||||
if self.update_existing:
|
if self.update_existing:
|
||||||
return Unit.objects.bulk_create(insert_list, update_conflicts=True, update_fields=('name', 'plural_name', 'base_unit', 'open_data_slug'), unique_fields=('space', 'name',))
|
return Unit.objects.bulk_create(insert_list, update_conflicts=True, update_fields=(
|
||||||
|
'name', 'plural_name', 'base_unit', 'open_data_slug'), unique_fields=('space', 'name',))
|
||||||
else:
|
else:
|
||||||
return Unit.objects.bulk_create(insert_list, update_conflicts=True, update_fields=('open_data_slug',), unique_fields=('space', 'name',))
|
return Unit.objects.bulk_create(insert_list, update_conflicts=True, update_fields=('open_data_slug',), unique_fields=('space', 'name',))
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ class OpenDataImporter:
|
|||||||
self._update_slug_cache(Food, 'food')
|
self._update_slug_cache(Food, 'food')
|
||||||
|
|
||||||
food_property_list = []
|
food_property_list = []
|
||||||
alias_list = []
|
# alias_list = []
|
||||||
|
|
||||||
for k in list(self.data[datatype].keys()):
|
for k in list(self.data[datatype].keys()):
|
||||||
for fp in self.data[datatype][k]['properties']['type_values']:
|
for fp in self.data[datatype][k]['properties']['type_values']:
|
||||||
@ -180,15 +180,6 @@ class OpenDataImporter:
|
|||||||
))
|
))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print(str(k) + ' is not in self.slug_id_cache["food"]')
|
print(str(k) + ' is not in self.slug_id_cache["food"]')
|
||||||
|
|
||||||
|
|
||||||
# for a in self.data[datatype][k]['alias']:
|
|
||||||
# alias_list.append(Automation(
|
|
||||||
# param_1=a,
|
|
||||||
# param_2=self.data[datatype][k]['name'],
|
|
||||||
# space=self.request.space,
|
|
||||||
# created_by=self.request.user,
|
|
||||||
# ))
|
|
||||||
|
|
||||||
Property.objects.bulk_create(food_property_list, ignore_conflicts=True, unique_fields=('space', 'import_food_id', 'property_type',))
|
Property.objects.bulk_create(food_property_list, ignore_conflicts=True, unique_fields=('space', 'import_food_id', 'property_type',))
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ from django.core.cache import caches
|
|||||||
|
|
||||||
from cookbook.helper.cache_helper import CacheHelper
|
from cookbook.helper.cache_helper import CacheHelper
|
||||||
from cookbook.helper.unit_conversion_helper import UnitConversionHelper
|
from cookbook.helper.unit_conversion_helper import UnitConversionHelper
|
||||||
from cookbook.models import PropertyType, Unit, Food, Property, Recipe, Step
|
from cookbook.models import PropertyType
|
||||||
|
|
||||||
|
|
||||||
class FoodPropertyHelper:
|
class FoodPropertyHelper:
|
||||||
@ -31,10 +31,12 @@ class FoodPropertyHelper:
|
|||||||
|
|
||||||
if not property_types:
|
if not property_types:
|
||||||
property_types = PropertyType.objects.filter(space=self.space).all()
|
property_types = PropertyType.objects.filter(space=self.space).all()
|
||||||
caches['default'].set(CacheHelper(self.space).PROPERTY_TYPE_CACHE_KEY, property_types, 60 * 60) # cache is cleared on property type save signal so long duration is fine
|
# cache is cleared on property type save signal so long duration is fine
|
||||||
|
caches['default'].set(CacheHelper(self.space).PROPERTY_TYPE_CACHE_KEY, property_types, 60 * 60)
|
||||||
|
|
||||||
for fpt in property_types:
|
for fpt in property_types:
|
||||||
computed_properties[fpt.id] = {'id': fpt.id, 'name': fpt.name, 'description': fpt.description, 'unit': fpt.unit, 'order': fpt.order, 'food_values': {}, 'total_value': 0, 'missing_value': False}
|
computed_properties[fpt.id] = {'id': fpt.id, 'name': fpt.name, 'description': fpt.description,
|
||||||
|
'unit': fpt.unit, 'order': fpt.order, 'food_values': {}, 'total_value': 0, 'missing_value': False}
|
||||||
|
|
||||||
uch = UnitConversionHelper(self.space)
|
uch = UnitConversionHelper(self.space)
|
||||||
|
|
||||||
@ -53,7 +55,8 @@ class FoodPropertyHelper:
|
|||||||
if c.unit == i.food.properties_food_unit:
|
if c.unit == i.food.properties_food_unit:
|
||||||
found_property = True
|
found_property = True
|
||||||
computed_properties[pt.id]['total_value'] += (c.amount / i.food.properties_food_amount) * p.property_amount
|
computed_properties[pt.id]['total_value'] += (c.amount / i.food.properties_food_amount) * p.property_amount
|
||||||
computed_properties[pt.id]['food_values'] = self.add_or_create(computed_properties[p.property_type.id]['food_values'], c.food.id, (c.amount / i.food.properties_food_amount) * p.property_amount, c.food)
|
computed_properties[pt.id]['food_values'] = self.add_or_create(
|
||||||
|
computed_properties[p.property_type.id]['food_values'], c.food.id, (c.amount / i.food.properties_food_amount) * p.property_amount, c.food)
|
||||||
if not found_property:
|
if not found_property:
|
||||||
computed_properties[pt.id]['missing_value'] = True
|
computed_properties[pt.id]['missing_value'] = True
|
||||||
computed_properties[pt.id]['food_values'][i.food.id] = {'id': i.food.id, 'food': i.food.name, 'value': 0}
|
computed_properties[pt.id]['food_values'][i.food.id] = {'id': i.food.id, 'food': i.food.name, 'value': 0}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django_scopes import scope, scopes_disabled
|
from django_scopes import scope, scopes_disabled
|
||||||
from oauth2_provider.contrib.rest_framework import OAuth2Authentication
|
from oauth2_provider.contrib.rest_framework import OAuth2Authentication
|
||||||
from rest_framework.authentication import TokenAuthentication
|
|
||||||
from rest_framework.authtoken.models import Token
|
|
||||||
from rest_framework.exceptions import AuthenticationFailed
|
from rest_framework.exceptions import AuthenticationFailed
|
||||||
|
|
||||||
from cookbook.views import views
|
from cookbook.views import views
|
||||||
|
@ -9,10 +9,10 @@ from cookbook.helper import dal
|
|||||||
from cookbook.version_info import TANDOOR_VERSION
|
from cookbook.version_info import TANDOOR_VERSION
|
||||||
from recipes.settings import DEBUG, PLUGINS
|
from recipes.settings import DEBUG, PLUGINS
|
||||||
|
|
||||||
from .models import (Automation, Comment, CustomFilter, Food, InviteLink, Keyword, MealPlan,
|
from .models import (Automation, Comment, CustomFilter, Food, InviteLink, Keyword, PropertyType,
|
||||||
PropertyType, Recipe, RecipeBook, RecipeBookEntry, RecipeImport, ShoppingList,
|
Recipe, RecipeBook, RecipeBookEntry, RecipeImport, ShoppingList, Space, Step,
|
||||||
Space, Step, Storage, Supermarket, SupermarketCategory, Sync, SyncLog, Unit,
|
Storage, Supermarket, SupermarketCategory, Sync, SyncLog, Unit, UnitConversion,
|
||||||
UnitConversion, UserFile, UserSpace, get_model_name)
|
UserFile, UserSpace, get_model_name)
|
||||||
from .views import api, data, delete, edit, import_export, lists, new, telegram, views
|
from .views import api, data, delete, edit, import_export, lists, new, telegram, views
|
||||||
from .views.api import CustomAuthToken, ImportOpenData
|
from .views.api import CustomAuthToken, ImportOpenData
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"target": "es5",
|
"target": "es5",
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
"allowJs": true,
|
||||||
"jsx": "preserve",
|
"jsx": "preserve",
|
||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
@ -32,8 +33,9 @@
|
|||||||
"src/**/*.tsx",
|
"src/**/*.tsx",
|
||||||
"src/**/*.vue",
|
"src/**/*.vue",
|
||||||
"tests/**/*.ts",
|
"tests/**/*.ts",
|
||||||
"tests/**/*.tsx"
|
"tests/**/*.tsx",
|
||||||
, "src/directives/OutsideClick.js" ],
|
"src/directives/OutsideClick.js"
|
||||||
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules"
|
"node_modules"
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user