import web


class PluginView:
    def GET(self, args):
        return self.request(args, "GET")

    def POST(self, args):
        return self.request(args, "POST")

    def request(self, args, method):
        argslist = args.partition('/')
        plugin_name = argslist[0]
        plugin = web.ctx.plugin_manager.get_plugin_by_name(plugin_name)
        if not plugin:
            print "plugin %s not found" % plugin_name
            raise web.notfound()

        if not plugin.is_enabled():
            print "plugin %s not enabled" % plugin_name
            raise web.notfound()

        return plugin._request(argslist[2], args, method)
