def current_show_and_next(request): """Sends info about the current show as JSON.""" # In case the worst happens and the schedule doesn't come back with # two items, we're very cautious about the size of day. day = list(s_range.day(limit=2)) json_data = {} if len(day) >= 1: on_air = day[0] if on_air.player_image: image = on_air.player_image.url else: image = settings.STATIC_URL + "img/default_show_player.png" json_data.update( { "onAir": on_air.title, "onAirDesc": on_air.description, "onAirPres": on_air.by_line(), "onAirTime": '{:%H:%M} - {:%H:%M}'.format( on_air.start_time, on_air.end_time ), "onAirImg": image, } ) if len(day) >= 2: up_next = day[1] json_data.update( { "upNext": up_next.title, "upNextDesc": up_next.description, "upNextPres": up_next.by_line(), "upNextTime": '{:%H:%M} - {:%H:%M}'.format( up_next.start_time, up_next.end_time ) } ) return HttpResponse( simplejson.dumps(json_data), content_type="application/json" )
def broadcast_info(request): """ Adds information about whether the radio station is currently broadcasting into the template context, as well as the currently broadcasting shows. """ now = timezone.now() # If any other ways of discerning whether broadcasting is # occurring, add them here! term = Term.of(now) if not term: preterm = Term.before(now) return { 'shows_on_air': day(now), # broadcasting is intended to be true when a schedule is # in play. 'broadcasting': getattr( settings, 'BROADCASTING', (term is not None) ), # transmitting is intended to be a stronger form of # broadcasting, in that it represents times when the station # is technically on air but not necessarily working to a # schedule. 'transmitting': getattr( settings, 'TRANSMITTING', ( term is not None or (preterm is not None and preterm.name.lower() != 'summer') ) ), }
def send_message(request): """ Sends a message to the current show via the website. """ # Current show timeslot = s_range.day(limit=1)[0] if 'comments' not in request.POST: result = render( request, 'website/send-message-error.html', {'error': "You didn't specify a message."}, status=403) elif not timeslot.can_be_messaged: result = render( request, 'website/send-message-error.html', {'error': "This show isn't messagable."}, status=403) else: message = request.POST['comments'] spam = [ '[url=', '<a href=', '<a href=' ] # Rudimentary spam check if True in (x in message for x in spam): result = render( request, 'website/send-message-error.html', {'error': 'Your message has been detected as potential spam.'}, status=403) else: # Check for possible computing words and warn presenters comp_words = [ 'fs1', 'server', 'icecast', 'stream', 'jukebox', 'restart', 'logger', 'computing team', 'compteam' ] if True in (x in message.lower() for x in comp_words): message = ''.join((""" <div class="ui-state-highlight"> <span> Computing Team will never ask you to switch to the jukebox or otherwise disrupt your show using a SIS message. </span> </div> """, message)) # Find out where the sender is from location = (request.META['REMOTE_ADDR'] if 'HTTP_X_FORWARDED_FOR' not in request.META else request.META['HTTP_X_FORWARDED_FOR']) message_comm = SISComm( commtypeid=3, # Website communication sender='URY Website', timeslotid=timeslot.id, subject=message[:255], content=message, statusid=1, # Unread comm_source=location) message_comm.save() result = redirect('index') return result