fix: some fixes
This commit is contained in:
@@ -172,6 +172,10 @@ def upload_ad_image(
|
|||||||
id=campaign_id,
|
id=campaign_id,
|
||||||
advertiser_id=advertiser_id,
|
advertiser_id=advertiser_id,
|
||||||
)
|
)
|
||||||
|
if ad_image.size >= 10 * 1024 * 1024:
|
||||||
|
raise HttpError(
|
||||||
|
status.BAD_REQUEST, "File can't be bigger than 10MB."
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
Image.open(ad_image).verify()
|
Image.open(ad_image).verify()
|
||||||
except (OSError, SyntaxError):
|
except (OSError, SyntaxError):
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ from apps.campaign.validators import (
|
|||||||
CampaignReportMessageValidator,
|
CampaignReportMessageValidator,
|
||||||
CampaignStartDateValidator,
|
CampaignStartDateValidator,
|
||||||
CampaignTargetingLocationValidator,
|
CampaignTargetingLocationValidator,
|
||||||
|
CampaignTargetingGenderValidator
|
||||||
)
|
)
|
||||||
from apps.client.models import Client
|
from apps.client.models import Client
|
||||||
from apps.core.models import BaseModel
|
from apps.core.models import BaseModel
|
||||||
@@ -96,6 +97,7 @@ class Campaign(BaseModel):
|
|||||||
return self.ad_title
|
return self.ad_title
|
||||||
|
|
||||||
def clean(self) -> None:
|
def clean(self) -> None:
|
||||||
|
CampaignTargetingGenderValidator()(self)
|
||||||
CampaignTargetingLocationValidator()(self)
|
CampaignTargetingLocationValidator()(self)
|
||||||
CampaignAgeValidator()(self)
|
CampaignAgeValidator()(self)
|
||||||
CampaignDurationValidator()(self)
|
CampaignDurationValidator()(self)
|
||||||
|
|||||||
@@ -11,18 +11,16 @@ if TYPE_CHECKING:
|
|||||||
class CampaignTargetingLocationValidator:
|
class CampaignTargetingLocationValidator:
|
||||||
def __call__(self, instance: "Campaign") -> None:
|
def __call__(self, instance: "Campaign") -> None:
|
||||||
if instance.location == "":
|
if instance.location == "":
|
||||||
err = {
|
err = "targeting.location can't be blank."
|
||||||
"targeting": {
|
|
||||||
type(
|
|
||||||
instance
|
|
||||||
).location.field.name: Field.default_error_messages[
|
|
||||||
"blank"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
raise ValidationError(err)
|
raise ValidationError(err)
|
||||||
|
|
||||||
|
|
||||||
|
class CampaignTargetingGenderValidator:
|
||||||
|
def __call__(self, instance: "Campaign") -> None:
|
||||||
|
if instance.gender == "":
|
||||||
|
err = "gender can't be blank."
|
||||||
|
raise ValidationError(err)
|
||||||
|
|
||||||
class CampaignAgeValidator:
|
class CampaignAgeValidator:
|
||||||
def __call__(self, instance: "Campaign") -> None:
|
def __call__(self, instance: "Campaign") -> None:
|
||||||
if (
|
if (
|
||||||
@@ -75,9 +73,5 @@ class CampaignStartDateValidator:
|
|||||||
class CampaignReportMessageValidator:
|
class CampaignReportMessageValidator:
|
||||||
def __call__(self, instance: "CampaignReport") -> None:
|
def __call__(self, instance: "CampaignReport") -> None:
|
||||||
if instance.message == "":
|
if instance.message == "":
|
||||||
err = {
|
err = "message can't be blank."
|
||||||
instance.message.field.name: Field.default_error_messages[
|
|
||||||
"blank"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
raise ValidationError(err)
|
raise ValidationError(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user