Generic views

MementoDetailView

class MementoDetailView(DetailView)

Extends Django’s generic DetailView to describe an archived resource.

A set of extra headers is added to the response. They are:

  • The Memento-Datetime when the resource was archived.
  • 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 and a TimeGate where a datetime can be submitted to find the closest mementos for this resource.
datetime_field

A string attribute that is the name of the database field that contains the timestamp when the resource was archived. Default 'datetime'.

timemap_pattern_name

The name of the URL pattern for this site’s TimeMap that, given the original url, is able to reverse to return the location of the map that serves as the directory of all versions of this resource archived by your site. Optional.

timegate_pattern_name

The name of the URL pattern for this site’s TimeGate that, given the original url, is able to reverse to return the location of the url where a datetime can be submitted to find the closest mementos for this resource. Optional.

get_original_url()

A method that, given the object being rendered by the view, will return the original URL of the archived resource.

Example myapp/views.py

from memento.timegate import MementoDetailView


class ExampleMementoDetailView(MementoDetailView):
    """
    A Memento-enabled detail page for a screenshot in my example
    archive.

    It is linked to a url that looks like something like:

        url(
            r'^screenshot/(?P<pk>\d+)/$',
            views.ExampleMementoDetailView.as_view(),
            name='screenshot-detail'
        )

    """
    model = Screenshot
    datetime_field = 'timestamp'
    timemap_pattern_name = "timemap-screenshot"
    timegate_pattern_name = "timegate-screenshot"

    def get_original_url(self, obj):
        return obj.site.url

Example response

$ curl -X HEAD -i http://www.example.com/screenshot/100/
HTTP/1.1 200 OK
Server: Apache/2.2.22 (Ubuntu)
Link: <http://archivedsite.com/>; rel="original", <http://www.example.com/timemap/link/http://archivedsite.com/>; rel="timemap"; type="application/link-format", <http://www.example.com/timegate/http://archivedsite.com/>; rel="timegate"
Memento-Datetime: Fri, 1 May 2015 00:00:01 GMT

TimeGateView

class TimeGateView(RedirectView)

Creates a TimeGate that handles a request with a ‘Accept-Datetime’ headers and returns a response that redirects to the corresponding Memento.

model

A Django database model where the object will be drawn with a Model.objects.filter() query. Optional. If you want to provide a more specific list, define the queryset attribute instead.

queryset

The list of objects that will be provided to the template. Can be any iterable of items, not just a Django queryset. Optional, but if this attribute is not defined the model attribute must be defined.

datetime_field

A string attribute that is the name of the database field that contains the timestamp when the resource was archived. Default 'datetime'.

url_kwarg

The name for the keyword argument in the URL pattern that will be used to filter the queryset down to objects archived for the resource. Default 'url'.

url_field

A string attribute that is the name of the database field that contains the original URL archived. Defailt 'url'.

timemap_pattern_name

The name of the URL pattern for this site’s TimeMap that, given the original url, is able to reverse to return the location of the map that serves as the directory of all versions of this resource archived by your site. Optional.

Example myapp/views.py

from memento.timegate import TimeGateView


class ExampleTimeGateView(TimeGateView):
    """
    A Memento TimeGate that, given a timestamp, will redirect to the detail page for a screenshot in my example archive

    It is linked to a url that looks like something like:

        url(
            r'^timegate/(?P<url>.*)$',
            views.ExampleTimeGateView.as_view(),
            name="timegate"
        ),

    """
    model = Screenshot
    url_field = 'site__url' # You can walk across ForeignKeys like normal
    datetime_field = 'timestamp'
    timemap_pattern_name = "timemap-screenshot"

Example response

$ curl -X HEAD -i http://www.example.com/timegate/http://archivedsite.com/ --header "Accept-Datetime: Fri, 1 May 2015 00:01:00 GMT"
HTTP/1.1 302 Moved Temporarily
Server: Apache/2.2.22 (Ubuntu)
Link: <http://archivedsite.com/>; rel="original", <http://www.example.com/timemap/link/http://archivedsite.com/>; rel="timemap"; type="application/link-format"
Location: http://www.example.com/screenshot/100/
Vary: accept-datetime