当前位置: 首页>>代码示例>>Python>>正文


Python Calendar.monthdatescalendar方法代码示例

本文整理汇总了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 ""
开发者ID:emlprime,项目名称:rcs,代码行数:9,代码来源:filters.py

示例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)
开发者ID:alexd2580,项目名称:evelyn,代码行数:33,代码来源:views.py

示例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
开发者ID:AdrianRibao,项目名称:django-extra-views,代码行数:36,代码来源:dates.py

示例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')
开发者ID:gazzman,项目名称:ib,代码行数:9,代码来源:reversal_feed_analyzer.py

示例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]
开发者ID:gabaldo,项目名称:edificio-olimpo,代码行数:10,代码来源:views.py

示例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)
开发者ID:krb3d,项目名称:flask-calendar,代码行数:10,代码来源:server.py

示例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,
    }
开发者ID:duanshuaimin,项目名称:sentry,代码行数:59,代码来源:reports.py

示例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)
开发者ID:enirinth,项目名称:free-food-calendar,代码行数:12,代码来源:server.py

示例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
开发者ID:tlam,项目名称:thisweekontv,代码行数:13,代码来源:views.py

示例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)
开发者ID:gazzman,项目名称:finalysis,代码行数:23,代码来源:parse_option_chain.py

示例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)
开发者ID:WebMole,项目名称:crawler-benchmark,代码行数:15,代码来源:traps.py

示例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 []
开发者ID:btbytes,项目名称:examples,代码行数:15,代码来源:slgc_process_data.py

示例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
开发者ID:JocelynDelalande,项目名称:atable,代码行数:40,代码来源:models.py

示例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)
开发者ID:dAnjou,项目名称:flask-calendar,代码行数:16,代码来源:server.py

示例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'))
开发者ID:soniacs,项目名称:cabinet,代码行数:17,代码来源:dashboard.py


注:本文中的calendar.Calendar.monthdatescalendar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。