本文整理汇总了Python中calendar.Calendar.monthdatescalendar方法的典型用法代码示例。如果您正苦于以下问题:Python Calendar.monthdatescalendar方法的具体用法?Python Calendar.monthdatescalendar怎么用?Python Calendar.monthdatescalendar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calendar.Calendar
的用法示例。
在下文中一共展示了Calendar.monthdatescalendar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def render(self, context):
mycal = Calendar()
context[self.var_name] = mycal.monthdatescalendar(
int(self.year.resolve(context)), int(self.month.resolve(context))
)
return ""
示例2: get_month_events
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def get_month_events(year, month):
# Get the day-dates of the current month
cal = Calendar(0) # default replace by user db? (starting day)
the_month = cal.monthdatescalendar(year, month)
# First day of first week
begin = the_month[0][0]
# Last day of last week
end = the_month[-1][-1]
events = Event.query.filter(
Event.event_date > begin.strftime('%Y-%m-%d'),
Event.event_date < end.strftime('%Y-%m-%d')) \
.options(lazyload('creator')).all()
# Load the days for the calendar
def per_day(day):
# Get the interval bounds of that day
day_start = datetime.combine(day, time())
day_end = day_start + timedelta(days = 1)
# Run through all events
day_events = []
for e in events:
if e.event_date >= day_start and e.event_date < day_end:
day_events.append(e)
return (day, day_events)
def per_week(week):
return [per_day(d) for d in week]
def per_month(month):
return [per_week(w) for w in month]
return per_month(the_month)
示例3: get_context_data
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def get_context_data(self, **kwargs):
data = super(BaseCalendarMonthArchiveView, self).get_context_data(**kwargs)
date = data['date_list'][0]
cal = Calendar(self.get_first_of_week())
month_calendar = []
now = datetime.datetime.utcnow()
date_lists = defaultdict(list)
for obj in data['object_list']:
obj_date = getattr(obj, self.get_date_field())
try:
obj_date = obj_date.date()
except AttributeError:
# It's a date rather than datetime, so we use it as is
pass
date_lists[obj_date].append(obj)
for week in cal.monthdatescalendar(date.year, date.month):
week_calendar = []
for day in week:
week_calendar.append({
'day': day,
'object_list': date_lists[day],
'today': day == now.date(),
'is_current_month': day.month == date.month,
})
month_calendar.append(week_calendar)
data['calendar'] = month_calendar
return data
示例4: m_to_expiry
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def m_to_expiry(self, m_expiry):
c = Calendar()
expiry = datetime.strptime(m_expiry, '%Y%m%d')
mdc = c.monthdatescalendar(expiry.year, expiry.month)
fridays = [x[4] for x in mdc if x[4].month == expiry.month]
if fridays[2] == expiry.date(): expiry += timedelta(days=1)
return expiry.strftime('%y%m%d')
示例5: _calendar
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def _calendar(selected_date, selected_place):
place = selected_place
year, month = selected_date.year, selected_date.month
filters = {'date__year': year, 'date__month': month, 'place': place}
bookings = {b.date: b for b in Booking.objects.filter(**filters)}
calendar = Calendar(firstweekday=6)
for week in calendar.monthdatescalendar(year, month):
yield [(day, bookings.get(day)) for day in week]
示例6: index
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def index(year):
cal = Calendar(0)
try:
if not year:
year = date.today().year
cal_list = [cal.monthdatescalendar(year, i+1) for i in xrange(12)]
except Exception, e:
abort(404)
示例7: to_calendar
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def to_calendar(interval, series):
start, stop = get_calendar_range(interval, 3)
legend, values = colorize(
[
'#fae5cf',
'#f9ddc2',
'#f9d6b6',
'#f9cfaa',
'#f8c79e',
'#f8bf92',
'#f8b786',
'#f9a66d',
'#f99d60',
'#fa9453',
'#fb8034',
'#fc7520',
'#f9600c',
'#f75500',
],
[value for timestamp, value in series if value is not None],
)
value_color_map = dict(values)
value_color_map[None] = '#F2F2F2'
series_value_map = dict(series)
def get_data_for_date(date):
dt = datetime(date.year, date.month, date.day, tzinfo=pytz.utc)
ts = to_timestamp(dt)
value = series_value_map.get(ts, None)
return (
dt,
{
'value': value,
'color': value_color_map[value],
}
)
calendar = Calendar(6)
sheets = []
for year, month in map(index_to_month, range(start, stop + 1)):
weeks = []
for week in calendar.monthdatescalendar(year, month):
weeks.append(map(get_data_for_date, week))
sheets.append((
datetime(year, month, 1, tzinfo=pytz.utc),
weeks,
))
return {
'legend': list(legend.keys()),
'sheets': sheets,
}
示例8: index
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def index(year):
conn = pymongo.MongoClient()
db = conn.test
cal = Calendar(0)
try:
if not year:
year = date.today().year
cal_list = [cal.monthdatescalendar(year, i+1) for i in xrange(12)]
except Exception, e:
abort(404)
示例9: week_calendar
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def week_calendar(days):
cal = Calendar(6)
today = date.today() + timedelta(days=days)
weeks = cal.monthdatescalendar(today.year, today.month)
current_week = []
for week in weeks:
if week[0] <= today <= week[6]:
current_week = week
break
return current_week
示例10: get_expiry_date
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def get_expiry_date(self, last_date, expiry):
data_dow = self.dt_date.isoweekday()
if 'week' in expiry.lower():
if last_date: return last_date + td(days=7)
else: return self.dt_date + td(days=(6 - data_dow))
elif 'q' in expiry.lower():
quarter, year = expiry.split('-')
month = int(quarter[1])*3
year = int(self.dt_date.strftime('%C') + year)
c = Calendar()
last_day = c.monthdatescalendar(year, month)[-1][-1]
while not (last_day.month == month and last_day.isoweekday() <= 5):
last_day = last_day - td(days=1)
return last_day
else:
e_dt = datetime.strptime(expiry, '%b-%y')
c = Calendar()
fridays = [x[4]
for x in c.monthdatescalendar(e_dt.year, e_dt.month)]
if fridays[0].month == e_dt.month: return fridays[2] + td(days=1)
else: return fridays[3] + td(days=1)
示例11: trap_calendar
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def trap_calendar(year):
cal = Calendar(0)
try:
if year is None:
year = date.today().year
year_mod = year
else:
year_mod = year % 9999
if year_mod < 1:
year_mod = 1
cal_list = [cal.monthdatescalendar(year_mod, i + 1) for i in xrange(12)]
except Exception, e:
logConsole(e)
示例12: getweek
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def getweek(t):
"""
Given a specific datetime, it picks the corresponding week and
returns an array containing the 7 dates corresponding to each day.
"""
# cal = Calendar(6) # sunday as first day of week
cal = Calendar(1) # tuesday as first day
weeks = [w for w in cal.monthdatescalendar(t.year, t.month)]
for w in weeks:
for d in w:
if d.day == t.day:
return w
return []
示例13: calendar
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def calendar(self):
"""generates calendars representing all meals in the session, as a list
of Calendar.monthdatescalendar() lists.
In those lists, the second values of tuples are the corresponding Meal
objects.
"""
cur_month = None
meals = self.meal_set.order_by('date')
meals_dates = {}
meals_count = 0
for meal in meals:
cur_month = meal.date if cur_month is None else cur_month
meals_count += 1
if meal.date not in meals_dates:
if meal.date.date() not in meals_dates:
meals_dates[meal.date.date()] = []
meals_dates[meal.date.date()].append(meal)
if not cur_month:
cur_month = datetime.now()
months = []
cal = Calendar()
month = cal.monthdatescalendar(cur_month.year, cur_month.month)
remaining_meals = meals_count
while remaining_meals > 0:
month = cal.monthdatescalendar(cur_month.year, cur_month.month)
for i, month_week in enumerate(month):
for j, day in enumerate(month_week):
meal_dates = meals_dates[day] if day in meals_dates and \
day.month == cur_month.month else []
remaining_meals -= len(meal_dates)
month[i][j] = {'date': month[i][j], 'meals': meal_dates}
months.append({'month': cur_month, 'dates': month})
cur_month = cur_month + relativedelta(months=1)
return months
示例14: index
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def index(year):
cal = Calendar(0)
try:
if not year:
year = date.today().year
cal_list = [
cal.monthdatescalendar(year, i+1)
for i in range(12)
]
except:
abort(404)
else:
return render_template('cal.html', year=year, cal=cal_list)
abort(404)
示例15: index
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdatescalendar [as 别名]
def index():
# check if user is logged in
if session.get('username'):
cal = Calendar(0)
year = date.today().year
month = date.today().month
# cal_list = [cal.monthdatescalendar(year, i + 1) for i in xrange(12)]
cal_list = [cal.monthdatescalendar(year, month)]
return render_template('index.html',
title = 'Dashboard',
year = year,
this_month = month,
calendar = cal_list)
else:
return redirect(url_for('login'))