def send_schedule_update(self, request, date, message=None): tb = Scheduler() mtg = get_meeting_for_date(date) players = tb.query_schedule(date) from_email = settings.EMAIL_HOST_USER # Generate Text and HTML versions. body = self.build_notify_message(mtg.date, players, message=message) html_body = self.build_html_notify_message(mtg.date, players, message=message) subject = settings.BLOCK_NOTIFY_SUBJECT % date if settings.TEST_BLOCK_NOTIFY_RECIPIENTS: recipients = settings.TEST_BLOCK_NOTIFY_RECIPIENTS cc_list = [] else: recipients, cc_list = tb.get_notify_email_lists() msg = EmailMultiAlternatives(subject=subject, body=body, from_email=from_email, to=recipients, cc=cc_list) msg.attach_alternative(html_body, 'text/html') msg.send() return JSONResponse({})
def delete(self, request, date=None): # ToDo: Insure is Admin user, not just authenticated tb = Scheduler() logger.info("blockSchedule DELETE for date:%s" % date) mgr = TeamManager() mgr.dbTeams.delete_matchup(date) tb.remove_all_couples_from_schedule(date) return Response({'status': 'success'})
def test_get_next_group_meeting_one(self): """ Test the initial version where there is no play history """ scheduler = Scheduler() group = scheduler.get_next_group(with_singles=False) self.assertIsNotNone(group) self.assertEqual(len(group), 4)
def post(self, request, date=None): couples = request.data.get('couples') result = {'status': "Did not execute"} if couples: tb = Scheduler() result['status'] = tb.update_schedule(date, couples) mgr = TeamManager() mgr.dbTeams.delete_matchup(date) else: result['status'] = "Did not decode the guys and gals" return Response(result)
def schedule(self, date): scheduler = Scheduler() logger.info("blockSchedule POST for date:%s" % date) group = scheduler.get_next_group(date) logger.info("Groups:") for g in group: logger.info("\tHe:%s She:%s" % (g.male.Name(), g.female.Name())) scheduler.add_group_to_schedule(date, group) mgr = TeamManager() mgr.dbTeams.delete_matchup(date) sched = scheduler.query_schedule(date)
def test_initial_update(self): """ Build structure of couples: couple: {'guy': {'id': Player.pk, 'issub': Boolean, 'verified': Boolean}, 'gal': {'id': Player.pk, 'issub': Boolean, 'verified': Boolean}, } couples is array of couple :return: """ meeting = self.meetings[0] couples = self.build_couples() scheduler = Scheduler() date = meeting.date.strftime("%Y-%m-%d") scheduler.update_schedule(date, couples) sch = Schedule.objects.filter(meeting=meeting).all() self.assertEqual(len(sch), len(couples) * 2) self.assertEqual(ScheduleVerify.objects.all().count(), 0) for s in sch: v = s.get_verification() self.assertEqual(len(couples) * 2, ScheduleVerify.objects.all().count(), f'Verify object count should have been {len(couples) * 2}') self.assertEqual(len(couples) * 2, ScheduleVerify.objects.filter(sent_on__isnull=True).count(), f'Verify object sent count should have been {len(couples) * 2}' ) request = factory.post(reverse('api:scheduleverify_for_date', kwargs={'date': date})) force_authenticate(request, user=self.admin_user) response = ScheduleNotifyView.as_view()(request, date=date) self.assertEqual(response.status_code, 200)
def get(self, request, date=None): logger.info(f"Getting players for block for date {date}") tb = Scheduler() data = tb.query_schedule(date) return Response(data)
def get(self, request, date=None): tb = Scheduler() sched = tb.query_schedule(date) return Response(sched)