def selectobjects(self): "Displays the select objects dialog" context = HttpContext.current() sCC = context.request.queryString['cc'][0] params = { 'ID': self.id or '/', 'IMG': self.__image__, 'DN': self.displayName.value, 'HAS_SUBFOLDERS': str(self.hasSubfolders()).lower(), 'MULTIPLE': context.request.queryString['multiple'][0], 'CC': sCC } oCmd = OqlCommand() sOql = "select * from '%s'" % self.id if sCC != '*': ccs = sCC.split('|') ccs = ["contentclass='%s'" % x for x in ccs] sConditions = " or ".join(ccs) sOql += " where %s" % sConditions oRes = oCmd.execute(sOql) sOptions = '' for obj in oRes: sOptions += '<option img="%s" value="%s" caption="%s"/>' % \ (obj.__image__, obj.id, obj.displayName.value) params['OPTIONS'] = sOptions return params
def executeOqlCommand(self, command, range=None): oCmd = OqlCommand() oRes = oCmd.execute(command) if range == None: return [rec for rec in oRes] else: return [oRes[range[0]:range[1]], len(oRes)]
def setParams(self): sLang = self.request.getLang() sCC = self.request.queryString['cc'][0] self.params = { 'ID': self.item.id or '/', 'IMG': self.item.__image__, 'DN': self.item.displayName.value, 'HAS_SUBFOLDERS': self.getStringFromBoolean(self.item.hasSubfolders()), 'MULTIPLE': self.request.queryString['multiple'][0], 'CC': sCC } oCmd = OqlCommand() sOql = "select * from '%s'" % self.item.id if sCC != '*': ccs = sCC.split('|') ccs = ["contentclass='%s'" % x for x in ccs] sConditions = " or ".join(ccs) sOql += " where %s" % sConditions oRes = oCmd.execute(sOql) sOptions = '' for obj in oRes: sOptions += '<a:option img="%s" value="%s" caption="%s"></a:option>' % (obj.__image__, obj.id, obj.displayName.value) self.params['OPTIONS'] = sOptions
def commitChanges(self): GenericSchemaEditor.commitChanges(self) if len(self._addedProps): # we must reload the class module oMod = misc.getCallableByName(self._class.__module__) reload(oMod) from porcupine.oql.command import OqlCommand db = offlinedb.getHandle() oql_command = OqlCommand() rs = oql_command.execute("select * from deep('/') where instanceof('%s')" % self._instance.contentclass) try: if len(rs): txn = offlinedb.OfflineTransaction() try: for item in rs: for name in self._addedProps: if not hasattr(item, name): setattr(item, name, self._addedProps[name]) db.putItem(item, txn) txn.commit() except Exception, e: txn.abort() raise e sys.exit(2) finally: offlinedb.close()
def removeProperty(self, name): from porcupine.oql.command import OqlCommand db = offlinedb.getHandle() oql_command = OqlCommand() rs = oql_command.execute( "select * from deep('/') where instanceof('%s')" % self._instance.contentclass) try: if len(rs): txn = offlinedb.OfflineTransaction() try: for item in rs: if hasattr(item, name): delattr(item, name) db.putItem(item, txn) txn.commit() except Exception, e: txn.abort() raise e sys.exit(2) finally: offlinedb.close() if self._attrs.has_key(name): del self._attrs[name]
def executeOqlCommand(self, command, range=None): oCmd = OqlCommand() oRes = oCmd.execute(command) if range == None: retVal = [rec for rec in oRes] return retVal else: total_recs = len(oRes) slice = [rec for rec in oRes[range[0] : range[1]]] return [slice, total_recs]
def user_settings(self): "Displays the user settings dialog" context = HttpContext.current() context.response.setHeader("cache-control", "no-cache") settings = context.session.user.settings taskbar_pos = settings.value.setdefault("TASK_BAR_POS", "bottom") params = {"TASK_BAR_POS": taskbar_pos} if taskbar_pos == "bottom": params["CHECKED_TOP"] = "false" params["CHECKED_BOTTOM"] = "true" else: params["CHECKED_TOP"] = "true" params["CHECKED_BOTTOM"] = "false" autoRun = settings.value.setdefault("AUTO_RUN", "") if settings.value.setdefault("RUN_MAXIMIZED", False) == True: params["RUN_MAXIMIZED_VALUE"] = "true" else: params["RUN_MAXIMIZED_VALUE"] = "false" # get applications oCmd = OqlCommand() sOql = "select displayName,launchUrl,icon from 'apps' " + "order by displayName asc" apps = oCmd.execute(sOql) sSelected = "" if autoRun == "": sSelected = "true" sApps = '<option caption="@@NONE_APP@@" selected="%s" value=""/>' % sSelected if len(apps) > 0: for app in apps: if autoRun == app["launchUrl"]: sSelected = "true" else: sSelected = "false" sApps += '<option img="%s" caption="%s" value="%s" selected="%s"/>' % ( app["icon"], app["displayName"], app["launchUrl"], sSelected, ) params["APPS"] = sApps return params
def user_settings(self): "Displays the user settings dialog" context = HttpContext.current() context.response.setHeader('cache-control', 'no-cache') settings = context.user.settings taskbar_pos = settings.value.setdefault('TASK_BAR_POS', 'bottom') params = {'TASK_BAR_POS' : taskbar_pos} if taskbar_pos == 'bottom': params['CHECKED_TOP'] = 'false' params['CHECKED_BOTTOM'] = 'true' else: params['CHECKED_TOP'] = 'true' params['CHECKED_BOTTOM'] = 'false' autoRun = settings.value.setdefault('AUTO_RUN', '') if settings.value.setdefault('RUN_MAXIMIZED', False) == True: params['RUN_MAXIMIZED_VALUE'] = 'true' else: params['RUN_MAXIMIZED_VALUE'] = 'false' # get applications oCmd = OqlCommand() sOql = "select displayName,launchUrl,icon from 'apps' " + \ "order by displayName asc" apps = oCmd.execute(sOql) sSelected = '' if autoRun == '': sSelected = 'true' sApps = '<option caption="@@NONE_APP@@" selected="%s" value=""/>' \ % sSelected if len(apps) > 0: for app in apps: if autoRun == app['launchUrl']: sSelected = 'true' else: sSelected = 'false' sApps += \ '<option img="%s" caption="%s" value="%s" selected="%s"/>' % \ (app['icon'], app['displayName'], app['launchUrl'], sSelected) params['APPS'] = sApps return params
def setParams(self): self.response.setHeader('cache-control', 'no-cache') sLang = self.request.getLang() self.params = { 'LOGOFF': resources.getResource('LOGOFF', sLang), 'LOGOFF?': resources.getResource('LOGOFF?', sLang), 'START': resources.getResource('START', sLang), 'APPLICATIONS': resources.getResource('APPLICATIONS', sLang), 'SETTINGS': resources.getResource('SETTINGS', sLang), 'INFO': resources.getResource('INFO', sLang), 'USER': self.session.user.displayName.value, 'AUTO_RUN' : self.session.user.settings.value.setdefault('AUTO_RUN', ''), 'RUN_MAXIMIZED' : int(self.session.user.settings.value.setdefault('RUN_MAXIMIZED', False)), } # has the user access to recycle bin? rb_icon = '' rb = self.server.store.getItem('rb') if rb: rb_icon = ''' <a:icon top="80" left="10" width="80" height="80" imgalign="top" ondblclick="generic.openContainer" img="desktop/images/trashcan_full.gif" color="white" caption="%s"> <a:prop name="folderID" value="rb"></a:prop> </a:icon> ''' % rb.displayName.value desktop_pane = DESKSTOP_PANE % (self.item.displayName.value, rb_icon) taskbar_position = self.session.user.settings.value.setdefault('TASK_BAR_POS', 'bottom') if taskbar_position == 'bottom': self.params['TOP'] = desktop_pane self.params['BOTTOM'] = '' else: self.params['TOP'] = '' self.params['BOTTOM'] = desktop_pane # get applications oCmd = OqlCommand() sOql = "select launchUrl,displayName,icon from 'apps' order by displayName asc" apps = oCmd.execute(sOql) sApps = '' if len(apps) > 0: for app in apps: sApps += '<a:menuoption img="%s" caption="%s" onclick="generic.runApp"><a:prop name="url" value="%s"></a:prop></a:menuoption>' % (app['icon'], app['displayName'], app['launchUrl']) self.params['APPS'] = sApps else: self.params['APPS'] = '<a:menuoption caption="%s" disabled="true"></a:menuoption>' % resources.getResource('EMPTY', sLang)
def commitChanges(self, generate_code=True): from porcupine.oql.command import OqlCommand if self._setProps or self._removedProps: if generate_code: GenericSchemaEditor.commitChanges(self) # we must reload the class module oMod = misc.get_rto_by_name(self._class.__module__) reload(oMod) db = offlinedb.getHandle() oql_command = OqlCommand() rs = oql_command.execute("select * from deep('/') where instanceof('%s')" % self._instance.contentclass) try: if len(rs): try: for item in rs: txn = db.get_transaction() for name in self._removedProps: if hasattr(item, name): delattr(item, name) for name in self._setProps: if not hasattr(item, name): # add new setattr(item, name, self._setProps[name]) else: # replace property old_value = getattr(item, name).value setattr(item, name, self._setProps[name]) new_attr = getattr(item, name) if isinstance(new_attr, datatypes.Password): new_attr._value = old_value else: new_attr.value = old_value if self.xform: item = self.xform(item) db.put_item(item, txn) txn.commit() except Exception, e: txn.abort() raise e sys.exit(2) finally: offlinedb.close()
def setParams(self): self.response.setHeader('cache-control', 'no-cache') settings = self.session.user.settings taskBarPos = settings.value.setdefault('TASK_BAR_POS', 'bottom') self.params['TASK_BAR_POS'] = taskBarPos if self.params['TASK_BAR_POS'] == 'bottom': self.params['CHECKED_TOP'] = 'false' self.params['CHECKED_BOTTOM'] = 'true' else: self.params['CHECKED_TOP'] = 'true' self.params['CHECKED_BOTTOM'] = 'false' autoRun = settings.value.setdefault('AUTO_RUN', '') if settings.value.setdefault('RUN_MAXIMIZED', False) == True: self.params['RUN_MAXIMIZED_VALUE'] = 'true' else: self.params['RUN_MAXIMIZED_VALUE'] = 'false' # get applications oCmd = OqlCommand() sOql = "select displayName,launchUrl,icon from 'apps' " + \ "order by displayName asc" apps = oCmd.execute(sOql) sSelected = '' if autoRun == '': sSelected = 'true' sApps = '<option caption="@@NONE_APP@@" selected="%s" value=""/>' \ % sSelected if len(apps) > 0: for app in apps: if autoRun == app['launchUrl']: sSelected = 'true' else: sSelected = 'false' sApps += \ '<option img="%s" caption="%s" value="%s" selected="%s"/>' % \ (app['icon'], app['displayName'], app['launchUrl'], sSelected) self.params['APPS'] = sApps
def setParams(self): self.response.setHeader('cache-control', 'no-cache') sLang = self.request.getLang() self.params = resources.getLocale(sLang).copy() if self.session.user.settings.value['TASK_BAR_POS'] == 'bottom': self.params['CHECKED_TOP'] = 'false' self.params['CHECKED_BOTTOM'] = 'true' else: self.params['CHECKED_TOP'] = 'true' self.params['CHECKED_BOTTOM'] = 'false' autoRun = self.session.user.settings.value.setdefault('AUTO_RUN', '') if self.session.user.settings.value.setdefault('RUN_MAXIMIZED', False) == True: self.params['RUN_MAXIMIZED_VALUE'] = 'true' else: self.params['RUN_MAXIMIZED_VALUE'] = 'false' # get applications oCmd = OqlCommand() sOql = "select displayName,launchUrl,icon from 'apps' order by displayName asc" apps = oCmd.execute(sOql) sSelected = '' if autoRun == '': sSelected = 'true' sApps = '<a:option caption="%s" selected="%s" value=""/>' % (resources.getResource("NONE_APP", sLang), sSelected) if len(apps) > 0: for app in apps: if autoRun == app['launchUrl']: sSelected = 'true' else: sSelected = 'false' sApps += '<a:option img="%s" caption="%s" value="%s" selected="%s"/>' % (app['icon'], app['displayName'], app['launchUrl'], sSelected) self.params['APPS'] = sApps
def setParams(self): sLang = self.request.getLang() self.params = { 'LOGOFF': self.server.resources.getResource('LOGOFF', sLang), 'LOGOFF?': self.server.resources.getResource('LOGOFF?', sLang), 'START': self.server.resources.getResource('START', sLang), 'APPLICATIONS': self.server.resources.getResource('APPLICATIONS', sLang), 'SETTINGS': self.server.resources.getResource('SETTINGS', sLang), 'INFO': self.server.resources.getResource('INFO', sLang), 'USER': self.session.user.displayName.value, 'ROOT': self.item.displayName.value, 'RECYCLE_BIN': '' } # has the user access to recycle bin? rb = self.server.store.getItem('rb') if rb: self.params['RECYCLE_BIN'] = ''' <a:icon top="80" left="10" width="80" height="80" imgalign="top" ondblclick="generic.openContainer" img="images/trashcan_full.gif" color="white" caption="%s"> <a:prop name="folderID" value="rb"></a:prop> </a:icon> ''' % rb.displayName.value # get applications oCmd = OqlCommand() sOql = "select id,displayName,icon from 'apps' order by displayName asc" apps = oCmd.execute(sOql) sApps = '' if len(apps) > 0: for app in apps: sApps += '<a:menuoption img="%s" caption="%s" onclick="generic.runApp"><a:prop name="ID" value="%s"></a:prop></a:menuoption>' % (app['icon'], app['displayName'], app['id']) self.params['APPS'] = sApps else: self.params['APPS'] = '<a:menuoption caption="%s" disabled="true"></a:menuoption>' % self.server.resources.getResource('EMPTY', sLang)
def __blank__(self): "Displays the desktop" context = HttpContext.current() oUser = context.user params = { 'USER' : oUser.displayName.value, 'AUTO_RUN' : '', 'RUN_MAXIMIZED' : 0, 'SETTINGS_DISABLED' : '', 'LOGOFF_DISABLED' : '' } if hasattr(oUser, 'authenticate'): settings = oUser.settings params['AUTO_RUN'] = \ settings.value.setdefault('AUTO_RUN', '') params['RUN_MAXIMIZED'] = \ int(settings.value.setdefault('RUN_MAXIMIZED', False)) taskbar_position = \ settings.value.setdefault('TASK_BAR_POS', 'bottom') else: taskbar_position = 'bottom' params['SETTINGS_DISABLED'] = 'true' params['LOGOFF_DISABLED'] = 'true' params['REPOSITORY_DISABLED'] = 'true' params['PERSONAL_FOLDER'] = '' if hasattr(oUser, 'personalFolder'): params['REPOSITORY_DISABLED'] = 'false' params['PERSONAL_FOLDER'] = oUser.personalFolder.value # has the user access to recycle bin? rb_icon = '' rb = db.get_item('rb') if rb: rb_icon = ''' <icon top="80" left="10" width="80" height="80" imgalign="top" ondblclick="generic.openContainer" img="desktop/images/trashcan_full.gif" color="white" caption="%s"> <prop name="folderID" value="rb"></prop> </icon> ''' % rb.displayName.value desktop_pane = DESKSTOP_PANE % (self.displayName.value, rb_icon) if taskbar_position == 'bottom': params['TOP'] = desktop_pane params['BOTTOM'] = '' else: params['TOP'] = '' params['BOTTOM'] = desktop_pane # get applications oCmd = OqlCommand() sOql = "select launchUrl,displayName,icon from 'apps' " + \ "order by displayName asc" apps = oCmd.execute(sOql) sApps = '' if len(apps) > 0: for app in apps: sApps += '''<menuoption img="%s" caption="%s" onclick="generic.runApp"> <prop name="url" value="%s"></prop> </menuoption>''' % \ (app['icon'], app['displayName'], app['launchUrl']) params['APPS'] = sApps else: params['APPS'] = '<menuoption caption="@@EMPTY@@"' + \ ' disabled="true"></menuoption>' return params
def __blank__(self): "Displays the desktop" context = HttpContext.current() context.response.setHeader("cache-control", "no-cache") oUser = context.session.user params = { "USER": oUser.displayName.value, "AUTO_RUN": "", "RUN_MAXIMIZED": 0, "SETTINGS_DISABLED": "", "LOGOFF_DISABLED": "", } if hasattr(oUser, "authenticate"): settings = oUser.settings params["AUTO_RUN"] = settings.value.setdefault("AUTO_RUN", "") params["RUN_MAXIMIZED"] = int(settings.value.setdefault("RUN_MAXIMIZED", False)) taskbar_position = settings.value.setdefault("TASK_BAR_POS", "bottom") else: taskbar_position = "bottom" params["SETTINGS_DISABLED"] = "true" params["LOGOFF_DISABLED"] = "true" params["REPOSITORY_DISABLED"] = "true" params["PERSONAL_FOLDER"] = "" if hasattr(oUser, "personalFolder"): params["REPOSITORY_DISABLED"] = "false" params["PERSONAL_FOLDER"] = oUser.personalFolder.value # has the user access to recycle bin? rb_icon = "" rb = db.getItem("rb") if rb: rb_icon = ( """ <icon top="80" left="10" width="80" height="80" imgalign="top" ondblclick="generic.openContainer" img="desktop/images/trashcan_full.gif" color="white" caption="%s"> <prop name="folderID" value="rb"></prop> </icon> """ % rb.displayName.value ) desktop_pane = DESKSTOP_PANE % (self.displayName.value, rb_icon) if taskbar_position == "bottom": params["TOP"] = desktop_pane params["BOTTOM"] = "" else: params["TOP"] = "" params["BOTTOM"] = desktop_pane # get applications oCmd = OqlCommand() sOql = "select launchUrl,displayName,icon from 'apps' " + "order by displayName asc" apps = oCmd.execute(sOql) sApps = "" if len(apps) > 0: for app in apps: sApps += """<menuoption img="%s" caption="%s" onclick="generic.runApp"> <prop name="url" value="%s"></prop> </menuoption>""" % ( app["icon"], app["displayName"], app["launchUrl"], ) params["APPS"] = sApps else: params["APPS"] = '<menuoption caption="@@EMPTY@@"' + ' disabled="true"></menuoption>' return params