From b7b0b9c690df29f11366dcb7aeba6c2260351249 Mon Sep 17 00:00:00 2001 From: smilerz Date: Tue, 28 Sep 2021 15:45:54 -0500 Subject: [PATCH] fixed wsgi error --- cookbook/models.py | 19 ++++++++++++++++--- recipes/settings.py | 5 ++--- recipes/wsgi.py | 10 ---------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/cookbook/models.py b/cookbook/models.py index 867d5fd8..68747e50 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -43,8 +43,7 @@ class TreeManager(MP_NodeManager): try: return self.get(name__exact=kwargs['name'], space=kwargs['space']), False except self.model.DoesNotExist: - with scopes_disabled(): - return self.model.add_root(**kwargs), True + return self.model.add_root(**kwargs), True class TreeModel(MP_Node): @@ -353,6 +352,13 @@ class Keyword(ExportModelOperationsMixin('keyword'), TreeModel, PermissionModelM indexes = (Index(fields=['id', 'name']),) +# when starting up run fix_tree to: +# a) make sure that nodes are sorted when switching between sort modes +# b) fix problems, if any, with tree consistency +with scopes_disabled(): + Keyword.fix_tree(fix_paths=True) + + class Unit(ExportModelOperationsMixin('unit'), models.Model, PermissionModelMixin): name = models.CharField(max_length=128, validators=[MinLengthValidator(1)]) description = models.TextField(blank=True, null=True) @@ -400,6 +406,13 @@ class Food(ExportModelOperationsMixin('food'), TreeModel, PermissionModelMixin): ) +# when starting up run fix_tree to: +# a) make sure that nodes are sorted when switching between sort modes +# b) fix problems, if any, with tree consistency +with scopes_disabled(): + Food.fix_tree(fix_paths=True) + + class Ingredient(ExportModelOperationsMixin('ingredient'), models.Model, PermissionModelMixin): # a pre-delete signal on Food checks if the Ingredient is part of a Step, if it is raises a ProtectedError instead of cascading the delete food = models.ForeignKey(Food, on_delete=models.CASCADE, null=True, blank=True) @@ -793,7 +806,7 @@ class ViewLog(ExportModelOperationsMixin('view_log'), models.Model, PermissionMo class Meta(): indexes = ( Index(fields=['recipe']), - Index(fields=[ '-created_at']), + Index(fields=['-created_at']), Index(fields=['created_by']), Index(fields=['recipe', '-created_at', 'created_by']), ) diff --git a/recipes/settings.py b/recipes/settings.py index ccb23acb..95ef48c1 100644 --- a/recipes/settings.py +++ b/recipes/settings.py @@ -73,7 +73,8 @@ ACCOUNT_SIGNUP_FORM_CLASS = 'cookbook.forms.AllAuthSignupForm' TERMS_URL = os.getenv('TERMS_URL', '') PRIVACY_URL = os.getenv('PRIVACY_URL', '') IMPRINT_URL = os.getenv('IMPRINT_URL', '') -SORT_TREE_BY_NAME = os.getenv('IMPRINT_URL', 1) +if SORT_TREE_BY_NAME:= bool(int(os.getenv('SQL_DEBUG', True))): + MIDDLEWARE += ('recipes.middleware.SqlPrintingMiddleware',) HOSTED = bool(int(os.getenv('HOSTED', False))) @@ -391,5 +392,3 @@ EMAIL_USE_SSL = bool(int(os.getenv('EMAIL_USE_SSL', False))) DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', 'webmaster@localhost') ACCOUNT_EMAIL_SUBJECT_PREFIX = os.getenv('ACCOUNT_EMAIL_SUBJECT_PREFIX', '[Tandoor Recipes] ') # allauth sender prefix -if os.getenv('SQL_DEBUG', False): - MIDDLEWARE += ('recipes.middleware.SqlPrintingMiddleware',) diff --git a/recipes/wsgi.py b/recipes/wsgi.py index 474e7f41..64e99737 100644 --- a/recipes/wsgi.py +++ b/recipes/wsgi.py @@ -8,20 +8,10 @@ https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ """ import os - from django.core.wsgi import get_wsgi_application -from django_scopes import scopes_disabled -from cookbook.models import Food, Keyword os.environ.setdefault("DJANGO_SETTINGS_MODULE", "recipes.settings") -# run fix tree here solves 2 problems: -# 1 if tree sorting is changed from unsorted to sorted ensures that objects are sorted -# 2 if any condition caused the tree to be in an inconsistent state this will fix most problems -with scopes_disabled(): - Food.fix_tree(fix_paths=True) - Keyword.fix_tree(fix_paths=True) - _application = get_wsgi_application()