Commit 8b0d72d4 authored by Louis's avatar Louis
Browse files

Add an `required` attribute to the Column class

parent 9b1beb71
Pipeline #7257 failed with stage
default:
gitlabci:
server: framagit.org
server: http://framagit.org
user: spalax
columns:
- color
......
default:
gitlabci:
server: framagit.org
server: http://framagit.org
user: spalax
columns:
- color
......
......@@ -39,6 +39,7 @@ class Column:
keyword = None
title = ""
default = {}
required = []
def __init__(self, renderer):
self.renderer = renderer
......@@ -51,6 +52,15 @@ class Column:
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:
if key not in filled:
missing.add(key)
if missing:
return self.render_error(context, self.keyword, package, "Missing argument(s) {}.".format(", ".join(["'{}'".format(key) for key in missing])))
return self.render(context, package, filled)
def render(self, context, package, column):
......
......@@ -8,17 +8,16 @@ class Empty(Column):
class Html(Column):
keyword = 'html'
default = {'html': ''}
required = ['html']
def render(self, context, package, column):
return column['html']
class Link(Jinja2):
keyword = 'link'
required = ['href']
def render(self, context, package, column):
if 'href' not in column:
return self.render_error(context, self.keyword, package, "Missing argument 'href'.")
if 'content' not in column:
column['content'] = column['href']
return super().render(context, package, column)
......
......@@ -10,5 +10,9 @@ class Gitlab(Jinja2):
class CI(Gitlab):
keyword = "gitlabci"
title = "CI"
title = "GitlabCI"
default = {
'server': 'http://gitlab.com',
}
required = ['user']
......@@ -4,3 +4,4 @@ from pypimonitor.column import Jinja2
class TravisCI(Jinja2):
keyword = "travisci"
required = ['user']
<a href="//{{ column.server }}/{{ column.user }}/{% if column.slug %}{{ column.slug }}{% else %}{{ package }}{% endif %}/builds">
<img src="//{{ column.server }}/{{ column.user }}/{% if column.slug %}{{ column.slug }}{% else %}{{ package }}{% endif %}/badges/master/build.svg" alt="Build">
<a href="{{ column.server }}/{{ column.user }}/{% if column.slug %}{{ column.slug }}{% else %}{{ package }}{% endif %}/builds">
<img src="{{ column.server }}/{{ column.user }}/{% if column.slug %}{{ column.slug }}{% else %}{{ package }}{% endif %}/badges/master/build.svg" alt="Build">
</a>
<a href="//{% if column.slug %}{{ column.slug }}{% else %}{{ package }}{% endif %}.readthedocs.io/{{ column.lang }}/{% if column.branch %}{{ column.branch }}{% endif %}">
<a href="//{% if column.slug %}{{ column.slug }}{% else %}{{ package }}{% endif %}.readthedocs.io/{% if column.branch %}{{ column.lang }}/{{ column.branch }}{% endif %}">
<img src="//readthedocs.org/projects/{% if column.slug %}{{ column.slug }}{% else %}{{ package }}{% endif %}/badge/{% if column.branch %}?version={{ column.branch }}{% endif %}" alt="Documentation">
</a>
<a href="//travis-ci.org/{{ user }}/{% if column.slug %}{{ column.slug }}{% else %}{{ package }}{% endif %}">
<img src="//api.travis-ci.org/{{ column.user }}/{% if column.slug %}{{ column.slug }}{% else %}{{ package }}{% endif %}.svg" alt="Travis build">
<a href="http://travis-ci.org/{{ column.user }}/{% if column.slug %}{{ column.slug }}{% else %}{{ package }}{% endif %}">
<img src="http://api.travis-ci.org/{{ column.user }}/{% if column.slug %}{{ column.slug }}{% else %}{{ package }}{% endif %}.svg" alt="Travis build">
</a>
Markdown is supported
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