Download:
child 47:5633f9a8dc95
parent 45:d120981c4310
46:0f45e02848a1
Anton Shestakov <av6@dwimlabs.net>, Sun, 19 Jun 2016 16:22:28 +0800
models: add Project.get_title() method, use it, test it

5 файлов изменено, 22 вставок(+), 5 удалений(-) [+]
candolint/models.py file | annotate | diff | comparison | revisions
templates/check.html file | annotate | diff | comparison | revisions
templates/index.html file | annotate | diff | comparison | revisions
templates/project.html file | annotate | diff | comparison | revisions
tests/test_models.py file | annotate | diff | comparison | revisions
--- a/candolint/models.py Sun Jun 19 15:52:04 2016 +0800
+++ b/candolint/models.py Sun Jun 19 16:22:28 2016 +0800
@@ -46,6 +46,10 @@
user = self.user if self.user is not None else '-'
return '/{}/{}/{}'.format(self.domain, user, self.name)
+ def get_title(self):
+ owner = self.user if self.user is not None else self.domain
+ return '{}/{}'.format(owner, self.name)
+
class Change(BaseModel):
rev = pw.IntegerField()
--- a/templates/check.html Sun Jun 19 15:52:04 2016 +0800
+++ b/templates/check.html Sun Jun 19 16:22:28 2016 +0800
@@ -5,7 +5,7 @@
{% block content %}
<div class="uk-container uk-container-center uk-margin-large-top">
<h2>
- <a href="{{ project.get_url() }}">{{ project.name }}</a>:
+ <a href="{{ project.get_url() }}">{{ project.get_title() }}</a>:
check #{{ check.ordinal }}
</h2>
<p>
--- a/templates/index.html Sun Jun 19 15:52:04 2016 +0800
+++ b/templates/index.html Sun Jun 19 16:22:28 2016 +0800
@@ -13,7 +13,7 @@
<tr>
<td class="uk-text-nowrap">{% module Badges(check) %}</td>
<td><a href="{{ check.get_url() }}">#{{ check.ordinal }}</a></td>
- <td><a href="{{ project.get_url() }}">{{ project.name }}</a></td>
+ <td><a href="{{ project.get_url() }}">{{ project.get_title() }}</a></td>
<td>{{ change.rev }}:{{ change.node[:12] }} {{ change.branch }}</td>
<td>{% module Time(check.started) %}</td>
<td>{% module Time(check.finished) %}</td>
--- a/templates/project.html Sun Jun 19 15:52:04 2016 +0800
+++ b/templates/project.html Sun Jun 19 16:22:28 2016 +0800
@@ -1,10 +1,10 @@
{% extends "base.html" %}
-{% block title %}{{ project.name }}{% end %}
+{% block title %}{{ project.get_title() }}{% end %}
{% block content %}
<div class="uk-container uk-container-center uk-margin-large-top">
- <h2>{{ project.name }}</h2>
+ <h2><a href="{{ project.get_url() }}">{{ project.get_title() }}</a></h2>
<img src="{{ project.get_url() }}/status.svg" alt="Lint Status">
<dl class="uk-description-list-horizontal list-terse">
{% if checks %}
--- a/tests/test_models.py Sun Jun 19 15:52:04 2016 +0800
+++ b/tests/test_models.py Sun Jun 19 16:22:28 2016 +0800
@@ -1,6 +1,19 @@
from datetime import datetime, timedelta
-from candolint.models import Check
+from candolint.models import Project, Check
+
+
+def test_get_title():
+ project = Project()
+ project.domain = 'example.com'
+ project.user = 'alice'
+ project.name = 'hello-world'
+ assert project.get_title() == 'alice/hello-world'
+
+ project.domain = 'hello-world.com'
+ project.user = None
+ project.name = 'central'
+ assert project.get_title() == 'hello-world.com/central'
def test_duration():