Exemplo n.º 1
0
 def effective_days_span(self):
     """
     Tells how many days this request spans.
     We add 1 because we want to consider start and end
     inclusive. (from 2012-11-01 to 2012-11-03 = 3 days off).
     Also, we want not to consider closure periods / weekdays
     for the associated project
     TODO: denormalize/cache this number into the request obj
     """
     request_date_range = date_range(self.start_date, self.end_date)
     closure_periods = self.project.closureperiod_set.all()
     # Chain multiple date range generators
     closure_dates = list(itertools.chain(*[date_range(period.start, period.end) for period in closure_periods]))
     total = sum(1 for day in request_date_range if day.weekday() not in self.project.weekly_closure_days and day not in closure_dates)
     return total
Exemplo n.º 2
0
def random_daterange(start, end, mix_length, max_length):
    date_range = list(cal.date_range(start, end))
    while True:
        start_index = random.randint(0, len(date_range))
        end_index = start_index + random.randint(mix_length, max_length)
        if end_index < len(date_range):
            break
    
    return date_range[start_index], date_range[end_index]
Exemplo n.º 3
0
 def get_context_data(self, **kwargs):
     context = super(GroupHolidays, self).get_context_data(**kwargs)
     queryset = models.HolidayRequest.objects.filter(author__approval_group=self.object)
     queryset = queryset.date_range(self.start, self.end).order_by('author')
     
     groups = []
     for author, requests in itertools.groupby(queryset, lambda x: x.author):
         groups.append((author, list(requests)))
     context.update({
         'object_list': groups,
         'week_days': list(date_range(self.start, self.end))
     })
     return context
Exemplo n.º 4
0
 def get(self, request, *args, **kwargs):
     today = datetime.datetime.now().date()
     start = self.request.GET.get('start')
     
     if start:
         self.start = datetime.datetime.fromtimestamp(int(start))
     else:
         self.start = datetime.date(today.year, today.month, 1)
         
     self.end = self.start + relativedelta(months=2) - relativedelta(days=1)
     
     self.next = self.end + relativedelta(days=1)
     self.prev = self.start - relativedelta(months=2)
                         
     self.week_days = list(date_range(self.start, self.end))
     return super(HolidayRequestWeek, self).get(request, *args, **kwargs)