def handle(self, *args, **kwargs): try: self.user = Athlete.objects.get(username=kwargs['username']) except Athlete.DoesNotExist: raise CommandError('No user %s' % kwargs['username']) # Init plan start = date_to_day(date.today()) self.plan = Plan.objects.create(name='Generated Plan %s' % self.user.first_name, creator=self.user, start=start) sport = Sport.objects.get(slug='running') # Add sessions nb = int(kwargs['sessions']) for i in range(0, nb): print 'Add session %d' % i data = { 'week': random.randint(0, nb / 2), 'day': random.randint(0, 6), 'name': 'session %d' % i, 'sport': sport, } print data self.plan.sessions.create(**data) # Publish plan self.plan.publish(Athlete.objects.filter(username=kwargs['username']))
def load_weeks(self): ''' Load previous weeks ''' # List 12 previous weeks start = date_to_day(self.today) weeks_future = 3 weeks_past = 6 weeks = [] empty = True # Check if there are some data to display for w in range(-weeks_past * 7, weeks_future * 7, 7): day = start + timedelta(days=w) week, year = int(day.strftime('%W')), day.year if w > 0: state = 'future' elif w < 0: state = 'past' else: state = 'current' st = StatsWeek(self.request.user, year, week) weeks.append({ 'date': day, 'year': year, 'week': week, 'stats': st, 'state': state, }) if empty: empty = st.data is None return { 'weeks_empty': empty, 'weeks': weeks, }
def handle(self, *args, **kwargs): try: self.user = Athlete.objects.get(username=kwargs['username']) except Athlete.DoesNotExist: raise CommandError('No user %s' % kwargs['username']) # Init plan start = date_to_day(date.today()) self.plan = Plan.objects.create(name='Generated Plan %s' % self.user.first_name, creator=self.user, start=start) sport = Sport.objects.get(slug='running') # Add sessions nb = int(kwargs['sessions']) for i in range(0, nb): print 'Add session %d' % i data = { 'week' : random.randint(0, nb / 2), 'day' : random.randint(0, 6), 'name' : 'session %d' % i, 'sport' : sport, } print data self.plan.sessions.create(**data) # Publish plan self.plan.publish(Athlete.objects.filter(username=kwargs['username']))
def load_weeks(self): ''' Load previous weeks ''' # List 12 previous weeks start = date_to_day(self.today) weeks_future = 3 weeks_past = 6 weeks = [] empty = True # Check if there are some data to display for w in range(-weeks_past * 7, weeks_future * 7, 7): day = start + timedelta(days=w) week, year = int(day.strftime('%W')), day.year if w > 0: state = 'future' elif w < 0: state = 'past' else: state = 'current' st = StatsWeek(self.request.user, year, week) weeks.append({ 'date' : day, 'year' : year, 'week' : week, 'stats' : st, 'state' : state, }) if empty: empty = st.data is None return { 'weeks_empty' : empty, 'weeks' : weeks, }
def check_limits(self, check=True): # Min date is oldest user sport week # or first day of current year by default oldest = SportDay.objects.filter(week__user=self.request.user).order_by('date').first() if oldest: self.min_date = oldest.week.get_date_start() else: self.min_date = date(self._today.year, 1, 1) # Load min & max date self.max_date = date_to_day(self._today) if not check: return # Check we are not in past or future if self.date > self._today: raise Http404('In the future.')
def check_limits(self, check=True): # Min date is oldest user sport week # or first day of current year by default oldest = SportDay.objects.filter( week__user=self.request.user).order_by('date').first() if oldest: self.min_date = oldest.week.get_date_start() else: self.min_date = date(self._today.year, 1, 1) # Load min & max date self.max_date = date_to_day(self._today) if not check: return # Check we are not in past or future if self.date > self._today: raise Http404('In the future.')
def is_current(self): today = date.today() return self.get_date_start() == date_to_day(today)