Beispiel #1
0
def url_for(path, cache_bust=False, **params):
    ''' Return the full url for the given path '''
    from pyutils.utils.config import Config
    url = Config.get_root_url() + "/" + path
    if params:
        url += "?"
        for k in params:
            url += "%s=%s&" % (k, params[k])
    if cache_bust:
        url += ("?" if not params else "") + "v=" + Config.get_version()
    return url
Beispiel #2
0
@author: Benjamin Dezile
'''

from mako.runtime import Context
from mako.lookup import TemplateLookup
from mako import exceptions
from pyutils.utils.config import Config
from pyutils.utils import helpers
from mvc.server import session
from cStringIO import StringIO
import urllib
import json
import os


FILE_CHECKS = Config.get("templates", "file_checks")
TEMPLATE_CACHE_DIR = Config.get("templates", "cache_dir")

DEFAULT_TEMPLATE_EXT = Config.get("templates", "default_ext")
if not DEFAULT_TEMPLATE_EXT:
    DEFAULT_TEMPLATE_EXT = "html"


def get_template_path_info(path):
    ''' Return (base_path, file_name) '''
    path_parts = path.split(os.path.sep)
    full_path = os.path.sep.join(path_parts[:-1])
    file_name = path_parts[-1]
    if file_name.find(".") < 0:
        file_name += "." + DEFAULT_TEMPLATE_EXT
    return (full_path, file_name)
    ret_f = wrapper
    ret_f.exposed = True
    return ret_f     

def _process_async_call(f, args):
    ''' Process an asynchronous action call and automatically format the response '''
    try:
        res = f(**args)
        data = res if res is not None else {}
        json_resp = format_async_response(data)
    except cherrypy.HTTPError, e:
        raise e
    except Exception, e:
        Logger.error("Error while processing call to %s" % f.__name__, e)
        json_resp = format_async_response(None, False, e)
    if Config.is_dev():
        Logger.debug("Async response to %s: %s" % (f.__name__, json_resp))
    return json_resp


##  CONTROLLER  #################################

class BaseController(object):
    ''' Base controller
    Abstract base for all controllers.
    Contains all sorts of helpers and structures that may be needed in controllers.
    '''
    
    instances = dict()
    web_dir = None