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

Commit

Permalink
Added method on the object that allows you to access to the underlyin…
Browse files Browse the repository at this point in the history
…g ArchivedURL object created by storytracker
  • Loading branch information
palewire committed Jul 28, 2014
1 parent 0ea61d6 commit c5fc4d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions urlarchivefield/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ def _get_archive_html(self):
return self.read()
archive_html = property(_get_archive_html)

def _get_archive_obj(self):
"""
Returns a storytracker object by rebuilding it out of the archive.
"""
return storytracker.ArchivedURL(
self.archive_url,
self.archive_timestamp,
self.archive_html
)
archive_obj = property(_get_archive_obj)


class URLArchiveFileDescriptor(FileDescriptor):
"""
Expand Down
11 changes: 11 additions & 0 deletions urlarchivefield/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import six
import shutil
import tempfile
import storytracker
from django.db import models
from datetime import datetime
from django.test import TestCase
Expand Down Expand Up @@ -45,6 +46,13 @@ def test_archive(self):
self.assertTrue(os.path.exists(obj.archive.path))
self.assertIsInstance(obj.archive.archive_url, six.string_types)
self.assertIsInstance(obj.archive.archive_timestamp, datetime)
self.assertIsInstance(
obj.archive.archive_obj, storytracker.ArchivedURL
)
self.assertEqual(
obj.archive.archive_html,
obj.archive.archive_obj.html
)
obj.archive.archive_html
obj.archive = self.url2
obj.save()
Expand All @@ -67,6 +75,9 @@ def test_long_url(self):
self.assertTrue(os.path.exists(obj.archive.path))
self.assertIsInstance(obj.archive.archive_url, six.string_types)
self.assertIsInstance(obj.archive.archive_timestamp, datetime)
self.assertIsInstance(
obj.archive.archive_obj, storytracker.ArchivedURL
)
obj.archive.archive_html

def test_compress(self):
Expand Down

0 comments on commit c5fc4d5

Please sign in to comment.