本文整理汇总了Python中timepiece.utils.get_week_start函数的典型用法代码示例。如果您正苦于以下问题:Python get_week_start函数的具体用法?Python get_week_start怎么用?Python get_week_start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_week_start函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:eschipul,项目名称:django-timepiece,代码行数:8,代码来源:dashboard.py
示例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())
开发者ID:george-silva,项目名称:django-timepiece,代码行数:9,代码来源:projection.py
示例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())
开发者ID:george-silva,项目名称:django-timepiece,代码行数:10,代码来源:projection.py
示例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())
开发者ID:george-silva,项目名称:django-timepiece,代码行数:10,代码来源:projection.py
示例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'
开发者ID:cheekybastard,项目名称:django-timepiece,代码行数:10,代码来源:schedule.py
示例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"
开发者ID:hsmett,项目名称:django-timepiece,代码行数:10,代码来源:test_schedule.py
示例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)
开发者ID:george-silva,项目名称:django-timepiece,代码行数:7,代码来源:projection.py
示例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)
开发者ID:Cashiuus,项目名称:django-timepiece,代码行数:28,代码来源:test_management.py
示例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
开发者ID:pobk,项目名称:django-timepiece,代码行数:32,代码来源:models.py
示例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))
开发者ID:george-silva,项目名称:django-timepiece,代码行数:33,代码来源:projection.py
示例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'])
开发者ID:george-silva,项目名称:django-timepiece,代码行数:7,代码来源:projection.py
示例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)
开发者ID:hsmett,项目名称:django-timepiece,代码行数:7,代码来源:test_schedule.py
示例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)
开发者ID:cheekybastard,项目名称:django-timepiece,代码行数:16,代码来源:views.py
示例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
开发者ID:Cashiuus,项目名称:django-timepiece,代码行数:26,代码来源:utils.py
示例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)
开发者ID:cheekybastard,项目名称:django-timepiece,代码行数:8,代码来源:base.py
示例16: test_weekly_commmitment_with_hours_worked
def test_weekly_commmitment_with_hours_worked(self):
""" Test weekly commitment with previously logged hours """
start = utils.get_week_start()
end = start + datetime.timedelta(weeks=2) - datetime.timedelta(days=1)
ca = self._assign(start, end, hours=30)
self.log_time(ca, start=start, delta=(10, 0))
self.assertEqual(ca.hours_worked, 10)
self.assertEqual(ca.hours_remaining, 20)
self.assertEqual(ca.weekly_commitment(start), 30)
开发者ID:george-silva,项目名称:django-timepiece,代码行数:9,代码来源:projection.py
示例17: get_entries_data
def get_entries_data(self):
projects = utils.get_setting('TIMEPIECE_PAID_LEAVE_PROJECTS')
# Account for the day added by the form
query = Q(end_time__gt=utils.get_week_start(self.from_date),
end_time__lt=self.to_date + relativedelta(days=1))
query &= ~Q(project__in=projects.values())
entries = timepiece.Entry.objects.date_trunc('week',
extra_values=('activity', 'project__status')).filter(query)
return entries
开发者ID:eschipul,项目名称:django-timepiece,代码行数:9,代码来源:reports.py
示例18: test_no_entries
def test_no_entries(self):
date = utils.get_week_start(datetime.date(2012, 3, 15))
data = {
'week_start': date.strftime('%Y-%m-%d'),
'submit': '',
}
response = self.client.get(self.url, data)
self.assertEquals(len(response.context['projects']), 0)
self.assertEquals(len(response.context['users']), 0)
开发者ID:cheekybastard,项目名称:django-timepiece,代码行数:9,代码来源:schedule.py
示例19: create_project_hours_entry
def create_project_hours_entry(self, week_start=None, project=None,
user=None, hours=None, published=None):
week_start = (utils.get_week_start(add_tzinfo=False)
if not week_start else week_start)
project = self.create_project() if not project else project
user = self.create_user() if not user else user
hours = Decimal(str(random.random() * 20)) if not hours else hours
return timepiece.ProjectHours.objects.create(week_start=week_start,
project=project, user=user, hours=hours,
published=published or False)
开发者ID:DarioGT,项目名称:schedulall,代码行数:10,代码来源:base.py
示例20: test_unallocated_hours
def test_unallocated_hours(self):
""" Test unallocated hours calculation """
start = utils.get_week_start()
end = start + datetime.timedelta(weeks=2) - datetime.timedelta(days=1)
ca = self._assign(start, end, hours=40)
unallocated_hours = ca.unallocated_hours_for_week(start)
self.assertEqual(unallocated_hours, 40)
ca.blocks.create(date=start, hours=5)
unallocated_hours = ca.unallocated_hours_for_week(start)
self.assertEqual(unallocated_hours, 35)
开发者ID:george-silva,项目名称:django-timepiece,代码行数:10,代码来源:projection.py
注:本文中的timepiece.utils.get_week_start函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论