# This file is part of Moksha.
#
# Moksha is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Moksha is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Moksha.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2008, Red Hat, Inc.
# Authors: John (J5) Palmieri <johnp@redhat.com>
from tw.jquery import jquery_js
from tw.api import JSLink
from tw.api import Widget
import tg
import pylons

moksha_js = JSLink(modname="moksha", filename='public/javascript/moksha.js',
                   javascript=[jquery_js])

class MokshaGlobals(Widget):
    javascript = [moksha_js]
    template = """<script type="text/javascript">
moksha_base_url = "${base_url}";
moksha_csrf_token = "${csrf_token}";
moksha_userid = "${user_id}";
</script>
"""
    params = ['base_url', 'csrf_token', 'user_id']
    engine_name = 'mako'

    base_url = '/'
    csrf_token = ''
    user_id = ''

    def update_params(self, d):
        super(MokshaGlobals, self).update_params(d)
        d['base_url'] = tg.url('/')
        identity = pylons.request.environ.get('repoze.who.identity')

        if identity:
            d['csrf_token'] = identity.get('_csrf_token','')
            d['user_id'] = identity.get('user_id', '')


@@ -725,16 +725,17 @@
 at.com%3E%0A
+%0A
 from tw.
@@ -1312,16 +1312,193 @@
 d = ''%0A%0A
+    def __init__(self, *args, **kw):%0A        super(MokshaGlobals, self).__init__(*args, **kw)%0A        self.csrf_token_id = tg.config.get('moksha.csrf.token_id', '_csrf_token')%0A%0A
     def 
@@ -1521,16 +1521,16 @@
 lf, d):%0A
-
         
@@ -1743,18 +1743,21 @@
 ity.get(
-'_
+self.
 csrf_tok
@@ -1758,18 +1758,21 @@
 rf_token
-',
+_id, 
 '')%0A    
@@ -1822,9 +1822,8 @@
 d', '')%0A
-%0A

Make the csrf_token id configurable in our MokshaGlobals object.