Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Jun 7, 2024
1 parent 8a58a5c commit 6459b96
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 27 deletions.
6 changes: 2 additions & 4 deletions apps/deepl_integration/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions apps/deepl_integration/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Type
from typing import Type, List, Dict
import logging
from rest_framework import serializers

Expand Down Expand Up @@ -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=[],
)


Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion apps/lead/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 = {
Expand All @@ -26,6 +29,7 @@
(Lead.source_type, LeadSourceTypeEnum),
(Lead.extraction_status, LeadExtractionStatusEnum),
(Lead.auto_entry_extraction_status, LeadAutoEntryExtractionTypeEnum),
(LeadPreviewAttachment.type, LeadPreviewAttachmentTypeEnum),
)
}

Expand Down
18 changes: 18 additions & 0 deletions apps/lead/migrations/0051_alter_leadpreviewattachment_type.py
Original file line number Diff line number Diff line change
@@ -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')]),
),
]
18 changes: 18 additions & 0 deletions apps/lead/migrations/0052_alter_leadpreviewattachment_type.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
8 changes: 4 additions & 4 deletions apps/lead/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand Down
11 changes: 5 additions & 6 deletions apps/lead/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
)
from .enums import (
LeadConfidentialityEnum,
LeadPreviewAttachmentTypeEnum,
LeadStatusEnum,
LeadPriorityEnum,
LeadSourceTypeEnum,
Expand Down Expand Up @@ -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',
)


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)


Expand Down
25 changes: 16 additions & 9 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,7 @@ type AppEnumCollection {
LeadSourceType: [AppEnumCollectionLeadSourceType!]
LeadExtractionStatus: [AppEnumCollectionLeadExtractionStatus!]
LeadAutoEntryExtractionStatus: [AppEnumCollectionLeadAutoEntryExtractionStatus!]
LeadPreviewAttachmentType: [AppEnumCollectionLeadPreviewAttachmentType!]
EntryEntryType: [AppEnumCollectionEntryEntryType!]
ExportFormat: [AppEnumCollectionExportFormat!]
ExportStatus: [AppEnumCollectionExportStatus!]
Expand Down Expand Up @@ -2022,6 +2023,12 @@ type AppEnumCollectionLeadExtractionStatus {
description: String
}

type AppEnumCollectionLeadPreviewAttachmentType {
enum: LeadPreviewAttachmentTypeEnum!
label: String!
description: String
}

type AppEnumCollectionLeadPriority {
enum: LeadPriorityEnum!
label: String!
Expand Down Expand Up @@ -4554,7 +4561,7 @@ type LeadDetailType {
statusDisplay: EnumDescription!
extractionStatus: LeadExtractionStatusEnum
leadPreview: LeadPreviewType
leadPreviewAttachments: [LeadPreviewAttachmentsType!]
leadPreviewAttachment: [LeadPreviewAttachmentType!]!
source: OrganizationType
authors: [OrganizationType!]
emmEntities: [EmmEntityType!]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -4759,7 +4766,7 @@ type LeadType {
statusDisplay: EnumDescription!
extractionStatus: LeadExtractionStatusEnum
leadPreview: LeadPreviewType
leadPreviewAttachments: [LeadPreviewAttachmentsType!]
leadPreviewAttachment: [LeadPreviewAttachmentType!]!
source: OrganizationType
authors: [OrganizationType!]
emmEntities: [EmmEntityType!]
Expand Down

0 comments on commit 6459b96

Please sign in to comment.