Return an HTML calendar of entries.
198748
def get_calendar_entries(context, year=None, month=None,
                         template='zinnia/tags/entries_calendar.html'):
    
    if not (year and month):
        day_week_month = (context.get('day') or
                          context.get('week') or
                          context.get('month'))
        publication_date = getattr(context.get('object'),
                                   'publication_date', None)
        if day_week_month:
            current_month = day_week_month
        elif publication_date:
            if settings.USE_TZ:
                publication_date = timezone.localtime(publication_date)
            current_month = publication_date.date()
        else:
            today = timezone.now()
            if settings.USE_TZ:
                today = timezone.localtime(today)
            current_month = today.date()
        current_month = current_month.replace(day=1)
    else:
        current_month = date(year, month, 1)

    dates = list(map(
        lambda x: settings.USE_TZ and timezone.localtime(x).date() or x.date(),
        Entry.published.datetimes('publication_date', 'month')))

    if current_month not in dates:
        dates.append(current_month)
        dates.sort()
    index = dates.index(current_month)

    previous_month = index > 0 and dates[index - 1] or None
    next_month = index != len(dates) - 1 and dates[index + 1] or None
    calendar = Calendar()

    return {'template': template,
            'next_month': next_month,
            'previous_month': previous_month,
            'calendar': calendar.formatmonth(
                current_month.year,
                current_month.month,
                previous_month=previous_month,
                next_month=next_month)}
628174
def _holiday_entry(self):
        """"""
        holidays_list = self.get_holidays_for_year()
        holidays_list = [
            holiday for holiday, holiday_hdate in holidays_list if
            holiday_hdate.hdate == self.hdate
        ]
        assert len(holidays_list) <= 1

        # If anything is left return it, otherwise return the "NULL" holiday
        return holidays_list[0] if holidays_list else htables.HOLIDAYS[0]
953025
def date_totals(entries, by):
    """"""
    date_dict = {}
    for date, date_entries in groupby(entries, lambda x: x['date']):
        if isinstance(date, datetime.datetime):
            date = date.date()
        d_entries = list(date_entries)

        if by == 'user':
            name = ' '.join((d_entries[0]['user__first_name'],
                             d_entries[0]['user__last_name']))
        elif by == 'project':
            name = d_entries[0]['project__name']
        else:
            name = d_entries[0][by]

        pk = d_entries[0][by]
        hours = get_hours_summary(d_entries)
        date_dict[date] = hours
    return name, pk, date_dict
1192287
def index():
    """"""
    kwdb = current_app.kwdb

    libraries = get_collections(kwdb, libtype="library")
    resource_files = get_collections(kwdb, libtype="resource")

    return flask.render_template("libraryNames.html",
                                 data={"libraries": libraries,
                                       "version": __version__,
                                       "resource_files": resource_files
                                   })
1351996
function Calendars() {
		this.regionalOptions = [];
		this.regionalOptions[''] = {
			invalidCalendar: 'Calendar {0} not found',
			invalidDate: 'Invalid {0} date',
			invalidMonth: 'Invalid {0} month',
			invalidYear: 'Invalid {0} year',
			differentCalendars: 'Cannot mix {0} and {1} dates'
		};
		this.local = this.regionalOptions[''];
		this.calendars = {};
		this._localCals = {};
	}
470788
def select(cls, symbol, start_date, end_date):
        """"""
        instance = cls(symbol, start_date, end_date)

        return instance.data
1144485
private static Calendar toCalendar(Date self) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(self);
        return cal;
    }
719621
def serveUpcoming(self, request):
        """"""
        myurl = self.get_url(request)
        today = timezone.localdate()
        monthlyUrl = myurl + self.reverse_subpage('serveMonth',
                                                  args=[today.year, today.month])
        weekNum = gregorian_to_week_date(today)[1]
        weeklyUrl = myurl + self.reverse_subpage('serveWeek',
                                                 args=[today.year, weekNum])
        listUrl = myurl + self.reverse_subpage('servePast')
        upcomingEvents = self._getUpcomingEvents(request)
        paginator = Paginator(upcomingEvents, self.EventsPerPage)
        try:
            eventsPage = paginator.page(request.GET.get('page'))
        except PageNotAnInteger:
            eventsPage = paginator.page(1)
        except EmptyPage:
            eventsPage = paginator.page(paginator.num_pages)

        # TODO Consider changing to a TemplateResponse
        # https://stackoverflow.com/questions/38838601
        return render(request, "joyous/calendar_list_upcoming.html",
                      {'self':         self,
                       'page':         self,
                       'version':      __version__,
                       'today':        today,
                       'weeklyUrl':    weeklyUrl,
                       'monthlyUrl':   monthlyUrl,
                       'listUrl':      listUrl,
                       'events':       eventsPage})
553314
def _getEventsByWeek(self, request, year, month):
        
        home = request.site.root_page
        return getAllEventsByWeek(request, year, month, home=home)
143591
def _getEventsByDay(self, request, firstDay, lastDay):
        
        return getAllEventsByDay(request, firstDay, lastDay, home=self)
1012777
public function entries()
    {
        // Used loader
        $loader = $this->loader()->upcoming();

        // Pagination
        $page = $this->page();

        // Filters
        $cat = $this->category();
        $date = $this->date();
        $year = $this->year();
        $month = $this->month();
        $day = $this->day();

        // Basicly.
        if ($year && $month && $day && !$date) {
            $date = new DateTime($year.'-'.$month.'-'.$day);
        }

        // Category is still valid.
        $extraSql = '';
        if ($cat) {
            $extraSql = '
            AND
                \''.$cat.'\' IN (category)';
        }

        // Get event from specific date.
        if ($date) {
            $loader = $this->loader()->all();
            $proto = $this->loader()->proto();
            $table = $proto->source()->table();
            $q = 'SELECT * FROM '.$table.'
                WHERE
                    \''.$date->format('Y-m-d').'\'
                BETWEEN
                    DATE(start_date) AND DATE(end_date)
                AND
                    active = 1'.$extraSql;

            $collection = $loader->loadFromQuery($q);

            return $collection;
        }

        // YEAR only filter.
        if ($year && !$month) {
            $loader = $this->loader()->all();
            $proto = $this->loader()->proto();
            $table = $proto->source()->table();
            $q = 'SELECT * FROM '.$table.'
                WHERE
                    \''.$this->year().'\' = YEAR(start_date)
                OR
                    \''.$this->year().'\' = YEAR(end_date)
                AND
                    active = 1'.$extraSql;

            $collection = $loader->loadFromQuery($q);

            return $collection;
        }

        // Year AND month filter.
        if ($year && $month) {
            $between = new DateTime($year.'-'.$month.'-01');
            $loader = $this->loader()->all();
            $proto = $this->loader()->proto();
            $table = $proto->source()->table();
            $q = 'SELECT * FROM '.$table.'
                WHERE
                    \''.$between->format('Y-m-d H:i:s').'\'
                BETWEEN
                    CAST(CONCAT(YEAR(start_date), \'-\', MONTH(start_date), \'-\', 01) AS DATETIME)
                AND
                    CAST(CONCAT(YEAR(end_date), \'-\', MONTH(end_date), \'-\', 01) AS DATETIME)
                AND
                    active = 1'.$extraSql;

            $collection = $loader->loadFromQuery($q);

            return $collection;
        }

        if (isset($this->entries[$cat])) {
            if (isset($this->entries[$cat][$page])) {
                return $this->entries[$cat][$page];
            }
        }

        if ($this->category()) {
            $loader->addFilter('category', $this->category(), [ 'operator' => 'in' ]);
        }

        if ($this->numPerPage()) {
            $loader->setPage($page);
            $loader->setNumPerPage($this->numPerPage());
        }
        $this->entries[$cat][$page] = $loader->load();

        return $this->entries[$cat][$page];
    }
1101932
def _getEventsOnDay(self, request, day):
        """"""
        return getAllEventsByDay(request, day, day, home=self)[0]
982673
private static Calendar buildCalendar() {

    Calendar calendar = calendarCache.get();
    if (calendar == null) {
      calendar = GregorianCalendar.getInstance();
      calendarCache.set(calendar);
    }
    return calendar;
  }
561640
def events_this_week(context):
    
    request = context['request']
    home = request.site.root_page
    cal = CalendarPage.objects.live().descendant_of(home).first()
    calUrl = cal.get_url(request) if cal else None
    calName = cal.title if cal else None
    today = dt.date.today()
    beginOrd = today.toordinal()
    if today.weekday() != 6:
        # Start week with Monday, unless today is Sunday
        beginOrd -= today.weekday()
    endOrd = beginOrd + 6
    dateFrom = dt.date.fromordinal(beginOrd)
    dateTo   = dt.date.fromordinal(endOrd)
    if cal:
        events = cal._getEventsByDay(request, dateFrom, dateTo)
    else:
        events = getAllEventsByDay(request, dateFrom, dateTo)
    return {'request':      request,
            'today':        today,
            'calendarUrl':  calUrl,
            'calendarName': calName,
            'events':       events }
1253220
def to_reminders(self, ical, label=None, priority=None, tags=None,
                     tail=None, sep=" ", postdate=None, posttime=None):
        """"""
        if not hasattr(ical, 'vevent_list'):
            return ''

        reminders = [self.to_remind(vevent, label, priority, tags, tail, sep,
                                    postdate, posttime)
                     for vevent in ical.vevent_list]
        return ''.join(reminders)
271737
def list(gandi, limit, step):
    """"""
    output_keys = ['id', 'type', 'step']

    options = {
        'step': step,
        'items_per_page': limit,
        'sort_by': 'date_created DESC'
    }

    result = gandi.oper.list(options)
    for num, oper in enumerate(reversed(result)):
        if num:
            gandi.separator_line()
        output_generic(gandi, oper, output_keys)

    return result
1215781
def list_matching_entries(program, arguments):
    """"""
    output("\n".join(entry.name for entry in program.smart_search(*arguments)))