This commit is contained in:
Vague Rabbit 2021-02-11 12:56:31 -08:00
parent b9358a9d74
commit 21867f0efa
3 changed files with 40 additions and 29 deletions

View file

@ -1,5 +1,6 @@
from io import StringIO from io import StringIO
import os.path import os.path
from django.apps import apps from django.apps import apps
from django.conf import settings from django.conf import settings
from django.core.management import call_command from django.core.management import call_command
@ -23,6 +24,8 @@ from ...utils.random_data import (
set_homepage_collection, set_homepage_collection,
) )
ADMIN_EMAIL = os.environ.get("ADMIN_EMAIL")
ADMIN_PASS = os.environ.get("ADMIN_PASS")
class Command(BaseCommand): class Command(BaseCommand):
help = "Populate database with test objects" help = "Populate database with test objects"
@ -43,6 +46,13 @@ class Command(BaseCommand):
default=False, default=False,
help="Create sample products, etc..", help="Create sample products, etc..",
) )
parser.add_argument(
"--fastdata",
action="store_true",
dest="fastdata",
default=False,
help="Sacrifice some of the safeguards of sqlite3 for speed.",
)
parser.add_argument( parser.add_argument(
"--withoutimages", "--withoutimages",
action="store_true", action="store_true",
@ -50,6 +60,13 @@ class Command(BaseCommand):
default=False, default=False,
help="Don't create product images", help="Don't create product images",
) )
parser.add_argument(
"--withoutsearch",
action="store_true",
dest="withoutsearch",
default=False,
help="Don't update search index",
)
parser.add_argument( parser.add_argument(
"--skipsequencereset", "--skipsequencereset",
action="store_true", action="store_true",
@ -60,7 +77,6 @@ class Command(BaseCommand):
def make_database_faster(self): def make_database_faster(self):
"""Sacrifice some of the safeguards of sqlite3 for speed. """Sacrifice some of the safeguards of sqlite3 for speed.
Users are not likely to run this command in a production environment. Users are not likely to run this command in a production environment.
They are even less likely to run it in production while using sqlite3. They are even less likely to run it in production while using sqlite3.
""" """
@ -71,7 +87,6 @@ class Command(BaseCommand):
def sequence_reset(self): def sequence_reset(self):
"""Run a SQL sequence reset on all saleor.* apps. """Run a SQL sequence reset on all saleor.* apps.
When a value is manually assigned to an auto-incrementing field When a value is manually assigned to an auto-incrementing field
it doesn't update the field's sequence, which might cause a conflict it doesn't update the field's sequence, which might cause a conflict
later on. later on.
@ -94,17 +109,10 @@ class Command(BaseCommand):
"DummyCreditCardGatewayPlugin", "DummyCreditCardGatewayPlugin",
] ]
ADMIN_EMAIL = os.environ.get("ADMIN_EMAIL") if options["fastdata"]:
ADMIN_PASS = os.environ.get("ADMIN_PASS") self.make_database_faster()
if options["createsuperuser"]:
credentials = {"email": ADMIN_EMAIL, "password": ADMIN_PASS}
msg = create_superuser(credentials)
self.stdout.write(msg)
add_address_to_admin(credentials["email"])
if options["sampledata"]: if options["sampledata"]:
self.make_database_faster()
create_images = not options["withoutimages"] create_images = not options["withoutimages"]
for msg in create_shipping_zones(): for msg in create_shipping_zones():
self.stdout.write(msg) self.stdout.write(msg)
@ -129,6 +137,12 @@ class Command(BaseCommand):
for msg in create_menus(): for msg in create_menus():
self.stdout.write(msg) self.stdout.write(msg)
if options["createsuperuser"]:
credentials = {"email": ADMIN_EMAIL, "password": ADMIN_PASS}
msg = create_superuser(credentials)
self.stdout.write(msg)
add_address_to_admin(credentials["email"])
if not options["skipsequencereset"]: if not options["skipsequencereset"]:
self.sequence_reset() self.sequence_reset()

View file

@ -10,7 +10,6 @@ import jaeger_client
import jaeger_client.config import jaeger_client.config
import pkg_resources import pkg_resources
import sentry_sdk import sentry_sdk
import sentry_sdk.utils
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.management.utils import get_random_secret_key from django.core.management.utils import get_random_secret_key
from pytimeparse import parse from pytimeparse import parse
@ -44,7 +43,7 @@ def get_bool_from_env(name, default_value):
return default_value return default_value
DEBUG = os.environ.get('DJANGO_DEBUG', '') != 'False' DEBUG = get_bool_from_env("DEBUG", False)
SITE_ID = 1 SITE_ID = 1
@ -167,7 +166,7 @@ ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL = get_bool_from_env(
"ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL", True "ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL", True
) )
ENABLE_SSL = True ENABLE_SSL = get_bool_from_env("ENABLE_SSL", True)
if ENABLE_SSL: if ENABLE_SSL:
SECURE_SSL_REDIRECT = not DEBUG SECURE_SSL_REDIRECT = not DEBUG
@ -351,7 +350,7 @@ LOGGING = {
"saleor": {"level": "DEBUG", "propagate": True}, "saleor": {"level": "DEBUG", "propagate": True},
"saleor.graphql.errors.handled": { "saleor.graphql.errors.handled": {
"handlers": ["default"], "handlers": ["default"],
"level": "INFO", "level": "ERROR",
"propagate": False, "propagate": False,
}, },
"graphql.execution.utils": {"propagate": False}, "graphql.execution.utils": {"propagate": False},
@ -378,6 +377,9 @@ DEFAULT_CURRENCY_CODE_LENGTH = 3
# Following the recommendation of https://tools.ietf.org/html/rfc5322#section-2.1.1 # Following the recommendation of https://tools.ietf.org/html/rfc5322#section-2.1.1
DEFAULT_MAX_EMAIL_DISPLAY_NAME_LENGTH = 78 DEFAULT_MAX_EMAIL_DISPLAY_NAME_LENGTH = 78
# note: having multiple currencies is not supported yet
AVAILABLE_CURRENCIES = [DEFAULT_CURRENCY]
COUNTRIES_OVERRIDE = {"EU": "European Union"} COUNTRIES_OVERRIDE = {"EU": "European Union"}
OPENEXCHANGERATES_API_KEY = os.environ.get("OPENEXCHANGERATES_API_KEY") OPENEXCHANGERATES_API_KEY = os.environ.get("OPENEXCHANGERATES_API_KEY")
@ -427,10 +429,6 @@ GS_PROJECT_ID = os.environ.get("GS_PROJECT_ID")
GS_STORAGE_BUCKET_NAME = os.environ.get("GS_STORAGE_BUCKET_NAME") GS_STORAGE_BUCKET_NAME = os.environ.get("GS_STORAGE_BUCKET_NAME")
GS_MEDIA_BUCKET_NAME = os.environ.get("GS_MEDIA_BUCKET_NAME") GS_MEDIA_BUCKET_NAME = os.environ.get("GS_MEDIA_BUCKET_NAME")
GS_AUTO_CREATE_BUCKET = get_bool_from_env("GS_AUTO_CREATE_BUCKET", False) GS_AUTO_CREATE_BUCKET = get_bool_from_env("GS_AUTO_CREATE_BUCKET", False)
GS_QUERYSTRING_AUTH = get_bool_from_env("GS_QUERYSTRING_AUTH", False)
GS_DEFAULT_ACL = os.environ.get("GS_DEFAULT_ACL", None)
GS_MEDIA_CUSTOM_ENDPOINT = os.environ.get("GS_MEDIA_CUSTOM_ENDPOINT", None)
GS_EXPIRATION = os.environ.get("GS_EXPIRATION", None)
# If GOOGLE_APPLICATION_CREDENTIALS is set there is no need to load OAuth token # If GOOGLE_APPLICATION_CREDENTIALS is set there is no need to load OAuth token
# See https://django-storages.readthedocs.io/en/latest/backends/gcloud.html # See https://django-storages.readthedocs.io/en/latest/backends/gcloud.html
@ -498,15 +496,13 @@ CELERY_RESULT_BACKEND = os.environ.get("CELERY_RESULT_BACKEND", None)
# e.g. HTTP_CF_Connecting_IP for Cloudflare or X_FORWARDED_FOR # e.g. HTTP_CF_Connecting_IP for Cloudflare or X_FORWARDED_FOR
REAL_IP_ENVIRON = os.environ.get("REAL_IP_ENVIRON", "REMOTE_ADDR") REAL_IP_ENVIRON = os.environ.get("REAL_IP_ENVIRON", "REMOTE_ADDR")
# The maximum length of a graphql query to log in tracings
OPENTRACING_MAX_QUERY_LENGTH_LOG = 2000
# Slugs for menus precreated in Django migrations # Slugs for menus precreated in Django migrations
DEFAULT_MENUS = {"top_menu_name": "navbar", "bottom_menu_name": "footer"} DEFAULT_MENUS = {"top_menu_name": "navbar", "bottom_menu_name": "footer"}
# Slug for channel precreated in Django migrations
DEFAULT_CHANNEL_SLUG = os.environ.get("DEFAULT_CHANNEL_SLUG", "default-channel")
# Sentry # Sentry
sentry_sdk.utils.MAX_STRING_LENGTH = 4096
SENTRY_DSN = os.environ.get("SENTRY_DSN") SENTRY_DSN = os.environ.get("SENTRY_DSN")
if SENTRY_DSN: if SENTRY_DSN:
sentry_sdk.init( sentry_sdk.init(

View file

@ -27,3 +27,4 @@ MEDIA_URL="{media}"
ADMIN_EMAIL="{adminemail}" ADMIN_EMAIL="{adminemail}"
DEBUG=False DEBUG=False
ENABLE_SSL=True