mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
Refactor for reuse
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from notifications_utils.field import Field
|
||||
from notifications_utils.formatters import formatted_list
|
||||
@@ -77,18 +78,30 @@ class NoCommasInPlaceHolders:
|
||||
raise ValidationError(self.message)
|
||||
|
||||
|
||||
class NoEmbeddedImagesInSVG:
|
||||
class NoElementInSVG(ABC):
|
||||
|
||||
def __init__(self, message='This SVG has an embedded raster image in it and will not render well'):
|
||||
self.message = message
|
||||
@property
|
||||
@abstractmethod
|
||||
def element(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def message(self):
|
||||
pass
|
||||
|
||||
def __call__(self, form, field):
|
||||
is_image_embedded = '<image' in field.data.stream.read().decode("utf-8")
|
||||
svg_contents = field.data.stream.read().decode("utf-8")
|
||||
field.data.stream.seek(0)
|
||||
if is_image_embedded:
|
||||
if f'<{self.element}' in svg_contents.lower():
|
||||
raise ValidationError(self.message)
|
||||
|
||||
|
||||
class NoEmbeddedImagesInSVG(NoElementInSVG):
|
||||
element = 'image'
|
||||
message = 'This SVG has an embedded raster image in it and will not render well'
|
||||
|
||||
|
||||
class OnlySMSCharacters:
|
||||
|
||||
def __init__(self, *args, template_type, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user