def make_link(self, title, date, method=None): if method is None: method = self.context.view.method # Build link link = ';{method}?start={date}&end={date}' link = link.format(date=Date.encode(date), method=method) # Enabled ? enabled = self.context.view.method == method return {'title': title, 'link': link, 'css': 'enabled' if enabled else ''}
def make_link(self, title, date, method=None): if method is None: method = self.context.view.method # Build link link = ';{method}?start={date}&end={date}' link = link.format(date=Date.encode(date), method=method) # Enabled ? enabled = self.context.view.method == method return { 'title': title, 'link': link, 'css': 'enabled' if enabled else '' }
def get_calendar_namespace(self, resource, context): # Base namespace proxy = super(MultiweekView, self) namespace = proxy.get_calendar_namespace(resource, context) # Get today date today_date = date.today() # Current date c_date = self.get_current_date(context) # Display link to add/edit an event with_new_url = self.get_with_new_url(resource, context) # Start date start = self.get_start_date(c_date) nweeks = self.get_nweeks(c_date, start) # Get header line with days of the week namespace['days_of_week'] = self.days_of_week_ns(start, ndays=self.ndays) # Get the 5 weeks namespace['weeks'] = [] link = ';new_event?dtstart={date}&dtend={date}' day = start for kk in range(nweeks): ns_week = [] # 7 days a week for d in range(7): # Day in timetable if d < self.ndays: ns_day = { 'url': None, 'nday': day.day, 'selected': (day == today_date), 'events': [] } if day.day == 1: month_name = months[day.month].gettext() ns_day['nday'] = u'%d %s' % (day.day, month_name) if with_new_url: ns_day['url'] = link.format(date=Date.encode(day)) # Get a list of events to display on view for event in self.get_events(day): ns_day['events'].append({ 'stream': event.render(event=event, day=day), 'color': event.get_color(), 'status': event.get_value('status') or 'cal_busy' }) ns_week.append(ns_day) day = day + timedelta(1) namespace['weeks'].append(ns_week) return namespace
def value_(self): value = self.value if value is None: return '', '' try: value = self.datatype.decode(value) except StandardError: # XXX Heuristic here from itools.web import get_context context = get_context() return (context.get_form_value(self.name), context.get_form_value('%s_time' % self.name)) if type(value) is datetime: value_date = value.date() value_time = value.time() else: value_date = value value_time = self.value_time_default if value_time is None: return Date.encode(value_date), '' return Date.encode(value_date), value_time.strftime('%H:%M')
def get_calendar_namespace(self, resource, context): # Base namespace proxy = super(MultiweekView, self) namespace = proxy.get_calendar_namespace(resource, context) # Get today date today_date = date.today() # Current date c_date = self.get_current_date(context) # Display link to add/edit an event with_new_url = self.get_with_new_url(resource, context) # Start date start = self.get_start_date(c_date) nweeks = self.get_nweeks(c_date, start) # Get header line with days of the week namespace['days_of_week'] = self.days_of_week_ns(start, ndays=self.ndays) # Get the 5 weeks namespace['weeks'] = [] link = ';new_event?dtstart={date}&dtend={date}' day = start for kk in range(nweeks): ns_week = [] # 7 days a week for d in range(7): # Day in timetable if d < self.ndays: ns_day = { 'url': None, 'nday': day.day, 'selected': (day == today_date), 'events': []} if day.day == 1: month_name = months[day.month].gettext() ns_day['nday'] = u'%d %s' % (day.day, month_name) if with_new_url: ns_day['url'] = link.format(date=Date.encode(day)) # Get a list of events to display on view for event in self.get_events(day): ns_day['events'].append( {'stream': event.render(event=event, day=day), 'color': event.get_color(), 'status': event.get_value('status') or 'cal_busy'}) ns_week.append(ns_day) day = day + timedelta(1) namespace['weeks'].append(ns_week) return namespace
def start(self): return Date.encode(self.c_date)
def get_grid_data(data, grid, start_date=None, templates=(None, None), with_new_url=True, add_icon=None): """ Build final namespace from data and grid to be used in gridlayout templates. """ template, template_fd = templates if template is None: template = default_template if template_fd is None: template_fd = default_template_fd # Build grid with Time objects grid = [Time.decode(x) for x in grid] # Build.. headers, events_with_time, events_without_time = [], [], [] for column in data: time_grid = [] full_day = [] events = column['events'] # Build the time grid for event in events: start, end = event['start'], event['end'] # Put the event in the right place if not event['TIME']: event['ns'] = stl(template_fd, {'event': event}) full_day.append(event) else: start, end = Time.decode(start), Time.decode(end) insert_item(time_grid, start, end, event, event['cal']) # Fix grid if needed if start not in grid: grid.append(start) if end not in grid: grid.append(end) # Finalize headers.append(column.get('header')) events_with_time.append(time_grid) events_without_time.append(full_day) # Sort the grid grid.sort() ###################################################################### # Build_timegrids_collection with given data: # (events_with_time, headers, grid, events_without_time, # start_date=None) today = date.today() if start_date: current_date = start_date ns_full_day = None if filter(lambda x: x, events_without_time): ns_full_day = [] ns_headers = [] cols = [] for i in range(len(events_with_time)): table, ncols = render_namespace(events_with_time[i], grid, with_new_url) if headers is not None: if current_date == today: h_class = 'cal_day_selected' else: h_class = 'header' ns_headers.append({ 'header': headers[i], 'width': ncols, 'class': h_class }) if ns_full_day is not None: ns_full_day.append({ 'events': events_without_time[i], 'width': ncols }) # Add date to newurl for each cell having this parameter # Build namespace for the content of cells containing event (new) if start_date is not None: str_date = Date.encode(current_date) for column in table: for cell in column['cells']: if cell['newurl'] is not None: url = '%s&date=%s' % (cell['newurl'], str_date) cell['newurl'] = url if cell['new']: cell['ns'] = stl(template, { 'cell': cell, 'add_icon': add_icon }) current_date = current_date + timedelta(1) cols.append(table) body = [] for i in range(len(grid) - 1): body.append({ 'start': Time.encode(grid[i]), 'end': Time.encode(grid[i + 1]), 'items': [col[i] for col in cols] }) namespace = { 'headers': ns_headers, 'body': body, 'full_day_events': ns_full_day } return namespace
def get_grid_data(data, grid, start_date=None, templates=(None, None), with_new_url=True, add_icon=None): """ Build final namespace from data and grid to be used in gridlayout templates. """ template, template_fd = templates if template is None: template = default_template if template_fd is None: template_fd = default_template_fd # Build grid with Time objects grid = [ Time.decode(x) for x in grid ] # Build.. headers, events_with_time, events_without_time = [], [], [] for column in data: time_grid = [] full_day = [] events = column['events'] # Build the time grid for event in events: start, end = event['start'], event['end'] # Put the event in the right place if not event['TIME']: event['ns'] = stl(template_fd, {'event': event}) full_day.append(event) else: start, end = Time.decode(start), Time.decode(end) insert_item(time_grid, start, end, event, event['cal']) # Fix grid if needed if start not in grid: grid.append(start) if end not in grid: grid.append(end) # Finalize headers.append(column.get('header')) events_with_time.append(time_grid) events_without_time.append(full_day) # Sort the grid grid.sort() ###################################################################### # Build_timegrids_collection with given data: # (events_with_time, headers, grid, events_without_time, # start_date=None) today = date.today() if start_date: current_date = start_date ns_full_day = None if filter(lambda x: x, events_without_time): ns_full_day = [] ns_headers = [] cols = [] for i in range(len(events_with_time)): table, ncols = render_namespace(events_with_time[i], grid, with_new_url) if headers is not None: if current_date == today: h_class = 'cal_day_selected' else: h_class = 'header' ns_headers.append({'header': headers[i], 'width': ncols, 'class': h_class}) if ns_full_day is not None: ns_full_day.append({'events': events_without_time[i], 'width': ncols}) # Add date to newurl for each cell having this parameter # Build namespace for the content of cells containing event (new) if start_date is not None: str_date = Date.encode(current_date) for column in table: for cell in column['cells']: if cell['newurl'] is not None: url = '%s&date=%s' % (cell['newurl'], str_date) cell['newurl'] = url if cell['new']: cell['ns'] = stl(template, {'cell': cell, 'add_icon': add_icon}) current_date = current_date + timedelta(1) cols.append(table) body = [] for i in range(len(grid)-1): body.append({'start': Time.encode(grid[i]), 'end': Time.encode(grid[i+1]), 'items': [col[i] for col in cols]}) namespace = {'headers': ns_headers, 'body': body, 'full_day_events': ns_full_day} return namespace