Skip to content

Commit 22ec6e3

Browse files
#271 add has_iamge
#309 temporary fix image uploads
1 parent aa91c52 commit 22ec6e3

File tree

5 files changed

+124
-1
lines changed

5 files changed

+124
-1
lines changed

OneSila/OneSila/asgi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from django.conf import settings
1313

1414
from django.core.asgi import get_asgi_application
15-
from strawberry_django.routers import AuthGraphQLProtocolTypeRouter
15+
from core.schema.routers import AuthGraphQLProtocolTypeRouter
1616
from starlette.middleware.cors import CORSMiddleware
1717

1818
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "OneSila.settings")
@@ -26,6 +26,7 @@
2626
application = AuthGraphQLProtocolTypeRouter(
2727
schema,
2828
django_application=django_application,
29+
multipart_uploads_enabled=True
2930
)
3031

3132
application = CORSMiddleware(

OneSila/core/schema/routers.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
from channels.auth import AuthMiddlewareStack
6+
from channels.routing import ProtocolTypeRouter, URLRouter
7+
from channels.security.websocket import AllowedHostsOriginValidator
8+
from django.urls import URLPattern, URLResolver, re_path
9+
from strawberry.channels.handlers.http_handler import GraphQLHTTPConsumer
10+
from strawberry.channels.handlers.ws_handler import GraphQLWSConsumer
11+
12+
if TYPE_CHECKING:
13+
from django.core.handlers.asgi import ASGIHandler
14+
from strawberry.schema import BaseSchema
15+
16+
# TEMPORARY SOLUTION UNTIL IT'S FIXED
17+
class AuthGraphQLProtocolTypeRouter(ProtocolTypeRouter):
18+
"""Convenience class to set up GraphQL on both HTTP and Websocket.
19+
20+
This convenience class will include AuthMiddlewareStack and the
21+
AllowedHostsOriginValidator to ensure you have user object available.
22+
23+
```
24+
from strawberry_django.routers import AuthGraphQLProtocolTypeRouter
25+
from django.core.asgi import get_asgi_application.
26+
27+
django_asgi = get_asgi_application()
28+
29+
from myapi import schema
30+
31+
application = AuthGraphQLProtocolTypeRouter(
32+
schema,
33+
django_application=django_asgi,
34+
)
35+
```
36+
37+
This will route all requests to /graphql on either HTTP or websockets to us,
38+
and everything else to the Django application.
39+
"""
40+
41+
def __init__(
42+
self,
43+
schema: BaseSchema,
44+
django_application: ASGIHandler | None = None,
45+
url_pattern: str = "^graphql",
46+
multipart_uploads_enabled: bool = False,
47+
):
48+
http_urls: list[URLPattern | URLResolver] = [
49+
re_path(url_pattern,
50+
GraphQLHTTPConsumer.as_asgi(schema=schema, multipart_uploads_enabled=multipart_uploads_enabled)),
51+
]
52+
if django_application is not None:
53+
http_urls.append(re_path(r"^", django_application))
54+
55+
super().__init__(
56+
{
57+
"http": AuthMiddlewareStack(
58+
URLRouter(
59+
http_urls,
60+
),
61+
),
62+
"websocket": AllowedHostsOriginValidator(
63+
AuthMiddlewareStack(
64+
URLRouter(
65+
[
66+
re_path(
67+
url_pattern,
68+
GraphQLWSConsumer.as_asgi(schema=schema),
69+
),
70+
],
71+
),
72+
),
73+
),
74+
},
75+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 5.1.1 on 2025-02-05 20:29
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('products_inspector', '0004_inspector_created_by_multi_tenant_user_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.DeleteModel(
14+
name='MissingSupplierPricesInspectorBlock',
15+
),
16+
migrations.CreateModel(
17+
name='MissingSupplierPriceInspectorBlock',
18+
fields=[
19+
],
20+
options={
21+
'verbose_name': 'Inspector Block Missing Supplier Prices',
22+
'proxy': True,
23+
'indexes': [],
24+
'constraints': [],
25+
},
26+
bases=('products_inspector.inspectorblock',),
27+
),
28+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.1.1 on 2025-02-05 20:29
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('properties', '0023_alter_propertyselectvaluetranslation_unique_together'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='property',
15+
name='has_image',
16+
field=models.BooleanField(default=False),
17+
),
18+
]

OneSila/properties/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class TYPES:
4141
is_public_information = models.BooleanField(default=True)
4242
add_to_filters = models.BooleanField(default=True)
4343
is_product_type = models.BooleanField(default=False)
44+
has_image = models.BooleanField(default=False)
4445

4546
# advanced tab
4647
value_validator = models.CharField(

0 commit comments

Comments
 (0)