Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

prepared it to work with django 1.4

  • Loading branch information...
commit 62b999a7fe2f8f28940a330f76ec49544ad1458b 1 parent 9b0d248
Peter Bengtsson authored
Showing with 298 additions and 350 deletions.
  1. +4 −4 django_mongokit/mongodb/base.py
  2. +4 −5 django_mongokit/test_settings.py
  3. +1 −1  django_mongokit/version.txt
  4. +0 −11 exampleproject/manage.py
  5. +0 −86 exampleproject/settings.py
  6. +0 −107 exampleproject/settings_django11.py
  7. +0 −42 exampleproject/test_runner.py
  8. +0 −8 exampleproject/test_settings.py
  9. +0 −20 exampleproject/urls.py
  10. 0  {exampleproject/exampleapp_sql → exampleproject2/exampleproject}/__init__.py
  11. 0  {exampleproject/exampleapp/templatetags → exampleproject2/exampleproject/benchmarker}/__init__.py
  12. 0  { → exampleproject2}/exampleproject/benchmarker/models.py
  13. 0  { → exampleproject2}/exampleproject/benchmarker/tests.py
  14. 0  { → exampleproject2}/exampleproject/benchmarker/urls.py
  15. +26 −28 { → exampleproject2}/exampleproject/benchmarker/views.py
  16. 0  { → exampleproject2}/exampleproject/exampleapp/__init__.py
  17. 0  { → exampleproject2}/exampleproject/exampleapp/forms.py
  18. 0  { → exampleproject2}/exampleproject/exampleapp/models.py
  19. +9 −7 {exampleproject → exampleproject2/exampleproject/exampleapp}/templates/exampleapp/home.html
  20. 0  {exampleproject/benchmarker → exampleproject2/exampleproject/exampleapp/templatetags}/__init__.py
  21. 0  { → exampleproject2}/exampleproject/exampleapp/templatetags/django11.py
  22. 0  { → exampleproject2}/exampleproject/exampleapp/tests.py
  23. +2 −2 { → exampleproject2}/exampleproject/exampleapp/urls.py
  24. +5 −2 { → exampleproject2}/exampleproject/exampleapp/views.py
  25. 0  {exampleproject → exampleproject2/exampleproject/exampleapp_sql}/__init__.py
  26. 0  { → exampleproject2}/exampleproject/exampleapp_sql/forms.py
  27. 0  { → exampleproject2}/exampleproject/exampleapp_sql/models.py
  28. +15 −17 { → exampleproject2}/exampleproject/exampleapp_sql/tests.py
  29. 0  { → exampleproject2}/exampleproject/exampleapp_sql/urls.py
  30. +6 −5 { → exampleproject2}/exampleproject/exampleapp_sql/views.py
  31. +156 −0 exampleproject2/exampleproject/settings.py
  32. +9 −0 exampleproject2/exampleproject/urls.py
  33. +28 −0 exampleproject2/exampleproject/wsgi.py
  34. +10 −0 exampleproject2/manage.py
  35. +4 −4 setup.py
  36. +19 −1 tox.ini
8 django_mongokit/mongodb/base.py
View
@@ -130,17 +130,17 @@ def _drop_database(self, database_name):
self.connection.connection.drop_database(database_name)
-
-
class DatabaseWrapper(BaseDatabaseWrapper):
operators = {}
_commit = ignore
_rollback = ignore
- autocommit = None # ignore
+ autocommit = None # ignore
- def __init__(self, settings_dict, alias=None, # alias was added in Django 1.2
+ def __init__(self, settings_dict, alias=None, # alias was added in Django 1.2
*args, **kwargs):
+ super(DatabaseWrapper, self).__init__(settings_dict, alias=alias, *args, **kwargs)
+
if settings_dict['HOST']:
kwargs['host'] = settings_dict['HOST']
if settings_dict['PORT']:
9 django_mongokit/test_settings.py
View
@@ -14,16 +14,16 @@
DATABASES = {
'default': {
- 'ENGINE': 'sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'example-sqlite3.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
- },
+ },
'mongodb': {
- 'ENGINE': 'django_mongokit.mongodb',
- 'NAME': 'example',
+ 'ENGINE': 'django_mongokit.mongodb',
+ 'NAME': 'example',
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
@@ -99,4 +99,3 @@
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
)
-
2  django_mongokit/version.txt
View
@@ -1 +1 @@
-0.2.2
+0.2.3
11 exampleproject/manage.py
View
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-from django.core.management import execute_manager
-try:
- import settings # Assumed to be in the same directory.
-except ImportError:
- import sys
- sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
- sys.exit(1)
-
-if __name__ == "__main__":
- execute_manager(settings)
86 exampleproject/settings.py
View
@@ -1,86 +0,0 @@
-# Django settings for exampleproject project.
-import os
-
-HERE = os.path.dirname(__file__)
-
-DEBUG = True
-TEMPLATE_DEBUG = DEBUG
-
-ADMINS = (
- # ('Your Name', 'your_email@domain.com'),
-)
-
-MANAGERS = ADMINS
-
-DATABASES = {
-# 'default': {
-# 'ENGINE': 'postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-# 'NAME': 'exampleapp', # Or path to database file if using sqlite3.
-# },
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': 'example-sqlite3.db', # Or path to database file if using sqlite3.
- },
- 'mongodb': {
- 'ENGINE': 'django_mongokit.mongodb',
- 'NAME': 'example',
- 'USER': '', # Not used with sqlite3.
- 'PASSWORD': '', # Not used with sqlite3.
- 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
- 'PORT': '', # Set to empty string for default. Not used with sqlite3.
- },
-}
-
-
-
-# Local time zone for this installation. Choices can be found here:
-# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
-# although not all choices may be available on all operating systems.
-# If running in a Windows environment this must be set to the same as your
-# system time zone.
-TIME_ZONE = 'America/Chicago'
-
-# Language code for this installation. All choices can be found here:
-# http://www.i18nguy.com/unicode/language-identifiers.html
-LANGUAGE_CODE = 'en-us'
-
-SITE_ID = 1
-
-# If you set this to False, Django will make some optimizations so as not
-# to load the internationalization machinery.
-USE_I18N = True
-
-# Absolute path to the directory that holds media.
-# Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = ''
-
-# URL that handles the media served from MEDIA_ROOT. Make sure to use a
-# trailing slash if there is a path component (optional in other cases).
-# Examples: "http://media.lawrence.com", "http://example.com/media/"
-MEDIA_URL = ''
-
-# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
-# trailing slash.
-# Examples: "http://foo.com/media/", "/media/".
-ADMIN_MEDIA_PREFIX = '/media/'
-
-# Make this unique, and don't share it with anybody.
-SECRET_KEY = '7o!nbm=a=j-%6m3vhd&m*8%&u-rdr)b(t%ksei)d+w$$(xb=2+'
-
-ROOT_URLCONF = 'exampleproject.urls'
-
-TEMPLATE_DIRS = (
- os.path.join(HERE, 'templates'),
-)
-
-INSTALLED_APPS = (
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.sites',
- 'django.contrib.messages',
- 'exampleapp',
- 'exampleapp_sql',
- # Uncomment the next line to enable the admin:
- # 'django.contrib.admin',
-)
107 exampleproject/settings_django11.py
View
@@ -1,107 +0,0 @@
-# Django settings for exampleproject project.
-import os
-
-HERE = os.path.dirname(__file__)
-
-DEBUG = True
-TEMPLATE_DEBUG = DEBUG
-
-ADMINS = (
- # ('Your Name', 'your_email@domain.com'),
-)
-
-MANAGERS = ADMINS
-
-DATABASE_ENGINE = 'sqlite3'
-DATABASE_NAME = 'example-sqlite3.db'
-
-#MONGO_DATABASE_ENGINE = 'django_mongokit.mongodb'
-MONGO_DATABASE_NAME = 'example'
-
-#DATABASES = {
-# 'default': {
-# 'ENGINE': 'postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-# 'NAME': 'exampleapp', # Or path to database file if using sqlite3.
-# },
-# 'default': {
-# 'ENGINE': 'sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-# 'NAME': 'example-sqlite3.db', # Or path to database file if using sqlite3.
-# },
-# 'mongodb': {
-# 'ENGINE': 'django_mongokit.mongodb',
-# 'NAME': 'example',
-# 'USER': '', # Not used with sqlite3.
-# 'PASSWORD': '', # Not used with sqlite3.
-# 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
-# 'PORT': '', # Set to empty string for default. Not used with sqlite3.
-# },
-#}
-
-
-
-# Local time zone for this installation. Choices can be found here:
-# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
-# although not all choices may be available on all operating systems.
-# If running in a Windows environment this must be set to the same as your
-# system time zone.
-TIME_ZONE = 'America/Chicago'
-
-# Language code for this installation. All choices can be found here:
-# http://www.i18nguy.com/unicode/language-identifiers.html
-LANGUAGE_CODE = 'en-us'
-
-SITE_ID = 1
-
-# If you set this to False, Django will make some optimizations so as not
-# to load the internationalization machinery.
-USE_I18N = True
-
-# Absolute path to the directory that holds media.
-# Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = ''
-
-# URL that handles the media served from MEDIA_ROOT. Make sure to use a
-# trailing slash if there is a path component (optional in other cases).
-# Examples: "http://media.lawrence.com", "http://example.com/media/"
-MEDIA_URL = ''
-
-# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
-# trailing slash.
-# Examples: "http://foo.com/media/", "/media/".
-ADMIN_MEDIA_PREFIX = '/media/'
-
-# Make this unique, and don't share it with anybody.
-SECRET_KEY = '7o!nbm=a=j-%6m3vhd&m*8%&u-rdr)b(t%ksei)d+w$$(xb=2+'
-
-# List of callables that know how to import templates from various sources.
-TEMPLATE_LOADERS = (
- 'django.template.loaders.filesystem.load_template_source',
- 'django.template.loaders.app_directories.load_template_source',
-# 'django.template.loaders.eggs.load_template_source',
-)
-
-
-MIDDLEWARE_CLASSES = (
- 'django.middleware.common.CommonMiddleware',
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
-)
-
-
-ROOT_URLCONF = 'exampleproject.urls'
-
-TEMPLATE_DIRS = (
- os.path.join(HERE, 'templates'),
-)
-
-INSTALLED_APPS = (
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.sites',
- 'exampleapp',
- 'exampleapp_sql',
- # Uncomment the next line to enable the admin:
- # 'django.contrib.admin',
-)
-
42 exampleproject/test_runner.py
View
@@ -1,42 +0,0 @@
-from django.conf import settings
-from django.test.simple import run_tests as django_test_runner
-import coverage
-def test_runner_with_coverage(test_labels, verbosity=1, interactive=True,
- extra_tests=[], failfast=None):
- """
- Custom test runner. Follows the django.test.simple.run_tests() interface.
- """
- # Start code coverage before anything else if necessary
- if hasattr(settings, 'COVERAGE_MODULES'):
- cov = coverage.coverage()
- #coverage.use_cache(0) # Do not cache any of the coverage.py stuff
- cov.use_cache(0) # Do not cache any of the coverage.py stuff
- cov.start()
-
- test_results = django_test_runner(test_labels,
- verbosity=verbosity,
- interactive=interactive,
- extra_tests=extra_tests,
- failfast=failfast)
-
- # Stop code coverage after tests have completed
- if hasattr(settings, 'COVERAGE_MODULES'):
- cov.stop()
-
- # Print code metrics header
- print ''
- print '----------------------------------------------------------------------'
- print ' Unit Test Code Coverage Results'
- print '----------------------------------------------------------------------'
-
- # Report code coverage metrics
- if hasattr(settings, 'COVERAGE_MODULES'):
- coverage_modules = []
- for module in settings.COVERAGE_MODULES:
- coverage_modules.append(__import__(module, globals(), locals(), ['']))
- cov.report(coverage_modules, show_missing=1)
- #cov.html_report(coverage_modules, directory='coverage_report')
- # Print code metrics footer
- print '----------------------------------------------------------------------'
-
- return test_results
8 exampleproject/test_settings.py
View
@@ -1,8 +0,0 @@
-from settings import *
-TEST_RUNNER='test_runner.test_runner_with_coverage'
-
-COVERAGE_MODULES = [
- 'exampleapp.views',
- 'exampleapp.models',
-]
-
20 exampleproject/urls.py
View
@@ -1,20 +0,0 @@
-from django.conf.urls.defaults import *
-
-# Uncomment the next two lines to enable the admin:
-# from django.contrib import admin
-# admin.autodiscover()
-
-urlpatterns = patterns('',
- # Example:
- (r'^exampleapp/', include('exampleapp.urls')),
- (r'^exampleapp_sql/', include('exampleapp_sql.urls', namespace='sql',
- app_name='exampleapp_sql')),
- (r'^benchmarker/', include('benchmarker.urls')),
-
- # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
- # to INSTALLED_APPS to enable admin documentation:
- # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
-
- # Uncomment the next line to enable the admin:
- # (r'^admin/', include(admin.site.urls)),
-)
0  exampleproject/exampleapp_sql/__init__.py → exampleproject2/exampleproject/__init__.py
View
File renamed without changes
0  exampleproject/exampleapp/templatetags/__init__.py → ...leproject2/exampleproject/benchmarker/__init__.py
View
File renamed without changes
0  exampleproject/benchmarker/models.py → exampleproject2/exampleproject/benchmarker/models.py
View
File renamed without changes
0  exampleproject/benchmarker/tests.py → exampleproject2/exampleproject/benchmarker/tests.py
View
File renamed without changes
0  exampleproject/benchmarker/urls.py → exampleproject2/exampleproject/benchmarker/urls.py
View
File renamed without changes
54 exampleproject/benchmarker/views.py → exampleproject2/exampleproject/benchmarker/views.py
View
@@ -4,39 +4,43 @@
import random
from cStringIO import StringIO
from time import time, sleep
-from pymongo.objectid import ObjectId
+try:
+ from bson import ObjectId
+except ImportError: # old pymongo
+ from pymongo.objectid import ObjectId
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.conf import settings
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
from django.template import RequestContext
+from django.utils.timezone import utc
-from exampleapp.models import Talk
-from exampleapp_sql.models import Talk as sql_Talk
+from exampleproject.exampleapp.models import Talk
+from exampleproject.exampleapp_sql.models import Talk as sql_Talk
from django_mongokit import get_database
def run(request):
how_many = int(request.GET.get('how_many', 1))
-
- TESTS = (('mongokit', _create_talks, _edit_talks, _delete_talks,
+
+ TESTS = (('mongokit', _create_talks, _edit_talks, _delete_talks,
settings.DATABASES['mongodb']['ENGINE']),
- ('sql', _create_talks_sql, _edit_talks_sql, _delete_talks_sql,
+ ('sql', _create_talks_sql, _edit_talks_sql, _delete_talks_sql,
settings.DATABASES['default']['ENGINE']),
)
-
+
response = StringIO()
-
+
for label, creator, editor, deletor, engine in TESTS:
total = 0.0
print >>response, label, engine
-
+
t0=time()
ids = creator(how_many)
t1=time()
total += t1-t0
print >>response, "Creating", how_many, "talks took", t1-t0, "seconds"
-
+
# give it a rest so that the database can internall index all the IDs
sleep(1)
@@ -54,13 +58,13 @@ def run(request):
t1=time()
total += t1-t0
print >>response, "Deleting", how_many, "talks took", t1-t0, "seconds"
-
-
+
+
print >>response, "IN TOTAL", total, "seconds"
print >>response, "\n"
-
+
return HttpResponse(response.getvalue(), mimetype='text/plain')
-
+
def __random_topic():
return random.choice(
(u'No talks added yet',
@@ -75,10 +79,10 @@ def __random_topic():
))
def __random_when():
- return datetime.datetime(random.randint(2000, 2010),
- random.randint(1, 12),
- random.randint(1, 28),
- 0,0,0)
+ return datetime.datetime(random.randint(2000, 2010),
+ random.randint(1, 12),
+ random.randint(1, 28),
+ 0, 0, 0).replace(tzinfo=utc)
def __random_tags():
tags = [u'one', u'two', u'three', u'four', u'five', u'six',
@@ -88,8 +92,8 @@ def __random_tags():
def __random_duration():
return round(random.random()*10, 1)
-
-
+
+
def _create_talks(how_many):
# 1 Create 1,000 talks
collection = get_database()[Talk.collection_name]
@@ -116,8 +120,8 @@ def _delete_talks(ids):
for id_ in ids:
talk = collection.Talk.one({'_id': ObjectId(id_)})
talk.delete()
-
-
+
+
def _create_talks_sql(how_many):
# 1 Create 1,000 talks
@@ -141,9 +145,3 @@ def _edit_talks_sql(ids):
talk = sql_Talk.objects.get(pk=id_)
talk.topic += "extra"
talk.save()
-
-
-
-
-
-
0  exampleproject/exampleapp/__init__.py → ...pleproject2/exampleproject/exampleapp/__init__.py
View
File renamed without changes
0  exampleproject/exampleapp/forms.py → exampleproject2/exampleproject/exampleapp/forms.py
View
File renamed without changes
0  exampleproject/exampleapp/models.py → exampleproject2/exampleproject/exampleapp/models.py
View
File renamed without changes
16 exampleproject/templates/exampleapp/home.html → ...project/exampleapp/templates/exampleapp/home.html
View
@@ -1,6 +1,8 @@
+<!DOCTYPE html>
<html>
<body>
<h1>Example app</h1>
+{% load url from future %}
{% for talk in talks %}
{% if forloop.first %}
@@ -9,10 +11,10 @@
<div>
<p><strong>{{ talk.topic }}</strong>
- &ndash; {{ talk.when|date:"j F Y" }}<br/>
- Duration: {{ talk.duration }}h<br/>
- Tags: {{ talk.tags|join:", " }}<br/>
- <a href="{% url delete_talk talk.pk %}">delete</a>
+ &ndash; {{ talk.when|date:"j F Y" }}<br>
+ Duration: {{ talk.duration }}h<br>
+ Tags: {{ talk.tags|join:", " }}<br>
+ <a href="{% url 'delete_talk' talk.pk %}">delete</a>
</p>
</div>
@@ -20,12 +22,12 @@
<p><em>No talks added yet</em></p>
{% endfor %}
-<hr/>
+<hr>
<form action="." method="post">
{% csrf_token %}
{{ form.as_p }}
-<input type="submit" value="+ Add talk"/>
+<input type="submit" value="+ Add talk">
</form>
</body>
-</html>
+</html>
0  exampleproject/benchmarker/__init__.py → ...xampleproject/exampleapp/templatetags/__init__.py
View
File renamed without changes
0  exampleproject/exampleapp/templatetags/django11.py → ...xampleproject/exampleapp/templatetags/django11.py
View
File renamed without changes
0  exampleproject/exampleapp/tests.py → exampleproject2/exampleproject/exampleapp/tests.py
View
File renamed without changes
4 exampleproject/exampleapp/urls.py → exampleproject2/exampleproject/exampleapp/urls.py
View
@@ -1,7 +1,7 @@
-from django.conf.urls.defaults import *
-
+from django.conf.urls.defaults import patterns, url
import views
+
urlpatterns = patterns('',
url(r'^$', views.homepage, name='homepage'),
url(r'^delete/(?P<_id>[\w-]+)$', views.delete_talk, name='delete_talk'),
7 exampleproject/exampleapp/views.py → exampleproject2/exampleproject/exampleapp/views.py
View
@@ -1,5 +1,8 @@
import datetime
-from pymongo.objectid import ObjectId
+try:
+ from bson import ObjectId
+except ImportError: # old pymongo
+ from pymongo.objectid import ObjectId
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.conf import settings
from django.core.urlresolvers import reverse
@@ -35,4 +38,4 @@ def delete_talk(request, _id):
collection = get_database()[Talk.collection_name]
talk = collection.Talk.one({"_id": ObjectId(_id)})
talk.delete()
- return HttpResponseRedirect(reverse("homepage"))
+ return HttpResponseRedirect(reverse("homepage"))
0  exampleproject/__init__.py → ...roject2/exampleproject/exampleapp_sql/__init__.py
View
File renamed without changes
0  exampleproject/exampleapp_sql/forms.py → ...leproject2/exampleproject/exampleapp_sql/forms.py
View
File renamed without changes
0  exampleproject/exampleapp_sql/models.py → ...eproject2/exampleproject/exampleapp_sql/models.py
View
File renamed without changes
32 exampleproject/exampleapp_sql/tests.py → ...leproject2/exampleproject/exampleapp_sql/tests.py
View
@@ -1,41 +1,44 @@
-from django.core.urlresolvers import reverse
import datetime
+from django.core.urlresolvers import reverse
from django.test import TestCase
from django.db import connections
from django.conf import settings
+from django.utils.timezone import utc
from models import Talk
+
class ExampleTest(TestCase):
+
def setUp(self):
self.connection = connections['mongodb'].connection
self.database = self.connection[settings.DATABASES['mongodb']['NAME']]
-
+
def tearDown(self):
for name in self.database.collection_names():
if name not in ('system.indexes',):
self.database.drop_collection(name)
-
+
def test_creating_talk_basic(self):
"""test to create a Talk instance"""
talk = Talk.objects.create(topic=u"Bla",
- when=datetime.datetime.now(),
+ when=datetime.datetime.utcnow().replace(tzinfo=utc),
tags=[u"foo", u"bar"],
duration=5.5,
)
self.assertTrue(talk.id)
self.assertEqual(talk.duration, 5.5)
-
+
def test_homepage(self):
- """rendering the homepage will show talks and will make it possible to
+ """rendering the homepage will show talks and will make it possible to
add more talks and delete existing ones"""
response = self.client.get(reverse('sql:homepage'))
self.assertTrue(response.status_code, 200)
self.assertTrue('No talks added yet' in response.content)
-
- data = {'topic': '',
+
+ data = {'topic': '',
'when': '2010-12-31',
'duration':'1.0',
'tags': ' foo , bar, ,'}
@@ -43,28 +46,23 @@ def test_homepage(self):
self.assertEqual(response.status_code, 200)
self.assertTrue('class="errorlist"' in response.content)
self.assertTrue('This field is required' in response.content)
-
+
data['topic'] = 'My Topic'
response = self.client.post(reverse('sql:homepage'), data)
self.assertEqual(response.status_code, 302)
-
+
response = self.client.get(reverse('sql:homepage'))
self.assertTrue(response.status_code, 200)
self.assertTrue('My Topic' in response.content)
self.assertTrue('31 December 2010' in response.content)
self.assertTrue('Tags: foo, bar' in response.content)
-
+
talk = Talk.objects.all()[0]
assert talk.topic == u"My Topic"
delete_url = reverse('sql:delete_talk', args=[talk.pk])
response = self.client.get(delete_url)
self.assertEqual(response.status_code, 302)
-
+
response = self.client.get(reverse('sql:homepage'))
self.assertTrue(response.status_code, 200)
self.assertTrue('My Topic' not in response.content)
-
-
-
-
-
0  exampleproject/exampleapp_sql/urls.py → ...pleproject2/exampleproject/exampleapp_sql/urls.py
View
File renamed without changes
11 exampleproject/exampleapp_sql/views.py → ...leproject2/exampleproject/exampleapp_sql/views.py
View
@@ -4,6 +4,7 @@
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
from django.template import RequestContext
+from django.utils.timezone import utc
from models import Talk
from forms import TalkForm
@@ -16,20 +17,20 @@ def homepage(request):
if form.is_valid():
topic = form.cleaned_data['topic']
w = form.cleaned_data['when']
- when = datetime.datetime(w.year, w.month, w.day, 0,0,0)
+ when = (datetime.datetime(w.year, w.month, w.day, 0, 0, 0)
+ .replace(tzinfo=utc))
tags = form.cleaned_data['tags']
duration = form.cleaned_data['duration']
talk = Talk.objects.create(topic=topic, when=when,
tags=tags, duration=duration)
-
return HttpResponseRedirect(reverse('homepage'))
else:
form = TalkForm()
-
- return render_to_response("exampleapp/home.html", locals(),
+ return render_to_response("exampleapp/home.html",
+ {'talks': talks, 'form': form},
context_instance=RequestContext(request))
def delete_talk(request, _id):
Talk.objects.filter(pk=_id).delete()
- return HttpResponseRedirect(reverse("homepage"))
+ return HttpResponseRedirect(reverse("homepage"))
156 exampleproject2/exampleproject/settings.py
View
@@ -0,0 +1,156 @@
+# Django settings for exampleproject2 project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+DEBUG_PROPAGATE_EXCEPTIONS = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@example.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': 'example-sqlite3.db',
+ },
+ 'mongodb': {
+ 'ENGINE': 'django_mongokit.mongodb',
+ 'NAME': 'example',
+ 'USER': '',
+ 'PASSWORD': '',
+ 'HOST': '',
+ 'PORT': '',
+ },
+}
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# In a Windows environment this must be set to your system time zone.
+USE_TZ = True
+TIME_ZONE = 'Europe/London'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale.
+USE_L10N = True
+
+# If you set this to False, Django will not use timezone-aware datetimes.
+USE_TZ = True
+
+# Absolute filesystem path to the directory that will hold user-uploaded files.
+# Example: "/home/media/media.lawrence.com/media/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash.
+# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
+MEDIA_URL = ''
+
+# Absolute path to the directory static files should be collected to.
+# Don't put anything in this directory yourself; store your static files
+# in apps' "static/" subdirectories and in STATICFILES_DIRS.
+# Example: "/home/media/media.lawrence.com/static/"
+STATIC_ROOT = ''
+
+# URL prefix for static files.
+# Example: "http://media.lawrence.com/static/"
+STATIC_URL = '/static/'
+
+# Additional locations of static files
+STATICFILES_DIRS = (
+ # Put strings here, like "/home/html/static" or "C:/www/django/static".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+# List of finder classes that know how to find static files in
+# various locations.
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
+)
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '7st0sdv&amp;7yw*eh)zmaz8#t48nr$&amp;ql#ow=$0l^#b_b&amp;$9c*$4c'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+# 'django.template.loaders.eggs.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ # Uncomment the next line for simple clickjacking protection:
+ # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
+)
+
+ROOT_URLCONF = 'exampleproject.urls'
+
+# Python dotted path to the WSGI application used by Django's runserver.
+WSGI_APPLICATION = 'exampleproject.wsgi.application'
+
+TEMPLATE_DIRS = (
+ # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'exampleproject.exampleapp',
+ 'exampleproject.exampleapp_sql',
+ 'exampleproject.benchmarker',
+)
+
+# A sample logging configuration. The only tangible logging
+# performed by this configuration is to send an email to
+# the site admins on every HTTP 500 error when DEBUG=False.
+# See http://docs.djangoproject.com/en/dev/topics/logging for
+# more details on how to customize your logging configuration.
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'filters': {
+ 'require_debug_false': {
+ '()': 'django.utils.log.RequireDebugFalse'
+ }
+ },
+ 'handlers': {
+ 'mail_admins': {
+ 'level': 'ERROR',
+ 'filters': ['require_debug_false'],
+ 'class': 'django.utils.log.AdminEmailHandler'
+ }
+ },
+ 'loggers': {
+ 'django.request': {
+ 'handlers': ['mail_admins'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
+ }
+}
9 exampleproject2/exampleproject/urls.py
View
@@ -0,0 +1,9 @@
+from django.conf.urls import patterns, include, url
+
+
+urlpatterns = patterns('',
+ (r'^exampleapp/', include('exampleproject.exampleapp.urls')),
+ (r'^exampleapp_sql/', include('exampleproject.exampleapp_sql.urls', namespace='sql',
+ app_name='exampleapp_sql')),
+ (r'^benchmarker/', include('exampleproject.benchmarker.urls')),
+)
28 exampleproject2/exampleproject/wsgi.py
View
@@ -0,0 +1,28 @@
+"""
+WSGI config for exampleproject2 project.
+
+This module contains the WSGI application used by Django's development server
+and any production WSGI deployments. It should expose a module-level variable
+named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
+this application via the ``WSGI_APPLICATION`` setting.
+
+Usually you will have the standard Django WSGI application here, but it also
+might make sense to replace the whole Django WSGI application with a custom one
+that later delegates to the Django one. For example, you could introduce WSGI
+middleware here, or combine a Django application with an application of another
+framework.
+
+"""
+import os
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "exampleproject2.settings")
+
+# This application object is used by any WSGI server configured to use this
+# file. This includes Django's development server, if the WSGI_APPLICATION
+# setting points here.
+from django.core.wsgi import get_wsgi_application
+application = get_wsgi_application()
+
+# Apply WSGI middleware here.
+# from helloworld.wsgi import HelloWorldApplication
+# application = HelloWorldApplication(application)
10 exampleproject2/manage.py
View
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+import os
+import sys
+
+if __name__ == "__main__":
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "exampleproject.settings")
+
+ from django.core.management import execute_from_command_line
+
+ execute_from_command_line(sys.argv)
8 setup.py
View
@@ -1,20 +1,20 @@
#!/usr/bin/env python
-# Copyright (c) 2010 Peter Bengtsson, peter@fry-it.com
+# Copyright (c) 2010-2012 Peter Bengtsson, mail@peterbe.com
from distutils.core import setup
setup(name='django-mongokit',
version=open('django_mongokit/version.txt').read(),
author="Peter Bengtsson",
- author_email="peter@fry-it.com",
+ author_email="mail@peterbe.com",
url="http://github.com/peterbe/django-mongokit",
description='Bridging Django to MongoDB with the MongoKit ODM',
long_description=open('README.md').read(),
- package_dir={'djangomongokitlib':'django-mongokitlib'},
+ package_dir={'djangomongokitlib': 'django-mongokitlib'},
packages=['django_mongokit',
'django_mongokit.forms',
'django_mongokit.mongodb',
],
- package_data={'django_mongokit':['version.txt']},
+ package_data={'django_mongokit': ['version.txt']},
classifiers=['Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Django',
20 tox.ini
View
@@ -4,7 +4,7 @@
# and then run "tox" from this directory.
[tox]
-envlist = py26_django13, py26_django12, py27_django13, py27_django12
+envlist = py26_django13, py26_django12, py26_django14, py27_django13, py27_django12, py27_django14
[testenv:py26_django13]
basenv = python2.6
@@ -24,6 +24,15 @@ deps =
Django==1.2
mongokit
+[testenv:py26_django14]
+basenv = python2.6
+setenv = DJANGO_SETTINGS_MODULE=test_settings
+commands =
+ {envpython} django_mongokit/tests.py
+deps =
+ Django==1.4
+ mongokit
+
[testenv:py27_django13]
basenv = python2.7
setenv = DJANGO_SETTINGS_MODULE=test_settings
@@ -41,3 +50,12 @@ commands =
deps =
Django==1.2
mongokit
+
+[testenv:py27_django14]
+basenv = python2.7
+setenv = DJANGO_SETTINGS_MODULE=test_settings
+commands =
+ {envpython} django_mongokit/tests.py
+deps =
+ Django==1.4
+ mongokit
Please sign in to comment.
Something went wrong with that request. Please try again.