"""splat.web.templates The PTL part of the SPLAT web interface -- templates to generate the user interface. """ __revision__ = "$Id: templates.ptl,v 1.24 2001/11/05 18:46:01 gward Exp $" from quixote.errors import QueryError from quixote.form.widget import \ RadiobuttonsWidget, SelectWidget, MultipleSelectWidget, SubmitButtonWidget from splat.bug import Bug from splat.util import format_priority from splat.config import get_config from splat.web import util class MySelectWidget (SelectWidget): def render (self, request): if self.size is None: self.size = min(10, len(self.allowed_values)) return SelectWidget.render(self, request) # blechh! evil! nasty! rude! but it works... MultipleSelectWidget.__bases__ = (MySelectWidget,) template header (title): '''\ SPLAT! - %s ''' % title template footer (): ''' ''' _column_heading = { "bug_id" : "ID", "bug_type" : "bug type", "submitter_id" : "submitter", "fixer_id" : "fixer", } template _q_index (request): prefs = request.session.prefs config = get_config() # Generate the main list of bugs, possibly filtered and sorted. bug_db = util.get_bug_database() header("Bug Index") '''\ [display preferences] [filter preferences] ''' for col in prefs.columns: ' \n' % _column_heading.get(col, col) ' \n' num_cols = len(prefs.columns) bugs = prefs.filter_bugs(bug_db) #bugs = [bug_db.get_bug(bug_id) for bug_id in bug_db.get_bug_ids()] # Loop over all bugs, grouping them by priority and filtering out bugs # that don't meet the filter criteria (currently, we just filter out # resolved bugs). 'groups' is a list of N lists, where N is # the number of priority levels. (groups, headings, heading_colours) = \ prefs.group_bugs(bug_db, bugs) ngroups = len(groups) # Now render each group of bugs in lovely HTML. visible_bugs = request.session.visible_bugs = [] for i in range(0, ngroups): group = groups[i] heading = headings[i] colour = util.rgb2hex(heading_colours[i]) (" \n" % (colour, num_cols, util.html_quote(heading))) for bug in group: ' \n' first = 1 for col in prefs.columns: if col == "bug_id": val = str(bug) elif col == "summary": val = '%s' % (bug, bug.summary) elif col in ("component", "bug_type",): val = getattr(bug, col) or 'unknown' elif col in ("submitter_id", "fixer_id"): val = getattr(bug, col) or 'none' elif col == "priority": val = bug.format_priority() or 'unknown' val = val.replace(" ", " ") elif col == "resolution": if bug.status != bug.ST_RESOLVED: val = "N/A" else: val = bug.resolution or 'unknown' else: val = getattr(bug, col) if first: val = '%s' % (bug, val) first = 0 ' \n' % val ' \n' visible_bugs.append(bug.bug_id) "
%s
%s
%s
\n" footer() bug_db.forget_all_bugs() # _q_index () def gen_display_widgets (request, widgets): prefs = request.session.prefs # Widgets for grouping/sorting/column selection widgets['group'] = RadiobuttonsWidget( "group", prefs.group, allowed_values=prefs.VALID_GROUPS, delim="
\n") widgets['sort'] = RadiobuttonsWidget( "sort", prefs.sort, allowed_values=prefs.VALID_SORTS, delim="
\n") widgets['select_columns'] = MultipleSelectWidget( "select_columns", prefs.columns, allowed_values=prefs.VALID_COLUMNS, size=len(prefs.VALID_COLUMNS)) def gen_filter_widgets (request, widgets): config = get_config() prefs = request.session.prefs widgets['component'] = MultipleSelectWidget( "component", prefs.filter["component"], allowed_values=config.bug_components) widgets['bug_type'] = MultipleSelectWidget( "bug_type", prefs.filter["bug_type"], allowed_values=config.bug_types) priorities = range(1, config.get_max_priority()+1) priority_descs = [format_priority(p) for p in priorities] widgets['priority'] = MultipleSelectWidget( "priority", prefs.filter["priority"], allowed_values=priorities, descriptions=priority_descs) widgets['status'] = MultipleSelectWidget( "status", prefs.filter["status"], allowed_values=Bug.VALID_STATUS) widgets['resolution'] = MultipleSelectWidget( "resolution", prefs.filter["resolution"], allowed_values=config.bug_resolutions) bug_db = util.get_bug_database() user_ids = bug_db.get_user_ids() user_desc = [bug_db.get_user(user_id).format_min() for user_id in user_ids] widgets['submitter_id'] = MultipleSelectWidget( "submitter_id", prefs.filter["submitter_id"], allowed_values=user_ids, descriptions=user_desc) widgets['fixer_id'] = MultipleSelectWidget( "fixer_id", prefs.filter["fixer_id"], allowed_values=user_ids, descriptions=user_desc) template display (request): header("Display Preferences") '

Display Preferences

\n' widgets = request.session.widgets gen_display_widgets(request, widgets) '''\
''' '\n' % widgets['group'].render(request) '\n' % widgets['sort'].render(request) '\n' % widgets['select_columns'].render(request) ' \n' '
Group bugs by: Sort bugs by: Columns to display:
\n%s\n%s\n%s
\n' SubmitButtonWidget("action", "display").render(request) + "\n" SubmitButtonWidget("action", "set filter prefs").render(request) + "\n" SubmitButtonWidget("action", "cancel").render(request) + "\n" '
\n' footer() template filter (request): header("Filtering Preferences") '

Filter Bugs By...

\n' widgets = request.session.widgets gen_filter_widgets(request, widgets) # Render the first bunch of filtering widgets in a row. '''\
''' for name in ('component', 'bug_type', 'priority', 'status', 'resolution'): '\n' ' \n' '
component bug type priority status resolution
\n' widgets[name].render(request) '\n
\n' # And the last two filtering widgets (submitter and fixer) '''\ ''' '\n' % widgets['submitter_id'].render(request) '\n' % widgets['fixer_id'].render(request) ' \n' '
submitter fixer
\n%s\n\n%s\n
\n' # A little bit of explanatory text '''\ Nothing selected means allow all values, ie. don\'t filter on that variable..
''' SubmitButtonWidget("action", "filter").render(request) + "\n" SubmitButtonWidget("action", "set display prefs").render(request) + "\n" SubmitButtonWidget("action", "cancel").render(request) + "\n" '
\n' footer() def set_display (request): action = request.form.get("action") if action != "cancel": widgets = request.session.widgets prefs = request.session.prefs group = widgets['group'].parse(request) sort = widgets['sort'].parse(request) columns = widgets['select_columns'].parse(request) if group and sort and group == sort: raise QueryError("You can't group and sort on the same key") if group: prefs.set_group(group) if sort: prefs.set_sort(sort) if columns is not None: prefs.set_columns(columns) config = get_config() if action in ("display", "cancel"): # straight to bug index return request.redirect(config.get_base_url(absolute=0)) else: # go to set filter prefs first return request.redirect("%s/filter" % config.get_base_url(absolute=0)) def set_filter (request): action = request.form.get("action") if action != "cancel": widgets = request.session.widgets prefs = request.session.prefs for f in prefs.VALID_FILTERS: values = widgets[f].parse(request) if values: prefs.set_filter(f, values) else: prefs.set_filter(f, None) config = get_config() if action in ("filter", "cancel"): return request.redirect(config.get_base_url(absolute=0)) else: return request.redirect("%s/display" % config.get_base_url(absolute=0))