mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Add specific social media image
This commit is contained in:
@@ -3,6 +3,7 @@ import uuid
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime, time, timedelta
|
||||
from operator import attrgetter
|
||||
from urllib.parse import urljoin
|
||||
|
||||
import pytz
|
||||
from django.conf import settings
|
||||
@@ -26,6 +27,7 @@ from pretix.base.validators import EventSlugBanlistValidator
|
||||
from pretix.helpers.database import GroupConcat
|
||||
from pretix.helpers.daterange import daterange
|
||||
from pretix.helpers.json import safe_string
|
||||
from pretix.helpers.thumb import get_thumbnail
|
||||
|
||||
from ..settings import settings_hierarkey
|
||||
from .organizer import Organizer, Team
|
||||
@@ -145,10 +147,13 @@ class EventMixin:
|
||||
"@context": "http://schema.org",
|
||||
"@type": "Event", "location": {
|
||||
"@type": "Place",
|
||||
"address": str(self.location)
|
||||
"address": str(self.location),
|
||||
},
|
||||
"name": str(self.name)
|
||||
"name": str(self.name),
|
||||
}
|
||||
img = getattr(self, 'event', self).social_image
|
||||
if img:
|
||||
eventdict['image'] = img
|
||||
|
||||
if self.settings.show_times:
|
||||
eventdict["startDate"] = self.date_from.isoformat()
|
||||
@@ -358,6 +363,20 @@ class Event(EventMixin, LoggedModel):
|
||||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
@property
|
||||
def social_image(self):
|
||||
from pretix.multidomain.urlreverse import build_absolute_uri
|
||||
|
||||
img = None
|
||||
logo_file = self.settings.get('logo_image', as_type=str, default='')[7:]
|
||||
og_file = self.settings.get('og_image', as_type=str, default='')[7:]
|
||||
if og_file:
|
||||
img = get_thumbnail(og_file, '1200').thumb.url
|
||||
elif logo_file:
|
||||
img = get_thumbnail(logo_file, '5000x120').thumb.url
|
||||
if img:
|
||||
return urljoin(build_absolute_uri(self, 'presale:event.index'), img)
|
||||
|
||||
@property
|
||||
def free_seats(self):
|
||||
from .orders import CartPosition, Order, OrderPosition
|
||||
|
||||
@@ -656,6 +656,10 @@ Your {event} team"""))
|
||||
'default': None,
|
||||
'type': File
|
||||
},
|
||||
'og_image': {
|
||||
'default': None,
|
||||
'type': File
|
||||
},
|
||||
'invoice_logo_image': {
|
||||
'default': None,
|
||||
'type': File
|
||||
|
||||
@@ -488,6 +488,15 @@ class EventSettingsForm(SettingsForm):
|
||||
help_text=_('If you provide a logo image, we will by default not show your events name and date '
|
||||
'in the page header. We will show your logo with a maximal height of 120 pixels.')
|
||||
)
|
||||
og_image = ExtFileField(
|
||||
label=_('Social media image'),
|
||||
ext_whitelist=(".png", ".jpg", ".gif", ".jpeg"),
|
||||
required=False,
|
||||
help_text=_('This picture will be used as a preview if you post links to your ticket shop on social media. '
|
||||
'Facebook advises to use a picture size of 1200 x 630 pixels, however some platforms like '
|
||||
'WhatsApp and Reddit only show a square preview, so we recommend to make sure it still looks good '
|
||||
'only the center square is shown. If you do not fill this, we will use the logo given above.')
|
||||
)
|
||||
frontpage_text = I18nFormField(
|
||||
label=_("Frontpage text"),
|
||||
required=False,
|
||||
|
||||
@@ -96,6 +96,7 @@
|
||||
<fieldset>
|
||||
<legend>{% trans "Shop design" %}</legend>
|
||||
{% bootstrap_field sform.logo_image layout="control" %}
|
||||
{% bootstrap_field sform.og_image layout="control" %}
|
||||
{% url "control:organizer.edit" organizer=request.organizer.slug as org_url %}
|
||||
{% propagated request.event org_url "primary_color" "primary_font" "theme_color_success" "theme_color_danger" %}
|
||||
{% bootstrap_field sform.primary_color layout="control" %}
|
||||
|
||||
@@ -59,7 +59,14 @@ def contextprocessor(request):
|
||||
|
||||
if request.event.settings.presale_css_file:
|
||||
ctx['css_file'] = default_storage.url(request.event.settings.presale_css_file)
|
||||
|
||||
ctx['event_logo'] = request.event.settings.get('logo_image', as_type=str, default='')[7:]
|
||||
ctx['social_image'] = request.event.cache.get_or_set(
|
||||
'social_image_url',
|
||||
request.event.social_image,
|
||||
60
|
||||
)
|
||||
|
||||
ctx['event'] = request.event
|
||||
ctx['languages'] = [get_language_info(code) for code in request.event.settings.locales]
|
||||
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
{% if event.settings.meta_noindex %}
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
{% endif %}
|
||||
<meta property="og:type" content="website" />
|
||||
{% if social_image %}
|
||||
<meta property="og:image" content="{{ social_image }}" />
|
||||
{% endif %}
|
||||
{{ block.super }}
|
||||
{% endblock %}
|
||||
{% block above %}
|
||||
|
||||
@@ -12,10 +12,6 @@
|
||||
{{ block.super }}
|
||||
<meta property="og:title" content="{{ ev.name }}" />
|
||||
<meta property="og:description" content="{{ ev.get_date_range_display }}" />
|
||||
{% if event_logo %}
|
||||
<meta property="og:image" content="{{ event_logo|thumb:'5000x120' }}" />
|
||||
{% endif %}
|
||||
<meta property="og:type" content="website" />
|
||||
{% if subevent %}
|
||||
<meta property="og:url" content="{% abseventurl request.event "presale:event.index" subevent=subevent.pk %}" />
|
||||
{% else %}
|
||||
|
||||
Reference in New Issue
Block a user