def _on_event_booked(sender, **kw): from conference.dataaccess import event_data from hcomments.models import ThreadSubscription try: talk_id = event_data(kw['event_id'])['talk']['id'] except Exception: return talk = Talk.objects.get(id=talk_id) user = User.objects.get(id=kw['user_id']) booked = kw['booked'] if booked: log.info( "\"%s\" has booked the event \"%s\", automatically subscribed to the talk's comments", u'{0} {1}'.format(user.first_name, user.last_name), talk.title) else: log.info( "\"%s\" has cancelled the reservation for the event \"%s\", automatically unsubscribed to the talk's comments", u'{0} {1}'.format(user.first_name, user.last_name), talk.title) if booked: ThreadSubscription.objects.subscribe(talk, user) else: ThreadSubscription.objects.unsubscribe(talk, user)
def render_event_video_cover(eid, thumb=(256, 256)): """ Helper function; utilizza la settings.VIDEO_COVER_IMAGE per generare la cover dell'evento passato e copiarla sotto la MEDIA_ROOT. """ import os import os.path from conference import dataaccess from conference import settings from django.conf import settings as dsettings event = dataaccess.event_data(eid) conference = event['conference'] base = os.path.join(dsettings.MEDIA_ROOT, 'conference', 'covers', conference) if not os.path.exists(base): os.makedirs(base) if event.get('talk'): fname = event['talk']['slug'] else: fname = 'event-%d' % eid image = settings.VIDEO_COVER_IMAGE(eid) if image is None: return False image.save(os.path.join(base, fname + '.jpg'), 'JPEG') # image = settings.VIDEO_COVER_IMAGE(eid, thumb=thumb) # image.save(os.path.join(base, fname + '.jpg.thumb'), 'JPEG') return True
def render_event_video_cover(eid, thumb=(256, 256)): """ Helper function; utilizza la settings.VIDEO_COVER_IMAGE per generare la cover dell'evento passato e copiarla sotto la MEDIA_ROOT. """ import os import os.path from conference import dataaccess from conference import settings from django.conf import settings as dsettings event = dataaccess.event_data(eid) conference = event['conference'] base = os.path.join(dsettings.MEDIA_ROOT, 'conference', 'covers', conference) if not os.path.exists(base): os.makedirs(base) if event.get('talk'): fname = event['talk']['slug'] else: fname = 'event-%d' % eid image = settings.VIDEO_COVER_IMAGE(eid) if image is None: return False image.save(os.path.join(base, fname + '.jpg'), 'JPEG') image = settings.VIDEO_COVER_IMAGE(eid, thumb=thumb) image.save(os.path.join(base, fname + '.jpg.thumb'), 'JPEG') return True
def handle(self, *args, **options): try: conference = args[0] except IndexError: raise CommandError('conference code is missing') events = settings.VIDEO_COVER_EVENTS(conference) for e in events: data = dataaccess.event_data(e) print '*', data['name'] render_event_video_cover(e)
def addEvents(self, events): from conference import dataaccess for e in events: if isinstance(e, int): e = dataaccess.event_data(e) for t in e['tracks']: if t not in self._tracks: raise ValueError("Unknown track: %s" % t) try: self.events[t].append(e) except KeyError: self.events[t] = [e] self._analyzed = False
def altf(data, component): if component == 'calendar': if user is None: url = reverse('p3-schedule', kwargs={'conference': conf}) else: url = reverse('p3-schedule-my-schedule', kwargs={'conference': conf}) data['uid'] = settings.DEFAULT_URL_PREFIX + url if curr.code == conf: data['ttl'] = timedelta(seconds=3600) else: data['ttl'] = timedelta(days=365) elif component == 'event': eid = data['uid'] data['uid'] = settings.DEFAULT_URL_PREFIX + '/p3/event/' + str( data['uid']) data['organizer'] = ('mailto:[email protected]', { 'CN': 'EuroPython' }) if hotel: data['coordinates'] = [hotel.lat, hotel.lng] if not isinstance(data['summary'], tuple): # this is a custom event, if it starts with an anchor I can # extract the reference import re m = re.match(r'<a href="(.*)">(.*)</a>', data['summary']) if m: url = m.group(1) if url.startswith('/'): url = settings.DEFAULT_URL_PREFIX + url data['summary'] = (m.group(2), {'ALTREP': url}) if abstract: e = dataaccess.event_data(eid) if e['talk']: from conference.templatetags.conference import name_abbrv speakers = [ name_abbrv(s['name']) for s in e['talk']['speakers'] ] speakers = ", ".join(speakers) data['summary'] = (data['summary'][0] + ' by ' + speakers, data['summary'][1]) ab = e['talk']['abstract'] if e['talk'] else e['abstract'] data['description'] = ab return data
def altf(data, component): if component == 'calendar': if user is None: url = reverse('p3-schedule', kwargs={'conference': conf}) else: url = reverse('p3-schedule-my-schedule', kwargs={'conference': conf}) data['uid'] = settings.DEFAULT_URL_PREFIX + url if curr.code == conf: data['ttl'] = timedelta(seconds=3600) else: data['ttl'] = timedelta(days=365) elif component == 'event': eid = data['uid'] data['uid'] = settings.DEFAULT_URL_PREFIX + '/p3/event/' + str(data['uid']) data['organizer'] = ('mailto:[email protected]', {'CN': 'Python Italia'}) if hotel: data['coordinates'] = [hotel.lat, hotel.lng] if not isinstance(data['summary'], tuple): # questo è un evento custom, se inizia con un anchor posso # estrane il riferimento import re m = re.match(r'<a href="(.*)">(.*)</a>', data['summary']) if m: url = m.group(1) if url.startswith('/'): url = settings.DEFAULT_URL_PREFIX + url data['summary'] = (m.group(2), {'ALTREP': url}) if abstract: e = dataaccess.event_data(eid) if e['talk']: from conference.templatetags.conference import name_abbrv speakers = [ name_abbrv(s['name']) for s in e['talk']['speakers'] ] speakers = ", ".join(speakers) data['summary'] = (data['summary'][0] + ' by ' + speakers, data['summary'][1]) ab = e['talk']['abstract'] if e['talk'] else e['abstract'] data['description'] = ab return data
def CONFERENCE_VIDEO_COVER_IMAGE(eid, type='front'): import re import os.path from PIL import Image, ImageDraw, ImageFont from conference import dataaccess event = dataaccess.event_data(eid) conference = event['conference'] stuff = os.path.normpath( os.path.join(os.path.dirname(__file__), '..', 'documents', 'cover', conference)) if not os.path.isdir(stuff): return None def wrap_text(font, text, width): words = re.split(' ', text) lines = [] while words: word = words.pop(0).strip() if not word: continue if not lines: lines.append(word) else: line = lines[-1] w, h = font.getsize(line + ' ' + word) if w <= width: lines[-1] += ' ' + word else: lines.append(word) for ix, line in enumerate(lines): line = line.strip() while True: w, h = font.getsize(line) if w <= width: break line = line[:-1] lines[ix] = line return lines def write_text(y, text, font, color, page_width, offset_x): lines = wrap_text(font, text, page_width) for line in lines: text_width, text_height = font.getsize(line) x = offset_x + (page_width / 2 - text_width / 2) d.text((x, y), line, font=font, fill=color) y += text_height + text_height / 2 return y master = Image.open(os.path.join(stuff, 'cover.png')).convert('RGBA') if type == 'back': return master font_title = ImageFont.truetype( os.path.join(stuff, 'ProximaNova-Semibold.otf'), 80, encoding="unic") font_author = ImageFont.truetype( os.path.join(stuff, 'Arial_Unicode.ttf'), 45, encoding="unic") title_y = 500 margin = 50 width = master.size[0] - margin * 2 d = ImageDraw.Draw(master) title = event['name'] if event.get('custom'): # this is a custom event, if starts with an anchor we can # extract the reference m = re.match(r'<a href="(.*)">(.*)</a>', title) if m: title = m.group(2) y = write_text(title_y, title, font_title, color=(226, 3, 59, 255), page_width=width, offset_x=margin) if event.get('talk'): spks = [spk['name'] for spk in event['talk']['speakers']] text = 'by ' + ', '.join(spks) y = write_text(y + 50, text, font_author, color=(255, 255, 255, 255), page_width=width, offset_x=margin) return master
def CONFERENCE_VIDEO_COVER_IMAGE(eid, type='front', thumb=False): import re import os.path from PIL import Image, ImageDraw, ImageFont from conference import dataaccess event = dataaccess.event_data(eid) conference = event['conference'] stuff = os.path.normpath( os.path.join(os.path.dirname(__file__), '..', 'documents', 'cover', conference)) if not os.path.isdir(stuff): return None def wrap_text(font, text, width): words = re.split(' ', text) lines = [] while words: word = words.pop(0).strip() if not word: continue if not lines: lines.append(word) else: line = lines[-1] w, h = font.getsize(line + ' ' + word) if w <= width: lines[-1] += ' ' + word else: lines.append(word) for ix, line in enumerate(lines): line = line.strip() while True: w, h = font.getsize(line) if w <= width: break line = line[:-1] lines[ix] = line return lines if conference in ('ep2012', 'ep2013'): master = Image.open(os.path.join(stuff, 'cover-start-end.png')).convert('RGBA') if type == 'back': return master if conference == 'ep2012': ftitle = ImageFont.truetype( os.path.join(stuff, 'League Gothic.otf'), 36, encoding="unic") fauthor = ImageFont.truetype( os.path.join(stuff, 'Arial_Unicode.ttf'), 21, encoding="unic") y = 175 elif conference == 'ep2013': ftitle = ImageFont.truetype( os.path.join(stuff, 'League_Gothic.otf'), 36, encoding="unic") fauthor = ImageFont.truetype( os.path.join(stuff, 'League_Gothic.otf'), 28, encoding="unic") y = 190 width = master.size[0] - 40 d = ImageDraw.Draw(master) title = event['name'] if event.get('custom'): # questo è un evento custom, se inizia con un anchor posso # estrane il riferimento m = re.match(r'<a href="(.*)">(.*)</a>', title) if m: title = m.group(2) lines = wrap_text(ftitle, title, width) for l in lines: d.text((20, y), l, font=ftitle, fill=(0x2f, 0x1c, 0x1c, 0xff)) y += ftitle.getsize(l)[1] + 8 if event.get('talk'): spks = [ x['name'] for x in event['talk']['speakers'] ] text = 'by ' + ','.join(spks) lines = wrap_text(fauthor, text, width) for l in lines: d.text((20, y), l, font=fauthor, fill=(0x3d, 0x7e, 0x8a, 0xff)) y += fauthor.getsize(l)[1] + 8 if thumb: master.thumbnail(thumb, Image.ANTIALIAS) return master else: return None
def CONFERENCE_VIDEO_COVER_IMAGE(eid, type='front', thumb=False): import re import os.path from PIL import Image, ImageDraw, ImageFont from p3 import dataaccess event = dataaccess.event_data(eid) conference = event['conference'] stuff = os.path.normpath( os.path.join(os.path.dirname(__file__), '..', 'documents', 'cover', conference)) if not os.path.isdir(stuff): return None def wrap_text(font, text, width): words = re.split(' ', text) lines = [] while words: word = words.pop(0).strip() if not word: continue if not lines: lines.append(word) else: line = lines[-1] w, h = font.getsize(line + ' ' + word) if w <= width: lines[-1] += ' ' + word else: lines.append(word) for ix, line in enumerate(lines): line = line.strip() while True: w, h = font.getsize(line) if w <= width: break line = line[:-1] lines[ix] = line return lines if conference in ('ep2012', 'ep2013', 'ep2015', 'ep2016', 'ep2017', 'ep2018'): master = Image.open(os.path.join( stuff, 'cover-start-end.png')).convert('RGBA') if type == 'back': return master if conference == 'ep2012': ftitle = ImageFont.truetype(os.path.join(stuff, 'League Gothic.otf'), 36, encoding="unic") fauthor = ImageFont.truetype(os.path.join(stuff, 'Arial_Unicode.ttf'), 21, encoding="unic") y = 175 elif conference in ('ep2013', 'ep2015', 'ep2016', 'ep2017', 'ep2018'): ftitle = ImageFont.truetype(os.path.join(stuff, 'League_Gothic.otf'), 36, encoding="unic") fauthor = ImageFont.truetype(os.path.join(stuff, 'League_Gothic.otf'), 28, encoding="unic") y = 190 width = master.size[0] - 40 d = ImageDraw.Draw(master) title = event['name'] if event.get('custom'): # this is a custom event, if starts with an anchor we can # extract the reference m = re.match(r'<a href="(.*)">(.*)</a>', title) if m: title = m.group(2) lines = wrap_text(ftitle, title, width) for l in lines: d.text((20, y), l, font=ftitle, fill=(0x2f, 0x1c, 0x1c, 0xff)) y += ftitle.getsize(l)[1] + 8 if event.get('talk'): spks = [x['name'] for x in event['talk']['speakers']] text = 'by ' + ','.join(spks) lines = wrap_text(fauthor, text, width) for l in lines: d.text((20, y), l, font=fauthor, fill=(0x3d, 0x7e, 0x8a, 0xff)) y += fauthor.getsize(l)[1] + 8 if thumb: master.thumbnail(thumb, Image.ANTIALIAS) return master else: return None
def CONFERENCE_VIDEO_COVER_IMAGE(eid, type='front'): import re import os.path from PIL import Image, ImageDraw, ImageFont from conference import dataaccess event = dataaccess.event_data(eid) conference = event['conference'] stuff = os.path.normpath( os.path.join(os.path.dirname(__file__), '..', 'documents', 'cover', conference)) if not os.path.isdir(stuff): return None def wrap_text(font, text, width): words = re.split(' ', text) lines = [] while words: word = words.pop(0).strip() if not word: continue if not lines: lines.append(word) else: line = lines[-1] w, h = font.getsize(line + ' ' + word) if w <= width: lines[-1] += ' ' + word else: lines.append(word) for ix, line in enumerate(lines): line = line.strip() while True: w, h = font.getsize(line) if w <= width: break line = line[:-1] lines[ix] = line return lines def write_text(y, text, font, color, page_width, offset_x): lines = wrap_text(font, text, page_width) for line in lines: text_width, text_height = font.getsize(line) x = offset_x + (page_width / 2 - text_width / 2) d.text((x, y), line, font=font, fill=color) y += text_height + text_height / 2 return y master = Image.open(os.path.join(stuff, 'cover.png')).convert('RGBA') if type == 'back': return master font_title = ImageFont.truetype(os.path.join(stuff, 'ProximaNova-Semibold.otf'), 80, encoding="unic") font_author = ImageFont.truetype(os.path.join(stuff, 'Arial_Unicode.ttf'), 45, encoding="unic") title_y = 500 margin = 50 width = master.size[0] - margin * 2 d = ImageDraw.Draw(master) title = event['name'] if event.get('custom'): # this is a custom event, if starts with an anchor we can # extract the reference m = re.match(r'<a href="(.*)">(.*)</a>', title) if m: title = m.group(2) y = write_text(title_y, title, font_title, color=(226, 3, 59, 255), page_width=width, offset_x=margin) if event.get('talk'): spks = [spk['name'] for spk in event['talk']['speakers']] text = 'by ' + ', '.join(spks) y = write_text(y + 50, text, font_author, color=(255, 255, 255, 255), page_width=width, offset_x=margin) return master