Skip to content

Version page should show build status + not being able to pick a non-built doc #5169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Empty file.
20 changes: 20 additions & 0 deletions readthedocs/builds/templatetags/builds_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

from django import template


register = template.Library()


@register.simple_tag
def is_latest_built_success(version):
"""
Checks the build status of the passed version.

Returns true if the latest build for the ``version``
is success else returns false. Returns None if no
build is found for the given version.
"""
res = version.builds.all().order_by('-date')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just fetch the success column from here, not the whole object

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
I have pushed the changes.

if res.exists():
return res.first().success
2 changes: 1 addition & 1 deletion readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def build_versions_form(project):
active = versions_qs.filter(active=True)
if active.exists():
active = sort_version_aware(active)
choices = [(version.slug, version.verbose_name) for version in active]
choices = [(version.slug, version.verbose_name) for version in active if version.built]
attrs['default-version'] = forms.ChoiceField(
label=_('Default Version'),
choices=choices,
Expand Down
11 changes: 11 additions & 0 deletions readthedocs/templates/core/project_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% load privacy_tags %}
{% load gravatar %}
{% load projects_tags %}
{% load builds_tags %}

<div id="project_details">
<div class="wrapper">
Expand Down Expand Up @@ -41,6 +42,16 @@ <h3>{% trans "Versions" %}</h3>
{% if request.user|is_admin:project %}
<ul class="module-item-menu">
<li><a href="{% url "project_version_detail" project.slug version.slug %}">{% trans "Edit" %}</a></li>
<li>
<span class="right quiet" style="margin:10px 5px 0px 0px;">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have inline styles

{% is_latest_built_success version as is_success %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use this model method: https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/projects/models.py#L882 -- it's likely much more efficient.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_latest_build returns the latest built of the project -- irrespective of the version.
We need the builds to be of specific version here.

{% if is_success %}
<span class="build-state build-state-passing">{% trans "passing" %}</span>
{% else %}
<span class="build-state build-state-failing" style="margin-left:14px">{% trans "failing" %}</span>
{% endif %}
</span>
<li>
</ul>
{% endif %}
</li>
Expand Down