Merge lp:~jamalta/zeitgeist-affinity/music-handler into lp:zeitgeist-affinity

Proposed by Jamal Fanaian on 2010-11-30
Status: Merged
Merged at revision: 11
Proposed branch: lp:~jamalta/zeitgeist-affinity/music-handler
Merge into: lp:zeitgeist-affinity
Diff against target: 168 lines (+107/-4)
6 files modified
README (+9/-0)
logger/handlers.py (+30/-1)
music/admin.py (+5/-0)
music/handlers.py (+59/-0)
music/urls.py (+3/-2)
settings.py (+1/-1)
To merge this branch: bzr merge lp:~jamalta/zeitgeist-affinity/music-handler
Reviewer Review Type Date Requested Status
Manish Sinha (मनीष सिन्हा) 2010-11-30 Approve on 2010-11-30
Review via email: mp+42201@code.launchpad.net

Description of the change

Created the piston handler for music. Currently, read is not implemented.

To post a comment you must log in.

Works like a charm. Perfect

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2010-11-24 20:06:32 +0000
3+++ README 2010-11-30 03:36:06 +0000
4@@ -21,6 +21,15 @@
5 To create an event:
6
7 curl -H 'Content-Type:application/json' -X POST -d '{"origin": "test origin", "interpretation": "test interpretation", "manifestation": "test manifestation", "actor": "test actor", "subject": {"interpretation": "test interpretation subject", "manifestation": "test manifestation subject", "origin": "test origin subject", "mimetype": "test mimetype", "text": "more testing"}}' http://localhost:8000/log/event
8+ 'title',
9+ 'artist',
10+ 'album',
11+ 'year',
12+ 'comment',
13+ 'track',
14+ 'genre',
15+ curl -H 'Content-Type:application/json' -X POST -d '{"title": "test title", "artist": "test artist", "album": "test album", "year": 2010, "comment": "test comment", "track": 1, "genre": "test genre", "event": {"origin": "test origin", "interpretation": "test interpretation", "manifestation": "test manifestation", "actor": "test actor", "subject": {"interpretation": "test interpretation subject", "manifestation": "test manifestation subject", "origin": "test origin subject", "mimetype": "test mimetype", "text": "more testing"}}}' http://localhost:8000/music/
16+
17
18 To query an event:
19
20
21=== modified file 'logger/handlers.py'
22--- logger/handlers.py 2010-10-21 05:38:06 +0000
23+++ logger/handlers.py 2010-11-30 03:36:06 +0000
24@@ -31,7 +31,7 @@
25
26 def read(self, request):
27 """
28- Query events.
29+ Query existing events by pass
30 """
31 operations = ('gt', 'lt') # Supported operations
32 operation_re = re.compile('^(?P<field>[a-z]+)_(?P<operation>[a-z]{2})$')
33@@ -68,3 +68,32 @@
34 query = Event.objects.filter(**data)
35
36 return query
37+
38+ @staticmethod
39+ def resource_uri():
40+ return ('api_event_handler', fields)
41+
42+doc = generate_doc(EventHandler)
43+
44+print doc.name
45+print dir(doc)
46+
47+#methods = doc.get_methods()
48+
49+#for method in methods:
50+ #print method.name
51+ #print method.signature
52+
53+ #sig = ''
54+
55+ #for argn, argdef in method.iter_args():
56+ #sig += argn
57+
58+ #if argdef:
59+ #sig += '=%s' % argdef
60+
61+ #sig += ', '
62+
63+ #sig = sig.rstrip(',')
64+
65+ #print sig
66
67=== added file 'music/admin.py'
68--- music/admin.py 1970-01-01 00:00:00 +0000
69+++ music/admin.py 2010-11-30 03:36:06 +0000
70@@ -0,0 +1,5 @@
71+from affinity.music.models import Music
72+from django.contrib import admin
73+
74+admin.site.register(Music)
75+
76
77=== added file 'music/handlers.py'
78--- music/handlers.py 1970-01-01 00:00:00 +0000
79+++ music/handlers.py 2010-11-30 03:36:06 +0000
80@@ -0,0 +1,59 @@
81+import datetime
82+import re
83+
84+from piston.doc import generate_doc
85+from piston.handler import BaseHandler
86+from piston.utils import rc, validate
87+
88+from affinity.logger.models import *
89+from affinity.music.models import *
90+
91+class MusicHandler(BaseHandler):
92+ """
93+ API endpoint for Music.
94+ """
95+ allowed_methods = ('POST','GET')
96+ fields = (
97+ 'title',
98+ 'artist',
99+ 'album',
100+ 'year',
101+ 'comment',
102+ 'track',
103+ 'genre',
104+
105+ ('event', (
106+ 'timestamp',
107+ 'origin',
108+ 'interpretation',
109+ 'manifestation',
110+ 'actor',
111+
112+ ('subject', (
113+ 'interpretation',
114+ 'manifestation',
115+ 'origin',
116+ 'mimetype',
117+ 'text')))))
118+
119+ def create(self, request):
120+ """
121+ Create a new music record.
122+ """
123+ data = request.data
124+
125+ data['event']['subject'] = Subject(**data['event']['subject'])
126+ data['event']['subject'].save()
127+
128+ data['event'] = Event(**data['event'])
129+ data['event'].save()
130+
131+ music = Music(**data)
132+ music.save()
133+
134+ return rc.CREATED
135+
136+ @staticmethod
137+ def resource_uri():
138+ return ('api_event_handler', fields)
139+
140
141=== modified file 'music/urls.py'
142--- music/urls.py 2010-11-28 20:49:35 +0000
143+++ music/urls.py 2010-11-30 03:36:06 +0000
144@@ -1,8 +1,9 @@
145 from django.conf.urls.defaults import *
146 from piston.resource import Resource
147
148+from affinity.music.handlers import *
149+
150 urlpatterns = patterns('affinity.music.views',
151 # Example:
152- (r'^$', 'index'),
153- #(r'^music$', Resource(EventHandler)),
154+ (r'^$', Resource(MusicHandler)),
155 )
156
157=== modified file 'settings.py'
158--- settings.py 2010-11-28 20:49:35 +0000
159+++ settings.py 2010-11-30 03:36:06 +0000
160@@ -14,7 +14,7 @@
161 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
162 'NAME': 'affinity', # Or path to database file if using sqlite3.
163 'USER': 'root', # Not used with sqlite3.
164- 'PASSWORD': 'root', # Not used with sqlite3.
165+ 'PASSWORD': '', # Not used with sqlite3.
166 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
167 'PORT': '', # Set to empty string for default. Not used with sqlite3.
168 }

Subscribers

People subscribed via source and target branches

to all changes: