From 986305d1ed01d49009b896014f3d50600eac50e9 Mon Sep 17 00:00:00 2001 From: Christopher Groskopf Date: Sat, 22 Aug 2009 16:16:53 -0700 Subject: [PATCH] Added very rough outline of an html view (citizen app). --- api/models.py | 3 --- api/urls.py | 5 +++++ api/views.py | 1 + citizen/__init__.py | 0 citizen/templates/all.html | 27 +++++++++++++++++++++++++ citizen/views.py | 40 ++++++++++++++++++++++++++++++++++++++ settings.py | 1 + urls.py | 18 +++++------------ 8 files changed, 79 insertions(+), 16 deletions(-) delete mode 100644 api/models.py create mode 100644 api/urls.py create mode 100644 citizen/__init__.py create mode 100644 citizen/templates/all.html create mode 100644 citizen/views.py diff --git a/api/models.py b/api/models.py deleted file mode 100644 index 71a8362..0000000 --- a/api/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/api/urls.py b/api/urls.py new file mode 100644 index 0000000..15bc13d --- /dev/null +++ b/api/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls.defaults import * + +urlpatterns = patterns('', + url(r'^all', 'votersdaily_web.api.views.all', name='api_all'), +) \ No newline at end of file diff --git a/api/views.py b/api/views.py index ba76072..da8b584 100644 --- a/api/views.py +++ b/api/views.py @@ -27,6 +27,7 @@ def all(request): result = json.dumps(document) + return HttpResponse(result, mimetype='application/json') else: raise NotImplementedError() diff --git a/citizen/__init__.py b/citizen/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/citizen/templates/all.html b/citizen/templates/all.html new file mode 100644 index 0000000..b075734 --- /dev/null +++ b/citizen/templates/all.html @@ -0,0 +1,27 @@ + + + + votersdaily_web.citizen.views.all + + + + + {% for document in documents %} + + + + + + + + + + + + + + {% endfor %} + +
{{ document.datetime }}{{ document.title }}{{ document.description }}{{ document.end_datetime }}{{ document.branch }}{{ document.entity }}{{ document.source_url }}{{ document.source_text }}{{ document.access_datetime }}{{ document.parser_name }}{{ document.parser_version }}
+ + \ No newline at end of file diff --git a/citizen/views.py b/citizen/views.py new file mode 100644 index 0000000..b354ec2 --- /dev/null +++ b/citizen/views.py @@ -0,0 +1,40 @@ +import json + +import couchdb +from couchdb.schema import * +from django.http import HttpResponse, HttpResponseRedirect, Http404 +from django.shortcuts import render_to_response + +from votersdaily_web import settings + +def get_event_db(): + """ + Setup CouchDB. Encapsulated for clarity. + """ + server = couchdb.Server(settings.COUCHDB_SERVER_URI) + event_db = server[settings.COUCHDB_EVENTDB_NAME] + + return event_db + +def all(request): + event_db = get_event_db() + + # JSON + #if request.accepts('application/json'): + # GET + if request.method == 'GET': + #doc_id = '2008-10-06T00:00:00Z - Judicial - Supreme Court - Order List' + #document = event_db[doc_id] + + documents = [] + + for doc_id in event_db: + documents.append(event_db[doc_id]) + + return render_to_response('all.html', { 'documents': documents }) + else: + raise NotImplementedError() + # HTML + #else: + # raise NotImplementedError() + \ No newline at end of file diff --git a/settings.py b/settings.py index 79a06f0..fb4dcd0 100644 --- a/settings.py +++ b/settings.py @@ -64,6 +64,7 @@ ROOT_URLCONF = 'votersdaily_web.urls' TEMPLATE_DIRS = ( + '/home/sk/src/votersdaily_web/citizen/templates', # 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. diff --git a/urls.py b/urls.py index 1474aa0..6552532 100644 --- a/urls.py +++ b/urls.py @@ -1,17 +1,9 @@ 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: - url(r'^all', 'api.views.all', name='all'), - - # 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/(.*)', admin.site.root), + # API + (r'^api/', include('votersdaily_web.api.urls')), + + # Citizen + url(r'^all', 'votersdaily_web.citizen.views.all', name='all'), )