Commits

Reid van Melle committed 53a5b71

redoing the dir structure to satisfy dotcloud requirements

Comments (0)

Files changed (22)

+import os
+import sys
+
+# Ken added this, only thing that is different from the example template (not counting settings file name)
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),'www')))
+os.environ['DJANGO_SETTINGS_MODULE'] = 'www.settings'
+
+import django.core.handlers.wsgi
+djangoapplication = django.core.handlers.wsgi.WSGIHandler()
+def application(environ, start_response):
+    if 'SCRIPT_NAME' in environ:
+        del environ['SCRIPT_NAME']
+    return djangoapplication(environ, start_response)

www/api/__init__.py

Empty file added.

www/api/handlers.py

+import re
+
+from piston.handler import BaseHandler
+from piston.utils import rc, throttle
+
+from www.myapp.models import Poll
+
+class PollHandler(BaseHandler):
+    allowed_methods = ('GET', 'PUT', 'DELETE')
+    fields = ('question',)
+    exclude = ('id', re.compile(r'^private_'))
+    model = Poll
+
+    @classmethod
+    def content_size(self, blogpost):
+        return len(blogpost.content)
+
+    def read(self, request, poll_slug=None):
+        if poll_slug:
+            return Poll.objects.get(slug=poll_slug)
+        else:
+            return Poll.objects.all()
+
+    @throttle(5, 10*60) # allow 5 times in 10 minutes
+    def update(self, request, poll_slug):
+        poll = Poll.objects.get(slug=poll_slug)
+
+        poll.question = request.PUT.get('question')
+        poll.save()
+
+        return post
+
+    def delete(self, request, poll_slug):
+        poll = Poll.objects.get(slug=poll_slug)
+
+        #if not request.user == post.author:
+        #    return rc.FORBIDDEN # returns HTTP 401
+
+        poll.delete()
+
+        return rc.DELETED # returns HTTP 204
+
+class ArbitraryDataHandler(BaseHandler):
+    methods_allowed = ('GET',)
+
+    def read(self, request, username, data):
+        user = User.objects.get(username=username)
+
+        return { 'user': user, 'data_length': len(data) }
+from django.conf.urls.defaults import *
+from piston.resource import Resource
+from piston.authentication import HttpBasicAuthentication
+
+from www.api.handlers import PollHandler, ArbitraryDataHandler
+
+auth = HttpBasicAuthentication(realm="My Realm")
+ad = { 'authentication': auth }
+
+poll_resource = Resource(handler=PollHandler, **ad)
+arbitrary_resource = Resource(handler=ArbitraryDataHandler, **ad)
+
+urlpatterns = patterns('',
+    url(r'^polls$', poll_resource, { 'emitter_format': 'json' }),
+    url(r'^polls/(?P<poll_slug>[^/]+)/$', poll_resource), 
+    url(r'^other/(?P<username>[^/]+)/(?P<data>.+)/$', arbitrary_resource),
+)

www/apps/__init__.py

Empty file removed.

www/apps/api/__init__.py

Empty file removed.

www/apps/api/handlers.py

-import re
-
-from piston.handler import BaseHandler
-from piston.utils import rc, throttle
-
-from apps.myapp.models import Poll
-
-class PollHandler(BaseHandler):
-    allowed_methods = ('GET', 'PUT', 'DELETE')
-    fields = ('question',)
-    exclude = ('id', re.compile(r'^private_'))
-    model = Poll
-
-    @classmethod
-    def content_size(self, blogpost):
-        return len(blogpost.content)
-
-    def read(self, request, poll_slug=None):
-        if poll_slug:
-            return Poll.objects.get(slug=poll_slug)
-        else:
-            return Poll.objects.all()
-
-    @throttle(5, 10*60) # allow 5 times in 10 minutes
-    def update(self, request, poll_slug):
-        poll = Poll.objects.get(slug=poll_slug)
-
-        poll.question = request.PUT.get('question')
-        poll.save()
-
-        return post
-
-    def delete(self, request, poll_slug):
-        poll = Poll.objects.get(slug=poll_slug)
-
-        #if not request.user == post.author:
-        #    return rc.FORBIDDEN # returns HTTP 401
-
-        poll.delete()
-
-        return rc.DELETED # returns HTTP 204
-
-class ArbitraryDataHandler(BaseHandler):
-    methods_allowed = ('GET',)
-
-    def read(self, request, username, data):
-        user = User.objects.get(username=username)
-
-        return { 'user': user, 'data_length': len(data) }

www/apps/api/urls.py

-from django.conf.urls.defaults import *
-from piston.resource import Resource
-from piston.authentication import HttpBasicAuthentication
-
-from apps.api.handlers import PollHandler, ArbitraryDataHandler
-
-auth = HttpBasicAuthentication(realm="My Realm")
-ad = { 'authentication': auth }
-
-poll_resource = Resource(handler=PollHandler, **ad)
-arbitrary_resource = Resource(handler=ArbitraryDataHandler, **ad)
-
-urlpatterns = patterns('',
-    url(r'^polls$', poll_resource, { 'emitter_format': 'json' }),
-    url(r'^polls/(?P<poll_slug>[^/]+)/$', poll_resource), 
-    url(r'^other/(?P<username>[^/]+)/(?P<data>.+)/$', arbitrary_resource),
-)

www/apps/myapp/__init__.py

Empty file removed.

www/apps/myapp/admin.py

-from django.contrib import admin
-from apps.myapp.models import *
-
-admin.site.register(Choice)
-admin.site.register(Poll)

www/apps/myapp/models.py

-from django.db import models
-
-class Poll(models.Model):
-    question = models.CharField(max_length=200)
-    pub_date = models.DateTimeField('date published')
-
-class Choice(models.Model):
-    poll = models.ForeignKey(Poll)
-    choice = models.CharField(max_length=200)
-    votes = models.IntegerField()

www/apps/myapp/tests.py

-"""
-This file demonstrates writing tests using the unittest module. These will pass
-when you run "manage.py test".
-
-Replace this with more appropriate tests for your application.
-"""
-
-from django.test import TestCase
-
-

www/apps/myapp/views.py

-# Create your views here.
-
-from django.http import HttpResponse
-
-def index(request):
-    return HttpResponse("Hello, world. You're at the index.")

www/apps/urls.py

-from django.conf.urls.defaults import patterns, include, url
-
-# Uncomment the next two lines to enable the admin:
-from django.contrib import admin
-admin.autodiscover()
-
-urlpatterns = patterns('',
-    (r'^$', 'apps.myapp.views.index'),
-    (r'^api/', include('apps.api.urls')),
-    # Examples:
-    # url(r'^$', 'www.views.home', name='home'),
-    # url(r'^www/', include('www.foo.urls')),
-
-    # Uncomment the admin/doc line below to enable admin documentation:
-    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
-    url(r'^admin/', include(admin.site.urls)),
-)

www/myapp/__init__.py

Empty file added.

www/myapp/admin.py

+from django.contrib import admin
+from www.myapp.models import *
+
+admin.site.register(Choice)
+admin.site.register(Poll)

www/myapp/models.py

+from django.db import models
+
+class Poll(models.Model):
+    question = models.CharField(max_length=200)
+    pub_date = models.DateTimeField('date published')
+
+class Choice(models.Model):
+    poll = models.ForeignKey(Poll)
+    choice = models.CharField(max_length=200)
+    votes = models.IntegerField()

www/myapp/tests.py

+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+

www/myapp/views.py

+# Create your views here.
+
+from django.http import HttpResponse
+
+def index(request):
+    return HttpResponse("Hello, world. You're at the index.")
     'django.contrib.messages.middleware.MessageMiddleware',
 )
 
-ROOT_URLCONF = 'apps.urls'
+ROOT_URLCONF = 'www.urls'
 
 TEMPLATE_DIRS = (
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'south',
-    'apps.api',
-    'apps.myapp',
+    'www.api',
+    'www.myapp',
     'django.contrib.admin',
     'django.contrib.admindocs',
 )
+from django.conf.urls.defaults import patterns, include, url
+
+# Uncomment the next two lines to enable the admin:
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+    (r'^$', 'www.myapp.views.index'),
+    (r'^api/', include('www.api.urls')),
+    # Examples:
+    # url(r'^$', 'www.views.home', name='home'),
+    # url(r'^www/', include('www.foo.urls')),
+
+    # Uncomment the admin/doc line below to enable admin documentation:
+    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+    url(r'^admin/', include(admin.site.urls)),
+)

www/wsgi.py

-import os
-import sys
-
-# Ken added this, only thing that is different from the example template (not counting settings file name)
-#sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),'..')))
-os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
-
-import django.core.handlers.wsgi
-djangoapplication = django.core.handlers.wsgi.WSGIHandler()
-def application(environ, start_response):
-    if 'SCRIPT_NAME' in environ:
-        del environ['SCRIPT_NAME']
-    return djangoapplication(environ, start_response)