Пример #1
0
def check_sharing_best_practices(obj, event):
    """Check if content follows social networks sharing best practices
    as defined by Twitter and Facebook.
    """
    record = ISocialLikeSettings.__identifier__ + '.validation_enabled'
    validation_enabled = api.portal.get_registry_record(record, default=False)
    if not validation_enabled:
        return

    try:
        review_state = api.content.get_state(obj)
    except WorkflowException:
        # images and files have no associated workflow by default
        review_state = 'published'

    if review_state not in ('published', ):
        return  # no need to validate

    request = obj.REQUEST

    title = getattr(obj, 'title', '')
    try:
        validate_og_title(title)
    except ValueError as e:
        api.portal.show_message(message=str(e),
                                request=request,
                                type='warning')

    description = getattr(obj, 'description', '')
    try:
        validate_og_description(description)
    except ValueError as e:
        api.portal.show_message(message=str(e),
                                request=request,
                                type='warning')

    image = get_content_image(obj)
    try:
        validate_og_lead_image(image)
    except ValueError as e:
        api.portal.show_message(message=str(e),
                                request=request,
                                type='warning')
Пример #2
0
def check_sharing_best_practices(obj, event):
    """Check if content follows social networks sharing best practices
    as defined by Twitter and Facebook.
    """
    record = ISocialLikeSettings.__identifier__ + '.validation_enabled'
    validation_enabled = api.portal.get_registry_record(record, default=False)
    if not validation_enabled:
        return

    try:
        review_state = api.content.get_state(obj)
    except WorkflowException:
        # images and files have no associated workflow by default
        review_state = 'published'

    if review_state not in ('published', ):
        return  # no need to validate

    request = obj.REQUEST

    title = getattr(obj, 'title', '')
    try:
        validate_og_title(title)
    except ValueError as e:
        api.portal.show_message(message=str(e), request=request, type='warning')

    description = getattr(obj, 'description', '')
    try:
        validate_og_description(description)
    except ValueError as e:
        api.portal.show_message(message=str(e), request=request, type='warning')

    image = get_content_image(obj)
    try:
        validate_og_lead_image(image)
    except ValueError as e:
        api.portal.show_message(message=str(e), request=request, type='warning')
Пример #3
0
    def test_validate_og_title_invalid(self):
        from sc.social.like.config import OG_TITLE_MAX_LENGTH
        from sc.social.like.utils import MSG_INVALID_OG_TITLE

        with self.assertRaises(ValueError):
            validate_og_title(None)
        with self.assertRaises(ValueError):
            validate_og_title('')

        title = get_random_string(OG_TITLE_MAX_LENGTH + 1)
        with self.assertRaises(ValueError):
            validate_og_title(title)

        # test validation message
        try:
            validate_og_description(title)
        except ValueError as e:
            self.assertEqual(str(e), MSG_INVALID_OG_TITLE)
Пример #4
0
    def test_validate_og_title_invalid(self):
        from sc.social.like.config import OG_TITLE_MAX_LENGTH
        from sc.social.like.utils import MSG_INVALID_OG_TITLE

        with self.assertRaises(ValueError):
            validate_og_title(None)
        with self.assertRaises(ValueError):
            validate_og_title('')

        title = get_random_string(OG_TITLE_MAX_LENGTH + 1)
        with self.assertRaises(ValueError):
            validate_og_title(title)

        # test validation message
        try:
            validate_og_description(title)
        except ValueError as e:
            self.assertEqual(str(e), MSG_INVALID_OG_TITLE)
Пример #5
0
 def test_validate_og_title_valid(self):
     self.assertTrue(validate_og_title('foo'))
Пример #6
0
 def test_validate_og_title_valid(self):
     self.assertTrue(validate_og_title('foo'))