from django.conf.urls.defaults import patterns, include, url

from piston.handler import AnonymousBaseHandler, BaseHandler
from piston.resource import Resource

from models import Plugin, PluginComment

class PluginHandler(BaseHandler):
    allowed_methods = ('GET',)
    model = Plugin

    def read(self, request, name=None):
        if name is None:
            return Plugin.objects.filter(published=True)
        else:
            return Plugin.objects.get(name=name, published=True)

class PluginCommentHandler(BaseHandler):
    allowed_methodes = ('GET',)
    model = PluginComment

    fields = ('text', 'user', ('key', ('name',)), 'created_date')

    def read(self, request, name=None):
        plugin = Plugin.objects.get(name=name, published=True)
        return PluginComment.objects.filter(key=plugin)

plugin_handler = Resource(PluginHandler)
plugin_comment_handler = Resource(PluginCommentHandler)
urlpatterns = patterns('',
    url(r'list/', plugin_handler),
    url(r'view/(?P<name>.*)/', plugin_handler),
    url('comments/(?P<name>.*)/', plugin_comment_handler)
)

@@ -55,16 +55,48 @@
 e, url%0A%0A
+from voting.models import Vote%0A%0A
 from pis
@@ -148,16 +148,16 @@
 Handler%0A
-
 from pis
@@ -574,17 +574,16 @@
 d_method
-e
 s = ('GE
@@ -841,16 +841,255 @@
 lugin)%0A%0A
+class PluginRatingHandler(BaseHandler):%0A    allowed_methods = ('GET',)%0A%0A    def read(self, request, name):%0A        plugin = Plugin.objects.get(name=name, published=True)%0A        score = Vote.objects.get_score(plugin)%0A        return score%0A%0A
 plugin_h
@@ -1177,16 +1177,70 @@
 andler)%0A
+plugin_rating_handler = Resource(PluginRatingHandler)%0A
 urlpatte
@@ -1333,32 +1333,32 @@
 lugin_handler),%0A
-
     url('comment
@@ -1398,11 +1398,69 @@
 handler)
+,%0A    url('ratings/(?P%3Cname%3E.*)/', plugin_rating_handler),
 %0A)%0A

Add ratings request.