Skip to content

Commit

Permalink
Update details for render.
Browse files Browse the repository at this point in the history
  • Loading branch information
tyronejosee committed Feb 20, 2024
1 parent cf9b653 commit e8fbac7
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 176 deletions.
2 changes: 1 addition & 1 deletion core/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

application = get_asgi_application()
18 changes: 11 additions & 7 deletions core/management/commands/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@


class Command(BaseCommand):
"""Command to create a superuser if 'admin' does not exist."""
"""Command to create a superuser if "admin" does not exist."""
help = "Create a superuser if 'admin' does not exist"

def handle(self, *args, **options):
user_admin = User.objects.filter(username='newstore')
user_admin = User.objects.filter(username="newstore")
if not user_admin:
user_admin = User.objects.create_superuser(
username = 'newstore',
email = '[email protected]',
first_name = 'new',
last_name = 'store',
password = 'newstoreadmin'
username="newstore",
email="[email protected]",
first_name="new",
last_name="store",
password="newstoreadmin"
)
self.stdout.write(
self.style.SUCCESS("Superuser created successfully.")
)
154 changes: 77 additions & 77 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,44 @@
environ.Env.read_env()

ENVIRONMENT = env
SECRET_KEY = os.environ.get('SECRET_KEY', default='your secret key')
SECRET_KEY = os.environ.get("SECRET_KEY", default="your secret key")


# DEBUG settings: FALSE in production
DEBUG = 'RENDER' not in os.environ
DEBUG = "RENDER" not in os.environ


# Host permission settings
ALLOWED_HOSTS = []

RENDER_EXTERNAL_HOSTNAME = os.environ.get('RENDER_EXTERNAL_HOSTNAME')
RENDER_EXTERNAL_HOSTNAME = os.environ.get("RENDER_EXTERNAL_HOSTNAME")
if RENDER_EXTERNAL_HOSTNAME:
ALLOWED_HOSTS.append(RENDER_EXTERNAL_HOSTNAME)


# Installed Apps categories
DJANGO_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]

CORE_APPS = [
'users',
'core',
'home',
'products',
'cart',
'management',
'payment',
"users",
"core",
"home",
"products",
"cart",
"management",
"payment",
]

THIRD_PARTY_APPS = [
'paypal.standard.ipn',
'import_export',
"paypal.standard.ipn",
"import_export",
]

INSTALLED_APPS = DJANGO_APPS + CORE_APPS + THIRD_PARTY_APPS
Expand All @@ -63,89 +63,89 @@


# Paypal settings
PAYPAL_RECEIVER_EMAIL = '[email protected]' # Sandbox email
PAYPAL_RECEIVER_EMAIL = "[email protected]"
PAYPAL_TEST = True
PAYPAL_BUY_BUTTON_IMAGE = '/static/img/buttom_paypal.svg'
PAYPAL_BUY_BUTTON_IMAGE = "/static/img/buttom_paypal.svg"


# Auth model settings
AUTH_USER_MODEL = 'users.CustomUser'
AUTH_USER_MODEL = "users.CustomUser"


# Log setting
LOGIN_URL = '/users/login/'
LOGIN_URL = "/users/login/"


# NPM
NPM_BIN_PATH = r"C:\Program Files\nodejs\npm.cmd"


AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
"django.contrib.auth.backends.ModelBackend",
]

# Middleware settings
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

# Root URL settings
ROOT_URLCONF = 'core.urls'
ROOT_URLCONF = "core.urls"


# Templates settings
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'utils.context_processors.company',
'utils.context_processors.user_preferences',
'utils.context_processors.products_featured',
'utils.context_processors.products_categories',
'utils.context_processors.cart_items_count',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"utils.context_processors.company",
"utils.context_processors.user_preferences",
"utils.context_processors.products_featured",
"utils.context_processors.products_categories",
"utils.context_processors.cart_items_count",
],
},
},
]

# WSGI entry point
WSGI_APPLICATION = 'core.wsgi.application'
WSGI_APPLICATION = "core.wsgi.application"


# Database settings
if 'test' in sys.argv:
if "test" in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": ":memory:",
}
}
else:
DATABASES = {
'default': dj_database_url.config(
default='postgresql://postgres:postgres@localhost:5432/mysite',
conn_max_age=600
)
}
# else:
# DATABASES = {
# "default": env.db("DATABASE_URL", default="postgres:///new_store"),
# }
# DATABASES["default"]["ATOMIC_REQUEST"] = True
# "default": dj_database_url.config(
# default="postgresql://postgres:postgres@localhost:5432/mysite",
# conn_max_age=600
# )
# }
else:
DATABASES = {
"default": env.db("DATABASE_URL", default="postgres:///new_store"),
}
DATABASES["default"]["ATOMIC_REQUEST"] = True



Expand All @@ -158,42 +158,42 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]

# Internationalization settings
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True


# Static file settings
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
STATIC_URL = "/static/"
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
STATIC_ROOT = os.path.join(BASE_DIR, "static_root")


# Media file settings
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")


if not DEBUG:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
MEDIA_ROOT = os.path.join(BASE_DIR, "mediafiles")
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"


DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
12 changes: 5 additions & 7 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@

urlpatterns = [
# Django URLs
path('admin/', admin.site.urls),
path("admin/", admin.site.urls),

# App URLs
path("", include("home.urls")),
path('users/', include('users.urls')),
path("users/", include("users.urls")),
path("products/", include("products.urls")),
path("cart/", include("cart.urls")),
path("management/", include("management.urls")),
path("payment/", include("payment.urls")),

# Third party URLs
path('paypal/', include("paypal.standard.ipn.urls")),
path("paypal/", include("paypal.standard.ipn.urls")),
]


# Debug Config
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)


# Custom attributes for admin
Expand Down
2 changes: 1 addition & 1 deletion core/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

application = get_wsgi_application()
26 changes: 13 additions & 13 deletions products/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@ class Meta:
@admin.register(Category)
class CategoryAdmin(ImportExportModelAdmin, ActionsMixin):
"""Admin config for the Category model."""
list_display = ('pk', 'title', 'slug', 'show_hide',)
ordering = ('pk',)
list_display = ("pk", "title", "slug", "show_hide",)
ordering = ("pk",)
resource_class = CategoryResource


@admin.register(Brand)
class BrandAdmin(ImportExportModelAdmin, ActionsMixin):
"""Admin config for the Brand model."""
list_display = ('pk', 'name', 'slug', 'show_hide',)
ordering = ('pk',)
list_display = ("pk", "name", "slug", "show_hide",)
ordering = ("pk",)
resource_class = BrandResource


@admin.register(Deal)
class DealAdmin(ImportExportModelAdmin, admin.ModelAdmin):
"""Admin config for the Deal model."""
list_display = ('name', 'slug', 'image', 'discount', 'start_date', 'end_date', 'pk')
ordering = ('pk',)
list_display = ("name", "slug", "image", "discount", "start_date", "end_date", "pk")
ordering = ("pk",)
resource_class = DealResource

def save_model(self, request, obj, form, change):
# Remove the image when clearing the path in the deal
if change and 'image' in form.changed_data:
if change and "image" in form.changed_data:
old_deal = Deal.objects.get(pk=obj.pk)
old_deal.image.delete(save=False)
super().save_model(request, obj, form, change)
Expand All @@ -73,16 +73,16 @@ def save_model(self, request, obj, form, change):
@admin.register(Product)
class ProductAdmin(ImportExportModelAdmin, ActionsMixin):
"""Admin config for the Product model."""
list_display = ('pk', 'title', 'updated_at', 'slug', 'normal_price',
'brand', 'stock', 'show_hide')
readonly_fields = ('created_at', 'updated_at')
search_fields = ('title',)
ordering = ('updated_at', 'pk',)
list_display = ("title", "updated_at", "slug", "normal_price",
"brand", "stock", "show_hide")
readonly_fields = ("created_at", "updated_at", "sale_price")
search_fields = ("title",)
ordering = ("pk",)
resource_class = ProductResource

def save_model(self, request, obj, form, change):
# Remove the image when clearing the path in the prod.
if change and 'image' in form.changed_data:
if change and "image" in form.changed_data:
old_product = Product.objects.get(pk=obj.pk)
old_product.image.delete(save=False)
super().save_model(request, obj, form, change)
4 changes: 2 additions & 2 deletions products/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.apps import AppConfig

class ProductsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'products'
default_auto_field = "django.db.models.BigAutoField"
name = "products"
Loading

0 comments on commit e8fbac7

Please sign in to comment.