# -*- coding: utf-8 # Copyright (c) 2008, iCamp Consortium # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. from Globals import InitializeClass from Products.Five import BrowserView as BaseView from zope.component import getUtility from Products.iFolio.interfaces import IAffordanceManager, IUsersManager from AccessControl.SecurityInfo import ClassSecurityInfo from AccessControl import getSecurityManager class iFolioSkinWatcher(BaseView): """ iFolio skin watcher """ def __call__(self): REQUEST = self.context.request if '++skin++' not in REQUEST.URL: url = '++skin++iFolio' return REQUEST.RESPONSE.redirect(self.context.absolute_url()+'/'+url) return class iFolioView(BaseView): """ iFolio View """ security = ClassSecurityInfo() def getYUIBase(self): #return "http://yheksa.htk.tlu.ee/~vahur/yui/build" return "http://www.htk.tlu.ee/~vahur/yui/yui/build" def listUsers(self): um = getUtility(IUsersManager) users = um._listUsers() res = [] for x in users: res.append([x.id, x.getTitle()]) #return [['vahur', 'Vahur Rebas'], ['pjotr', 'Pjotr Savitski']] return res def isLoggedIn(self): u = getSecurityManager().getUser() if u is None or u.getUserName() == 'Anonymous User': return 0 return 1 def getUserInfo(self): # retrun all empty in case of anonymous user if self.isLoggedIn() == 0: return ['', '', ''] u = getSecurityManager().getUser() uname = u.getUserName() um = getUtility(IUsersManager) user = um.getUser(uname) fname = '' lname = '' email = '' try: fname = user.firstname except AttributeError: pass try: lname = user.lastname except AttributeError: pass try: email = user.email except AttributeError: pass return [fname, lname, email] def getUserPerspective(self): v = {} req = self.request uname = req.get('username') pers = 'default' am = getUtility(IAffordanceManager) userobj = getUtility(IUsersManager).getUser(uname) if userobj is None: return v for a in am.getAffordances(): v[a.id] = userobj.getAffordanceData(pers, a.id) return v def normalizeForKML(self, coords): basex = float(24) basey = float(25) x = coords[0] y = coords[1] xpref = "" ypref = "" if x < 0: xpref = "-" if y < 0: ypref = "-" x = xpref+"0."+str(abs(x)) y = ypref+"0."+str(abs(y)) x = basex + float(x) y = basey + float(y) return str(x)+','+str(y) InitializeClass(iFolioView)