Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

frontend: migrate all templates to Jinja2 #377

Merged
merged 1 commit into from
Oct 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions squad/ci/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ def send_testjob_resubmit_admin_email(job_id, resubmitted_job_id):
}

text_message = render_to_string(
'squad/ci/testjob_resubmit.txt',
'squad/ci/testjob_resubmit.txt.jinja2',
context=context,
)
html_message = ''
html_message = render_to_string(
'squad/ci/testjob_resubmit.html',
'squad/ci/testjob_resubmit.html.jinja2',
context=context,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% load squad %}
<html>
<head>
<style type='text/css'>
Expand Down
7 changes: 2 additions & 5 deletions squad/ci/templatetags/filter_jobs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from django import template
from django.db.models import Count
from squad.jinja2 import register_filter


register = template.Library()


@register.filter
@register_filter
def filter_jobs(build):
filtered_jobs = build.test_jobs.values_list('job_status').annotate(Count('job_status'))
return filtered_jobs
2 changes: 1 addition & 1 deletion squad/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Custom401Middleware(object):
def process_exception(self, request, exception):
if isinstance(exception, PermissionDenied):
return render_to_response(
"401.html",
"401.jinja2",
{'request': request},
status=401)
return None
9 changes: 6 additions & 3 deletions squad/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ def __init__(self, *args, **kwargs):
@property
def status(self):
if not self.__status__:
self.__status__ = ProjectStatus.objects.filter(
build__project=self
).latest('created_at')
try:
self.__status__ = ProjectStatus.objects.filter(
build__project=self
).latest('created_at')
except ProjectStatus.DoesNotExist:
pass
return self.__status__

def accessible_to(self, user):
Expand Down
9 changes: 4 additions & 5 deletions squad/core/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,14 @@ def message(self, do_html=True, custom_email_template=None):
html_message = html_template.render(context)
else:
text_message = render_to_string(
'squad/notification/diff.txt',
'squad/notification/diff.txt.jinja2',
context=context,
)
if do_html:
html_message = render_to_string(
'squad/notification/diff.html',
'squad/notification/diff.html.jinja2',
context=context,
)

return (text_message, html_message)

def send(self):
Expand Down Expand Up @@ -171,14 +170,14 @@ def subject(self):
def message(self, do_html=True, custom_email_template=None):
txt, html = super(PreviewNotification, self).message(do_html, custom_email_template)
txt_banner = render_to_string(
'squad/notification/moderation.txt',
'squad/notification/moderation.txt.jinja2',
{
"settings": settings,
"status": self.status,
}
)
html_banner = render_to_string(
'squad/notification/moderation.html',
'squad/notification/moderation.html.jinja2',
{
"settings": settings,
"status": self.status,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "squad/notification/base.html" %}
{% load squad %}
{% extends "squad/notification/base.jinja2" %}
{% block content %}
<h1>Summary</h1>
<div class='row'><div class='col-3 key'>Tests: </div> <div class='col-9'>{{summary.tests_total}} </div></div>
Expand All @@ -9,7 +8,7 @@ <h1>Summary</h1>
<div class='row'><div class='col-3 key'>Build: </div> <div class='col-9'>{{build.version}} </div></div>
<div class='row'><div class='col-12 key'> <a href="{{settings.BASE_URL}}/{{build.project}}/build/{{build.version}}">See details</a> </div></div>
{% if important_metadata %}
{% for key, value in important_metadata.items %}
{% for key, value in important_metadata.items() %}
<div class='row'>
<div class='col-3 key'>{{key}}</div>
<div class='col-9'>{{value|metadata_value|urlize}}</div>
Expand All @@ -21,7 +20,7 @@ <h1>Summary</h1>
<h1>Regressions{%if previous_build %} (compared to build {{previous_build.version}}){% endif %}</h1>
{% if regressions %}
<ul>
{% for env, tests in regressions.items %}
{% for env, tests in regressions.items() %}
<li><strong>{{env}}:</strong>
<ul>
{% for test in tests %}
Expand All @@ -39,7 +38,7 @@ <h1>Regressions{%if previous_build %} (compared to build {{previous_build.versio
<h1>Failures</h1>
{% if summary.failures %}
<ul>
{% for env, tests in summary.failures.items %}
{% for env, tests in summary.failures.items() %}
<li>
<strong>{{env}}:</strong>
<ul>
Expand All @@ -51,7 +50,7 @@ <h1>Failures</h1>
{% endif %}
{% for issue in known_issues %}
{% if issue.test_name == test.full_name %}
{% for issue_environment in issue.environment.all %}
{% for issue_environment in issue.environment.all() %}
{% if env == issue_environment.slug %}
<br/>
Known issue:
Expand Down Expand Up @@ -98,12 +97,12 @@ <h1>All changes detected{%if previous_build %} (compared to build {{previous_bui
{% endfor %}
{% endfor %}
</tr>
{% for test, results in comparison.diff.items %}
{% for test, results in comparison.diff.items() %}
<tr>
<th>{{test}}</th>
{% for environment in comparison.all_environments %}
{% for build in comparison.builds %}
{% with result=results|test_result_by_build:build|test_result_by_env:environment %}
{% with result=results.get((build, environment)) %}
<td class='{{result}}'>
{% if result %}
<strong>{{result}}</strong>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{% load squad_notification %}
Tests: {{summary.tests_total}}
Failed: {{summary.tests_fail}}
Passed: {{summary.tests_pass}}
Skipped: {{summary.tests_skip}}
Build: {{build.version}}
Details: {{settings.BASE_URL}}/{{build.project}}/build/{{build.version}}

{% for key, value in important_metadata.items %}{{key}}: {{value|metadata_txt:key}}
{% for key, value in important_metadata.items() %}{{key}}: {{value|metadata_txt(key)}}
{% endfor %}

Regressions{%if previous_build %} (compared to build {{previous_build.version}}){% endif %}
------------------------------------------------------------------------
{% if regressions %}
{% for env, tests in regressions.items %}{{env}}:
{% for env, tests in regressions.items() %}{{env}}:
{% for test in tests %}
* {{test}}{% endfor %}
{% endfor %}
Expand All @@ -23,7 +22,7 @@ Regressions{%if previous_build %} (compared to build {{previous_build.version}})
Failures
------------------------------------------------------------------------
{% if summary.failures %}
{% for env, tests in summary.failures.items %}{{env}}:
{% for env, tests in summary.failures.items() %}{{env}}:
{% for test in tests %}
* {{test.full_name}}{% for issue in known_issues %}{% if issue.test_name == test.full_name %}{% for issue_environment in issue.environment.all %}{% if env == issue_environment.slug %}
* Known issue: {{issue.title}}{% if issue.url %} {{issue.url}}{% endif %}{% if issue.intermittent %} (intermittent){% endif %}{% endif %}{% endfor %}{% endif %}{% endfor %}{% endfor %}
Expand All @@ -35,7 +34,7 @@ Failures
All changes{%if previous_build %} (compared to build {{previous_build.version}}){% endif %}
------------------------------------------------------------------------
{% if previous_build %}
{% tabulate_test_comparison notification.comparison notification.comparison.diff %}
{{tabulate_test_comparison(notification.comparison, notification.comparison.diff)}}
{% else %}
(none)
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "squad/notification/base.html" %}
{% extends "squad/notification/base.jinja2" %}

{% block content %}
<h1>Build information</h1>
Expand Down
9 changes: 3 additions & 6 deletions squad/core/templatetags/squad_notification.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from django import template
from squad.core.utils import format_metadata
from squad.jinja2 import register_global_function, register_filter


register = template.Library()


@register.simple_tag
@register_global_function
def tabulate_test_comparison(comparison, test_results=None):
if test_results is None:
test_results = comparison.results
Expand Down Expand Up @@ -38,7 +35,7 @@ def tabulate_test_comparison(comparison, test_results=None):
return "\n".join(text)


@register.filter
@register_filter
def metadata_txt(v, key=None):
separator = " "
if key:
Expand Down
2 changes: 1 addition & 1 deletion squad/frontend/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def testjobs(request, group_slug, project_slug, build_version):
"testjobs": testjobs,
}

return render(request, 'squad/testjobs.html', context)
return render(request, 'squad/testjobs.jinja2', context)
4 changes: 2 additions & 2 deletions squad/frontend/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def compare_projects(request):
'comparison': comparison,
}

return render(request, 'squad/compare_projects.html', context)
return render(request, 'squad/compare_projects.jinja2', context)


def compare_test(request):

context = {}
return render(request, 'squad/compare.html', context)
return render(request, 'squad/compare.jinja2', context)
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "squad/base.html" %}
{% load squad %}
{% extends "squad/base.jinja2" %}

{% block content %}
<h1>Authentication needed!</h1>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "squad/base.html" %}
{% load squad %}
{% extends "squad/base.jinja2" %}

{% block content %}
<h1>Page not found!<h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load static %}
{% load squad %}

{% block title %}{% site_name %} API{% endblock %}
{% block title %}{% squad_site_name %} API{% endblock %}

{% block bootstrap_theme %}
<link rel="stylesheet" href="{% static "bootstrap/css/bootstrap.css" %}">
Expand All @@ -15,7 +15,7 @@
{% block branding %}
<a class='navbar-brand' rel="nofollow" href='{% url "home" %}'>
<span class="fa fa-line-chart" aria-hidden="true"></span>
{% site_name %}
{% squad_site_name %}
</a>
<ul class="nav navbar-nav">
<li class="{% active 'home'%}"><a href="{% url 'home' %}">Explore</a></li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{# keep this file sync'ed with 'squad/frontend/templates/squad/_user_menu.jinja2' #}

{% load squad %}

{% if user.is_authenticated %}
<li>
<a class="dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{% load humanize %}
{% load squad %}
<div class='highlight-row'>
{% for status in statuses %}
{% with build=status.build %}
<a href="{% build_url build %}">
<a href="{{build_url(build)}}">
<div class="row row-bordered build">
<div class="col-md-2 col-sm-2">
{% include "squad/_unfinished_build.html" %}
{% include "squad/_regressions_and_fixes.html" %}
{% include "squad/_unfinished_build.jinja2" %}
{% include "squad/_regressions_and_fixes.jinja2" %}
<strong>
{{build.version}}
</strong>
Expand Down Expand Up @@ -47,7 +45,7 @@
{% if status.has_metrics %}
<div title='Metrics summary'>
<i class='fa fa-line-chart'></i>
{{status.metrics_summary|floatformat:3}}
{{status.metrics_summary|floatformat(3)}}
</div>
{% endif %}
</div>
Expand All @@ -59,7 +57,7 @@
</div>
<div>
<i class='fa fa-clock-o' style='color: transparent'>&nbsp;</i>
{{status.last_updated}}
{{status.last_updated|date}}
</div>
{% endif %}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% load squad %}
<div class='metadata'>
{% for key, value in metadata %}
<div class='row row-bordered'>
Expand All @@ -11,6 +10,6 @@
</div>
{% endfor %}
{% if has_extra_metadata %}
<a class='extra-metadata-button' href='{% url "build_metadata" project.group.slug project.slug build.version %}'><small><i class='fa fa-plus'></i> Display more</small></a>
<a class='extra-metadata-button' href='{{url("build_metadata", args=[project.group.slug, project.slug, build.version])}}'><small><i class='fa fa-plus'></i> Display more</small></a>
{% endif %}
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% load squad %}
{% if items.paginator.num_pages > 1 %}
<nav aria-label="Page navigation">
<ul class="pagination">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
{% load humanize %}
{% load squad %}

<div class='highlight-row'>
{% for project in projects %}
<div class="row row-bordered project">
{% with status=project.status %}
<a href="{% project_url project %}">
<a href="{{project_url(project)}}">
<div class="col-md-4 col-sm-4">
<strong>
{% if not hide_group %}{{project.group.name}}/{% endif %}{{project.name}}
</strong>
{% if project.description%}
<div class='description-{{project.id}}'>
{{project.description|urlize|truncatechars_html:50}}
{{project.description|urlize|truncatechars_html(50)}}
{% if project.description|length > 50 %}
<a class='toggle-description' style='cursor: pointer' onclick='$(".description-{{project.id}}").toggle(); return false'>»</a>
{% endif %}
Expand All @@ -39,7 +36,7 @@
{% if status.has_metrics %}
<div title='Metrics summary'>
<i class='fa fa-line-chart'></i>
{{status.metrics_summary|floatformat:3}}
{{status.metrics_summary|floatformat(3)}}
</div>
{% endif %}
</div>
Expand All @@ -51,7 +48,7 @@
</div>
<div>
<i class='fa fa-clock-o' style='color: transparent'>&nbsp;</i>
{{status.last_updated}}
{{status.last_updated|date}}
</div>
{% endif %}
</div>
Expand Down
Loading