-
Notifications
You must be signed in to change notification settings - Fork 510
Add email placeholder for picture #6580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add email placeholder for picture #6580
Conversation
| def render(cls, regform, registration): | ||
| picture_data = registration.get_personal_data_picture() | ||
| if not picture_data: | ||
| return _('NO PICTURE') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks quite ugly, especially w/ the uppercase.
Two potential options:
- Returning an empty string
- Returning a placeholder image (like the one with the initial we use e.g. in meeting participant lists)
| url = url_for('event_registration.registration_picture', picture_data.locator.file, | ||
| _external=True, token=registration.uuid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we agreed to use the cid and attach the image to the email? External image references in emails are generally a bad idea.
|
I updated the code using cid, but for the preview it doesn't work as attachments can't be done. |
indico/util/string.py
Outdated
| css_sanitizer = IndicoCSSSanitizer(allowed_css_properties=BLEACH_ALLOWED_STYLES_HTML) | ||
| return bleach.clean(string, tags=BLEACH_ALLOWED_TAGS_HTML, attributes=BLEACH_ALLOWED_ATTRIBUTES_HTML, | ||
| css_sanitizer=css_sanitizer) | ||
| protocols=BLEACH_ALLOWED_PROTOCOLS_HTML, css_sanitizer=css_sanitizer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should not be applied globally, but only when sending emails that require it (ie make it a default-false arg of this function).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to define the 'sanitise_html' with default arg:
app.add_template_filter(lambda s: Markup(sanitize_html(s or '', default_protocols=False)), 'sanitize_html')
but when I use the filter
{{ email_body | sanitize_html(True) }}
got error:
"setup_jinja..() takes 1 positional argument but 2 were given"
Could you please help ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app.add_template_filter(lambda s, **kwargs: Markup(sanitize_html(s or '', **kwargs)), 'sanitize_html')And then just add , *, allow_cid=False to the argument list of sanitize_html and depending on that arg use the default protocols or default protocols + cid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same error: "setup_jinja..() takes 1 positional argument but 2 were given"
when calling the filter with arg:
app.add_template_filter(lambda s, **kwargs: Markup(sanitize_html(s or '', **kwargs)), 'sanitize_html')
def sanitize_html(string, *, allow_cid=False):
{{ email_body | sanitize_html(True) }}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are passing it as a positional arg, but it should be a keyword arg...
indico/util/string.py
Outdated
| 'text-decoration', 'text-indent', 'text-shadow', 'text-transform', 'unicode-bidi', 'visibility', 'vertical-align', | ||
| 'width', 'widows', 'white-space', 'word-spacing', 'word-wrap', 'z-index' | ||
| ] | ||
| BLEACH_ALLOWED_PROTOCOLS_HTML = ['cid'] # used for embedded image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will most likely break the current list of allowed protocols since you're only passing cid but no http/https now.
Damn, forgot about the preview... One solution could be to use a base64 data url for this placeholder while rendering the preview. Or use your original solution for the preview and the cid only when generating the actual mail. |
|
To render differently the picture in preview, I need to know the context "preview".
What would be your suggestion ? |
|
i had option 2 in mind, but i somehow thought we already accept kwargs and thus would not need to modify every placeholder... maybe checking if |
|
One last point: |
|
constant in python sure, but I don't think having an indico.conf setting for this would really make sense - it's SO specific and probably you guys are the only ones who would change this... |
indico/modules/events/registration/templates/emails/custom_email.html
Outdated
Show resolved
Hide resolved
indico/modules/events/registration/placeholders/registrations.py
Outdated
Show resolved
Hide resolved
indico/modules/events/registration/placeholders/registrations.py
Outdated
Show resolved
Hide resolved
506289a to
3ca0fb5
Compare
…il.html Co-authored-by: Adrian <[email protected]>
Co-authored-by: Adrian <[email protected]>
Request to add a placeholder to display the personal data picture in email.