Skip to content

Commit 979c2c8

Browse files
committed
Add support to upload event image
1 parent 08cbd0e commit 979c2c8

6 files changed

Lines changed: 12 additions & 5 deletions

File tree

common/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import uuid
22

3-
from django.db import models
3+
from django.db import models, transaction
44
from django.utils.translation import ugettext_lazy as _
55
from parler.managers import TranslatableQuerySet as ParlerTranslatableQuerySet
66
from parler.models import TranslatableModel as ParlerTranslatableModel
@@ -24,6 +24,7 @@ class Meta:
2424

2525

2626
class TranslatableQuerySet(ParlerTranslatableQuerySet):
27+
@transaction.atomic
2728
def create_translatable_object(self, **kwargs):
2829
translations = kwargs.pop("translations")
2930
obj = self.create(**kwargs)

events/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.db import transaction
44
from graphene import relay
55
from graphene_django import DjangoConnectionField, DjangoObjectType
6+
from graphene_file_upload.scalars import Upload
67
from graphql_jwt.decorators import login_required, staff_member_required
78
from graphql_relay import from_global_id
89

@@ -71,6 +72,7 @@ class Input:
7172
participants_per_invite = graphene.String(required=True)
7273
capacity_per_occurrence = graphene.Int(required=True)
7374
published_at = graphene.DateTime()
75+
image = Upload()
7476

7577
event = graphene.Field(EventNode)
7678

@@ -80,7 +82,6 @@ class Input:
8082
def mutate_and_get_payload(cls, root, info, **kwargs):
8183
# TODO: Add validation
8284
event = Event.objects.create_translatable_object(**kwargs)
83-
# TODO: Add support for image upload
8485
return AddEventMutation(event=event)
8586

8687

kukkuu/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.conf import settings
2+
from django.conf.urls.static import static
23
from django.http import HttpResponse
34
from django.urls import path
45
from django.views.decorators.csrf import csrf_exempt
@@ -24,3 +25,5 @@ def readiness(*args, **kwargs):
2425

2526

2627
urlpatterns += [path("healthz", healthz), path("readiness", readiness)]
28+
if settings.DEBUG:
29+
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

kukkuu/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import sentry_sdk
2-
from graphene_django.views import GraphQLView
2+
from graphene_file_upload.django import FileUploadGraphQLView
33

44
from kukkuu.exceptions import KukkuuGraphQLError
55

66

7-
class SentryGraphQLView(GraphQLView):
7+
class SentryGraphQLView(FileUploadGraphQLView):
88
def execute_graphql_request(self, request, data, query, *args, **kwargs):
99
"""Extract any exceptions and send some of them to Sentry"""
1010
result = super().execute_graphql_request(request, data, query, *args, **kwargs)

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ django-ilmoitin
77
django-parler
88
factory-boy
99
graphene-django
10+
graphene-file-upload
1011
psycopg2
1112
sentry-sdk
1213
Pillow

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ factory-boy==2.12.0
2323
faker==2.0.4 # via factory-boy
2424
future==0.17.1 # via pyjwkest, python-jose
2525
graphene-django==2.6.0
26+
graphene-file-upload==1.2.2
2627
graphene==2.1.8 # via graphene-django
2728
graphql-core==2.2.1 # via django-graphql-jwt, graphene, graphene-django, graphql-relay
2829
graphql-relay==2.0.0 # via graphene
@@ -45,7 +46,7 @@ rsa==4.0 # via python-jose
4546
rx==1.6.1 # via graphql-core
4647
sentry-sdk==0.12.3
4748
singledispatch==3.4.0.3 # via graphene-django
48-
six==1.12.0 # via django-anymail, django-mailer, faker, graphene, graphene-django, graphql-core, graphql-relay, promise, pyjwkest, python-dateutil, python-jose, singledispatch
49+
six==1.12.0 # via django-anymail, django-mailer, faker, graphene, graphene-django, graphene-file-upload, graphql-core, graphql-relay, promise, pyjwkest, python-dateutil, python-jose, singledispatch
4950
sqlparse==0.3.0 # via django
5051
text-unidecode==1.3 # via faker
5152
urllib3==1.25.6 # via requests, sentry-sdk

0 commit comments

Comments
 (0)