def send_tour_reminder_text(tour): to_person = tour.guide allow_texting = core_utils.get_setting('Allow Texting to Info Center') info_center_name = core_utils.get_setting('Info Center Director Name') info_center_phone = core_utils.get_setting('Info Center Phone Number') context = {'tour': tour, 'allow_texting': allow_texting, 'info_center_name': info_center_name, 'info_center_phone': info_center_phone} core_utils.send_text(unicode(to_person.phone), 'texts/tour_reminder.txt', context)
def send_tour_reminder_email(tour): from_email = get_email_by_position('Tour Coordinator (Primary)', 'Tour Coordinator') to_person = tour.guide to_emails = ['{} <{}>'.format(to_person.full_name, to_person.email)] subject = 'Tour Tomorrow at {}'.format(tour.time_local().strftime('%-I:%M %p')) allow_texting = core_utils.get_setting('Allow Texting to Info Center') info_center_name = core_utils.get_setting('Info Center Director Name') info_center_phone = core_utils.get_setting('Info Center Phone Number') context = {'tour': tour, 'allow_texting': allow_texting, 'info_center_name': info_center_name, 'info_center_phone': info_center_phone} core_utils.send_email(subject, to_emails, from_email, 'email/tour_reminder.txt', 'email/tour_reminder.html', context)
def make_request(self, song_requested): if isinstance(song_requested, int): try: song = Song.objects.get(pk=song_requested) except Song.DoesNotExist: raise MakeRequestError('Song does not exist.') else: song = song_requested if self.disabled: raise MakeRequestError('User is currently disabled.') if self.has_reached_request_max(): max_requests = get_setting('max_song_requests') message = 'User has reached the maximum request limit ({}).' raise MakeRequestError(message.format(max_requests)) if song.is_jingle and not self.user.is_staff: raise MakeRequestError('Users cannot request a jingle.') if song.is_song and not self.user.is_staff and not song.is_requestable: if not song.is_available: raise MakeRequestError('Song not available at this time.') if song.is_playable: raise MakeRequestError('Song is already in request queue.') play_again = song.get_date_when_requestable().isoformat( ' ', 'seconds') message = ('Song has been played recently and cannot be requested ' 'again until {}') raise MakeRequestError(message.format(play_again)) SongRequest.objects.create(profile=self, song=song)
def get_email_by_position(*positions): """ Return email of first person at position, falls back on fallback email address. """ person = get_person_by_position(*positions) fallback = get_setting('Fallback Email Address') return '{} {} <{}>'.format(person.first_name, person.last_name, person.email) if person is not None else fallback
def wait_total(self, adjusted_ratio=0.0): ''' Default length in seconds before a song can be played again. This is based on the replay ratio set in the application settings. ''' total_ratio = get_setting('replay_ratio') + adjusted_ratio wait = self.playlist_length() * Decimal(total_ratio) wait = wait.quantize(Decimal('.01'), rounding=ROUND_UP) return timedelta(seconds=float(wait))
def get_email_by_position(*positions): """ Return email of first person at position, falls back on fallback email address. """ person = get_person_by_position(*positions) fallback = get_setting('Fallback Email Address') return '{} {} <{}>'.format( person.first_name, person.last_name, person.email) if person is not None else fallback
def get_date_when_requestable(self, last_play=None): ''' Datetime when a song can be requested again. ''' last = self.last_played if last_play is None else last_play if self._is_song() and self._is_available(): if last: # Check if we have enough ratings to change ratio min_ratings = get_setting('min_ratings_for_variance') if self.rating_set.count() >= min_ratings: rate_ratio = get_setting('rating_variance_ratio') # -((average - 1)/(highest_rating - 1)) * rating_ratio base = -((self._average_rating() - 1) / 4) * rate_ratio adjusted_ratio = float(base + (rate_ratio * 0.5)) else: adjusted_ratio = float(0.0) return last + Song.music.wait_total(adjusted_ratio) return timezone.now() return None
def shifts_required_num(self, semester=None, year=None): year, semester = core_utils.parse_year_semester(year, semester) # start with default shifts_required = core_utils.get_default_num_shifts(semester=semester, year=year) # check for override try: overridden_reqs = self.overridden_requirements.get(semester=semester, year=year) shifts_required = overridden_reqs.shifts_required except OverrideRequirement.DoesNotExist: pass # get number of missed shifts num_missed = self.shifts.semester(semester=semester, year=year).filter(missed=True).count() num_extra = num_missed * core_utils.get_setting('Missed Shift Penalty') return shifts_required + num_extra
def retrieve(self, request): dj_profile = RadioProfile.objects.get(user__is_dj=True) limit = get_setting('songs_per_jingle') played_songs = SongRequest.music.get_played_requests(limit) if [j for j in played_songs if j.song.is_jingle]: if not SongRequest.music.unplayed().exists(): random_song = Song.music.get_random_requestable_song() next_play = SongRequest.objects.create(profile=dj_profile, song=random_song) else: next_play = SongRequest.music.next_request() else: random_jingle = Song.music.get_random_jingle() next_play = SongRequest.objects.create(profile=dj_profile, song=random_jingle) next_play.queued_at = timezone.now() next_play.save(update_fields=['queued_at']) serializer = GetRequestSerializer(next_play, many=False) return Response(serializer.data)
def has_reached_request_max(self): self_requests = SongRequest.music.unplayed().filter(profile=self) max_requests = get_setting('max_song_requests') return self_requests.count() >= max_requests