From 4065f0b0d6f4fbbdf04c0707ce49c8ffbc687032 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Thu, 15 Jul 2010 00:03:46 -0400 Subject: Adding JSON API. --- snakeplan/api/__init__.py | 0 snakeplan/api/handlers.py | 26 ++++++++++++++++++++++++++ snakeplan/api/urls.py | 35 +++++++++++++++++++++++++++++++++++ snakeplan/settings.py | 2 ++ snakeplan/urls.py | 9 ++++++--- 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 snakeplan/api/__init__.py create mode 100644 snakeplan/api/handlers.py create mode 100644 snakeplan/api/urls.py diff --git a/snakeplan/api/__init__.py b/snakeplan/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/snakeplan/api/handlers.py b/snakeplan/api/handlers.py new file mode 100644 index 0000000..0377ffc --- /dev/null +++ b/snakeplan/api/handlers.py @@ -0,0 +1,26 @@ +from piston.handler import BaseHandler +from projects import models + + +class ProjectHandler(BaseHandler): + + allowed_methods = ('GET', ) + exclude = () + model = models.Project + + +class TaskHandler(BaseHandler): + + allowed_methods = ('GET', ) + exclude = () + model = models.Task + + +class ProjectStoryHandler(BaseHandler): + + allowed_methds = ('GET', ) + exclude = () + model = models.Project + + def read(self, request, id): + return self.model.objects.get(id=id).stories.all() diff --git a/snakeplan/api/urls.py b/snakeplan/api/urls.py new file mode 100644 index 0000000..1d223fb --- /dev/null +++ b/snakeplan/api/urls.py @@ -0,0 +1,35 @@ +# vim: set filencoding=utf8 +""" +API URLConf + +@author: Mike Crute (mcrute@gmail.com) +@organization: SoftGroup Interactive, Inc. +@date: July 13, 2010 +""" + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from django.conf.urls.defaults import patterns, include, url +from piston.resource import Resource + +import handlers + +urlpatterns = patterns('', + url(r'project/(?P[^/]+)/stories', Resource(handlers.ProjectStoryHandler)), + url(r'project/(?P[^/]+)/', Resource(handlers.ProjectHandler)), + url(r'project/', Resource(handlers.ProjectHandler)), + + url(r'task/(?P[^/]+)/', Resource(handlers.TaskHandler)), + url(r'task/', Resource(handlers.TaskHandler)), +) diff --git a/snakeplan/settings.py b/snakeplan/settings.py index c735997..da055fb 100644 --- a/snakeplan/settings.py +++ b/snakeplan/settings.py @@ -77,8 +77,10 @@ INSTALLED_APPS = ( 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', + 'piston', 'snakeplan.projects', 'snakeplan.accounts', + 'snakeplan.api', ) AUTH_PROFILE_MODULE = 'snakeplan.accounts.UserProfile' diff --git a/snakeplan/urls.py b/snakeplan/urls.py index 6d910f1..c6feb22 100644 --- a/snakeplan/urls.py +++ b/snakeplan/urls.py @@ -19,14 +19,17 @@ SnakePlan URL Configuration # limitations under the License. from django.views import static +from django.views.generic.simple import direct_to_template from django.conf.urls.defaults import patterns, include from django.contrib import admin; admin.autodiscover() -urlpatterns = patterns('django.views.generic.simple', - (r'^$', 'redirect_to', {'url': 'projects/' }), - (r'^projects/', include('projects.urls')), +urlpatterns = patterns('', + (r'^api/', include('api.urls')), + (r'^', include('projects.urls')), + (r'^$', direct_to_template, { 'template': 'base.html' }), + (r'^admin/', include(admin.site.urls)), (r'^media/(?P.*)$', static.serve, {'document_root':'templates/media'}), ) -- cgit v1.2.3