# -*- 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 __future__ import division from Globals import InitializeClass from Products.Five import BrowserView as BaseView from zope.component import getUtility from Products.mFolio.interfaces import IAffordanceManager, IUsersManager from AccessControl.SecurityInfo import ClassSecurityInfo from AccessControl import getSecurityManager import time from App import config as zconfig mfolioconf = zconfig.getConfiguration().product_config.get('mfolio', {}) class mFolioManage(BaseView): """ mFolio management view """ security = ClassSecurityInfo() def __init__(self, context, request): self.request = request self.context = context def listData(self): if not hasattr(self.context, '_datastore'): return [] x = self.context._datastore.values() x.sort(reverse=True) return x def formatTime(self, ts): print type(ts) k = time.localtime(ts) return time.strftime('%Y-%m-%d %H:%M', k) InitializeClass(mFolioManage) class mFolioView(BaseView): """ mFolio View """ security = ClassSecurityInfo() def __init__(self, context, request): self.request = request self.context = context self.kml_name = None def getYUIBase(self): return mfolioconf.get('yui_base', '') def getGoogleAPIKey(self): return mfolioconf.get('google_api_key', '') 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 = self.getKMLName() pers = 'default' am = getUtility(IAffordanceManager) userobj = getUtility(IUsersManager).getUser(uname) if userobj is None: print "... 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(1) basey = float(1) x = coords[0] y = coords[1] return str(basex+(x/1000))+","+str(basey+(y/1000)) 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) print coords, x, y return str(x)+','+str(y) def getKMLName(self): return self.kml_name def setKMLName(self, v): self.kml_name = v InitializeClass(mFolioView)