本文整理汇总了Python中timepiece.utils.get_week_start函数的典型用法代码示例。如果您正苦于以下问题:Python get_week_start函数的具体用法?Python get_week_start怎么用?Python get_week_start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_week_start函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get
def test_get(self):
"""Get without param gets entries for this week."""
response = self.client.get(reverse('dashboard'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['week_start'],
utils.get_week_start().date())
self.assertEqual(response.context['week_end'],
utils.get_week_start().date() + relativedelta(days=6))
示例2: test_week_start
def test_week_start(self):
""" Test that all days Sun. through Sat. return the previous Monday"""
monday = datetime.date(2011, 1, 10)
self.assertEqual(monday, utils.get_week_start(monday).date())
sunday = datetime.date(2011, 1, 16)
self.assertEqual(monday, utils.get_week_start(sunday).date())
following_monday = datetime.date(2011, 1, 17)
saturday = datetime.date(2011, 1, 22)
self.assertEqual(following_monday, utils.get_week_start(saturday).date())
示例3: test_assignment_active_starts_mid_week
def test_assignment_active_starts_mid_week(self):
""" Test manager returns assignments that start before window """
start = utils.get_week_start() + datetime.timedelta(days=2)
end = start + datetime.timedelta(weeks=2)
ca = self._assign(start, end)
week = utils.get_week_start()
next_week = week + datetime.timedelta(weeks=1)
assignments = timepiece.ContractAssignment.objects
assignments = assignments.active_during_week(week, next_week)
self.assertTrue(assignments.filter(pk=ca.pk).exists())
示例4: test_assignment_active_within_week
def test_assignment_active_within_week(self):
""" Test manager returns assignments that contain entire week """
start = utils.get_week_start() - datetime.timedelta(weeks=1)
end = start + datetime.timedelta(weeks=3)
ca = self._assign(start, end)
week = utils.get_week_start()
next_week = week + datetime.timedelta(weeks=1)
assignments = timepiece.ContractAssignment.objects
assignments = assignments.active_during_week(week, next_week)
self.assertTrue(assignments.filter(pk=ca.pk).exists())
示例5: setUp
def setUp(self):
super(ProjectHoursListViewTestCase, self).setUp()
self.past_week = utils.get_week_start(datetime.date(2012, 4, 1)).date()
self.current_week = utils.get_week_start().date()
for i in range(5):
self.create_project_hours_entry(self.past_week, published=True)
self.create_project_hours_entry(self.current_week, published=True)
self.url = reverse('view_schedule')
self.client.login(username='user', password='abc')
self.date_format = '%Y-%m-%d'
示例6: setUp
def setUp(self):
super(ProjectHoursListViewTestCase, self).setUp()
self.past_week = utils.get_week_start(datetime.date(2012, 4, 1)).date()
self.current_week = utils.get_week_start().date()
for i in range(5):
factories.ProjectHours(week_start=self.past_week, published=True)
factories.ProjectHours(week_start=self.current_week, published=True)
self.url = reverse("view_schedule")
self.login_user(self.user)
self.date_format = "%Y-%m-%d"
示例7: test_weekly_commitment_over_remaining
def test_weekly_commitment_over_remaining(self):
# 1 week assignment, 20 hours
start = utils.get_week_start()
end = start + datetime.timedelta(weeks=1) - datetime.timedelta(days=1)
ca = self._assign(start, end, hours=20)
# only 20 hours left on assignment
self.assertEqual(ca.weekly_commitment(start), 20)
示例8: testFindStart
def testFindStart(self):
"""
With various kwargs, find_start should return the correct date
"""
# Establish some datetimes
now = timezone.now()
today = now - relativedelta(
hour=0, minute=0, second=0, microsecond=0)
last_billing = today - relativedelta(months=1, day=1)
yesterday = today - relativedelta(days=1)
ten_days_ago = today - relativedelta(days=10)
thisweek = utils.get_week_start(today)
thismonth = today - relativedelta(day=1)
thisyear = today - relativedelta(month=1, day=1)
# Use command flags to obtain datetimes
start_default = check_entries.Command().find_start()
start_yesterday = check_entries.Command().find_start(days=1)
start_ten_days_ago = check_entries.Command().find_start(days=10)
start_of_week = check_entries.Command().find_start(week=True)
start_of_month = check_entries.Command().find_start(month=True)
start_of_year = check_entries.Command().find_start(year=True)
# assure the returned datetimes are correct
self.assertEqual(start_default, last_billing)
self.assertEqual(start_yesterday, yesterday)
self.assertEqual(start_ten_days_ago, ten_days_ago)
self.assertEqual(start_of_week, thisweek)
self.assertEqual(start_of_month, thismonth)
self.assertEqual(start_of_year, thisyear)
示例9: weekly_commitment
def weekly_commitment(self, day=None):
self._log("Commitment for {0}".format(day))
# earlier assignments may have already allocated time for this week
unallocated = self.unallocated_hours_for_week(day)
self._log('Unallocated hours {0}'.format(unallocated))
reserved = self.remaining_min_hours()
self._log('Reserved hours {0}'.format(reserved))
# start with unallocated hours
commitment = unallocated
# reserve required hours on later assignments (min_hours_per_week)
commitment -= self.remaining_min_hours()
self._log('Commitment after reservation {0}'.format(commitment))
# if we're under the needed minimum hours and we have available
# time, then raise our commitment to the desired level
if commitment < self.min_hours_per_week \
and unallocated >= self.min_hours_per_week:
commitment = self.min_hours_per_week
self._log('Commitment after minimum weekly hours {0}'\
.format(commitment))
# calculate hours left on contract (subtract worked hours this week)
week_start = utils.get_week_start(day)
remaining = self.num_hours - self._filtered_hours_worked(week_start)
total_allocated = self.blocks.aggregate(s=Sum('hours'))['s'] or 0
remaining -= total_allocated
if remaining < 0:
remaining = 0
self._log('Remaining {0}'.format(remaining))
# reduce commitment to remaining hours
if commitment > remaining:
commitment = remaining
self._log('Final commitment {0}'.format(commitment))
return commitment
示例10: test_generate_dates
def test_generate_dates(self):
""" Test generation of full date ranges """
### test WEEKLY
# 2 weeks
start = datetime.date(2011, 1, 17)
end = datetime.date(2011, 1, 29)
weeks = utils.generate_dates(start=start, end=end)
self.assertEqual(2, weeks.count())
# 3 weeks
start = datetime.date(2011, 1, 17)
end = datetime.date(2011, 1, 31)
weeks = utils.generate_dates(start=start, end=end)
self.assertEqual(3, weeks.count())
# random weeks
num = random.randint(5, 20)
start = utils.get_week_start(datetime.date.today())
end = start + datetime.timedelta(weeks=num - 1)
weeks = utils.generate_dates(start=start, end=end)
self.assertEqual(num, weeks.count())
### test MONTHLY
start = datetime.date(2011, 1, 17)
end = datetime.date(2011, 4, 29)
months = utils.generate_dates(start=start, end=end, by='month')
self.assertEqual(4, months.count())
for index, month in enumerate(months):
self.assertEqual(month.date(), datetime.date(2011, index + 1, 1))
### test DAILY
start = datetime.date(2011, 2, 1)
end = datetime.date(2011, 2, 15)
days = utils.generate_dates(start=start, end=end, by='day')
self.assertEqual(15, days.count())
for index, day in enumerate(days):
self.assertEqual(day.date(), datetime.date(2011, 2, index + 1))
示例11: test_single_assignment_projection
def test_single_assignment_projection(self):
# 2 weeks, 60 hours
start = utils.get_week_start()
end = start + datetime.timedelta(weeks=2) - datetime.timedelta(days=1)
ca = self._assign(start, end, hours=60)
run_projection()
self.assertEqual(60, ca.blocks.aggregate(s=Sum('hours'))['s'])
示例12: test_week_filter_midweek
def test_week_filter_midweek(self):
"""Filter corrects mid-week date to Monday of specified week."""
wednesday = datetime.date(2012, 7, 4)
monday = utils.get_week_start(wednesday).date()
data = {"week_start": wednesday.strftime(self.date_format), "submit": ""}
response = self.client.get(self.url, data)
self.assertEquals(response.context["week"].date(), monday)
示例13: dispatch
def dispatch(self, request, *args, **kwargs):
# Since we use get param in multiple places, attach it to the class
default_week = utils.get_week_start(datetime.date.today()).date()
if request.method == 'GET':
week_start_str = request.GET.get('week_start', '')
else:
week_start_str = request.POST.get('week_start', '')
# Account for an empty string
self.week_start = default_week if week_start_str == '' \
else utils.get_week_start(datetime.datetime.strptime(
week_start_str, '%Y-%m-%d').date())
return super(ScheduleMixin, self).dispatch(request, *args,
**kwargs)
示例14: grouped_totals
def grouped_totals(entries):
select = {
"day": {"date": """DATE_TRUNC('day', end_time)"""},
"week": {"date": """DATE_TRUNC('week', end_time)"""},
}
weekly = entries.extra(select=select["week"]).values('date', 'billable')
weekly = weekly.annotate(hours=Sum('hours')).order_by('date')
daily = entries.extra(select=select["day"]).values('date', 'project__name',
'billable')
daily = daily.annotate(hours=Sum('hours')).order_by('date',
'project__name')
weeks = {}
for week, week_entries in groupby(weekly, lambda x: x['date']):
if week is not None:
week = add_timezone(week)
weeks[week] = get_hours_summary(week_entries)
days = []
last_week = None
for day, day_entries in groupby(daily, lambda x: x['date']):
week = get_week_start(day)
if last_week and week > last_week:
yield last_week, weeks.get(last_week, {}), days
days = []
days.append((day, daily_summary(day_entries)))
last_week = week
yield week, weeks.get(week, {}), days
示例15: create_project_hours_entry
def create_project_hours_entry(self, week_start=None, project=None,
user=None, hours=None, **kwargs):
week_start = week_start or utils.get_week_start(add_tzinfo=False)
project = project or self.create_project()
user = user or self.create_user()
hours = Decimal(str(random.random() * 20)) if hours is None else hours
return ProjectHours.objects.create(week_start=week_start,
project=project, user=user, hours=hours, **kwargs)