def _process_list(self, req, query, data, start_date, period): calendar = TicketCalendar(self.env, req) events = calendar.get_list_events(data['tickets'], start_date, period) data['ticketcalendar'] = { 'events': events, 'last_week': calendar.get_list_href(query, start_date - timedelta(days=7), period + 7), 'next_week': calendar.get_list_href(query, start_date, period + 7), 'create_ticket': calendar._create_ticket_item, 'create_milestone': calendar._create_milestone_item, } data['title'] = _('Ticket Calendar (List view)') data['macro'] = \ '[[TicketCalendar(type=list,duration=%s,query=%s,order=%s%s)]]' % ( '%s/P%dD' % (start_date.strftime('%Y-%m-%d'), period), calendar.build_query_string(query.constraints), query.order, query.desc and ',desc=1' or '') add_ctxtnav(req, _('Calendar view'), calendar.get_box_href(query, get_today(req.tz))) add_ctxtnav(req, _('List view')) return 'ticketcalendar_calendar.html', data, None
def _process_list(self, req, query, data, start_date, period): calendar = TicketCalendar(self.env, req) events = calendar.get_list_events(data['tickets'], start_date, period) data['ticketcalendar'] = { 'events': events, 'last_week': calendar.get_list_href(query, start_date - timedelta(days=7), period + 7), 'next_week': calendar.get_list_href(query, start_date, period + 7), 'create_ticket': calendar._create_ticket_item, 'create_milestone': calendar._create_milestone_item, } data['title'] = _('Ticket Calendar (List view)') data['macro'] = \ '[[TicketCalendar(type=list,duration=%s,query=%s,order=%s%s)]]' % ( '%s/P%dD' % (start_date.strftime('%Y-%m-%d'), period), calendar.build_query_string(query.constraints), query.order, query.desc and ',desc=1' or '') add_ctxtnav(req, _('Calendar view'), calendar.get_box_href(query, date.today())) add_ctxtnav(req, _('List view')) return 'ticketcalendar_calendar.html', data, None
def _process_box(self, req, query, data, month): calendar = TicketCalendar(self.env, req) content = calendar.gen_calendar(data['tickets'], query, month) data['title'] = _('Ticket Calendar (Calendar view)') data['month'] = month.strftime('%Y-%m') data['content'] = content data['ticketcalendar'] = {'mode': 'calendar'} add_ctxtnav(req, _('Calendar view')) add_ctxtnav(req, _('List view'), calendar.get_list_href(query)) return 'ticketcalendar_calendar.html', data, None
def gentd(week_idx, day_info): day = day_info['date'] tt = day_info['milestones'] + day_info['tickets'] if len(tt) < 6: ttshow = tt ttall = [] else: ttshow = tt[:4] ttall = tt tdclass = [] if day == today: tdclass.append('today') if day.weekday() in (5, 6): tdclass.append('weekend') formatted_day = format_date(day, format='long', locale=locale) td = tag.td(class_=' '.join(tdclass), data_for_start_date=day.strftime(start_date_format), data_for_due_date=day.strftime(due_date_format), data_fdate=formatted_day) label = [] if day == today: label.append(tag.span(_("Today"), class_='today')) label.append( tag.span(unicode(day.day), class_=('day normal', 'day')[day == today])) td(tag.div(label)) if ttshow: td(tag.ul([genli(t) for t in ttshow])) if ttall: id = 'calendar-more-%s' % str(day) td( tag.a(_("%d more tickets...") % (len(ttall) - 4), href='#' + id, class_='show-all-list'), tag.div(tag.h4(formatted_day), tag.ul([genli(t) for t in ttall]), class_='ticketcalendar-popup-list', id=id, data_title=format_date(day, locale=locale, format='full'))) return td
def nav_pager(d): return tag.span( tag.a(u'\u25c4', href=nav_href(d - timedelta(days=1))), tag.a(_("Current month"), href=nav_href(get_today(req.tz))), tag.a(u'\u25ba', href=nav_href(d + timedelta(days=31))), class_='ticketcalendar-pager')
def gentd(week_idx, day_info): day = day_info['date'] tt = day_info['milestones'] + day_info['tickets'] if len(tt) < 6: ttshow = tt ttall = [] else: ttshow = tt[:4] ttall = tt tdclass = [] if day == today: tdclass.append('today') if is_weekend(day, locale): tdclass.append('weekend') formatted_day = format_date(day, format='long', locale=locale) td = tag.td( class_=' '.join(tdclass), data_for_start_date=day.strftime(start_date_format), data_for_due_date=day.strftime(due_date_format), data_fdate=formatted_day) label = [] if day == today: label.append(tag.span(_("Today"), class_='today')) label.append(tag.span(unicode(day.day), class_=('day normal', 'day')[day == today])) td(tag.div(label)) if ttshow: td(tag.ul([genli(t) for t in ttshow])) if ttall: id = 'calendar-more-%s' % str(day) td(tag.a(_("%d more tickets...") % (len(ttall) - 4), href='#' + id, class_='show-all-list'), tag.div(tag.h4(formatted_day), tag.ul([genli(t) for t in ttall]), class_='ticketcalendar-popup-list', id=id, data_title=format_date(day, locale=locale, format='full'))) return td
def nav_pager(d): return tag.span(tag.a(u'\u25c4', href=nav_href(d - timedelta(days=1))), tag.a(_("Current month"), href=nav_href(date.today())), tag.a(u'\u25ba', href=nav_href(d + timedelta(days=31))), class_='ticketcalendar-pager')
def nav_macro(): macro = ( '[[TicketCalendar(type=box,month=%(month)s,' 'query=%(query)s,order=%(order)s%(extra)s)]]' % (dict(month=month.strftime('%Y-%m'), query=self.build_query_string(query.constraints), order=query.order, extra=query.desc and ',desc=1' or ''))) text = tag.input(type='text', readonly='readonly', size='80', value=macro, style='width:0;display:none') return tag.span(_("Macro"), text, class_='ticketcalendar-macro')
def get_navigation_items(self, req): if 'TICKET_VIEW' in req.perm: anchor = tag.a(_("Ticket Calendar"), href=req.href('ticketcalendar-box')) yield ('mainnav', 'ticketcalendar-box', anchor)
def gen_calendar(self, tickets, query, month, width=None, nav=True): milestones = self._get_milestones() req = self.req locale = self._get_locale() first_week_day = self._get_first_week_day(locale) start_date_format = self.mod.start_date_format due_date_format = self.mod.due_date_format if not month: month = get_today(req.tz).replace(day=1) # init data today = get_today(req.tz) # generate calendar data weeks = self._get_month_calendar(month.year, month.month, first_week_day, locale) days = sorted(sum(weeks, [])) tickets = self._filter_tickets(days, tickets, req.tz) milestones = self._filter_milestones(days, milestones, req.tz) cal = [[{'date': day, 'tickets': tickets[day], 'milestones': milestones[day]} for day in week] for week in weeks] def genli(t): if isinstance(t, Milestone): return self._create_milestone_item(t) else: return self._create_ticket_item(t) def gentd(week_idx, day_info): day = day_info['date'] tt = day_info['milestones'] + day_info['tickets'] if len(tt) < 6: ttshow = tt ttall = [] else: ttshow = tt[:4] ttall = tt tdclass = [] if day == today: tdclass.append('today') if is_weekend(day, locale): tdclass.append('weekend') formatted_day = format_date(day, format='long', locale=locale) td = tag.td( class_=' '.join(tdclass), data_for_start_date=day.strftime(start_date_format), data_for_due_date=day.strftime(due_date_format), data_fdate=formatted_day) label = [] if day == today: label.append(tag.span(_("Today"), class_='today')) label.append(tag.span(unicode(day.day), class_=('day normal', 'day')[day == today])) td(tag.div(label)) if ttshow: td(tag.ul([genli(t) for t in ttshow])) if ttall: id = 'calendar-more-%s' % str(day) td(tag.a(_("%d more tickets...") % (len(ttall) - 4), href='#' + id, class_='show-all-list'), tag.div(tag.h4(formatted_day), tag.ul([genli(t) for t in ttall]), class_='ticketcalendar-popup-list', id=id, data_title=format_date(day, locale=locale, format='full'))) return td day_names = get_day_names(locale=locale, width='abbreviated') day_names = [day_names[(idx + first_week_day) % 7] for idx in xrange(7)] header = tag.div(class_='ticketcalendar-header') if nav: def nav_href(d): return self.get_box_href(query, d) def nav_pager(d): return tag.span( tag.a(u'\u25c4', href=nav_href(d - timedelta(days=1))), tag.a(_("Current month"), href=nav_href(get_today(req.tz))), tag.a(u'\u25ba', href=nav_href(d + timedelta(days=31))), class_='ticketcalendar-pager') def nav_macro(): macro = ( '[[TicketCalendar(type=box,month=%(month)s,' 'query=%(query)s,order=%(order)s%(extra)s)]]' % (dict(month=month.strftime('%Y-%m'), query=self.build_query_string(query.constraints), order=query.order, extra=query.desc and ',desc=1' or ''))) text = tag.input(type='text', readonly='readonly', size='80', value=macro, style='width:0;display:none') return tag.span(_("Macro"), text, class_='ticketcalendar-macro') header(tag.div(nav_macro(), nav_pager(month), class_='ticketcalendar-nav')) header(tag.h4(_("%(month_name)s, %(year)s", month_name=_get_month_name(month, locale), year=month.year))) calendar = tag.table( tag.thead(tag.tr(tag.th(name) for name in day_names)), tag.tbody([tag.tr([gentd(idx, d) for d in w]) for idx, w in enumerate(cal)]), class_='calendar') can_create = 'TICKET_CREATE' in req.perm ticket_box = tag.div( tag.h4(tag.span('', class_='tc-today-date')), tag.ul( tag.li(tag.a( tag_("New ticket with \"%(date)s\" as the start date", date=tag.span('', data='start-date')), data_href=req.href('newticket', [(self.mod.start_date_name, '')]), class_='newticket-start-date')), tag.li(tag.a( tag_("New ticket with \"%(date)s\" as the due date", date=tag.span('', data='due-date')), data_href=req.href('newticket', [(self.mod.due_date_name, '')]), class_='newticket-due-date'))), title=_("Create new ticket"), class_='ticketcalendar-newticket-box', style='display:none', data_writable=(None, 'writable')[can_create]) class_ = ('ticketcalendar', 'ticketcalendar ticketcalendar-can-create')[can_create] return tag.div(header, calendar, ticket_box, class_=class_, style=width and ('width: %s' % width) or None)
def gen_calendar(self, tickets, query, month, width=None, nav=True): milestones = self._get_milestones() req = self.req locale = self._get_locale() first_week_day = self._get_first_week_day(locale) start_date_format = self.mod.start_date_format due_date_format = self.mod.due_date_format if not month: month = datetime.now(req.tz) month = datetime(month.year, month.month, 1).date() # init data today = datetime.now(req.tz).date() # generate calendar data weeks = self._get_month_calendar(month.year, month.month, first_week_day, locale) days = sorted(sum(weeks, [])) tickets = self._filter_tickets(days, tickets, req.tz) milestones = self._filter_milestones(days, milestones, req.tz) cal = [[{ 'date': day, 'tickets': tickets[day], 'milestones': milestones[day] } for day in week] for week in weeks] def genli(t): if isinstance(t, Milestone): return self._create_milestone_item(t) else: return self._create_ticket_item(t) def gentd(week_idx, day_info): day = day_info['date'] tt = day_info['milestones'] + day_info['tickets'] if len(tt) < 6: ttshow = tt ttall = [] else: ttshow = tt[:4] ttall = tt tdclass = [] if day == today: tdclass.append('today') if day.weekday() in (5, 6): tdclass.append('weekend') formatted_day = format_date(day, format='long', locale=locale) td = tag.td(class_=' '.join(tdclass), data_for_start_date=day.strftime(start_date_format), data_for_due_date=day.strftime(due_date_format), data_fdate=formatted_day) label = [] if day == today: label.append(tag.span(_("Today"), class_='today')) label.append( tag.span(unicode(day.day), class_=('day normal', 'day')[day == today])) td(tag.div(label)) if ttshow: td(tag.ul([genli(t) for t in ttshow])) if ttall: id = 'calendar-more-%s' % str(day) td( tag.a(_("%d more tickets...") % (len(ttall) - 4), href='#' + id, class_='show-all-list'), tag.div(tag.h4(formatted_day), tag.ul([genli(t) for t in ttall]), class_='ticketcalendar-popup-list', id=id, data_title=format_date(day, locale=locale, format='full'))) return td day_names = get_day_names(locale=locale, width='abbreviated') day_names = [ day_names[(idx + first_week_day) % 7] for idx in xrange(7) ] header = tag.div(class_='ticketcalendar-header') if nav: def nav_href(d): return self.get_box_href(query, d) def nav_pager(d): return tag.span(tag.a(u'\u25c4', href=nav_href(d - timedelta(days=1))), tag.a(_("Current month"), href=nav_href(date.today())), tag.a(u'\u25ba', href=nav_href(d + timedelta(days=31))), class_='ticketcalendar-pager') def nav_macro(): macro = ( '[[TicketCalendar(type=box,month=%(month)s,' 'query=%(query)s,order=%(order)s%(extra)s)]]' % (dict(month=month.strftime('%Y-%m'), query=self.build_query_string(query.constraints), order=query.order, extra=query.desc and ',desc=1' or ''))) text = tag.input(type='text', readonly='readonly', size='80', value=macro, style='width:0;display:none') return tag.span(_("Macro"), text, class_='ticketcalendar-macro') header( tag.div(nav_macro(), nav_pager(month), class_='ticketcalendar-nav')) header( tag.h4( _("%(month_name)s, %(year)s", month_name=_get_month_name(month, locale), year=month.year))) calendar = tag.table( tag.thead(tag.tr(tag.th(name) for name in day_names)), tag.tbody([ tag.tr([gentd(idx, d) for d in w]) for idx, w in enumerate(cal) ]), class_='calendar') can_create = 'TICKET_CREATE' in req.perm ticket_box = tag.div( tag.h4(tag.span('', class_='tc-today-date')), tag.ul( tag.li( tag.a(tag_( "New ticket with \"%(date)s\" as the start date", date=tag.span('', data='start-date')), data_href=req.href('newticket', [(self.mod.start_date_name, '')]), class_='newticket-start-date')), tag.li( tag.a(tag_("New ticket with \"%(date)s\" as the due date", date=tag.span('', data='due-date')), data_href=req.href('newticket', [(self.mod.due_date_name, '')]), class_='newticket-due-date'))), title=_("Create new ticket"), class_='ticketcalendar-newticket-box', style='display:none', data_writable=(None, 'writable')[can_create]) class_ = ('ticketcalendar', 'ticketcalendar ticketcalendar-can-create')[can_create] return tag.div(header, calendar, ticket_box, class_=class_, style=width and ('width: %s' % width) or None)