diff --git a/readthedocs/builds/views.py b/readthedocs/builds/views.py index 30bc50ddd..4be37d268 100644 --- a/readthedocs/builds/views.py +++ b/readthedocs/builds/views.py @@ -6,11 +6,14 @@ import logging from django.shortcuts import get_object_or_404 from django.views.generic import ListView, DetailView -from django.http import HttpResponsePermanentRedirect +from django.http import HttpResponsePermanentRedirect, HttpResponseRedirect from django.conf import settings +from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse +from django.utils.decorators import method_decorator from readthedocs.builds.models import Build, Version +from readthedocs.core.utils import trigger_build from readthedocs.projects.models import Project from redis import Redis, ConnectionError @@ -33,7 +36,26 @@ class BuildBase(object): return queryset -class BuildList(BuildBase, ListView): +class BuildTriggerMixin(object): + + @method_decorator(login_required) + def post(self, request, project_slug): + project = get_object_or_404( + Project.objects.for_admin_user(self.request.user), + slug=project_slug + ) + version_slug = request.POST.get('version_slug') + version = get_object_or_404( + Version, + project=project, + slug=version_slug, + ) + + trigger_build(project=project, version=version) + return HttpResponseRedirect(reverse('builds_project_list', args=[project.slug])) + + +class BuildList(BuildBase, BuildTriggerMixin, ListView): def get_context_data(self, **kwargs): context = super(BuildList, self).get_context_data(**kwargs) diff --git a/readthedocs/projects/views/public.py b/readthedocs/projects/views/public.py index 86222dbd8..c976fb706 100644 --- a/readthedocs/projects/views/public.py +++ b/readthedocs/projects/views/public.py @@ -26,6 +26,7 @@ import requests from .base import ProjectOnboardMixin from readthedocs.builds.constants import LATEST from readthedocs.builds.models import Version +from readthedocs.builds.views import BuildTriggerMixin from readthedocs.projects.models import Project, ImportedFile from readthedocs.search.indexes import PageIndex from readthedocs.search.views import LOG_TEMPLATE @@ -67,7 +68,7 @@ class ProjectIndex(ListView): project_index = ProjectIndex.as_view() -class ProjectDetailView(ProjectOnboardMixin, DetailView): +class ProjectDetailView(BuildTriggerMixin, ProjectOnboardMixin, DetailView): """Display project onboard steps""" diff --git a/readthedocs/templates/builds/build_list.html b/readthedocs/templates/builds/build_list.html index 3b7797f9a..f58499692 100644 --- a/readthedocs/templates/builds/build_list.html +++ b/readthedocs/templates/builds/build_list.html @@ -40,7 +40,8 @@ {% if versions %}
-
+ + {% csrf_token %}
  • diff --git a/readthedocs/templates/core/project_details.html b/readthedocs/templates/core/project_details.html index 140251829..eafef9798 100644 --- a/readthedocs/templates/core/project_details.html +++ b/readthedocs/templates/core/project_details.html @@ -59,7 +59,8 @@

    {% trans "Build a version" %}

    - + + {% csrf_token %}