Skip to content

Commit a37a8a0

Browse files
authored
Merge pull request #183 from purplship/purplship-2022.1
[patch] Purplship 2022.1
2 parents f80c7e0 + 92ee615 commit a37a8a0

File tree

49 files changed

+473
-473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+473
-473
lines changed

insiders/server/orders/purplship/server/orders/apps.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from django.apps import AppConfig
2+
from django.utils.translation import gettext_lazy as _
23

34

45
class OrdersConfig(AppConfig):
5-
default_auto_field = "django.db.models.BigAutoField"
66
name = "purplship.server.orders"
7+
verbose_name = _("Orders")
8+
default_auto_field = "django.db.models.BigAutoField"
79

810
def ready(self):
911
from purplship.server.orders import signals

insiders/server/orders/purplship/server/orders/signals.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
2+
from attr import has
23
from django.db.models import signals
34

5+
from purplship.server.conf import settings
46
from purplship.server.core.utils import failsafe
57
from purplship.server.events.serializers import EventTypes
68
from purplship.server.orders.serializers.order import compute_order_status
@@ -68,16 +70,15 @@ def shipment_updated(
6870
logger.info("shipment related order successfully updated")
6971

7072

71-
def order_updated(
72-
sender, instance, created, raw, using, update_fields, *args, **kwargs
73-
):
73+
def order_updated(sender, instance, *args, **kwargs):
7474
"""Order related events:
7575
- order created
7676
- order status changed (in-transit, delivered or blocked)
7777
"""
78-
changes = update_fields or []
78+
created = kwargs.get("created", False)
79+
changes = kwargs.get("update_fields") or []
7980

80-
if created:
81+
if created or "created_at" in changes:
8182
event = EventTypes.order_created.value
8283
elif "status" not in changes:
8384
return
@@ -95,7 +96,14 @@ def order_updated(
9596
test_mode = instance.test_mode
9697
context = dict(
9798
user_id=failsafe(lambda: instance.created_by.id),
98-
org_id=getattr(getattr(instance, "org", None), "id", None),
99+
org_id=failsafe(
100+
lambda: instance.org.first().id if hasattr(instance, "org") else None
101+
),
99102
)
100103

101-
tasks.notify_webhooks(event, data, event_at, context, test_mode)
104+
if settings.MULTI_ORGANIZATIONS and context["org_id"] is None:
105+
return
106+
107+
tasks.notify_webhooks(
108+
event, data, event_at, context, test_mode, schema=settings.schema
109+
)
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import List
21
from purplship.server.settings.base import *
32

43

5-
PURPLSHIP_URLS: List[str] = [*PURPLSHIP_URLS, "purplship.server.orders.urls"] # noqa
6-
INSTALLED_APPS: List[str] = [*INSTALLED_APPS, "purplship.server.orders"] # noqa
4+
PURPLSHIP_URLS += ["purplship.server.orders.urls"]
5+
INSTALLED_APPS += ["purplship.server.orders"]

insiders/server/orders/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="purplship.server.orders",
8-
version="2022.1",
8+
version="2022.1.3",
99
description="Multi-carrier shipping API orders module",
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",

insiders/server/orgs/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="purplship.server.orgs",
8-
version="2022.1",
8+
version="2022.1.3",
99
description="Multi-carrier shipping API organization module",
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",

insiders/server/tenants/purplship/server/settings/tenants.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,43 @@
22
from purplship.server.settings.base import *
33

44

5-
DATABASES["default"]["ENGINE"] = 'django_tenants.postgresql_backend'
5+
DATABASES["default"]["ENGINE"] = "django_tenants.postgresql_backend"
66

77
MIDDLEWARE = [
8-
'django_tenants.middleware.main.TenantMainMiddleware',
8+
"django_tenants.middleware.main.TenantMainMiddleware",
99
*MIDDLEWARE,
1010
]
1111

12-
DATABASE_ROUTERS = (
13-
'django_tenants.routers.TenantSyncRouter',
14-
)
12+
DATABASE_ROUTERS = ("django_tenants.routers.TenantSyncRouter",)
1513

1614
SHARED_APPS = [
17-
'constance',
15+
"constance",
1816
"django_tenants",
1917
"purplship.server.tenants",
20-
2118
*BASE_APPS,
22-
23-
'constance.backends.database',
19+
"constance.backends.database",
2420
]
2521

26-
EXCLUDED_TENANT_APPS = ['constance', 'constance.backends.database']
22+
EXCLUDED_TENANT_APPS = ["constance", "constance.backends.database"]
2723

2824
TENANT_APPS = [app for app in INSTALLED_APPS if app not in EXCLUDED_TENANT_APPS]
2925

30-
INSTALLED_APPS = [
31-
"django_tenants",
32-
"purplship.server.tenants",
33-
34-
*INSTALLED_APPS
35-
]
26+
INSTALLED_APPS = ["django_tenants", "purplship.server.tenants", *INSTALLED_APPS]
3627

3728

3829
TENANT_MODEL = "tenants.Client" # app.Model
3930
TENANT_DOMAIN_MODEL = "tenants.Domain" # app.Model
4031

41-
PUBLIC_SCHEMA_NAME = 'public'
42-
PUBLIC_SCHEMA_URLCONF = 'purplship.server.tenants.urls'
32+
PUBLIC_SCHEMA_NAME = "public"
33+
PUBLIC_SCHEMA_URLCONF = "purplship.server.tenants.urls"
4334
TENANT_LIMIT_SET_CALLS = True
4435
TENANT_COLOR_ADMIN_APPS = False
4536

4637
# Storage config
47-
MEDIA_ROOT = BASE_DIR / '/media'
48-
MEDIA_URL = '/media/'
49-
DEFAULT_FILE_STORAGE = 'django_tenants.storage.TenantFileSystemStorage'
38+
MEDIA_ROOT = BASE_DIR / "/media"
39+
MEDIA_URL = "/media/"
40+
DEFAULT_FILE_STORAGE = "django_tenants.storage.TenantFileSystemStorage"
5041

5142
# Cache config
52-
CACHES["default"]['KEY_FUNCTION'] = 'django_tenants.cache.make_key'
53-
CACHES["default"]['REVERSE_KEY_FUNCTION'] = 'django_tenants.cache.reverse_key'
43+
CACHES["default"]["KEY_FUNCTION"] = "django_tenants.cache.make_key"
44+
CACHES["default"]["REVERSE_KEY_FUNCTION"] = "django_tenants.cache.reverse_key"

insiders/server/tenants/purplship/server/tenants/admin.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.contrib.auth.models import Group
44
from django.contrib.auth.admin import GroupAdmin
55
from django_tenants.admin import TenantAdminMixin
6+
from constance.admin import ConstanceAdmin, Config
67

78
from purplship.server.user.admin import UserAdmin
89
import purplship.server.tenants.models as models
@@ -15,11 +16,13 @@ class TenantsAdmin(AdminSite):
1516

1617

1718
class ClientAdmin(TenantAdminMixin, ModelAdmin):
18-
list_display = ('name', )
19+
list_display = ("name",)
1920

2021

21-
site = TenantsAdmin(name='system')
22+
site = TenantsAdmin(name="system")
2223
site.register(get_user_model(), UserAdmin)
2324
site.register(Group, GroupAdmin)
2425
site.register(models.Client, ClientAdmin)
2526
site.register(models.Domain)
27+
28+
site.register([Config], ConstanceAdmin)

insiders/server/tenants/purplship/server/tenants/apps.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,4 @@
22

33

44
class TenantsConfig(AppConfig):
5-
name = 'purplship.server.tenants'
6-
7-
def ready(self):
8-
# Setup signal for tenant creation update
9-
from django_tenants.signals import post_schema_sync
10-
from purplship.server.tenants.models import Client
11-
from purplship.server.tenants.signals import created_default_admin
12-
post_schema_sync.connect(created_default_admin, sender=Client)
13-
14-
# Init Constance for all tenants
15-
# from django_tenants.utils import tenant_context
16-
# for client in Client.objects.all():
17-
# with tenant_context(client):
18-
# import constance
19-
# from purplship.server.core.signals import update_settings
20-
# update_settings(constance.config)
21-
5+
name = "purplship.server.tenants"

insiders/server/tenants/purplship/server/tenants/urls.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
1. Import the include() function: from django.urls import include, path
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
16-
from django.urls import path
16+
from django.conf import settings
17+
from django.urls import path, include
1718
from purplship.server.tenants import admin as tenants_admin
1819

1920

21+
BASE_PATH = getattr(settings, "BASE_PATH", "")
2022
urlpatterns = [
21-
path('', tenants_admin.site.urls, name='tenants_admin')
23+
path(
24+
BASE_PATH,
25+
include([path("", tenants_admin.site.urls, name="tenants_admin")]),
26+
name="purplship:tenats:index",
27+
),
2228
]

insiders/server/tenants/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="purplship.server.tenants",
8-
version="2021.11",
8+
version="2022.1.3",
99
description="Multi-carrier shipping API muti-tenant module",
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)