def render_admin_panel(self, req, cat, page, path_info): """ Handles the admin page requests """ req.perm.require("TRAC_ADMIN") # Default values perm = 'TRAC_ADMIN' stat_types = [('activity', 'Activity'), ('registration', 'Registrations')] stat_type = 'registration' maxresult_opts = [5, 10, 30, 50, 100, 0] maxresults = 10 now = datetime.utcnow() weekday, endday = calendar.monthrange(now.year, now.month) starttime = datetime(year=now.year, month=now.month, day=1, hour=0, minute=0, second=0) endtime = datetime(year=now.year, month=now.month, day=endday, hour=23, minute=59, second=59) # This ain't timemachine if endtime > now: endtime = now # Set or reset filters back to defaults if 'update' in req.args.keys(): # Try parsing the dates try: starttime = datetime.strptime(req.args.get('starttime', ''), DATEFORMATS['py']) endtime = datetime.strptime(req.args.get('endtime', ''), DATEFORMATS['py']) # Set the time to be from 00:00 -- 23:59:59 starttime = datetime( year=starttime.year, month=starttime.month, day=starttime.day, hour=0, minute=0, second=0 ) endtime = datetime( year=endtime.year, month=endtime.month, day=endtime.day, hour=23, minute=59, second=59 ) except Exception, ex: self.log.warning('Date conversion failed: %s' % ex) add_warning(req, _('Please check the time range values as they seem inappropriate. The format is: MM/DD/YY')) # Set filters # NOTE: UI allows only one category atm categories_raw = req.args.get('categories', '') if categories_raw.strip(): categories = [plaintext(categories_raw)] maxresults = req.args.get('maxresults', maxresults) stat_type = req.args.get('stat_type', stat_type) # If maxresults does not seem num if isinstance(maxresults, basestring): maxresults = int(maxresults) if maxresults.isdigit() else 10
def _parse_heading(self, formatter, match, fullmatch): shorten = False match = match.strip() depth = min(len(fullmatch.group('nhdepth')), 6) try: formatter.close_table() formatter.close_paragraph() formatter.close_indentation() formatter.close_list() formatter.close_def_list() except: pass ## BEGIN of code provided by Joshua Hoke, see th:#4521. # moved and modified by Martin # Figure out headline numbering for outline counters = self.outline_counters.get(formatter, []) if formatter not in self.outline_counters: self.outline_counters[formatter] = counters if len(counters) < depth: delta = depth - len(counters) counters.extend([0] * (delta - 1)) counters.append(1) else: del counters[depth:] counters[-1] += 1 ## END num = fullmatch.group('nheadnum') or '' anchor = fullmatch.group('nhanchor') or '' heading_text = match[depth + 1 + len(num):-depth - 1 - len(anchor)].strip() num = num.strip() if num and num[-1] == '.': num = num[:-1] if num: numbers = [self._int(n) for n in num.split('.')] if len(numbers) == 1: counters[depth - 1] = numbers[0] else: if len(numbers) > depth: del numbers[depth:] n = 0 while numbers[n] == -1: n = n + 1 counters[depth - len(numbers[n:]):] = numbers[n:] if not heading_text: return tag() heading = format_to_oneliner(formatter.env, formatter.context, heading_text, False) if anchor: anchor = anchor[1:] else: sans_markup = plaintext(heading, keeplinebreaks=False) anchor = WikiParser._anchor_re.sub('', sans_markup) if not anchor or anchor[0].isdigit() or anchor[0] in '.-': # an ID must start with a Name-start character in XHTML anchor = 'a' + anchor # keeping 'a' for backward compat i = 1 anchor_base = anchor while anchor in formatter._anchors: anchor = anchor_base + str(i) i += 1 formatter._anchors[anchor] = True # Add number directly if CSS is not used s = self.startatleveltwo and 1 or 0 #self.env.log.debug('NHL:' + str(counters)) while s < len(counters) and counters[s] == 0: s = s + 1 oheading_text = heading_text heading_text = '.'.join(map(str, counters[s:]) + [" "]) + heading_text if self.number_outline: oheading_text = heading_text heading = format_to_oneliner(formatter.env, formatter.context, heading_text, False) oheading = format_to_oneliner(formatter.env, formatter.context, oheading_text, False) ## BEGIN of code provided by Joshua Hoke, see th:#4521. # modified by Martin # Strip out link tags oheading = re.sub(r'</?a(?: .*?)?>', '', oheading) try: # Add heading to outline formatter.outline.append((depth, anchor, oheading)) except AttributeError: # Probably a type of formatter that doesn't build an # outline. pass ## END of provided code html = tag.__getattr__('h' + str(depth))(heading, id=anchor) if self.fix_paragraph: return '</p>' + to_unicode(html) + '<p>' else: return html
def _parse_heading(self, formatter, match, fullmatch): shorten = False match = match.strip() depth = min(len(fullmatch.group('nhdepth')), 6) try: formatter.close_table() formatter.close_paragraph() formatter.close_indentation() formatter.close_list() formatter.close_def_list() except: pass ## BEGIN of code provided by Joshua Hoke, see th:#4521. # moved and modified by Martin # Figure out headline numbering for outline counters = self.outline_counters.get(formatter, []) if formatter not in self.outline_counters: self.outline_counters[formatter] = counters if len(counters) < depth: delta = depth - len(counters) counters.extend([0] * (delta - 1)) counters.append(1) else: del counters[depth:] counters[-1] += 1 ## END num = fullmatch.group('nheadnum') or '' anchor = fullmatch.group('nhanchor') or '' heading_text = match[depth+1+len(num):-depth-1-len(anchor)].strip() num = num.strip() if num and num[-1] == '.': num = num[:-1] if num: numbers = [self._int(n) for n in num.split('.')] if len(numbers) == 1: counters[depth-1] = numbers[0] else: if len(numbers) > depth: del numbers[depth:] n = 0 while numbers[n] == -1: n = n + 1 counters[depth-len(numbers[n:]):] = numbers[n:] if not heading_text: return tag() heading = format_to_oneliner(formatter.env, formatter.context, heading_text, False) if anchor: anchor = anchor[1:] else: sans_markup = plaintext(heading, keeplinebreaks=False) anchor = WikiParser._anchor_re.sub('', sans_markup) if not anchor or anchor[0].isdigit() or anchor[0] in '.-': # an ID must start with a Name-start character in XHTML anchor = 'a' + anchor # keeping 'a' for backward compat i = 1 anchor_base = anchor while anchor in formatter._anchors: anchor = anchor_base + str(i) i += 1 formatter._anchors[anchor] = True # Add number directly if CSS is not used s = self.startatleveltwo and 1 or 0 #self.env.log.debug('NHL:' + str(counters)) while s < len(counters) and counters[s] == 0: s = s + 1 oheading_text = heading_text heading_text = '.'.join(map(str, counters[s:]) + [" "]) + heading_text if self.number_outline: oheading_text = heading_text heading = format_to_oneliner(formatter.env, formatter.context, heading_text, False) oheading = format_to_oneliner(formatter.env, formatter.context, oheading_text, False) ## BEGIN of code provided by Joshua Hoke, see th:#4521. # modified by Martin # Strip out link tags oheading = re.sub(r'</?a(?: .*?)?>', '', oheading) try: # Add heading to outline formatter.outline.append((depth, anchor, oheading)) except AttributeError: # Probably a type of formatter that doesn't build an # outline. pass ## END of provided code html = tag.__getattr__('h' + str(depth))( heading, id = anchor) if self.fix_paragraph: return '</p>' + to_unicode(html) + '<p>' else: return html