Skip to content

Commit

Permalink
Revert "Revert "Added ability for aliases to redirect to "highest ava…
Browse files Browse the repository at this point in the history
…ilable version" ""

This reverts commit 5453e91.
  • Loading branch information
ericholscher committed Mar 2, 2011
1 parent d56a502 commit 2a8f9df
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions pip_requirements.txt
Expand Up @@ -13,6 +13,7 @@ mercurial
bzr
github2
httplib2
distutils2
django-sentry
-e git+http://github.com/nathanborror/django-basic-apps.git#egg=basic
-e hg+http://bitbucket.org/andrewgodwin/south/#egg=south
Expand Down
3 changes: 2 additions & 1 deletion readthedocs/builds/models.py
Expand Up @@ -33,7 +33,8 @@ def get_absolute_url(self):
class VersionAlias(models.Model):
project = models.ForeignKey(Project, related_name='aliases')
from_slug = models.CharField(max_length=255, default='')
to_slug = models.CharField(max_length=255, default='')
to_slug = models.CharField(max_length=255, default='', blank=True)
largest = models.BooleanField(default=False)

def __unicode__(self):
return "Alias for %s: %s -> %s" % (self.project, self.from_slug, self.to_slug)
Expand Down
12 changes: 12 additions & 0 deletions readthedocs/projects/utils.py
Expand Up @@ -7,6 +7,7 @@
import re
import subprocess
import traceback
from distutils2.version import NormalizedVersion, suggest_normalized_version


def find_file(file):
Expand Down Expand Up @@ -92,3 +93,14 @@ def slugify_uniquely(model, initial, field, max_length, **filters):
current = '%s%s' % (slug[:-len(suffix)], suffix)
index += 1
return current

def mkversion(version_obj):
return NormalizedVersion(suggest_normalized_version(version_obj.slug))

def highest_version(version_list):
highest = [version_list[0], mkversion(version_list[0])]
for version in version_list:
ver = mkversion(version)
if ver > highest[1]:
highest = [version, ver]
return highest
7 changes: 5 additions & 2 deletions readthedocs/projects/views/public.py
Expand Up @@ -8,8 +8,9 @@
from django.views.generic.list_detail import object_list, object_detail
from django.views.static import serve

from projects.models import Project
from core.views import serve_docs
from projects.models import Project
from projects.utils import highest_version
from watching.models import PageView


Expand Down Expand Up @@ -177,8 +178,10 @@ def subdomain_handler(request, subdomain, filename):
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))
return HttpResponseRedirect('/en/%s/%s' %
(other_aliases[0].to_slug,
(highest_ver[0].slug,
'/'.join(split_filename[1:])))

valid_version = proj.versions.filter(slug=version)
Expand Down

0 comments on commit 2a8f9df

Please sign in to comment.