Example #1
0
def project_versions(request, project_slug):
    """Project version list view

    Shows the available versions and lets the user choose which ones to build.
    """
    project = get_object_or_404(Project.objects.protected(request.user),
                                slug=project_slug)

    versions = Version.objects.public(user=request.user,
                                      project=project,
                                      only_active=False)
    active_versions = versions.filter(active=True)
    inactive_versions = versions.filter(active=False)
    inactive_filter = VersionSlugFilter(request.GET,
                                        queryset=inactive_versions)
    active_filter = VersionSlugFilter(request.GET, queryset=active_versions)

    # If there's a wiped query string, check the string against the versions
    # list and display a success message. Deleting directories doesn't know how
    # to fail.  :)
    wiped = request.GET.get('wipe', '')
    wiped_version = versions.filter(slug=wiped)
    if wiped and wiped_version.count():
        messages.success(request, 'Version wiped: ' + wiped)

    return render_to_response('projects/project_version_list.html', {
        'inactive_filter': inactive_filter,
        'active_filter': active_filter,
        'project': project,
    },
                              context_instance=RequestContext(request))
Example #2
0
    def get_context_data(self, **kwargs):
        context = super(ProjectDetailView, self).get_context_data(**kwargs)

        project = self.get_object()
        context['versions'] = Version.objects.public(user=self.request.user,
                                                     project=project)
        context['filter'] = VersionSlugFilter(self.request.GET,
                                              queryset=context['versions'])

        protocol = 'http'
        if self.request.is_secure():
            protocol = 'https'

        version_slug = project.get_default_version()

        context['badge_url'] = "%s://%s%s?version=%s" % (
            protocol,
            settings.PRODUCTION_DOMAIN,
            reverse('project_badge', args=[project.slug]),
            project.get_default_version(),
        )
        context['site_url'] = "{url}?badge={version}".format(
            url=project.get_docs_url(version_slug), version=version_slug)

        return context
Example #3
0
def version_filter_autocomplete(request, project_slug):
    queryset = Project.objects.public(request.user)
    project = get_object_or_404(queryset, slug=project_slug)
    versions = Version.objects.public(request.user)
    version_filter = VersionSlugFilter(request.GET, queryset=versions)
    resp_format = request.GET.get('format', 'json')

    if resp_format == 'json':
        names = version_filter.qs.values_list('slug', flat=True)
        json_response = json.dumps(list(names))
        return HttpResponse(json_response, content_type='text/javascript')
    elif resp_format == 'html':
        return render_to_response(
            'core/version_list.html',
            {
                'project': project,
                'versions': versions,
                'filter': version_filter,
            },
            context_instance=RequestContext(request),
        )
    else:
        return HttpResponse(status=400)