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

Proposed by Jamal Fanaian
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 (मनीष सिन्हा) Approve
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.
Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

Works like a charm. Perfect

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README'
--- README 2010-11-24 20:06:32 +0000
+++ README 2010-11-30 03:36:06 +0000
@@ -21,6 +21,15 @@
21To create an event:21To create an event:
2222
23 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/event23 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
24 'title',
25 'artist',
26 'album',
27 'year',
28 'comment',
29 'track',
30 'genre',
31 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/
32
2433
25To query an event:34To query an event:
2635
2736
=== modified file 'logger/handlers.py'
--- logger/handlers.py 2010-10-21 05:38:06 +0000
+++ logger/handlers.py 2010-11-30 03:36:06 +0000
@@ -31,7 +31,7 @@
3131
32 def read(self, request):32 def read(self, request):
33 """33 """
34 Query events.34 Query existing events by pass
35 """35 """
36 operations = ('gt', 'lt') # Supported operations36 operations = ('gt', 'lt') # Supported operations
37 operation_re = re.compile('^(?P<field>[a-z]+)_(?P<operation>[a-z]{2})$')37 operation_re = re.compile('^(?P<field>[a-z]+)_(?P<operation>[a-z]{2})$')
@@ -68,3 +68,32 @@
68 query = Event.objects.filter(**data)68 query = Event.objects.filter(**data)
6969
70 return query70 return query
71
72 @staticmethod
73 def resource_uri():
74 return ('api_event_handler', fields)
75
76doc = generate_doc(EventHandler)
77
78print doc.name
79print dir(doc)
80
81#methods = doc.get_methods()
82
83#for method in methods:
84 #print method.name
85 #print method.signature
86
87 #sig = ''
88
89 #for argn, argdef in method.iter_args():
90 #sig += argn
91
92 #if argdef:
93 #sig += '=%s' % argdef
94
95 #sig += ', '
96
97 #sig = sig.rstrip(',')
98
99 #print sig
71100
=== added file 'music/admin.py'
--- music/admin.py 1970-01-01 00:00:00 +0000
+++ music/admin.py 2010-11-30 03:36:06 +0000
@@ -0,0 +1,5 @@
1from affinity.music.models import Music
2from django.contrib import admin
3
4admin.site.register(Music)
5
06
=== added file 'music/handlers.py'
--- music/handlers.py 1970-01-01 00:00:00 +0000
+++ music/handlers.py 2010-11-30 03:36:06 +0000
@@ -0,0 +1,59 @@
1import datetime
2import re
3
4from piston.doc import generate_doc
5from piston.handler import BaseHandler
6from piston.utils import rc, validate
7
8from affinity.logger.models import *
9from affinity.music.models import *
10
11class MusicHandler(BaseHandler):
12 """
13 API endpoint for Music.
14 """
15 allowed_methods = ('POST','GET')
16 fields = (
17 'title',
18 'artist',
19 'album',
20 'year',
21 'comment',
22 'track',
23 'genre',
24
25 ('event', (
26 'timestamp',
27 'origin',
28 'interpretation',
29 'manifestation',
30 'actor',
31
32 ('subject', (
33 'interpretation',
34 'manifestation',
35 'origin',
36 'mimetype',
37 'text')))))
38
39 def create(self, request):
40 """
41 Create a new music record.
42 """
43 data = request.data
44
45 data['event']['subject'] = Subject(**data['event']['subject'])
46 data['event']['subject'].save()
47
48 data['event'] = Event(**data['event'])
49 data['event'].save()
50
51 music = Music(**data)
52 music.save()
53
54 return rc.CREATED
55
56 @staticmethod
57 def resource_uri():
58 return ('api_event_handler', fields)
59
060
=== modified file 'music/urls.py'
--- music/urls.py 2010-11-28 20:49:35 +0000
+++ music/urls.py 2010-11-30 03:36:06 +0000
@@ -1,8 +1,9 @@
1from django.conf.urls.defaults import *1from django.conf.urls.defaults import *
2from piston.resource import Resource2from piston.resource import Resource
33
4from affinity.music.handlers import *
5
4urlpatterns = patterns('affinity.music.views',6urlpatterns = patterns('affinity.music.views',
5 # Example:7 # Example:
6 (r'^$', 'index'),8 (r'^$', Resource(MusicHandler)),
7 #(r'^music$', Resource(EventHandler)),
8)9)
910
=== modified file 'settings.py'
--- settings.py 2010-11-28 20:49:35 +0000
+++ settings.py 2010-11-30 03:36:06 +0000
@@ -14,7 +14,7 @@
14 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.14 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
15 'NAME': 'affinity', # Or path to database file if using sqlite3.15 'NAME': 'affinity', # Or path to database file if using sqlite3.
16 'USER': 'root', # Not used with sqlite3.16 'USER': 'root', # Not used with sqlite3.
17 'PASSWORD': 'root', # Not used with sqlite3.17 'PASSWORD': '', # Not used with sqlite3.
18 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.18 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
19 'PORT': '', # Set to empty string for default. Not used with sqlite3.19 'PORT': '', # Set to empty string for default. Not used with sqlite3.
20 }20 }

Subscribers

People subscribed via source and target branches

to all changes: