本文整理汇总了Python中calendar.Calendar.iterweekdays方法的典型用法代码示例。如果您正苦于以下问题:Python Calendar.iterweekdays方法的具体用法?Python Calendar.iterweekdays怎么用?Python Calendar.iterweekdays使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calendar.Calendar
的用法示例。
在下文中一共展示了Calendar.iterweekdays方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: week_sales
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import iterweekdays [as 别名]
def week_sales(self,farm):
'''This function returns the weekly deals'''
date = datetime.date.today()
orders = PurchaseOrder.objects.order_week(farm=farm,date=date)
products_order=PurchaseOrder.objects.product_order_week(farm=farm,orders=orders)
total_products = products_order[0]['total']
products = products_order[1]
sales_day=[]
count_sales=[]
total_day=0
cal = Calendar()
days = list(cal.iterweekdays())
for day in days:
sales_day.append(0)
count_sales.append(0)
for order in orders:
order_day=order.date.isocalendar()[2]
total = order.total_order
t_products = order.quantity
for day in days:
if day==order_day:
if sales_day[day]!=0:
price = sales_day[day]+total
sales_day[day]=price
total_day+=total
count = count_sales[day]
count_sales[day]=(count+t_products)
else:
total_day+=total
sales_day[day]=total_day
count_sales[day]=(t_products)
break
data = {'values':sales_day, 'count':count_sales, 'total_day':total_day, 'total_products':total_products, 'products':products}
return data
示例2: calc_month_leave_accnt
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import iterweekdays [as 别名]
def calc_month_leave_accnt(db, empid, month=datetime.date.today().month, year=datetime.date.today().year):
leaves = get_leaves(db, empid, month, year)
cal = Calendar()
working_days = [w for w in cal.iterweekdays()]
total_working_days = len(working_days) + len(get_working_days(db)) - len(get_holidays(db))
total_leaves = (0, len(leaves) - 2)[len(leaves) > 2]
total_pay_days = total_working_days - total_leaves
return {'working_days':total_working_days, 'total_leaves':total_leaves}
示例3: get_context_data
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import iterweekdays [as 别名]
def get_context_data(self, **kwargs):
"""
Injects variables necessary for rendering the calendar into the context.
Variables added are: `calendar`, `weekdays`, `month`, `next_month` and `previous_month`.
"""
data = super(BaseCalendarMonthView, self).get_context_data(**kwargs)
year = self.get_year()
month = self.get_month()
date = _date_from_string(year, self.get_year_format(),
month, self.get_month_format())
cal = Calendar(self.get_first_of_week())
month_calendar = []
now = datetime.datetime.utcnow()
date_lists = defaultdict(list)
multidate_objs = []
for obj in data['object_list']:
obj_date = self.get_start_date(obj)
end_date_field = self.get_end_date_field()
if end_date_field:
end_date = self.get_end_date(obj)
if end_date and end_date != obj_date:
multidate_objs.append({
'obj': obj,
'range': [x for x in daterange(obj_date, end_date)]
})
continue # We don't put multi-day events in date_lists
date_lists[obj_date].append(obj)
for week in cal.monthdatescalendar(date.year, date.month):
week_range = set(daterange(week[0], week[6]))
week_events = []
for val in multidate_objs:
intersect_length = len(week_range.intersection(val['range']))
if intersect_length:
# Event happens during this week
slot = 1
width = intersect_length # How many days is the event during this week?
nowrap_previous = True # Does the event continue from the previous week?
nowrap_next = True # Does the event continue to the next week?
if val['range'][0] >= week[0]:
slot = 1 + (val['range'][0] - week[0]).days
else:
nowrap_previous = False
if val['range'][-1] > week[6]:
nowrap_next = False
week_events.append({
'event': val['obj'],
'slot': slot,
'width': width,
'nowrap_previous': nowrap_previous,
'nowrap_next': nowrap_next,
})
week_calendar = {
'events': week_events,
'date_list': [],
}
for day in week:
week_calendar['date_list'].append({
'day': day,
'events': date_lists[day],
'today': day == now.date(),
'is_current_month': day.month == date.month,
})
month_calendar.append(week_calendar)
data['calendar'] = month_calendar
data['weekdays'] = [DAYS[x] for x in cal.iterweekdays()]
data['month'] = date
data['next_month'] = self.get_next_month(date)
data['previous_month'] = self.get_previous_month(date)
return data
示例4: WeekCal
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import iterweekdays [as 别名]
class WeekCal(IntervalModule):
"""
Displays the days of the current week as they would be represented on a calendar sheet,
with the current day highlighted.
By default, the current day of week is displayed in the front, and the month and year are
displayed in the back.
Example: ``Sat 16 17 18 19 20[21]22 May 2016``
"""
settings = (
("startofweek", "First day of the week (0 = Monday, 6 = Sunday), defaults to 0."),
("prefixformat", "Prefix in strftime-format"),
("suffixformat", "Suffix in strftime-format"),
("todayhighlight", "Characters to highlight today's date"),
)
startofweek = 0
interval = 30
prefixformat = "%a"
suffixformat = "%b %Y"
todayhighlight = ("[", "]")
def __init__(self, *args, **kwargs):
IntervalModule.__init__(self, *args, **kwargs)
self.cal = Calendar(self.startofweek)
def run(self):
today = date.today()
yesterday = today - timedelta(days=1)
outstr = today.strftime(self.prefixformat) + " "
weekdays = self.cal.iterweekdays()
if today.weekday() == self.startofweek:
outstr += self.todayhighlight[0]
else:
outstr += " "
nextweek = False # keep track of offset if week doesn't start on monday
for w in weekdays:
if w == 0 and self.startofweek != 0:
nextweek = True
if nextweek and today.weekday() >= self.startofweek:
w += 7
elif not nextweek and today.weekday() < self.startofweek:
w -= 7
weekday_offset = today.weekday() - w
weekday_delta = timedelta(days=weekday_offset)
weekday = today - weekday_delta
if weekday == yesterday:
outstr += weekday.strftime("%d") + self.todayhighlight[0]
elif weekday == today:
outstr += weekday.strftime("%d") + self.todayhighlight[1]
else:
outstr += weekday.strftime("%d ")
outstr += " " + today.strftime(self.suffixformat)
self.output = {
"full_text": outstr,
"urgent": False,
}