Skip to content
This repository has been archived by the owner on Dec 28, 2020. It is now read-only.

Commit

Permalink
Added timegate link header to the detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Dec 1, 2015
1 parent 6e8bd49 commit c7a7cb7
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions memento/timegate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class MementoDetailView(DetailView):
* A "Link" that includes the URL of the original resource as well
as the location of the TimeMap the publishes the directory of
all versions archived by your site.
all versions archived by your site and a TimeGate where a datetime
can be submitted to find the closest mementos for this resource.
The view should be subclassed and configured like any other DetailView
with a few extra options. They are:
Expand All @@ -40,6 +41,7 @@ class MementoDetailView(DetailView):
"""
datetime_field = 'datetime'
timemap_pattern_name = None
timegate_pattern_name = None

def get_timemap_url(self, request, url):
"""
Expand All @@ -54,6 +56,19 @@ def get_timemap_url(self, request, url):
request.is_secure(),
)

def get_timemap_url(self, request, url):
"""
Returns the location of the TimeGate where a datetime
can be submitted to find the closest mementos for this resource.
"""
path = reverse(self.timegate_pattern_name, kwargs={'url': url})
current_site = get_current_site(request)
return add_domain(
current_site.domain,
path,
request.is_secure(),
)

def get_original_url(self, obj):
raise NotImplementedError("get_original_url method not implemented")

Expand All @@ -68,10 +83,13 @@ def get(self, request, *args, **kwargs):
if self.timemap_pattern_name:
original_url = self.get_original_url(self.object)
timemap_url = self.get_timemap_url(self.request, original_url)
timegate_url = self.get_timegate_url(self.request, original_url)
response['Link'] = """<%(original_url)s>; rel="original", \
<%(timemap_url)s>; rel="timemap"; type="application/link-format\"""" % dict(
<%(timemap_url)s>; rel="timemap"; type="application/link-format" \
<%(timegate_url)s>; rel="timegate\"""" % dict(
original_url=urllib.unquote(original_url),
timemap_url=urllib.unquote(timemap_url)
timemap_url=urllib.unquote(timemap_url),
timegate_url=urllib.unquote(timegate_url),
)
return response

Expand Down

0 comments on commit c7a7cb7

Please sign in to comment.