Commit eba2634b authored by Louis's avatar Louis
Browse files

Better behaviour with non-existent columns

- Default values are set earlier, so that column type can be set in
  default valuers
- Columns keyword (in yaml file) can be a non-existent column (if so, it
  is used as the column title)
- Add a new Error column type
parent b0fec808
default:
gitlabci:
CI:
column: gitlabci
server: http://framagit.org
user: spalax
columns:
......@@ -10,7 +11,7 @@ columns:
- pypiwdownloads
- pypiddownloads
- readthedocs
- gitlabci
- CI
packages:
argdispatch:
cahier:
......@@ -26,7 +27,7 @@ packages:
mklog:
papersize:
patacrep:
gitlabci:
CI:
column: travisci
user: patacrep
pdfautonup:
......
......@@ -68,6 +68,10 @@ class Renderer:
for column in self.config['columns']:
if self.config['packages'][package].get(column, None) is None:
self.config['packages'][package][column] = {}
# Set default values
for key in self.config.get('default', {}):
if key not in self.config['packages'][package]:
self.config['packages'][package][key] = self.config['default'][key]
self.config['packages'][package][column]['column'] = self.config['packages'][package][column].get('column', column)
# Processing packages
......
......@@ -49,10 +49,8 @@ class Column:
@jinja2.contextfunction
def __call__(self, context, column, package):
filled = self.default.copy()
if ('default' in self.config) and (self.keyword in self.config['default']):
filled.update(self.config['default'][self.keyword])
filled.update(self.config['packages'][package].get(column, {}))
# Detecting missing parameters
missing = set()
for key in self.required:
......
......@@ -13,6 +13,17 @@ class Html(Column):
def render(self, context, package, column):
return column['html']
class Error(Column):
keyword = 'error'
def render(self, context, package, column):
return self.render_error(
context,
self.keyword,
package,
"Undefined column '{}'.".format(column['column']),
)
class Link(Jinja2):
keyword = 'link'
required = ['href']
......
......@@ -52,7 +52,13 @@
<table>
<thead><tr>
{% for column in config['columns'] -%}
<td>{{ columns[column].title }}</td>
<td>
{% if column in columns %}
{{ columns[column].title }}
{% else %}
{{ column }}
{% endif %}
</td>
{%- endfor %}
</tr></thead>
<tbody>
......@@ -60,7 +66,11 @@
<tr bgcolor="{{ package |color(0.1, 0.8) }}">
{% for column in config['columns'] -%}
<td>
{% if config['packages'][package][column]['column'] in columns %}
{{ columns[config['packages'][package][column]['column']](column, package) }}
{% else %}
{{ columns["error"](column, package) }}
{% endif %}
</td>
{%- endfor %}
</tr>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment