Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/project/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyright: reportUninitializedInstanceVariable=false
import typing
from warnings import deprecated

import ulid
from django.contrib.gis.db import models as gis_models
Expand Down Expand Up @@ -109,8 +110,8 @@ class UploadHelper:
def project_asset(instance: "ProjectAsset", filename: str):
return f"project/{instance.project_id}/asset/{instance.type}/{ulid.ULID()!s}/{filename}"

@deprecated("This is kept because it's referenced in migrations")
@staticmethod
# FIXME: This is not be used anymore
def project_image(instance: "Project", filename: str):
return f"project/{instance.pk}/image/{filename}"

Expand Down
4 changes: 2 additions & 2 deletions apps/tutorial/graphql/inputs/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TutorialInformationPageBlockCreateInput(UserResourceCreateInputMixin):
block_number: strawberry.auto
block_type: strawberry.auto
text: strawberry.auto
image: Upload | None = strawberry.UNSET
image: strawberry.ID | None = strawberry.UNSET


@strawberry_django.partial(TutorialInformationPageBlock)
Expand All @@ -103,7 +103,7 @@ class TutorialInformationPageBlockUpdateInput(UserResourceUpdateInputMixin):
block_number: strawberry.auto
block_type: strawberry.auto
text: strawberry.auto
image: Upload | None = strawberry.UNSET
image: strawberry.ID | None = strawberry.UNSET


@strawberry.input
Expand Down
18 changes: 10 additions & 8 deletions apps/tutorial/graphql/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
from .project_types.validate_image import ValidateImageTutorialTaskPropertyType


@strawberry_django.type(TutorialAsset)
class TutorialAssetType(UserResourceTypeMixin, CommonAssetTypeMixin):
id: strawberry.ID
file: strawberry.auto
tutorial_id: strawberry.ID


@strawberry_django.type(TutorialTask)
class TutorialTaskType(UserResourceTypeMixin):
id: strawberry.ID
Expand Down Expand Up @@ -104,7 +111,9 @@ class TutorialInformationPageBlockType(UserResourceTypeMixin):
block_number: strawberry.auto
block_type: strawberry.auto
text: strawberry.auto
image: strawberry.auto
# TODO(tnagorra): Check if this creates N+1 issue
image_id: strawberry.ID | None
image: TutorialAssetType | None


@strawberry_django.type(TutorialInformationPage)
Expand All @@ -127,10 +136,3 @@ class TutorialType(UserResourceTypeMixin):
# The tests are failing randomly.
scenarios: list[TutorialScenarioPageType]
information_pages: list[TutorialInformationPageType]


@strawberry_django.type(TutorialAsset)
class TutorialAssetType(UserResourceTypeMixin, CommonAssetTypeMixin):
id: strawberry.ID
file: strawberry.auto
tutorial_id: strawberry.ID
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.1.6 on 2025-07-31 04:53

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tutorial', '0007_alter_tutorialasset_marked_as_deleted'),
]

operations = [
migrations.RemoveField(
model_name='tutorialinformationpageblock',
name='image',
),
migrations.AddField(
model_name='tutorialinformationpageblock',
name='image',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='tutorial.tutorialasset'),
),
]
13 changes: 10 additions & 3 deletions apps/tutorial/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyright: reportUninitializedInstanceVariable=false
import typing
from warnings import deprecated

import ulid
from django.core.exceptions import ValidationError
Expand All @@ -13,6 +14,7 @@


class UploadHelper:
@deprecated("This is kept because it's referenced in migrations")
@staticmethod
def information_page_block_image(instance: "TutorialInformationPageBlock", filename: str):
return f"tutorial/{instance.page.tutorial_id}/block-image/{ulid.ULID()!s}/{filename}"
Expand Down Expand Up @@ -190,8 +192,13 @@ class TutorialInformationPageBlock(UserResource):
block_type = IntegerChoicesField(choices_enum=TutorialInformationPageBlockTypeEnum)
# NOTE: Previously was text_description
text = models.TextField(null=True, blank=True)
# NOTE: Previously was image_file
image = models.ImageField(upload_to=UploadHelper.information_page_block_image, null=True, blank=True)
image: "TutorialAsset | None" = models.ForeignKey( # type: ignore[reportAssignmentType]
"tutorial.TutorialAsset",
related_name="+",
blank=True,
null=True,
on_delete=models.SET_NULL,
)

# Type hints
page_id: int
Expand All @@ -213,5 +220,5 @@ def block_type_enum(self):
def clean(self):
if self.block_type_enum == TutorialInformationPageBlockTypeEnum.TEXT and (self.text is None or self.text == ""):
raise ValidationError(gettext("Text should be provided for text block"))
if self.block_type_enum == TutorialInformationPageBlockTypeEnum.IMAGE and self.image.name is None:
if self.block_type_enum == TutorialInformationPageBlockTypeEnum.IMAGE and self.image is None:
raise ValidationError(gettext("Image should be provided for image block"))
16 changes: 4 additions & 12 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,6 @@ union DeleteProjectPayload = ProjectType | OperationInfo

union DeleteTutorialPayload = TutorialType | OperationInfo

type DjangoImageType {
name: String!
path: String!
size: Int!
url: String!
width: Int!
height: Int!
}

input DjangoModelFilterInput {
id: ID!
}
Expand Down Expand Up @@ -1742,7 +1733,7 @@ input TutorialInformationPageBlockCreateInput {
blockNumber: Int!
blockType: TutorialInformationPageBlockTypeEnum!
text: String
image: Upload
image: ID
}

input TutorialInformationPageBlockInput {
Expand All @@ -1765,7 +1756,8 @@ type TutorialInformationPageBlockType implements UserResourceTypeMixin {
blockNumber: Int!
blockType: TutorialInformationPageBlockTypeEnum!
text: String
image: DjangoImageType
imageId: ID
image: TutorialAssetType
}

enum TutorialInformationPageBlockTypeEnum {
Expand All @@ -1782,7 +1774,7 @@ input TutorialInformationPageBlockUpdateInput {
blockNumber: Int
blockType: TutorialInformationPageBlockTypeEnum
text: String
image: Upload
image: ID
}

"""
Expand Down
Loading