Skip to content

Commit

Permalink
Merge branch 'dev.552' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Phillips committed Jun 11, 2014
2 parents 04c7c4c + 20e513d commit 45a5e91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion perma_web/perma/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
url(r'^cdx$', 'common.cdx', name='cdx'),

# Our Perma ID catchall
url(r'^%s/?$' % guid_pattern, 'common.single_linky', name='single_linky'),
url(r'^%s/?$' % r'(?P<guid>.+)', 'common.single_linky', name='single_linky'),

)

Expand Down
11 changes: 9 additions & 2 deletions perma_web/perma/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.views.generic import TemplateView

from datetime import datetime
import urllib2, os, logging
import urllib2, os, logging, re
from urlparse import urlparse
from django.views.decorators.csrf import csrf_exempt
from pywb.warc.archiveindexer import ArchiveIndexer
Expand Down Expand Up @@ -124,10 +124,17 @@ def single_linky(request, guid):
"""

if request.method == 'POST' and request.user.is_authenticated():
Link.objects.filter(guid=guid).update(vested = True, vested_by_editor = request.user, vested_timestamp = datetime.now())
Link.objects.filter(guid=guid).update(vested = True,
vested_by_editor = request.user, vested_timestamp = datetime.now())

return HttpResponseRedirect(reverse('single_linky', args=[guid]))

# Replace all non-[a-zA-Z0-9] chars with a single hyphen
# We want to translate em-dashes, double hyphens and the like and redirect
if guid != re.sub('[^0-9a-zA-Z]+', '-', guid):
return HttpResponsePermanentRedirect(reverse('single_linky',
args=[re.sub('[^0-9a-zA-Z]+', '-', guid)]))

canonical_guid = Link.get_canonical_guid(guid)
if canonical_guid != guid:
return HttpResponsePermanentRedirect(reverse('single_linky', args=[canonical_guid]))
Expand Down

0 comments on commit 45a5e91

Please sign in to comment.