from AccessControl.SecurityInfo import ClassSecurityInfo from Products.Five import BrowserView from zope.component import getUtility from Products.iva.interfaces import IStatistics, IUserManager from Products.iva.config import IVA_VERSION try: from Products.iva.config import image_base except ImportError: image_base = "" from AccessControl import getSecurityManager import time from Products.iva.common import translate class IVA(BrowserView): def get_image_path(self): return image_base def getCurrentCourseId(self): """ get current course id for currently logged in user """ um = getUtility(IUserManager) userid = str(getSecurityManager().getUser()) ui = getattr(um, userid, None) if not ui: return 0 return ui.get_jooksev_kursus() def registerVisit(self): um = getUtility(IUserManager) cid = self.getCurrentCourseId() userLocation = um.kasutajaasukoht(self.request) s = getUtility(IStatistics) s._registerVisit(self.request, cid, userLocation) return 0 def get_formatted_current_date(self): """Return date formatted depending on user's language.""" return time.strftime(translate(self.context,'short_date_format',default="%Y-%m-%d",target=self.context.giveLanguage(self.request)), time.localtime()) def get_printable_date(self, dates): """Return date formatted""" #return "11-22-33" return time.strftime(translate(self.context, 'short_date_format', default="%Y-%m-%d", target=self.context.giveLanguage(self.request)), time.localtime(dates)) def is_logged_in(self, uname): return uname in getUtility(IStatistics).active_users()