diff --git a/apps/deepl_integration/handlers.py b/apps/deepl_integration/handlers.py index 5cb5ee4223..e035044099 100644 --- a/apps/deepl_integration/handlers.py +++ b/apps/deepl_integration/handlers.py @@ -656,8 +656,7 @@ def save_data( # TODO: The logic is same for unified_connector leads as well. Maybe have a single func? attachement_base_path = f'{lead.pk}' - images = [dict(item) for item in images_uri] - for image_uri in images: + for image_uri in images_uri: for image in image_uri['images']: lead_attachement = LeadPreviewAttachment(lead=lead) image_obj = RequestHelper(url=image, ignore_error=True).get_file() @@ -672,8 +671,7 @@ def save_data( lead_attachement.save() - table_path = [dict(item) for item in table_uri] - for table in table_path: + for table in table_uri: lead_attachement = LeadPreviewAttachment(lead=lead) table_img = RequestHelper(url=table['image_link'], ignore_error=True).get_file() table_attahcment = RequestHelper(url=table['content_link'], ignore_error=True).get_file() diff --git a/apps/deepl_integration/serializers.py b/apps/deepl_integration/serializers.py index 203701e542..afaddc9315 100644 --- a/apps/deepl_integration/serializers.py +++ b/apps/deepl_integration/serializers.py @@ -1,4 +1,4 @@ -from typing import Type +from typing import Type, List, Dict import logging from rest_framework import serializers @@ -67,7 +67,7 @@ class ImagePathSerializer(serializers.Serializer): page_number = serializers.IntegerField(required=True) images = serializers.ListField( child=serializers.CharField(allow_blank=True), - default=[] + default=[], ) @@ -111,7 +111,7 @@ def validate(self, data): raise serializers.ValidationError(errors) return data - def create(self, data): + def create(self, data: List[Dict]): success = data['status'] == self.Status.SUCCESS lead = data['object'] # Added from validate if success: diff --git a/apps/lead/enums.py b/apps/lead/enums.py index 39516159ed..07e9f5d448 100644 --- a/apps/lead/enums.py +++ b/apps/lead/enums.py @@ -5,7 +5,7 @@ get_enum_name_from_django_field, ) -from .models import Lead +from .models import Lead, LeadPreviewAttachment LeadConfidentialityEnum = convert_enum_to_graphene_enum(Lead.Confidentiality, name='LeadConfidentialityEnum') LeadStatusEnum = convert_enum_to_graphene_enum(Lead.Status, name='LeadStatusEnum') @@ -15,6 +15,9 @@ LeadAutoEntryExtractionTypeEnum = convert_enum_to_graphene_enum( Lead.AutoExtractionStatus, name='LeadAutoEntryExtractionTypeEnum' ) +LeadPreviewAttachmentTypeEnum = convert_enum_to_graphene_enum( + LeadPreviewAttachment.AttachementFileType, name='LeadPreviewAttachmentTypeEnum' +) enum_map = { @@ -26,6 +29,7 @@ (Lead.source_type, LeadSourceTypeEnum), (Lead.extraction_status, LeadExtractionStatusEnum), (Lead.auto_entry_extraction_status, LeadAutoEntryExtractionTypeEnum), + (LeadPreviewAttachment.type, LeadPreviewAttachmentTypeEnum), ) } diff --git a/apps/lead/migrations/0051_alter_leadpreviewattachment_type.py b/apps/lead/migrations/0051_alter_leadpreviewattachment_type.py new file mode 100644 index 0000000000..bfa87741c4 --- /dev/null +++ b/apps/lead/migrations/0051_alter_leadpreviewattachment_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.25 on 2024-06-07 06:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lead', '0050_auto_20240606_0608'), + ] + + operations = [ + migrations.AlterField( + model_name='leadpreviewattachment', + name='type', + field=models.SmallIntegerField(choices=[('1', 'XLSX'), ('2', 'Image')]), + ), + ] diff --git a/apps/lead/migrations/0052_alter_leadpreviewattachment_type.py b/apps/lead/migrations/0052_alter_leadpreviewattachment_type.py new file mode 100644 index 0000000000..0185485a73 --- /dev/null +++ b/apps/lead/migrations/0052_alter_leadpreviewattachment_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.25 on 2024-06-07 08:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lead', '0051_alter_leadpreviewattachment_type'), + ] + + operations = [ + migrations.AlterField( + model_name='leadpreviewattachment', + name='type', + field=models.PositiveSmallIntegerField(choices=[('1', 'XLSX'), ('2', 'Image')], default='1'), + ), + ] diff --git a/apps/lead/models.py b/apps/lead/models.py index 98403aa87f..f941e2b4f4 100644 --- a/apps/lead/models.py +++ b/apps/lead/models.py @@ -377,17 +377,17 @@ class LeadPreviewAttachment(models.Model): NOTE: File can be only used by gallery (when attached to a entry) """ class AttachementFileType(models.TextChoices): - XLSX = 'XLSX', 'XLSX' - IMAGE = 'image', 'Image' + XLSX = 1, 'XLSX' + IMAGE = 2, 'Image' lead = models.ForeignKey( Lead, related_name='images', on_delete=models.CASCADE, ) order = models.IntegerField(default=0) page_number = models.IntegerField(default=0) - type = models.CharField( - max_length=20, + type = models.PositiveSmallIntegerField( choices=AttachementFileType.choices, + default=AttachementFileType.XLSX ) file = models.FileField(upload_to='lead-preview/attachments/') file_preview = models.FileField(upload_to='lead-preview/attachments-preview/') diff --git a/apps/lead/schema.py b/apps/lead/schema.py index 519aee5b13..24c3107373 100644 --- a/apps/lead/schema.py +++ b/apps/lead/schema.py @@ -37,6 +37,7 @@ ) from .enums import ( LeadConfidentialityEnum, + LeadPreviewAttachmentTypeEnum, LeadStatusEnum, LeadPriorityEnum, LeadSourceTypeEnum, @@ -217,18 +218,16 @@ class Meta: ) -class LeadPreviewAttachmentsType(DjangoObjectType): +class LeadPreviewAttachmentType(DjangoObjectType): file = graphene.Field(FileFieldType) file_preview = graphene.Field(FileFieldType) + type = graphene.Field(LeadPreviewAttachmentTypeEnum) class Meta: model = LeadPreviewAttachment only_fields = ( - 'type', 'page_number', 'order', - 'file', - 'file_preview', ) @@ -363,7 +362,7 @@ class Meta: extraction_status = graphene.Field(LeadExtractionStatusEnum) lead_preview = graphene.Field(LeadPreviewType) - lead_preview_attachments = graphene.List(graphene.NonNull(LeadPreviewAttachmentsType)) + lead_preview_attachment = graphene.List(graphene.NonNull(LeadPreviewAttachmentType), required=True) source = graphene.Field(OrganizationType) authors = DjangoListField(OrganizationType) assignee = graphene.Field(UserType) @@ -429,7 +428,7 @@ def resolve_attachment(root, info, **kwargs): if root.attachment_id: return info.context.dl.deep_gallery.file.load(root.attachment_id) - def resolve_lead_preview_attachments(root, info, **kwargs): + def resolve_lead_preview_attachment(root, info, **kwargs): return info.context.dl.lead.lead_preview_attachment.load(root.pk) diff --git a/schema.graphql b/schema.graphql index f9d55e3671..b36971ecf3 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1574,6 +1574,7 @@ type AppEnumCollection { LeadSourceType: [AppEnumCollectionLeadSourceType!] LeadExtractionStatus: [AppEnumCollectionLeadExtractionStatus!] LeadAutoEntryExtractionStatus: [AppEnumCollectionLeadAutoEntryExtractionStatus!] + LeadPreviewAttachmentType: [AppEnumCollectionLeadPreviewAttachmentType!] EntryEntryType: [AppEnumCollectionEntryEntryType!] ExportFormat: [AppEnumCollectionExportFormat!] ExportStatus: [AppEnumCollectionExportStatus!] @@ -2022,6 +2023,12 @@ type AppEnumCollectionLeadExtractionStatus { description: String } +type AppEnumCollectionLeadPreviewAttachmentType { + enum: LeadPreviewAttachmentTypeEnum! + label: String! + description: String +} + type AppEnumCollectionLeadPriority { enum: LeadPriorityEnum! label: String! @@ -4554,7 +4561,7 @@ type LeadDetailType { statusDisplay: EnumDescription! extractionStatus: LeadExtractionStatusEnum leadPreview: LeadPreviewType - leadPreviewAttachments: [LeadPreviewAttachmentsType!] + leadPreviewAttachment: [LeadPreviewAttachmentType!]! source: OrganizationType authors: [OrganizationType!] emmEntities: [EmmEntityType!] @@ -4686,17 +4693,17 @@ enum LeadOrderingEnum { DESC_ENTRIES_COUNT } -enum LeadPreviewAttachmentType { - XLSX - IMAGE -} - -type LeadPreviewAttachmentsType { +type LeadPreviewAttachmentType { order: Int! pageNumber: Int! - type: LeadPreviewAttachmentType! file: FileFieldType filePreview: FileFieldType + type: LeadPreviewAttachmentTypeEnum +} + +enum LeadPreviewAttachmentTypeEnum { + XLSX + IMAGE } type LeadPreviewType { @@ -4759,7 +4766,7 @@ type LeadType { statusDisplay: EnumDescription! extractionStatus: LeadExtractionStatusEnum leadPreview: LeadPreviewType - leadPreviewAttachments: [LeadPreviewAttachmentsType!] + leadPreviewAttachment: [LeadPreviewAttachmentType!]! source: OrganizationType authors: [OrganizationType!] emmEntities: [EmmEntityType!]