Permalink
Browse files

newforms-admin: Merged to [6370].

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6371 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 019e3c6 commit 0de9a6490577432b9d6204097ac22f57d9c60981 @jkocherhans jkocherhans committed Sep 17, 2007
Showing with 1,106 additions and 173 deletions.
  1. +8 −0 AUTHORS
  2. +25 −10 django/bin/compile-messages.py
  3. +8 −6 django/conf/global_settings.py
  4. +1 −1 django/contrib/admin/views/main.py
  5. 0 django/contrib/sessions/backends/__init__.py
  6. +143 −0 django/contrib/sessions/backends/base.py
  7. +26 −0 django/contrib/sessions/backends/cache.py
  8. +49 −0 django/contrib/sessions/backends/db.py
  9. +68 −0 django/contrib/sessions/backends/file.py
  10. +11 −78 django/contrib/sessions/middleware.py
  11. +2 −1 django/contrib/sessions/models.py
  12. +42 −18 django/contrib/sessions/tests.py
  13. +11 −3 django/core/context_processors.py
  14. +5 −2 django/core/handlers/modpython.py
  15. +5 −0 django/db/models/base.py
  16. +5 −0 django/db/models/fields/__init__.py
  17. +3 −2 django/middleware/http.py
  18. +9 −1 django/newforms/fields.py
  19. +6 −4 django/newforms/forms.py
  20. +9 −14 django/test/client.py
  21. +20 −0 django/utils/datastructures.py
  22. +2 −2 django/utils/dateformat.py
  23. +15 −3 django/utils/timesince.py
  24. +2 −2 docs/apache_auth.txt
  25. +3 −3 docs/django-admin.txt
  26. +1 −1 docs/email.txt
  27. +6 −3 docs/i18n.txt
  28. +1 −1 docs/install.txt
  29. +11 −0 docs/model-api.txt
  30. +30 −1 docs/newforms.txt
  31. +86 −8 docs/sessions.txt
  32. +30 −3 docs/settings.txt
  33. +8 −2 docs/templates.txt
  34. +5 −0 tests/modeltests/basic/models.py
  35. +9 −0 tests/modeltests/custom_pk/models.py
  36. +8 −1 tests/modeltests/fixtures/models.py
  37. +13 −3 tests/regressiontests/backends/models.py
  38. +86 −0 tests/regressiontests/forms/tests.py
  39. +8 −0 tests/regressiontests/templates/tests.py
  40. +10 −0 tests/regressiontests/utils/tests.py
  41. +77 −0 tests/regressiontests/utils/timesince.py
  42. 0 tests/regressiontests/views/__init__.py
  43. +25 −0 tests/regressiontests/views/fixtures/testdata.json
  44. BIN tests/regressiontests/views/locale/en/LC_MESSAGES/djangojs.mo
  45. +20 −0 tests/regressiontests/views/locale/en/LC_MESSAGES/djangojs.po
  46. BIN tests/regressiontests/views/locale/es/LC_MESSAGES/djangojs.mo
  47. +21 −0 tests/regressiontests/views/locale/es/LC_MESSAGES/djangojs.po
  48. BIN tests/regressiontests/views/locale/fr/LC_MESSAGES/djangojs.mo
  49. +20 −0 tests/regressiontests/views/locale/fr/LC_MESSAGES/djangojs.po
  50. +1 −0 tests/regressiontests/views/media/file.txt
  51. +24 −0 tests/regressiontests/views/models.py
  52. +3 −0 tests/regressiontests/views/tests/__init__.py
  53. +39 −0 tests/regressiontests/views/tests/defaults.py
  54. +30 −0 tests/regressiontests/views/tests/i18n.py
  55. +15 −0 tests/regressiontests/views/tests/static.py
  56. +26 −0 tests/regressiontests/views/urls.py
  57. +12 −0 tests/regressiontests/views/views.py
  58. +3 −0 tests/urls.py
View
@@ -84,10 +84,12 @@ answer newbie questions, and generally made Django that much better:
Russell Cloran <russell@rucus.net>
colin@owlfish.com
crankycoder@gmail.com
+ Paul Collier <paul@paul-collier.com>
Pete Crosier <pete.crosier@gmail.com>
Matt Croydon <http://www.postneo.com/>
flavio.curella@gmail.com
Jure Cuhalev <gandalf@owca.info>
+ John D'Agostino <john.dagostino@gmail.com>
dackze+django@gmail.com
David Danier <goliath.mailinglist@gmx.de>
Dirk Datzert <dummy@habmalnefrage.de>
@@ -121,6 +123,7 @@ answer newbie questions, and generally made Django that much better:
Afonso Fernández Nogueira <fonzzo.django@gmail.com>
Matthew Flanagan <http://wadofstuff.blogspot.com>
Eric Floehr <eric@intellovations.com>
+ Vincent Foley <vfoleybourgon@yahoo.ca>
Jorge Gajon <gajon@gajon.org>
gandalf@owca.info
Marc Garcia <marc.garcia@accopensys.com>
@@ -195,7 +198,11 @@ answer newbie questions, and generally made Django that much better:
Waylan Limberg <waylan@gmail.com>
limodou
Philip Lindborg <philip.lindborg@gmail.com>
+<<<<<<< .working
Simon Litchfield <simon@quo.com.au>
+=======
+ msaelices <msaelices@gmail.com>
+>>>>>>> .merge-right.r6370
Matt McClanahan <http://mmcc.cx/>
Martin Maney <http://www.chipy.org/Martin_Maney>
Petr Marhoun <petr.marhoun@gmail.com>
@@ -262,6 +269,7 @@ answer newbie questions, and generally made Django that much better:
Brian Rosner <brosner@gmail.com>
Oliver Rutherfurd <http://rutherfurd.net/>
ryankanno
+ Manuel Saelices <msaelices@yaco.es>
Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/>
Vinay Sajip <vinay_sajip@yahoo.co.uk>
David Schein
@@ -4,20 +4,31 @@
import os
import sys
+try:
+ set
+except NameError:
+ from sets import Set as set # For Python 2.3
+
+
def compile_messages(locale=None):
- basedir = None
-
- if os.path.isdir(os.path.join('conf', 'locale')):
- basedir = os.path.abspath(os.path.join('conf', 'locale'))
- elif os.path.isdir('locale'):
- basedir = os.path.abspath('locale')
- else:
- print "This script should be run from the Django SVN tree or your project or app tree."
+ basedirs = [os.path.join('conf', 'locale'), 'locale']
+ if os.environ.get('DJANGO_SETTINGS_MODULE'):
+ from django.conf import settings
+ basedirs += settings.LOCALE_PATHS
+
+ # Gather existing directories.
+ basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs)))
+
+ if not basedirs:
+ print "This script should be run from the Django SVN tree or your project or app tree, or with the settings module specified."
sys.exit(1)
- if locale is not None:
- basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
+ for basedir in basedirs:
+ if locale:
+ basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
+ compile_messages_in_dir(basedir)
+def compile_messages_in_dir(basedir):
for dirpath, dirnames, filenames in os.walk(basedir):
for f in filenames:
if f.endswith('.po'):
@@ -40,9 +51,13 @@ def main():
parser = optparse.OptionParser()
parser.add_option('-l', '--locale', dest='locale',
help="The locale to process. Default is to process all.")
+ parser.add_option('--settings',
+ help='Python path to settings module, e.g. "myproject.settings". If provided, all LOCALE_PATHS will be processed. If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be checked as well.')
options, args = parser.parse_args()
if len(args):
parser.error("This program takes no arguments")
+ if options.settings:
+ os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
compile_messages(options.locale)
if __name__ == "__main__":
@@ -271,12 +271,14 @@
# SESSIONS #
############
-SESSION_COOKIE_NAME = 'sessionid' # Cookie name. This can be whatever you want.
-SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # Age of cookie, in seconds (default: 2 weeks).
-SESSION_COOKIE_DOMAIN = None # A string like ".lawrence.com", or None for standard domain cookie.
-SESSION_COOKIE_SECURE = False # Whether the session cookie should be secure (https:// only).
-SESSION_SAVE_EVERY_REQUEST = False # Whether to save the session data on every request.
-SESSION_EXPIRE_AT_BROWSER_CLOSE = False # Whether sessions expire when a user closes his browser.
+SESSION_COOKIE_NAME = 'sessionid' # Cookie name. This can be whatever you want.
+SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # Age of cookie, in seconds (default: 2 weeks).
+SESSION_COOKIE_DOMAIN = None # A string like ".lawrence.com", or None for standard domain cookie.
+SESSION_COOKIE_SECURE = False # Whether the session cookie should be secure (https:// only).
+SESSION_SAVE_EVERY_REQUEST = False # Whether to save the session data on every request.
+SESSION_EXPIRE_AT_BROWSER_CLOSE = False # Whether sessions expire when a user closes his browser.
+SESSION_ENGINE = 'django.contrib.sessions.backends.db' # The module to store session data
+SESSION_FILE_PATH = '/tmp/' # Directory to store session files if using the file session module
#########
# CACHE #
@@ -85,7 +85,7 @@ def __init__(self, field, field_mapping, original):
def original_value(self):
if self.original:
- return self.original.__dict__[self.field.column]
+ return self.original.__dict__[self.field.attname]
def existing_display(self):
try:
@@ -0,0 +1,143 @@
+import base64
+import md5
+import os
+import random
+import sys
+import time
+from django.conf import settings
+from django.core.exceptions import SuspiciousOperation
+
+try:
+ import cPickle as pickle
+except ImportError:
+ import pickle
+
+class SessionBase(object):
+ """
+ Base class for all Session classes.
+ """
+
+ TEST_COOKIE_NAME = 'testcookie'
+ TEST_COOKIE_VALUE = 'worked'
+
+ def __init__(self, session_key=None):
+ self._session_key = session_key
+ self.accessed = False
+ self.modified = False
+
+ def __contains__(self, key):
+ return key in self._session
+
+ def __getitem__(self, key):
+ return self._session[key]
+
+ def __setitem__(self, key, value):
+ self._session[key] = value
+ self.modified = True
+
+ def __delitem__(self, key):
+ del self._session[key]
+ self.modified = True
+
+ def keys(self):
+ return self._session.keys()
+
+ def items(self):
+ return self._session.items()
+
+ def get(self, key, default=None):
+ return self._session.get(key, default)
+
+ def pop(self, key, *args):
+ return self._session.pop(key, *args)
+
+ def set_test_cookie(self):
+ self[self.TEST_COOKIE_NAME] = self.TEST_COOKIE_VALUE
+
+ def test_cookie_worked(self):
+ return self.get(self.TEST_COOKIE_NAME) == self.TEST_COOKIE_VALUE
+
+ def delete_test_cookie(self):
+ del self[self.TEST_COOKIE_NAME]
+
+ def encode(self, session_dict):
+ "Returns the given session dictionary pickled and encoded as a string."
+ pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL)
+ pickled_md5 = md5.new(pickled + settings.SECRET_KEY).hexdigest()
+ return base64.encodestring(pickled + pickled_md5)
+
+ def decode(self, session_data):
+ encoded_data = base64.decodestring(session_data)
+ pickled, tamper_check = encoded_data[:-32], encoded_data[-32:]
+ if md5.new(pickled + settings.SECRET_KEY).hexdigest() != tamper_check:
+ raise SuspiciousOperation("User tampered with session cookie.")
+ try:
+ return pickle.loads(pickled)
+ # Unpickling can cause a variety of exceptions. If something happens,
+ # just return an empty dictionary (an empty session).
+ except:
+ return {}
+
+ def _get_new_session_key(self):
+ "Returns session key that isn't being used."
+ # The random module is seeded when this Apache child is created.
+ # Use settings.SECRET_KEY as added salt.
+ while 1:
+ session_key = md5.new("%s%s%s%s" % (random.randint(0, sys.maxint - 1),
+ os.getpid(), time.time(), settings.SECRET_KEY)).hexdigest()
+ if not self.exists(session_key):
+ break
+ return session_key
+
+ def _get_session_key(self):
+ if self._session_key:
+ return self._session_key
+ else:
+ self._session_key = self._get_new_session_key()
+ return self._session_key
+
+ def _set_session_key(self, session_key):
+ self._session_key = session_key
+
+ session_key = property(_get_session_key, _set_session_key)
+
+ def _get_session(self):
+ # Lazily loads session from storage.
+ self.accessed = True
+ try:
+ return self._session_cache
+ except AttributeError:
+ if self._session_key is None:
+ self._session_cache = {}
+ else:
+ self._session_cache = self.load()
+ return self._session_cache
+
+ _session = property(_get_session)
+
+ # Methods that child classes must implement.
+
+ def exists(self, session_key):
+ """
+ Returns True if the given session_key already exists.
+ """
+ raise NotImplementedError
+
+ def save(self):
+ """
+ Saves the session data.
+ """
+ raise NotImplementedError
+
+ def delete(self, session_key):
+ """
+ Clears out the session data under this key.
+ """
+ raise NotImplementedError
+
+ def load(self):
+ """
+ Loads the session data and returns a dictionary.
+ """
+ raise NotImplementedError
+
@@ -0,0 +1,26 @@
+from django.conf import settings
+from django.contrib.sessions.backends.base import SessionBase
+from django.core.cache import cache
+
+class SessionStore(SessionBase):
+ """
+ A cache-based session store.
+ """
+ def __init__(self, session_key=None):
+ self._cache = cache
+ super(SessionStore, self).__init__(session_key)
+
+ def load(self):
+ session_data = self._cache.get(self.session_key)
+ return session_data or {}
+
+ def save(self):
+ self._cache.set(self.session_key, self._session, settings.SESSION_COOKIE_AGE)
+
+ def exists(self, session_key):
+ if self._cache.get(session_key):
+ return True
+ return False
+
+ def delete(self, session_key):
+ self._cache.delete(session_key)
@@ -0,0 +1,49 @@
+from django.conf import settings
+from django.contrib.sessions.models import Session
+from django.contrib.sessions.backends.base import SessionBase
+from django.core.exceptions import SuspiciousOperation
+import datetime
+
+class SessionStore(SessionBase):
+ """
+ Implements database session store
+ """
+ def __init__(self, session_key=None):
+ super(SessionStore, self).__init__(session_key)
+
+ def load(self):
+ try:
+ s = Session.objects.get(
+ session_key = self.session_key,
+ expire_date__gt=datetime.datetime.now()
+ )
+ return self.decode(s.session_data)
+ except (Session.DoesNotExist, SuspiciousOperation):
+
+ # Create a new session_key for extra security.
+ self.session_key = self._get_new_session_key()
+ self._session_cache = {}
+
+ # Save immediately to minimize collision
+ self.save()
+ return {}
+
+ def exists(self, session_key):
+ try:
+ Session.objects.get(session_key=session_key)
+ except Session.DoesNotExist:
+ return False
+ return True
+
+ def save(self):
+ Session.objects.create(
+ session_key = self.session_key,
+ session_data = self.encode(self._session),
+ expire_date = datetime.datetime.now() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE)
+ )
+
+ def delete(self, session_key):
+ try:
+ Session.objects.get(session_key=session_key).delete()
+ except Session.DoesNotExist:
+ pass
Oops, something went wrong.

0 comments on commit 0de9a64

Please sign in to comment.