diff options
author | Mike Crute <mcrute@gmail.com> | 2010-07-15 00:03:46 -0400 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2010-07-15 00:03:46 -0400 |
commit | 4065f0b0d6f4fbbdf04c0707ce49c8ffbc687032 (patch) | |
tree | ac7c4ab8b8cc3f129ca5008c88103c5ce5bb6f6a | |
parent | 7359bd23ec232c238fc07c579776f7869dd3f00d (diff) | |
download | snakeplan-4065f0b0d6f4fbbdf04c0707ce49c8ffbc687032.tar.bz2 snakeplan-4065f0b0d6f4fbbdf04c0707ce49c8ffbc687032.tar.xz snakeplan-4065f0b0d6f4fbbdf04c0707ce49c8ffbc687032.zip |
Adding JSON API.
-rw-r--r-- | snakeplan/api/__init__.py | 0 | ||||
-rw-r--r-- | snakeplan/api/handlers.py | 26 | ||||
-rw-r--r-- | snakeplan/api/urls.py | 35 | ||||
-rw-r--r-- | snakeplan/settings.py | 2 | ||||
-rw-r--r-- | snakeplan/urls.py | 9 |
5 files changed, 69 insertions, 3 deletions
diff --git a/snakeplan/api/__init__.py b/snakeplan/api/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/snakeplan/api/__init__.py | |||
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 @@ | |||
1 | from piston.handler import BaseHandler | ||
2 | from projects import models | ||
3 | |||
4 | |||
5 | class ProjectHandler(BaseHandler): | ||
6 | |||
7 | allowed_methods = ('GET', ) | ||
8 | exclude = () | ||
9 | model = models.Project | ||
10 | |||
11 | |||
12 | class TaskHandler(BaseHandler): | ||
13 | |||
14 | allowed_methods = ('GET', ) | ||
15 | exclude = () | ||
16 | model = models.Task | ||
17 | |||
18 | |||
19 | class ProjectStoryHandler(BaseHandler): | ||
20 | |||
21 | allowed_methds = ('GET', ) | ||
22 | exclude = () | ||
23 | model = models.Project | ||
24 | |||
25 | def read(self, request, id): | ||
26 | 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 @@ | |||
1 | # vim: set filencoding=utf8 | ||
2 | """ | ||
3 | API URLConf | ||
4 | |||
5 | @author: Mike Crute (mcrute@gmail.com) | ||
6 | @organization: SoftGroup Interactive, Inc. | ||
7 | @date: July 13, 2010 | ||
8 | """ | ||
9 | |||
10 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
11 | # you may not use this file except in compliance with the License. | ||
12 | # You may obtain a copy of the License at | ||
13 | # | ||
14 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
15 | # | ||
16 | # Unless required by applicable law or agreed to in writing, software | ||
17 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
19 | # See the License for the specific language governing permissions and | ||
20 | # limitations under the License. | ||
21 | |||
22 | |||
23 | from django.conf.urls.defaults import patterns, include, url | ||
24 | from piston.resource import Resource | ||
25 | |||
26 | import handlers | ||
27 | |||
28 | urlpatterns = patterns('', | ||
29 | url(r'project/(?P<id>[^/]+)/stories', Resource(handlers.ProjectStoryHandler)), | ||
30 | url(r'project/(?P<id>[^/]+)/', Resource(handlers.ProjectHandler)), | ||
31 | url(r'project/', Resource(handlers.ProjectHandler)), | ||
32 | |||
33 | url(r'task/(?P<id>[^/]+)/', Resource(handlers.TaskHandler)), | ||
34 | url(r'task/', Resource(handlers.TaskHandler)), | ||
35 | ) | ||
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 = ( | |||
77 | 'django.contrib.sessions', | 77 | 'django.contrib.sessions', |
78 | 'django.contrib.sites', | 78 | 'django.contrib.sites', |
79 | 'django.contrib.admin', | 79 | 'django.contrib.admin', |
80 | 'piston', | ||
80 | 'snakeplan.projects', | 81 | 'snakeplan.projects', |
81 | 'snakeplan.accounts', | 82 | 'snakeplan.accounts', |
83 | 'snakeplan.api', | ||
82 | ) | 84 | ) |
83 | 85 | ||
84 | AUTH_PROFILE_MODULE = 'snakeplan.accounts.UserProfile' | 86 | 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 | |||
19 | # limitations under the License. | 19 | # limitations under the License. |
20 | 20 | ||
21 | from django.views import static | 21 | from django.views import static |
22 | from django.views.generic.simple import direct_to_template | ||
22 | from django.conf.urls.defaults import patterns, include | 23 | from django.conf.urls.defaults import patterns, include |
23 | 24 | ||
24 | from django.contrib import admin; admin.autodiscover() | 25 | from django.contrib import admin; admin.autodiscover() |
25 | 26 | ||
26 | 27 | ||
27 | urlpatterns = patterns('django.views.generic.simple', | 28 | urlpatterns = patterns('', |
28 | (r'^$', 'redirect_to', {'url': 'projects/' }), | 29 | (r'^api/', include('api.urls')), |
29 | (r'^projects/', include('projects.urls')), | 30 | (r'^', include('projects.urls')), |
31 | (r'^$', direct_to_template, { 'template': 'base.html' }), | ||
32 | |||
30 | (r'^admin/', include(admin.site.urls)), | 33 | (r'^admin/', include(admin.site.urls)), |
31 | (r'^media/(?P<path>.*)$', static.serve, {'document_root':'templates/media'}), | 34 | (r'^media/(?P<path>.*)$', static.serve, {'document_root':'templates/media'}), |
32 | ) | 35 | ) |