def settings_api(request, event_id): # Attempt to fetch custom settings from database try: settings = {} s = ScreenConfig.objects.get(event_id=event_id) settings['enable_twitter'] = s.enable_twitter settings['enable_irc'] = s.enable_irc settings['enable_videos'] = s.enable_videos settings['video_interval'] = s.video_interval return JSONResponse({'settings': settings}) except: pass # Return settings return JSONResponse({})
def order_search_ac(request): """Autocomplete suggestions for the infodesk general purpose search. Each suggestion's "id" should find something in the order_search view. """ term = request.GET.get('term') if not term: raise Http404 # find transactions that contain the search term txns = StoreTransaction.objects.filter(ta_fuzzy_query(term)) items = TransactionItem.objects.filter(ti_fuzzy_query(term)) def fmt_t(t): return arrow.get(t).to(settings.TIME_ZONE).format('DD.MM.YYYY HH:mm') def format_transaction(t): return '%s, %s (%s)' % (t.lastname, t.firstname, fmt_t(t.time_created)) results = [ { 'id': ("%s%s") % (TXN_PREFIX, t.id), # exact query link 'text': format_transaction(t) } for t in txns ] results.extend([{ 'id': ("%s%s") % (TXN_ITEM_PREFIX, item.key), 'text': '%s -- ostaja %s' % (item.item, format_transaction(item.transaction)) } for item in items]) return JSONResponse({'more': False, 'results': results})
def playing_api(request, event_id): playlist = [] for item in NPSong.objects.filter(event_id=event_id).order_by('-id')[:10]: playlist.append({ 'title': item.title, 'artist': item.artist, 'state': item.state, }) return JSONResponse({'playlist': playlist})
def playlist_api(request, event_id): playlist = [] for v in PlaylistVideo.objects.filter(event_id=event_id).order_by('index'): playlist.append({ 'name': v.name, 'url': v.url, 'id': v.id, 'index': v.index }) return JSONResponse({'playlist': playlist})
def events_api(request, event_id): e = get_object_or_404(Event, pk=event_id) # Get upcoming stuff k = 0 events = [] for event in get_upcoming(e): event['date'] = event['date'].strftime("%H:%M") events.append(event) # Only pick 5 k += 1 if k >= 5: break return JSONResponse({'events': events})
def irc_api(request, event_id): # See if we got request data filter_id = 0 try: filter_id = request.GET['last_id'] except: pass # handle datetimes messages = [] for msg in IRCMessage.objects.filter(id__gt=filter_id, event_id=event_id): messages.append({ 'id': msg.id, 'text': msg.message, 'nick': msg.nick, 'time': msg.date.strftime("%H:%M"), }) # Respond return JSONResponse({'log': messages})
def messages_api(request, event_id): messages = [] for msg in Message.objects.filter(event_id=event_id): if msg.show_start <= timezone.now() <= msg.show_end: messages.append(mark_safe(msg.text)) return JSONResponse({'messages': messages})