Ejemplo n.º 1
0
 def version_compare(self, request, **kwargs):
     project = get_object_or_404(Project, slug=kwargs['project_slug'])
     highest = highest_version(project.versions.filter(active=True))
     base = kwargs.get('base', None)
     ret_val = {
         'project': highest[0],
         'version': highest[1],
         'is_highest': True,
     }
     if highest[0]:
         ret_val['url'] = highest[0].get_absolute_url()
         ret_val['slug'] = highest[0].slug,
     if base and base != 'latest':
         try:
             ver_obj = project.versions.get(slug=base)
             base_ver = mkversion(ver_obj)
             if base_ver:
                 # This is only place where is_highest can get set.  All
                 # error cases will be set to True, for non- standard
                 # versions.
                 ret_val['is_highest'] = base_ver >= highest[1]
             else:
                 ret_val['is_highest'] = True
         except (Version.DoesNotExist, TypeError):
             ret_val['is_highest'] = True
     return self.create_response(request, ret_val)
Ejemplo n.º 2
0
 def version_compare(self, request, **kwargs):
     project = get_object_or_404(Project, slug=kwargs['project_slug'])
     highest = highest_version(project.versions.filter(active=True))
     base = kwargs.get('base', None)
     ret_val = {
         'project': highest[0],
         'version': highest[1],
         'is_highest': True,
     }
     if highest[0]:
         ret_val['url'] = highest[0].get_absolute_url()
         ret_val['slug'] =  highest[0].slug,
     if base and base != 'latest':
         try:
             ver_obj = project.versions.get(slug=base)
             base_ver = mkversion(ver_obj)
             if base_ver:
                 #This is only place where is_highest can get set.
                 #All error cases will be set to True, for non-
                 #standard versions.
                 ret_val['is_highest'] = base_ver >= highest[1]
             else:
                 ret_val['is_highest'] = True
         except (Version.DoesNotExist, TypeError) as e:
             ret_val['is_highest'] = True
     return self.create_response(request, ret_val)
Ejemplo n.º 3
0
def subdomain_handler(request, subdomain, filename):
    """
    This provides the fall-back routing for subdomain requests.

    This was made primarily to redirect old subdomain's to their version'd brothers.
    """
    if not filename:
        filename = "index.html"
    split_filename = filename.split('/')
    #A correct URL, with a language and version.
    proj = get_object_or_404(Project, slug=subdomain)
    if len(split_filename) > 2:
        language = split_filename[0]
        version = split_filename[1]
        other_aliases = proj.aliases.filter(from_slug=version)
        if other_aliases.count():
            return HttpResponseRedirect('/en/%s/%s' %
                                        (other_aliases[0].to_slug,
                                         '/'.join(split_filename[1:])))

        other_projects = proj.versions.filter(slug=version).count()
        if not other_projects:
            other_projects = proj.versions.filter(slug=language).count()
            if other_projects:
                return HttpResponseRedirect('/en/%s/%s' %
                                            (language,
                                             '/'.join(split_filename[1:])))
        #Hard code this for now.
        if other_projects or version == 'latest' and language == 'en':
            version_slug = version
            filename = '/'.join(split_filename[2:])
            return serve_docs(request=request,
                              project_slug=subdomain,
                              lang_slug='en',
                              version_slug=version_slug,
                              filename=filename)
        else:
            raise Http404('No version matching query')
    elif len(split_filename) == 2:
        version = split_filename[0]
        other_aliases = proj.aliases.filter(from_slug=version)
        if other_aliases.count():
            if other_aliases[0].largest:
                highest_ver = highest_version(proj.versions.filter(slug__contains=version, active=True))
                version_slug = highest_ver[0].slug
            else:
                version_slug = other_aliases[0].to_slug
            return HttpResponseRedirect('/en/%s/%s' %
                                        (version_slug,
                                         '/'.join(split_filename[1:])))

        valid_version = proj.versions.filter(slug=version)
        if valid_version:
            return HttpResponseRedirect('/en/%s/%s' %
                                        (version,
                                         '/'.join(split_filename[1:])))

    default_version = proj.get_default_version()
    return HttpResponseRedirect('/en/%s/%s' % (default_version, filename))
Ejemplo n.º 4
0
def subdomain_handler(request, subdomain, filename):
    """
    This provides the fall-back routing for subdomain requests.

    This was made primarily to redirect old subdomain's to their version'd brothers.
    """
    if not filename:
        filename = "index.html"
    split_filename = filename.split('/')
    #A correct URL, with a language and version.
    proj = get_object_or_404(Project, slug=subdomain)
    if len(split_filename) > 2:
        language = split_filename[0]
        version = split_filename[1]
        other_aliases = proj.aliases.filter(from_slug=version)
        if other_aliases.count():
            return HttpResponseRedirect(
                '/en/%s/%s' %
                (other_aliases[0].to_slug, '/'.join(split_filename[1:])))

        other_projects = proj.versions.filter(slug=version).count()
        if not other_projects:
            other_projects = proj.versions.filter(slug=language).count()
            if other_projects:
                return HttpResponseRedirect(
                    '/en/%s/%s' % (language, '/'.join(split_filename[1:])))
        #Hard code this for now.
        if other_projects or version == 'latest' and language == 'en':
            version_slug = version
            filename = '/'.join(split_filename[2:])
            return serve_docs(request=request,
                              project_slug=subdomain,
                              lang_slug='en',
                              version_slug=version_slug,
                              filename=filename)
        else:
            raise Http404('No version matching query')
    elif len(split_filename) == 2:
        version = split_filename[0]
        other_aliases = proj.aliases.filter(from_slug=version)
        if other_aliases.count():
            if other_aliases[0].largest:
                highest_ver = highest_version(
                    proj.versions.filter(slug__contains=version, active=True))
                version_slug = highest_ver[0].slug
            else:
                version_slug = other_aliases[0].to_slug
            return HttpResponseRedirect(
                '/en/%s/%s' % (version_slug, '/'.join(split_filename[1:])))

        valid_version = proj.versions.filter(slug=version)
        if valid_version:
            return HttpResponseRedirect(
                '/en/%s/%s' % (version, '/'.join(split_filename[1:])))

    default_version = proj.get_default_version()
    return HttpResponseRedirect('/en/%s/%s' % (default_version, filename))
Ejemplo n.º 5
0
def subdomain_handler(request, lang_slug=None, version_slug=None, filename=''):
    """This provides the fall-back routing for subdomain requests.

    This was made primarily to redirect old subdomain's to their version'd
    brothers.

    """
    project = get_object_or_404(Project, slug=request.slug)
    # Don't add index.html for htmldir.
    if not filename and project.documentation_type != 'sphinx_htmldir':
        filename = "index.html"
    if version_slug is None:
        # Handle / on subdomain.
        default_version = project.get_default_version()
        url = reverse(serve_docs,
                      kwargs={
                          'version_slug': default_version,
                          'lang_slug': project.language,
                          'filename': filename
                      })
        return HttpResponseRedirect(url)
    if version_slug and lang_slug is None:
        # Handle /version/ on subdomain.
        aliases = project.aliases.filter(from_slug=version_slug)
        # Handle Aliases.
        if aliases.count():
            if aliases[0].largest:
                highest_ver = highest_version(
                    project.versions.filter(slug__contains=version_slug,
                                            active=True))
                version_slug = highest_ver[0].slug
            else:
                version_slug = aliases[0].to_slug
            url = reverse(serve_docs,
                          kwargs={
                              'version_slug': version_slug,
                              'lang_slug': project.language,
                              'filename': filename
                          })
        else:
            try:
                url = reverse(serve_docs,
                              kwargs={
                                  'version_slug': version_slug,
                                  'lang_slug': project.language,
                                  'filename': filename
                              })
            except NoReverseMatch:
                raise Http404
        return HttpResponseRedirect(url)
    # Serve normal docs
    return serve_docs(request=request,
                      project_slug=project.slug,
                      lang_slug=lang_slug,
                      version_slug=version_slug,
                      filename=filename)
Ejemplo n.º 6
0
def subdomain_handler(request, lang_slug=None, version_slug=None, filename=''):
    """This provides the fall-back routing for subdomain requests.

    This was made primarily to redirect old subdomain's to their version'd
    brothers.

    """
    project = get_object_or_404(Project, slug=request.slug)
    # Don't add index.html for htmldir.
    if not filename and project.documentation_type != 'sphinx_htmldir':
        filename = "index.html"
    if version_slug is None:
        # Handle / on subdomain.
        default_version = project.get_default_version()
        url = reverse(serve_docs, kwargs={
            'version_slug': default_version,
            'lang_slug': project.language,
            'filename': filename
        })
        return HttpResponseRedirect(url)
    if version_slug and lang_slug is None:
        # Handle /version/ on subdomain.
        aliases = project.aliases.filter(from_slug=version_slug)
        # Handle Aliases.
        if aliases.count():
            if aliases[0].largest:
                highest_ver = highest_version(project.versions.filter(
                    slug__contains=version_slug, active=True))
                version_slug = highest_ver[0].slug
            else:
                version_slug = aliases[0].to_slug
            url = reverse(serve_docs, kwargs={
                'version_slug': version_slug,
                'lang_slug': project.language,
                'filename': filename
            })
        else:
            try:
                url = reverse(serve_docs, kwargs={
                    'version_slug': version_slug,
                    'lang_slug': project.language,
                    'filename': filename
                })
            except NoReverseMatch:
                raise Http404
        return HttpResponseRedirect(url)
    # Serve normal docs
    return serve_docs(request=request,
                      project_slug=project.slug,
                      lang_slug=lang_slug,
                      version_slug=version_slug,
                      filename=filename)
Ejemplo n.º 7
0
 def version_compare(self, request, **kwargs):
     project = get_object_or_404(Project, slug=kwargs["project_slug"])
     highest = highest_version(project.versions.filter(active=True))
     base = kwargs.get("base", None)
     ret_val = {"project": highest[0], "version": highest[1]}
     if highest[0]:
         ret_val["url"] = highest[0].get_absolute_url()
     if base:
         try:
             ver_obj = project.versions.get(slug=base)
             base_ver = mkversion(ver_obj)
             if base_ver:
                 if base == "latest":
                     ret_val["is_highest"] = True
                 else:
                     ret_val["is_highest"] = base_ver >= highest[1]
             else:
                 ret_val["is_highest"] = False
         except Version.DoesNotExist:
             ret_val["is_highest"] = False
     return self.create_response(request, ret_val)
Ejemplo n.º 8
0
 def version_compare(self, request, **kwargs):
     project = get_object_or_404(Project, slug=kwargs["project_slug"])
     highest = highest_version(project.versions.filter(active=True))
     base = kwargs.get("base", None)
     ret_val = {"project": highest[0], "version": highest[1], "is_highest": True}
     if highest[0]:
         ret_val["url"] = highest[0].get_absolute_url()
         ret_val["slug"] = (highest[0].slug,)
     if base and base != "latest":
         try:
             ver_obj = project.versions.get(slug=base)
             base_ver = mkversion(ver_obj)
             if base_ver:
                 # This is only place where is_highest can get set.
                 # All error cases will be set to True, for non-
                 # standard versions.
                 ret_val["is_highest"] = base_ver >= highest[1]
             else:
                 ret_val["is_highest"] = True
         except (Version.DoesNotExist, TypeError) as e:
             ret_val["is_highest"] = True
     return self.create_response(request, ret_val)
Ejemplo n.º 9
0
 def version_compare(self, request, **kwargs):
     project = get_object_or_404(Project, slug=kwargs['project_slug'])
     highest = highest_version(project.versions.filter(active=True))
     base = kwargs.get('base', None)
     ret_val = {
         'project': highest[0],
         'version': highest[1],
     }
     if highest[0]:
         ret_val['url'] = highest[0].get_absolute_url()
     if base:
         try:
             ver_obj = project.versions.get(slug=base)
             base_ver = mkversion(ver_obj)
             if base_ver:
                 if base == "latest":
                     ret_val['is_highest'] = True
                 else:
                     ret_val['is_highest'] = base_ver >= highest[1]
             else:
                 ret_val['is_highest'] = False
         except Version.DoesNotExist:
             ret_val['is_highest'] = False
     return self.create_response(request, ret_val)