Skip to content

adding query string support to URL redirects #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
84d008d
adding support for querystring URLs
Sep 7, 2012
936d6ef
removing the versiontools package for now
Sep 7, 2012
4940f7b
travis CI settings file added
Sep 7, 2012
544b1d3
tox is now part of the develop requirements
Sep 7, 2012
b2aec02
Extended the length of the old and new url to 200 to match the length…
jezdez Jan 29, 2013
5f76aa8
Merge branch 'master' into max-length
jezdez Jan 29, 2013
e3880f4
Bumped to 0.1.3 and updated changelog.
jezdez Jan 29, 2013
0a92775
Merge pull request #1 from jezdez/max-length
Jan 29, 2013
6c2b851
Add Travis CI image to README
Jan 29, 2013
b6ab171
Improved the admin interface.
jezdez Feb 13, 2013
cfb8f86
Merge pull request #2 from jezdez/admin
Feb 14, 2013
fc88999
Bump dev version to 0.1.4
Feb 14, 2013
fcd280a
Allowed infinate URL lengths at the database level
saulshanabrook Feb 19, 2013
320bd8b
Forgot to add new files
saulshanabrook Feb 19, 2013
4d8a089
Replace manage.py with django-mini
Feb 25, 2013
2d61613
Update changelog
Feb 25, 2013
191733d
Switch to use mixin to track multiple URLs
Mar 11, 2013
7034d16
Add proper support for multiple URLs per model
Mar 17, 2013
b9bd3ff
Update tests to use nose
Mar 17, 2013
ccfdc72
Update travis build to run against multiple Django versions
Mar 17, 2013
3082c5f
Updated Readme to support new tracking mixin
saulshanabrook Mar 23, 2013
2cfbfdd
Optimized django queryset use
saulshanabrook Mar 23, 2013
79061d6
Changed to deal better with None values
saulshanabrook Mar 23, 2013
316eb98
Add minor change to updated docs
Mar 24, 2013
a17e03e
Remove unused variables
Mar 24, 2013
faa2028
Merge branch 'saulshanabrook-feature/query-optimizations'
Mar 24, 2013
ae0c17f
Clean up some typos
Mar 24, 2013
5777d9d
Merge branch 'saulshanabrook-fix/url-returns'
Mar 24, 2013
63b1028
Add coveralls to CI testing
Mar 24, 2013
2aaa7bc
Merge pull request #10 from elbaschid/feature/integrate_coverall
Mar 24, 2013
4e34925
Check for a blank old_url before creating delete
saulshanabrook Mar 25, 2013
3a091d8
Merge pull request #11 from saulshanabrook/patch-1
Mar 25, 2013
9a11840
Add myself to authors
saulshanabrook Mar 25, 2013
00018c3
Merge pull request #12 from saulshanabrook/patch-2
Mar 26, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
*.pot
*.py[co]

htmlcov/
.coverage
.coveralls.yml

dist/
htmlcov/
coverage/
django_url_tracker.egg-info/
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: python
python:
- "2.6"
- "2.7"
env:
- DJANGO_VERSION="1.3.7"
- DJANGO_VERSION="1.4.5"
- DJANGO_VERSION="1.5"
# command to install dependencies
install:
# NOTE: easy_install *will* downgrade if setup.py specifies a max version
# # This leads to seemingly passing tests
- easy_install Django==$DJANGO_VERSION
# command to run tests
script:
- make travis
after_script:
- coveralls
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
AUTHOR

* Sebastian Vetter (elbaschid)
* Sebastian Vetter (elbaschid)
* Saul Shanabrook (saulshanabrook)

CONTRIBUTORS
29 changes: 29 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=========
Changelog
=========

0.1.4
-----

* Changed URL record fields from ``CharField`` to ``TextField``
* Improved admin interface

0.1.3
-----

* Increased the max length of the old and new URL database fields to match
Django's redirects app (200).

0.1.2
-----

* The middleware now supports URLs that contain a query string and
redirect using 301 or 410 as with other URLs now. That means it
is possible to redirect ``/some/old/url/using.php?with=query&in=string``
to a shiny new URL.


0.1.1
-----

* Initial release of the package
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
include README.rst LICENSE AUTHORS *.rst
recursive-include tests *
include LICENSE AUTHORS *.rst
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
install:
python setup.py develop
pip install -r requirements.txt --use-mirrors

tests: install
python run_tests.py --with-specplugin

coverage: install
python run_tests.py --with-coverage --cover-package=url_tracker \
--with-specplugin --no-spec-color \
--cover-html --cover-html-dir=coverage

travis: coverage
coveralls

.PHONY: install tests travis coverage
30 changes: 27 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
django-url-tracker
==================

.. image:: https://travis-ci.org/elbaschid/django-url-tracker.png
:target: https://travis-ci.org/elbaschid/django-url-tracker

.. image:: https://coveralls.io/repos/elbaschid/django-url-tracker/badge.png?branch=master
:target: https://coveralls.io/r/elbaschid/django-url-tracker

The ``django-url-tracker`` is meant to be a easy-to-use addition to
a website to enhance its SEO. This might seem slightly pointless
as `Cool URIs don't change
Expand Down Expand Up @@ -95,13 +101,23 @@ the model::
def get_absolute_url(self):
return ('project-detail', (), {'slug': self.slug})

And now the missing link to actually start tracking URL changes is adding
the following command to the bottom of the class definition, or the file
for that matter::
And now the missing link to actually start tracking URL changes. Add the
``URLTrackingMixin`` to your model and add the following command to the
bottom of the class definition (or the file if you prefer that)::

import url_tracker

class Project(url_tracker.URLTrackingMixin, models.Model):
...

url_tracker.track_url_changes_for_model(Project)


To change which functions are called to tracks urls, add a
``url_tracking_methods`` attribute to the clast, which is a list of
method names to track. By default the the list contains
``get_absolute_url``.

You are done. If you go to the admin interface, create a new project
and then change its slug (which changes its URL) you will see a new
``URLChangeRecord`` reflecting the change. Opening the ``old_url`` should
Expand All @@ -120,4 +136,12 @@ Create a new branch for your feature::

git commit -b feature/whatever-you-like

Then make sure all the tests past (and write new ones for any new features)::

make tests

push the finished feature to github and open a pull request form the branch.

If you make a change to models.py that requires a database migration,
use ``django-mini.py -p --app url_tracker --app south schemamigration
url_tracker --auto`` to create a south migration.
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
argparse==1.2.1
coverage==3.5.2
mock==1.0b1
wsgiref==0.1.2
tox==1.4.2
django-mini==0.4
spec==0.10.0
django-nose==1.1
coveralls==0.1.1
7 changes: 4 additions & 3 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import logging
logging.disable(logging.CRITICAL)

from argparse import ArgumentParser
from argparse import ArgumentParser
from coverage import coverage

import tests.config
from django.test.simple import DjangoTestSuiteRunner
from django_nose import NoseTestSuiteRunner


def run_tests(verbosity, *test_args):
if not test_args:
test_args = ['url_tracker']
test_runner = DjangoTestSuiteRunner(verbosity=verbosity)
test_runner = NoseTestSuiteRunner(verbosity=verbosity)
num_failures = test_runner.run_tests(test_args)
if num_failures:
sys.exit(num_failures)
Expand All @@ -38,4 +38,5 @@ def run_tests(verbosity, *test_args):
c.html_report()
else:
print 'Running tests'
args += ['--with-specplugin', '-s', '-x']
run_tests(options.verbosity, *args)
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name = "django-url-tracker",
version = '0.1.1',
version = '0.1.4',
url = "https://github.com/tangentlabs/django-url-tracker",
author = "Sebastian Vetter",
author_email = "sebastian.vetter@tangentone.com.au",
Expand All @@ -22,7 +22,7 @@
packages = find_packages(exclude=["docs*", "tests*"]),
include_package_data = True,
install_requires=[
'django>=1.3.1',
'django>=1.3.1,<1.6',
'South>=0.7.3',
],
classifiers=[
Expand All @@ -38,5 +38,3 @@
],
keywords = "seo, django, framework",
)


40 changes: 40 additions & 0 deletions tests/functional_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django.test import TestCase

from url_tracker.models import URLChangeRecord


class TestUrlRecord(TestCase):

def test_returns_404_for_invalid_url(self):
response = self.client.get('/work/an-invalid-project/')
self.assertEquals(response.status_code, 404)

def test_returns_301_for_a_changed_url(self):
URLChangeRecord.objects.create(
old_url='/the/old-url/',
new_url='/the/new/url/',
)

response = self.client.get('/the/old-url/')
self.assertEquals(response.status_code, 301)
self.assertEquals(response['location'], 'http://testserver/the/new/url/')

def test_returns_410_for_a_deleted_url(self):
URLChangeRecord.objects.create(
old_url='/the/old-url/',
new_url='',
deleted=True
)

response = self.client.get('/the/old-url/')
self.assertEquals(response.status_code, 410)

def test_returns_301_for_a_changed_url_containing_querystring(self):
old_url = '/the/old-url/afile.php?q=test&another=45'
URLChangeRecord.objects.create(
old_url=old_url,
new_url='/the/new/url/',
)

response = self.client.get(old_url)
self.assertEquals(response.status_code, 301)
16 changes: 0 additions & 16 deletions tests/manage.py

This file was deleted.

Loading