Created
November 14, 2011 12:35
-
-
Save uppfinnarjohnny/1363861 to your computer and use it in GitHub Desktop.
Django app for internal aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from alias.models import Alias | |
from django.contrib import admin | |
class AliasAdmin(admin.ModelAdmin): | |
list_display = ('path', 'target') | |
admin.site.register(Alias, AliasAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from alias.models import Alias | |
class AliasMiddleware(object): | |
def process_request(self, request): | |
try: | |
alias = Alias.objects.get(path=request.path) | |
request.path = alias.target | |
request.path_info = alias.target | |
except Alias.DoesNotExist: | |
pass | |
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Alias(models.Model): | |
path = models.CharField(max_length=255) | |
target = models.CharField(max_length=255) | |
def __unicode__(self): | |
return '%s -> %s' % (self.path, self.target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment