Added proper logging for the whole store and mailing application
rodzic
dcae7a433f
commit
a8b03dd1a1
|
@ -21,6 +21,7 @@ from sentry_sdk.integrations.django import DjangoIntegration
|
||||||
|
|
||||||
# -> GlitchTip error reporting
|
# -> GlitchTip error reporting
|
||||||
sentry_sdk.init(
|
sentry_sdk.init(
|
||||||
|
dsn=os.environ.get("SENTRY_DSN", ''),
|
||||||
integrations=[DjangoIntegration()],
|
integrations=[DjangoIntegration()],
|
||||||
auto_session_tracking=False,
|
auto_session_tracking=False,
|
||||||
traces_sample_rate=0
|
traces_sample_rate=0
|
||||||
|
@ -212,3 +213,18 @@ EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD", '')
|
||||||
EMAIL_PORT = os.environ.get('EMAIL_PORT', 587)
|
EMAIL_PORT = os.environ.get('EMAIL_PORT', 587)
|
||||||
EMAIL_USE_TLS = True
|
EMAIL_USE_TLS = True
|
||||||
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', 'artel-sklep@tepewu.pl')
|
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', 'artel-sklep@tepewu.pl')
|
||||||
|
|
||||||
|
|
||||||
|
LOGGING = {
|
||||||
|
"version": 1,
|
||||||
|
"disable_existing_loggers": False,
|
||||||
|
"handlers": {
|
||||||
|
"console": {
|
||||||
|
"class": "logging.StreamHandler",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"handlers": ["console"],
|
||||||
|
"level": "WARNING",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ from search import views as search_views
|
||||||
|
|
||||||
handler404 = 'artel.views.my_custom_page_not_found_view'
|
handler404 = 'artel.views.my_custom_page_not_found_view'
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("django-admin/", admin.site.urls),
|
path("django-admin/", admin.site.urls),
|
||||||
path("admin/", include(wagtailadmin_urls)),
|
path("admin/", include(wagtailadmin_urls)),
|
||||||
|
|
|
@ -6,6 +6,7 @@ services:
|
||||||
- "1025:1025"
|
- "1025:1025"
|
||||||
- "8025:8025"
|
- "8025:8025"
|
||||||
comfy:
|
comfy:
|
||||||
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
- smtp-server
|
- smtp-server
|
||||||
- db
|
- db
|
||||||
|
@ -16,7 +17,7 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "8001:8000"
|
- "8001:8000"
|
||||||
volumes:
|
volumes:
|
||||||
# - ./:/app
|
- ./:/app
|
||||||
- media:/app/media
|
- media:/app/media
|
||||||
environment:
|
environment:
|
||||||
- SECRET_KEY
|
- SECRET_KEY
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
@ -11,6 +13,9 @@ from django.core.mail import EmailMessage
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Attachment:
|
class Attachment:
|
||||||
name: str
|
name: str
|
||||||
|
@ -34,7 +39,11 @@ def send_mail(
|
||||||
message.content_subtype = 'html'
|
message.content_subtype = 'html'
|
||||||
for attachment in attachments:
|
for attachment in attachments:
|
||||||
message.attach(attachment.name, attachment.content, attachment.contenttype)
|
message.attach(attachment.name, attachment.content, attachment.contenttype)
|
||||||
return bool(message.send())
|
|
||||||
|
sent = bool(message.send())
|
||||||
|
if not sent:
|
||||||
|
logger.exception(f"Sending email to {to} with subject {subject} caused an exception")
|
||||||
|
return sent
|
||||||
|
|
||||||
|
|
||||||
class MailTemplate(models.Model):
|
class MailTemplate(models.Model):
|
||||||
|
@ -54,6 +63,10 @@ class MailTemplate(models.Model):
|
||||||
|
|
||||||
def load_and_process_template(self, context: dict|Context):
|
def load_and_process_template(self, context: dict|Context):
|
||||||
if not self.template:
|
if not self.template:
|
||||||
|
logger.exception(
|
||||||
|
f"Template file is missing for template with "+
|
||||||
|
f"pk={self.pk}, template_name={self.template_name}"
|
||||||
|
)
|
||||||
raise FileNotFoundError("Template file is missing")
|
raise FileNotFoundError("Template file is missing")
|
||||||
if isinstance(context, dict):
|
if isinstance(context, dict):
|
||||||
context = Context(context)
|
context = Context(context)
|
||||||
|
|
|
@ -92,7 +92,6 @@ class SessionCart(BaseCart):
|
||||||
self.session.modified = True
|
self.session.modified = True
|
||||||
|
|
||||||
def add_item(self, item_id: int, quantity: int) -> None:
|
def add_item(self, item_id: int, quantity: int) -> None:
|
||||||
# TODO - add logging
|
|
||||||
product = self.validate_and_get_product(item_id)
|
product = self.validate_and_get_product(item_id)
|
||||||
author = product.author
|
author = product.author
|
||||||
quantity = int(quantity)
|
quantity = int(quantity)
|
||||||
|
|
|
@ -2,6 +2,7 @@ import pdfkit
|
||||||
import datetime
|
import datetime
|
||||||
import builtins
|
import builtins
|
||||||
import uuid
|
import uuid
|
||||||
|
import logging
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import (
|
from typing import (
|
||||||
|
@ -40,6 +41,9 @@ from mailings.models import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class BaseImageModel(models.Model):
|
class BaseImageModel(models.Model):
|
||||||
image = models.ImageField()
|
image = models.ImageField()
|
||||||
is_main = models.BooleanField(default=False)
|
is_main = models.BooleanField(default=False)
|
||||||
|
@ -179,7 +183,10 @@ class ProductManager(models.Manager):
|
||||||
|
|
||||||
# There should be only one
|
# There should be only one
|
||||||
if not products.count() <= 1:
|
if not products.count() <= 1:
|
||||||
raise ValidationError("There should be only one product with given set of params")
|
logger.exception(
|
||||||
|
f"There should be only one product with given set of params, detected: " +
|
||||||
|
f"{products.count()}, params: {params}, template: {template}"
|
||||||
|
)
|
||||||
|
|
||||||
product = products.first()
|
product = products.first()
|
||||||
if not product:
|
if not product:
|
||||||
|
@ -268,9 +275,8 @@ def validate_param(sender, **kwargs):
|
||||||
for pk in pk_set:
|
for pk in pk_set:
|
||||||
try:
|
try:
|
||||||
param = ProductCategoryParamValue.objects.get(pk=pk).param
|
param = ProductCategoryParamValue.objects.get(pk=pk).param
|
||||||
except ProductCategoryParamValue.DoesNotExist:
|
except ProductCategoryParamValue.DoesNotExist as e:
|
||||||
# TODO log this
|
logger.exception(f"Product param validation failed with exception: {str(e)}")
|
||||||
...
|
|
||||||
count = product_instance.params.filter(productparam__param_value__param=param).count()
|
count = product_instance.params.filter(productparam__param_value__param=param).count()
|
||||||
if count >= 1:
|
if count >= 1:
|
||||||
errors.append(ValueError("Product param with this key already exists."))
|
errors.append(ValueError("Product param with this key already exists."))
|
||||||
|
@ -320,7 +326,10 @@ class OrderProductManager(models.Manager):
|
||||||
pks = []
|
pks = []
|
||||||
for item in items:
|
for item in items:
|
||||||
if item["quantity"] < 1:
|
if item["quantity"] < 1:
|
||||||
# TODO - logging
|
logger.exception(
|
||||||
|
f"This is not possible to add less than one item to Order, omitting item: "+
|
||||||
|
f"{item['product']}"
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
pk = self.create(
|
pk = self.create(
|
||||||
|
@ -420,8 +429,9 @@ class OrderManager(models.Manager):
|
||||||
sent = self._send_notifications(order, author, customer_data, docs)
|
sent = self._send_notifications(order, author, customer_data, docs)
|
||||||
|
|
||||||
if not sent:
|
if not sent:
|
||||||
# TODO - store data temporarily
|
logger.exception(
|
||||||
raise Exception("Error while sending emails")
|
f"Error while sending emails, for order: {order.order_number}"
|
||||||
|
)
|
||||||
|
|
||||||
return Order.objects.filter(pk__in=orders_pks)
|
return Order.objects.filter(pk__in=orders_pks)
|
||||||
|
|
||||||
|
@ -435,6 +445,7 @@ class PaymentMethod(models.Model):
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class DeliveryMethod(models.Model):
|
class DeliveryMethod(models.Model):
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
description = models.TextField(blank=True)
|
description = models.TextField(blank=True)
|
||||||
|
|
Ładowanie…
Reference in New Issue