# Path: studio/lib/base.py
# class BaseController(WSGIController):
#     def __call__(self, environ, start_response):
# 
# Path: studio/lib/helpers.py
# def gen_mapname():
# def _gen_string(length=8, chars=string.digits + string.letters):


import logging
import simplejson
from pylons import request, response, session, tmpl_context as c
from pylons.controllers.util import abort, redirect_to
from pylons.decorators import jsonify
from repoze.what.predicates import not_anonymous, has_permission
from repoze.what.plugins.pylonshq import ActionProtector
from studio.lib.base import BaseController, render
from studio.lib import helpers as h
from studio.model import *

    @ActionProtector(has_permission('view_layertemplates'))
    @jsonify
    def index(self, format='html'):
        """GET /layertemplates: All items in the collection."""
        # url('layertemplates')
        lts = meta.Session.query(LayerTemplate)
        # use following query for getting layertemplates owned by current user
        #lts = self._get_lts_from_user(c.user)
        serialized_lts = []
        for lt in lts:
            serialized_lts.append({
                'id': lt.id,
                'name': lt.name,
                'comment': lt.comment,
                "href": h.url_for(controller="layertemplates", action="show", id=lt.id)
                })
        # prevent JSON Array Cross-site Exploits (XSRF/CSRF)
        return {'layertemplates': serialized_lts}

    @ActionProtector(has_permission('create_update_layertemplates'))
    @jsonify
    def create(self):
        """POST /layertemplates: Create a new item."""
        # url('layertemplates')
        content = request.environ['wsgi.input'].read(int(request.environ['CONTENT_LENGTH']))
        content = content.decode('utf8')
        content = simplejson.loads(content)
        lt = self._new_lt_from_user(content['name'], content['comment'], content['json'], c.user)
        response.status = 201

# Path: studio/lib/base.py
# class BaseController(WSGIController):
#     def __call__(self, environ, start_response):
# 
# Path: studio/lib/helpers.py
# def gen_mapname():
# def _gen_string(length=8, chars=string.digits + string.letters):


# Path: studio/controllers/layertemplates.py
import logging
import simplejson
from pylons import request, response, session, tmpl_context as c
from pylons.controllers.util import abort, redirect_to
from pylons.decorators import jsonify
from repoze.what.predicates import not_anonymous, has_permission
from repoze.what.plugins.pylonshq import ActionProtector
from studio.lib.base import BaseController, render
from studio.lib import helpers as h
from studio.model import *


    @ActionProtector(has_permission('view_layertemplates'))
    @jsonify
    def index(self, format='html'):
        """GET /layertemplates: All items in the collection."""
        # url('layertemplates')
        lts = meta.Session.query(LayerTemplate)
        # use following query for getting layertemplates owned by current user
        #lts = self._get_lts_from_user(c.user)
        serialized_lts = []
        for lt in lts:
            serialized_lts.append({
                'id': lt.id,
                'name': lt.name,
                'comment': lt.comment,
                "href": h.url_for(controller="layertemplates", action="show", id=lt.id)
                })
        # prevent JSON Array Cross-site Exploits (XSRF/CSRF)
        return {'layertemplates': serialized_lts}

    @ActionProtector(has_permission('create_update_layertemplates'))
    @jsonify
    def create(self):
        """POST /layertemplates: Create a new item."""
        # url('layertemplates')
        content = request.environ['wsgi.input'].read(int(request.environ['CONTENT_LENGTH']))
        content = content.decode('utf8')
        content = simplejson.loads(content)
        lt = self._new_lt_from_user(content['name'], content['comment'], content['json'], c.user)
        response.status = 201

        href = h.url_for(controller="layertemplates", action="show", id=lt.id)