Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

prepared it to work with django 1.4

  • Loading branch information...
commit 62b999a7fe2f8f28940a330f76ec49544ad1458b 1 parent 9b0d248
Peter Bengtsson authored August 11, 2012

Showing 36 changed files with 298 additions and 350 deletions. Show diff stats Hide diff stats

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

0 notes on commit 62b999a

Please sign in to comment.
Something went wrong with that request. Please try again.