def add_oneliner(user, message): message = message.strip() can_post = user.is_superuser or not user.has_perm('webview.mute_oneliner') r = user.get_profile().is_muted() if can_post and r: can_post = False models.send_notification('You can not post until <span class="tzinfo">%s</span>. Reason: %s' % (r["time"].strftime("%H:%M"), r["reason"]), user) if message and can_post: models.Oneliner.objects.create(user = user, message = message) get_oneliner(True) make_oneliner_xml(True) models.add_event(event='oneliner')
def add_oneliner(user, message): message = message.strip() can_post = user.is_superuser or not user.has_perm('webview.mute_oneliner') r = user.get_profile().is_muted() if can_post and r: can_post = False models.send_notification( 'You can not post until <span class="tzinfo">%s</span>. Reason: %s' % (r["time"].strftime("%H:%M"), r["reason"]), user) if message and can_post: models.Oneliner.objects.create(user=user, message=message) f = get_oneliner(True) models.add_event(event='oneliner')
def queue_song(song, user, event=True, force=False): event_metadata = {'song': song.id, 'user': user.id} if user.get_profile().is_hellbanned(): return False if SELFQUEUE_DISABLED and song.is_connected_to(user): models.send_notification("You can't request your own songs!", user) return False # To update lock time and other stats # select_for_update is used to lock the song row, so no other request # can modify it at the same time. song = models.Song.objects.select_for_update().get(id=song.id) num_dj_hours = getattr(settings, 'DJ_HOURS', 0) if not force and num_dj_hours: # Don't allow requests to be played during DJ hours play_start = models.Queue(song=song).get_eta() hours_at_start = get_dj_hours(play_start, num_dj_hours) play_end = play_start + datetime.timedelta( seconds=song.get_songlength()) if play_end.day == play_start.day: hours_at_end = hours_at_start else: hours_at_end = get_dj_hours(play_end, num_dj_hours) if play_start.hour in hours_at_start or play_end.hour in hours_at_end: if datetime.datetime.now().hour in hours_at_start: s = "Queuing songs is disabled during DJ Random sessions. DJ Random has the floor!!!" else: s = "Queuing songs during hour of expected play time is not allowed. DJ Random will have the floor!!!" models.send_notification(s, user) return False key = "songqueuenum-" + str(user.id) EVS = [] Q = False time = song.create_lock_time() result = True total_req_count = models.Queue.objects.filter(played=False).count() if total_req_count < MIN_QUEUE_SONGS_LIMIT and not song.is_locked(): Q = models.Queue.objects.filter(played=False, requested_by=user) user_req_and_play_count = Q.count() total_req_and_play_count = total_req_count now_playing = get_now_playing_song() if now_playing: total_req_and_play_count += 1 if now_playing.requested_by == user: user_req_and_play_count += 1 # Is user the only one requesting (and also same user as requester of # currently playing song) ? Then allow forced queueing. # In all other cases there's at least one other requester and # then the normal rules apply. if user_req_and_play_count == total_req_and_play_count: force = True time_full, time_left, time_next = find_queue_time_limit(user, song) time_left_delta = models.TimeDelta(seconds=time_left) if not force: if time_full: result = False models.send_notification( "Song is too long. Remaining timeslot : %s. Next timeslot change: <span class='tzinfo'>%s</span>" % (time_left_delta.to_string(), time_next.strftime("%H:%M")), user) requests = cache.get(key, None) if not Q: Q = models.Queue.objects.filter(played=False, requested_by=user) if requests == None: requests = Q.count() else: requests = len(requests) if result and requests >= settings.SONGS_IN_QUEUE: models.send_notification( "You have reached your unplayed queue entry limit! Please wait for your requests to play.", user) result = False if result and song.is_locked(): # In a case, this should not append since user (from view) can't reqs song locked models.send_notification("Song is already locked", user) result = False if result and LOWRATE and song.rating and song.rating <= LOWRATE[ 'lowvote']: if Q.filter(song__rating__lte=LOWRATE['lowvote']).count( ) >= LOWRATE['limit']: models.send_notification( "Anti-Crap: Song Request Denied (Rating Too Low For Current Queue)", user) result = False if result: song.locked_until = datetime.datetime.now() + time song.save() Q = models.Queue(song=song, requested_by=user, played=False) Q.eta = Q.get_eta() Q.save() EVS.append('a_queue_%i' % song.id) #Need to add logic to decrease or delete when song gets played #cache.set(key, requests + 1, 600) if event: get_queue(True) # generate new queue cached object EVS.append('queue') msg = "%s has been queued." % escape(song.title) msg += " It is expected to play at <span class='tzinfo'>%s</span>." % Q.eta.strftime( "%H:%M") if time_left != False: msg += " Remaining timeslot : %s." % time_left_delta.to_string( ) models.send_notification(msg, user) models.add_event(eventlist=EVS, metadata=event_metadata) return Q
def forum(request, slug): """ Displays a list of threads within a forum. Threads are sorted by their sticky flag, followed by their most recent post. """ f = get_object_or_404(Forum, slug=slug) # If the user is not authorized to view the thread, then redirect if f.is_private and request.user.is_staff != True: return HttpResponseRedirect('/forum') # Process new thread form if data was sent if request.method == 'POST': if not request.user.is_authenticated(): return HttpResponseServerError() thread_form = ThreadForm(request.POST) r = check_muted(request) if r: return r if thread_form.is_valid(): new_thread = thread_form.save(commit = False) new_thread.forum = f new_thread.save() Post.objects.create(thread=new_thread, author=request.user, body=thread_form.cleaned_data['body'], time=datetime.now()) if new_thread.is_visible(None): if NOTIFY_THREAD and not f.is_private: wm.send_notification("%s created a new thread \"<a href='%s'>%s</a>\" in forum \"%s\"" % ( escape(request.user.username), new_thread.get_absolute_url(), escape(new_thread.title), escape(new_thread.forum.title), ), None, 1) if (thread_form.cleaned_data['subscribe'] == True): Subscription.objects.create(author=request.user, thread=new_thread) return HttpResponseRedirect(new_thread.get_absolute_url()) else: thread_form = ThreadForm() # Pagination t = f.thread_set.all() paginator = Paginator(t, settings.FORUM_PAGINATE) try: page = int(request.GET.get('page', 1)) except: page = 1 try: threads = paginator.page(page) except (EmptyPage, InvalidPage): threads = paginator.page(paginator.num_pages) return j2shim.r2r('forum/thread_list.html', { 'forum': f, 'threads': threads.object_list, 'page_range': paginator.page_range, 'page': page, 'thread_form': thread_form }, request)
def thread(request, thread): """ Increments the viewed count on a thread then displays the posts for that thread, in chronological order. """ t = get_object_or_404(Thread, pk=thread) p = t.post_set.all().order_by('time') if request.user.is_authenticated(): s = t.subscription_set.filter(author=request.user) else: s = False # If the user is not authorized to view, we redirect them if t.forum.is_private and request.user.is_staff != True: return HttpResponseRedirect('/forum') # Process reply form if it was sent if (request.method == 'POST'): if not request.user.is_authenticated() or t.closed: return HttpResponseServerError() r = check_muted(request) if r: return r reply_form = ReplyForm(request.POST) if reply_form.is_valid(): new_post = reply_form.save(commit = False) new_post.author = request.user new_post.thread = t new_post.time=datetime.now() new_post.save() # Change subscription if reply_form.cleaned_data['subscribe']: Subscription.objects.get_or_create(thread=t, author=request.user) else: Subscription.objects.filter(thread=t, author=request.user).delete() # Send email if new_post.is_visible(None): forum_email_notification(new_post) if NOTIFY_POST and not t.forum.is_private: wm.send_notification("%s posted a reply to \"<a href='%s#post%s'>%s</a>\" in forum \"%s\"" % ( escape(request.user.username), new_post.thread.get_absolute_url(), new_post.id, escape(new_post.thread.title), escape(new_post.thread.forum.title), ), None, 1) return HttpResponseRedirect(new_post.get_absolute_url()) else: reply_form = ReplyForm(initial={'subscribe': s}) # Pagination paginator = Paginator(p, settings.FORUM_PAGINATE) try: page = int(request.GET.get('page', paginator.num_pages)) except: page = paginator.num_pages try: posts = paginator.page(page) except (EmptyPage, InvalidPage): posts = paginator.page(paginator.num_pages) t.views += 1 t.save() #{'object_list' : artistic.object_list, 'page_range' : paginator.page_range, 'page' : page, 'letter' : letter, 'al': alphalist}, \ return j2shim.r2r('forum/thread.html', { 'forum': t.forum, 'thread': t, 'posts': posts.object_list, 'page_range': paginator.page_range, 'page': page, 'reply_form': reply_form }, request)
def queue_song(song, user, event=True, force=False): event_metadata = {'song': song.id, 'user': user.id} if SELFQUEUE_DISABLED and song.is_connected_to(user): models.send_notification("You can't request your own songs!", user) return False #To update lock time and other stats song = models.Song.objects.get(id=song.id) key = "songqueuenum-" + str(user.id) EVS = [] Q = False time = song.create_lock_time() result = True if models.Queue.objects.filter(played=False).count( ) < MIN_QUEUE_SONGS_LIMIT and not song.is_locked(): force = True time_full, time_left, time_next = find_queue_time_limit(user, song) time_left_delta = models.TimeDelta(seconds=time_left) if not force: if time_full: result = False models.send_notification( "Song is too long. Remaining timeslot : %s. Next timeslot change: <span class='tzinfo'>%s</span>" % (time_left_delta.to_string(), time_next.strftime("%H:%M")), user) requests = cache.get(key, None) Q = models.Queue.objects.filter(played=False, requested_by=user) if requests == None: requests = Q.count() else: requests = num(requests) if result and requests >= settings.SONGS_IN_QUEUE: models.send_notification( "You have reached your unplayed queue entry limit! Please wait for your requests to play.", user) result = False if result and song.is_locked(): # In a case, this should not append since user (from view) can't reqs song locked models.send_notification("Song is already locked", user) result = False if result and LOWRATE and song.rating and song.rating <= LOWRATE[ 'lowvote']: if Q.filter(song__rating__lte=LOWRATE['lowvote']).count( ) >= LOWRATE['limit']: models.send_notification( "Anti-Crap: Song Request Denied (Rating Too Low For Current Queue)", user) result = False if result: song.locked_until = datetime.datetime.now() + time song.save() Q = models.Queue(song=song, requested_by=user, played=False) Q.eta = Q.get_eta() Q.save() EVS.append('a_queue_%i' % song.id) #Need to add logic to decrease or delete when song gets played #cache.set(key, requests + 1, 600) if event: bla = get_queue(True) # generate new queue cached object EVS.append('queue') msg = "%s has been queued." % escape(song.title) msg += " It is expected to play at <span class='tzinfo'>%s</span>." % Q.eta.strftime( "%H:%M") if time_left != False: msg += " Remaining timeslot : %s." % time_left_delta.to_string( ) models.send_notification(msg, user) models.add_event(eventlist=EVS, metadata=event_metadata) return Q
def queue_song(song, user, event = True, force = False): event_metadata = {'song': song.id, 'user': user.id} if SELFQUEUE_DISABLED and song.is_connected_to(user): models.send_notification("You can't request your own songs!", user) return False #To update lock time and other stats song = models.Song.objects.get(id=song.id) key = "songqueuenum-" + str(user.id) EVS = [] Q = False time = song.create_lock_time() result = True if models.Queue.objects.filter(played=False).count() < MIN_QUEUE_SONGS_LIMIT and not song.is_locked(): force = True time_full, time_left, time_next = find_queue_time_limit(user, song) time_left_delta = models.TimeDelta(seconds=time_left) if not force: if time_full: result = False models.send_notification("Song is too long. Remaining timeslot : %s. Next timeslot change: <span class='tzinfo'>%s</span>" % (time_left_delta.to_string(), time_next.strftime("%H:%M")), user) requests = cache.get(key, None) Q = models.Queue.objects.filter(played=False, requested_by = user) if requests == None: requests = Q.count() else: requests = len(requests) if result and requests >= settings.SONGS_IN_QUEUE: models.send_notification("You have reached your unplayed queue entry limit! Please wait for your requests to play.", user) result = False if result and song.is_locked(): # In a case, this should not append since user (from view) can't reqs song locked models.send_notification("Song is already locked", user) result = False if result and LOWRATE and song.rating and song.rating <= LOWRATE['lowvote']: if Q.filter(song__rating__lte = LOWRATE['lowvote']).count() >= LOWRATE['limit']: models.send_notification("Anti-Crap: Song Request Denied (Rating Too Low For Current Queue)", user) result = False if result: song.locked_until = datetime.datetime.now() + time song.save() Q = models.Queue(song=song, requested_by=user, played = False) Q.eta = Q.get_eta() Q.save() EVS.append('a_queue_%i' % song.id) #Need to add logic to decrease or delete when song gets played #cache.set(key, requests + 1, 600) if event: get_queue(True) # generate new queue cached object EVS.append('queue') msg = "%s has been queued." % escape(song.title) msg += " It is expected to play at <span class='tzinfo'>%s</span>." % Q.eta.strftime("%H:%M") if time_left != False: msg += " Remaining timeslot : %s." % time_left_delta.to_string() models.send_notification(msg, user) models.add_event(eventlist=EVS, metadata = event_metadata) return Q
def forum(request, slug): """ Displays a list of threads within a forum. Threads are sorted by their sticky flag, followed by their most recent post. """ f = get_object_or_404(Forum, slug=slug) # If the user is not authorized to view the thread, then redirect if f.is_private and request.user.is_staff != True: return HttpResponseRedirect('/forum') # Process new thread form if data was sent if request.method == 'POST': if not request.user.is_authenticated(): return HttpResponseServerError() thread_form = ThreadForm(request.POST) r = check_muted(request) if r: return r if thread_form.is_valid(): new_thread = thread_form.save(commit=False) new_thread.forum = f new_thread.save() if NOTIFY_THREAD and not f.is_private: wm.send_notification( "%s created a new thread \"<a href='%s'>%s</a>\" in forum \"%s\"" % ( escape(request.user.username), new_thread.get_absolute_url(), escape(new_thread.title), escape(new_thread.forum.title), ), None, 1) Post.objects.create(thread=new_thread, author=request.user, body=thread_form.cleaned_data['body'], time=datetime.now()) if (thread_form.cleaned_data['subscribe'] == True): Subscription.objects.create(author=request.user, thread=new_thread) return HttpResponseRedirect(new_thread.get_absolute_url()) else: thread_form = ThreadForm() # Pagination t = f.thread_set.all() paginator = Paginator(t, settings.FORUM_PAGINATE) try: page = int(request.GET.get('page', 1)) except: page = 1 try: threads = paginator.page(page) except (EmptyPage, InvalidPage): threads = paginator.page(paginator.num_pages) return j2shim.r2r( 'forum/thread_list.html', { 'forum': f, 'threads': threads.object_list, 'page_range': paginator.page_range, 'page': page, 'thread_form': thread_form }, request)
def thread(request, thread): """ Increments the viewed count on a thread then displays the posts for that thread, in chronological order. """ t = get_object_or_404(Thread, pk=thread) p = t.post_set.all().order_by('time') if request.user.is_authenticated(): s = t.subscription_set.filter(author=request.user) else: s = False # If the user is not authorized to view, we redirect them if t.forum.is_private and request.user.is_staff != True: return HttpResponseRedirect('/forum') # Process reply form if it was sent if (request.method == 'POST'): if not request.user.is_authenticated() or t.closed: return HttpResponseServerError() r = check_muted(request) if r: return r reply_form = ReplyForm(request.POST) if reply_form.is_valid(): new_post = reply_form.save(commit=False) new_post.author = request.user new_post.thread = t new_post.time = datetime.now() new_post.save() # Change subscription if reply_form.cleaned_data['subscribe']: Subscription.objects.get_or_create(thread=t, author=request.user) else: Subscription.objects.filter(thread=t, author=request.user).delete() # Send email forum_email_notification(new_post) if NOTIFY_POST and not t.forum.is_private: wm.send_notification( "%s posted a reply to \"<a href='%s#post%s'>%s</a>\" in forum \"%s\"" % ( escape(request.user.username), new_post.thread.get_absolute_url(), new_post.id, escape(new_post.thread.title), escape(new_post.thread.forum.title), ), None, 1) return HttpResponseRedirect(new_post.get_absolute_url()) else: reply_form = ReplyForm(initial={'subscribe': s}) # Pagination paginator = Paginator(p, settings.FORUM_PAGINATE) try: page = int(request.GET.get('page', paginator.num_pages)) except: page = paginator.num_pages try: posts = paginator.page(page) except (EmptyPage, InvalidPage): posts = paginator.page(paginator.num_pages) t.views += 1 t.save() #{'object_list' : artistic.object_list, 'page_range' : paginator.page_range, 'page' : page, 'letter' : letter, 'al': alphalist}, \ return j2shim.r2r( 'forum/thread.html', { 'forum': t.forum, 'thread': t, 'posts': posts.object_list, 'page_range': paginator.page_range, 'page': page, 'reply_form': reply_form }, request)