Permalink
Browse files

cleaned out inline copy of django-revisions; added license headers

  • Loading branch information...
1 parent 11c69dd commit ea490e9092ed9454d0b1cdb7d249a17d5eed760f @trey0 trey0 committed Apr 30, 2011
Showing with 83 additions and 1,594 deletions.
  1. +5 −5 README.rst
  2. +5 −5 doc_src/getting_started.rst
  3. +5 −5 doc_src/index.rst
  4. +5 −5 doc_src/installation.rst
  5. +5 −5 doc_src/reference/index.rst
  6. +5 −5 doc_src/reference/settings.rst
  7. 0 example/manage.py
  8. +6 −0 geocamMemo/authentication_example.py
  9. +6 −0 geocamMemo/management/commands/randommemo.py
  10. +6 −0 geocamMemo/media/geocamMemo/js/jquery-1.5.min.js
  11. +5 −0 geocamMemo/tests/__init__.py
  12. +1 −1 geocamMemo/urls.py
  13. +6 −0 geocamTalk/management/commands/randomtalk.py
  14. +6 −6 geocamTalk/models.py
  15. +5 −0 geocamTalk/tests/__init__.py
  16. +6 −6 geocamTalk/tests/unit.py
  17. +6 −6 geocamTalk/views.py
  18. +0 −6 revisions/__init__.py
  19. +0 −57 revisions/admin.py
  20. +0 −17 revisions/fields.py
  21. +0 −89 revisions/managers.py
  22. +0 −31 revisions/middleware.py
  23. +0 −298 revisions/models.py
  24. +0 −35 revisions/shortcuts.py
  25. +0 −1 revisions/tests/__init__.py
  26. +0 −19 revisions/tests/admin.py
  27. +0 −80 revisions/tests/fixtures/asides_scenario.json
  28. +0 −37 revisions/tests/fixtures/basemodel_fancy_revisions_scenario.json
  29. +0 −52 revisions/tests/fixtures/basemodel_revisions_scenario.json
  30. +0 −37 revisions/tests/fixtures/fancy_revisions_scenario.json
  31. +0 −37 revisions/tests/fixtures/fancy_trashable_scenario.json
  32. +0 −52 revisions/tests/fixtures/revisions_scenario.json
  33. +0 −35 revisions/tests/fixtures/trashable_scenario.json
  34. +0 −38 revisions/tests/fixtures/users.json
  35. +0 −52 revisions/tests/fixtures/uuidmodel_revisions_scenario.json
  36. +0 −139 revisions/tests/models.py
  37. +0 −375 revisions/tests/tests.py
  38. +0 −11 revisions/tests/urls.py
  39. +0 −34 revisions/utils.py
  40. +0 −13 revisions/views.py
View
@@ -74,8 +74,8 @@ Testing can be initiated from your ./geocamMemoWeb/example path using the test c
See the Django documentation for more information on using manage.py
-| __BEGIN_LICENSE__
-| Copyright (C) 2008-2010 United States Government as represented by
-| the Administrator of the National Aeronautics and Space Administration.
-| All Rights Reserved.
-| __END_LICENSE__
+.. o __BEGIN_LICENSE__
+.. o Copyright (C) 2008-2010 United States Government as represented by
+.. o the Administrator of the National Aeronautics and Space Administration.
+.. o All Rights Reserved.
+.. o __END_LICENSE__
@@ -2,8 +2,8 @@
Getting Started
===============
-| __BEGIN_LICENSE__
-| Copyright (C) 2008-2010 United States Government as represented by
-| the Administrator of the National Aeronautics and Space Administration.
-| All Rights Reserved.
-| __END_LICENSE__
+.. o __BEGIN_LICENSE__
+.. o Copyright (C) 2008-2010 United States Government as represented by
+.. o the Administrator of the National Aeronautics and Space Administration.
+.. o All Rights Reserved.
+.. o __END_LICENSE__
View
@@ -20,8 +20,8 @@ Indices and tables
* :ref:`modindex`
* :ref:`search`
-| __BEGIN_LICENSE__
-| Copyright (C) 2008-2010 United States Government as represented by
-| the Administrator of the National Aeronautics and Space Administration.
-| All Rights Reserved.
-| __END_LICENSE__
+.. o __BEGIN_LICENSE__
+.. o Copyright (C) 2008-2010 United States Government as represented by
+.. o the Administrator of the National Aeronautics and Space Administration.
+.. o All Rights Reserved.
+.. o __END_LICENSE__
View
@@ -16,8 +16,8 @@ or
Dependencies
************
-| __BEGIN_LICENSE__
-| Copyright (C) 2008-2010 United States Government as represented by
-| the Administrator of the National Aeronautics and Space Administration.
-| All Rights Reserved.
-| __END_LICENSE__
+.. o __BEGIN_LICENSE__
+.. o Copyright (C) 2008-2010 United States Government as represented by
+.. o the Administrator of the National Aeronautics and Space Administration.
+.. o All Rights Reserved.
+.. o __END_LICENSE__
@@ -11,8 +11,8 @@ Reference
settings
-| __BEGIN_LICENSE__
-| Copyright (C) 2008-2010 United States Government as represented by
-| the Administrator of the National Aeronautics and Space Administration.
-| All Rights Reserved.
-| __END_LICENSE__
+.. o __BEGIN_LICENSE__
+.. o Copyright (C) 2008-2010 United States Government as represented by
+.. o the Administrator of the National Aeronautics and Space Administration.
+.. o All Rights Reserved.
+.. o __END_LICENSE__
@@ -2,8 +2,8 @@
Settings
========
-| __BEGIN_LICENSE__
-| Copyright (C) 2008-2010 United States Government as represented by
-| the Administrator of the National Aeronautics and Space Administration.
-| All Rights Reserved.
-| __END_LICENSE__
+.. o __BEGIN_LICENSE__
+.. o Copyright (C) 2008-2010 United States Government as represented by
+.. o the Administrator of the National Aeronautics and Space Administration.
+.. o All Rights Reserved.
+.. o __END_LICENSE__
View
0 example/manage.py 100644 → 100755
No changes.
@@ -1,3 +1,9 @@
+# __BEGIN_LICENSE__
+# Copyright (C) 2008-2010 United States Government as represented by
+# the Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+# __END_LICENSE__
+
GOOGLE_TOKEN = "blahblahblah" #copy paste your token
#SID=DQAAAK4AAABnT14QB__UrAs3MtBH-6jBOPl4jMtBEZNPvneo7wAClyUmgQCSm-_CIcjBGuQxRxWNKY1S4fC17lZbGhObYVmHPT9LnHXCiqwX8WSr2mK-sFSt0k9HSVBeelAlgEWmttPcatEVOJc_Y5v_7Kj9vg4vIPA2CY6UdJkbMW0w2F5r-xSbVH5v5UUw-wnKb-PSPhLIru9DRJIqbBQ_yz4DB6d3vJ7Z-VNrhibGm49XGoV85Q
@@ -1,3 +1,9 @@
+# __BEGIN_LICENSE__
+# Copyright (C) 2008-2010 United States Government as represented by
+# the Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+# __END_LICENSE__
+
from django.core.management.base import BaseCommand, CommandError
from geocamMemo.models import MemoMessage
from django.contrib.auth.models import User

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,3 +1,8 @@
+# __BEGIN_LICENSE__
+# Copyright (C) 2008-2010 United States Government as represented by
+# the Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+# __END_LICENSE__
from geocamMemo.tests.unit import *
from geocamMemo.tests.views import *
View
@@ -1,4 +1,4 @@
-'edit_message'# __BEGIN_LICENSE__
+# __BEGIN_LICENSE__
# Copyright (C) 2008-2010 United States Government as represented by
# the Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
@@ -1,3 +1,9 @@
+# __BEGIN_LICENSE__
+# Copyright (C) 2008-2010 United States Government as represented by
+# the Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+# __END_LICENSE__
+
from django.core.management.base import BaseCommand, CommandError
from geocamTalk.models import TalkMessage
from django.contrib.auth.models import User
View
@@ -1,9 +1,9 @@
-# __BEGIN_LICENSE__
-# Copyright (C) 2008-2010 United States Government as represented by
-# the Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-# __END_LICENSE__
-
+# __BEGIN_LICENSE__
+# Copyright (C) 2008-2010 United States Government as represented by
+# the Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+# __END_LICENSE__
+
from django.db import models
from geocamMemo.models import GeocamMessage, get_user_string
from django.contrib.auth.models import User
@@ -1,3 +1,8 @@
+# __BEGIN_LICENSE__
+# Copyright (C) 2008-2010 United States Government as represented by
+# the Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+# __END_LICENSE__
from geocamTalk.tests.unit import *
from geocamTalk.tests.views import *
View
@@ -1,9 +1,9 @@
-# __BEGIN_LICENSE__
-# Copyright (C) 2008-2010 United States Government as represented by
-# the Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-# __END_LICENSE__
-
+# __BEGIN_LICENSE__
+# Copyright (C) 2008-2010 United States Government as represented by
+# the Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+# __END_LICENSE__
+
from django.test import TestCase
from django.contrib.auth.models import User
from datetime import datetime
View
@@ -1,9 +1,9 @@
-# __BEGIN_LICENSE__
-# Copyright (C) 2008-2010 United States Government as represented by
-# the Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-# __END_LICENSE__
-
+# __BEGIN_LICENSE__
+# Copyright (C) 2008-2010 United States Government as represented by
+# the Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+# __END_LICENSE__
+
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404, \
HttpResponseBadRequest
View
@@ -1,6 +0,0 @@
-# encoding: utf-8
-
-VERSION = (0, 5, 0)
-
-import models
-import shortcuts
View
@@ -1,57 +0,0 @@
-# encoding: utf-8
-
-"""
-To make sure ``django-versioning`` works smoothly with the admin interface, you should add ``revisions.middleware.VersionedModelRedirectMiddleware`` to your middlewares in ``settings.py``, e.g.::
-
- MIDDLEWARE_CLASSES = (
- 'django.middleware.common.CommonMiddleware',
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'revisions.middleware.VersionedModelRedirectMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- )
-
-To enable versioning in the admin, subclass from revisions.admin.VersionedAdmin instead of from django.admin.ModelAdmin. By default, this class has ``revisions.admin.AutoRevisionForm`` as its form, but you're not tied to this ModelForm:
-
-* AutoRevisionForm makes sure to clear any revision-specific fields, like log messages. Since these are tied to each individual revision, revision-specific fields should be empty upon each new edit.
-* RevisionForm inherits from AutoRevisionForm, but adds a checkbox to the form that allows users to specify they only want to make a small change, and that we ought to save it in-place rather than creating a new revision.
-* If you need neither, feel free to use a regular ModelForm instead.
-
-Specify fields that need to be cleared as a list of attribute names like so::
-
- class MyModel(VersionedModel):
- class Versioning:
- clear_each_revision = ['log_message', 'codename', ]
-
-When in doubt, don't specify your own form and stick to the default: the AutoRevisionForm.
-"""
-
-from django.contrib import admin
-from revisions.managers import LatestManager
-from django import forms
-
-class AutoRevisionForm(forms.ModelForm):
- def __init__(self, *args, **kwargs):
- super(AutoRevisionForm, self).__init__(*args, **kwargs)
-
- for field in self.instance.Versioning.clear_each_revision:
- self.initial[field] = ''
-
-class RevisionForm(AutoRevisionForm):
- small_change = forms.BooleanField(initial=False,
- help_text="Fixed a typo, changed a couple of words. (Doesn't create a new revision)",
- required=False)
-
- def clean(self):
- self.instance.is_small_change = self.cleaned_data.get('small_change', False)
- del self.fields['small_change']
- del self.cleaned_data['small_change']
- return self.cleaned_data
-
-class VersionedAdmin(admin.ModelAdmin):
- form = AutoRevisionForm
-
- def save_model(self, request, obj, form, change):
- """
- Given a model instance save it to the database.
- """
- obj.revise()
View
@@ -1,17 +0,0 @@
-# encoding: utf-8
-
-from django.db import models
-
-"""
-1. Shouldn't trigger a django.core.management.validation error (which is tricky because it
- doesn't check if the field is actually a regular ForeignKey, it just checks if it has a
- ``rel`` attribute.
-2. Shouldn't add a true FK to databases that support it (that is, anything other than MySQL
- and SQLite), but treat the foreign key as a regular integerfield/charfield that just
- happens to be a reference.
-"""
-
-# a pseudo-foreign key that supports referencing either the bundle or the individual revision
-class ForeignKey(models.ForeignKey):
- def __init__(self):
- raise NotImplementedError()
View
@@ -1,89 +0,0 @@
-# encoding: utf-8
-
-from datetime import datetime
-from django.db import models
-import inspect
-
-
-def get_table_for_field(model, field_name):
- for field in model._meta.fields:
- if field_name == field.attname:
- return field.model._meta.db_table
- return None
-
-
-class LatestQuerySet(models.query.QuerySet):
- # not too nice performance-wise, but the easiest solution
- # to make counts play nice with revisions
- def count(self):
- return len(list(self.iterator()))
-
-
-class LatestManager(models.Manager):
- """ A manager that returns the latest revision of each bundle of content. """
- # use_for_related_fields makes sure this manager works
- # seamlessly with inline formsets
- use_for_related_fields = True
-
- @property
- def current(self):
- qs = LatestQuerySet(self.model, using=self._db)
-
- # in case of concrete inheritance, we need the base table, not the leaf
- base = qs.query.model.get_base_model()
- base_table = base._meta.db_table
-
- # this may or may not be the fastest way to get the last revision of every
- # piece of content, depending on how your database query optimizer works,
- # but it sure as hell is the easiest way to do it in Django without resorting
- # to multiple queries or working entirely with raw SQL.
- comparator_name = base.get_comparator_name()
- comparator_table = get_table_for_field(qs.query.model, comparator_name)
- where = '{comparator_table}.{comparator} = (SELECT MAX({comparator}) FROM {table} as sub WHERE {table}.cid = sub.cid)'.format(
- table=base_table,
- comparator=comparator_name,
- comparator_table=comparator_table)
-
- qs = qs.extra(where=[where])
- return qs
-
- def get_query_set(self):
- # Django uses the default manager (which on versioned models is this one)
- # to determine what to do when it saves a model instance. Because older
- # revisions aren't included in the queryset for LatestManager, when trying
- # to update such an older revision, the ORM gets confused and tries to insert
- # a new record, or, when you pass force_update=True, Django complains that it
- # couldn't find the right row to update.
- #
- # Specifically, you either get an IntegrityError saying "PRIMARY KEY must be unique"
- # or a DatabaseError saying "Forced update did not affect any rows."
- #
- # We solve this little issue by simply using the plain models.Manager queryset
- # when saving. Simple fix, but it does require some trickery with the inspect
- # module and it does make this module prone to breakage whenever a new Django
- # version comes out.
- #
- # revisions.tests.AppTests.test_update_old_revision_in_place tests whether this works.
- #
- # The Django team advises against using a manager that filters out rows as the default one:
- # http://docs.djangoproject.com/en/dev/topics/db/managers/#do-not-filter-away-any-results-in-this-type-of-manager-subclass
- # ... but we feel that versioning should be an absolutely transparant concern,
- # and work on related resources and in the admin without any fuss, leading us
- # to waive this concern.
-
- stack = inspect.stack()[3][3]
- # * 'save' for saving for plain models
- # * 'save_base' for saving models with inheritance
- # * '_collect_sub_objects' for deleting models with inheritance (Django 1.2)
- # * 'collect' for deleting models with inheritance (Django 1.3)
- if stack.startswith('save') or stack == 'collect' or stack == '_collect_sub_objects':
- return super(LatestManager, self).get_query_set()
- else:
- return self.current
-
-
-def trash_aware(cls):
- for manager in cls._meta.abstract_managers:
- manager[2].trash = manager[2].filter(_is_trash=True)
- manager[2].live = manager[2].filter(_is_trash=False)
- return cls
Oops, something went wrong.

0 comments on commit ea490e9

Please sign in to comment.