# -*- coding: utf-8 # $Id$ # # Copyright 2001, 2002 by IVA Team and contributors # # This file is part of IVA. # # IVA 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 2 of the License, or # (at your option) any later version. # # IVA 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 IVA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Contains class Webtop, which is the root object for users' webtops.""" __version__ = "$Revision$"[11:-2] import Globals #from Globals import Persistent, HTMLFile import AccessControl #import TraversableWrapper import WebtopFolder import WebtopTrash from TraversableWrapper import TWFolder from common import perm_view, perm_edit, perm_manage, perm_add_lo # This object is the root of a user's webtop and should reside inside # the UserInfo object of the user. # # A webtop contains a clipboard folder, a trash folder and any # WebtopItems the user has created. WebtopItem is a superclass, and # actually the webtop will contain specific subclass instances, like # WebtopFolder, WebtopFile, WebtopLink and WebtopMemo. # # Clipboard is removed starting from IVA 0.7.+ class Webtop( WebtopFolder.WebtopFolder, ): """User's Webtop.""" meta_type = "Webtop" location_type="standard" #Jaagup, 10.10.2002 def index_html(self, REQUEST=None): "Avaleht" return self.fle_root().wt_index_html(self, REQUEST) security = AccessControl.ClassSecurityInfo() def __init__(self, newlocationtype="standard"): #Jaagup """Construct the webtop root object.""" self.__id_counter = 0L self.toplevel=1 self.location_type=newlocationtype #Jaagup security.declarePrivate('manage_afterAdd') def manage_afterAdd(self, item, container): """Create trash and clipboard and call superclass initialization code.""" WebtopFolder.WebtopFolder.__init__(self, None, 'webtop') self.id = 'webtop' # if self.location_type=="sahtel": # self.id="sahtel" #Vahur #try: # self._setObject('clipboard', TWFolder()) #except: # pass #Vahur try: WebtopFolder.WebtopFolder.manage_afterAdd(self, item, container) self._setObject('trash', WebtopTrash.WebtopTrash()) except: pass from common import roles_admin, roles_staff, roles_user security.declarePrivate('generate_id') def generate_id(self): """Return a unique (within this webtop) id. These ids are used for any and all WebtopItems created instead of their visible names so we avoid any problems with visible name conflicts and can use more complex visible names for items.""" self.__id_counter += 1L while hasattr(self.aq_self,"wt"+str(self.__id_counter)): self.__id_counter += 1L return "wt"+str(self.__id_counter) security.declareProtected(perm_view, 'is_quota_limit_reached') def is_quota_limit_reached(self,REQUEST=None): """Is quota limit reached?""" limit = self.get_quota() #Do the multiply if limit < 0: return 0 # no quota else: ui = getattr(self.fle_root().fle_users, str(REQUEST.AUTHENTICATED_USER)) limit = limit * len(ui.user_courses()) return self.get_size() >= limit security.declareProtected(perm_view, 'search_form_handler') def search_form_handler( self, REQUEST, cancel=None, # submit buttons submit=None, # get_name = None, get_content= None ): """Search form handler.""" if submit and ((get_name) or (get_content)): for s in 'get_name', 'get_content': REQUEST.set(s, REQUEST[s]) if REQUEST['get_author_name'] == '___anyone___': uname = str(self.REQUEST.AUTHENTICATED_USER) if len(self.fle_users.get_user_info(uname).user_courses()) > 0: REQUEST.set('get_author_name', self.courses.get_unames_on_my_courses(REQUEST)) else: REQUEST.set('get_author_name', uname) else: REQUEST.set('get_author_name', REQUEST['get_author_name']) return self.wt_search_results(self, REQUEST) elif cancel: REQUEST.RESPONSE.redirect('index_html') else: REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER']) # We don't want to display GroupFolderProxy objects that are # located on other users' webtops. def ok_to_display_search_result(self, REQUEST, fixed_url, meta_type): """Return whether to display search result (specified by fixed_url and meta_type).""" if (fixed_url == ''): return 0 uname = str(self.REQUEST.AUTHENTICATED_USER) if uname == re.search('fle_users/(.*?)/', fixed_url).group(1): return 1 if meta_type == 'GroupFolderProxy': return 0 obj = self.get_object_of_url(fixed_url, self) while obj.meta_type != 'FLE': if obj.meta_type == 'GroupFolderProxy': return 0 obj = obj.parent() return 1 # Objects are really in the GroupFolder, but we want to return # URLs to objects inside GroupFolderProxy in the user's webtop. # So we do the mapping here... security.declareProtected(perm_view, 'get_fixed_urls') def get_fixed_urls(self, REQUEST, url, view_url, context_url, meta_type, ): """Return a tuple (fixed_view_url, fixed_context_url)""" if url.find('/courses') == -1: # We are not inside course folder, nothing to fix! return view_url, context_url course_id = re.search("/courses/([^/]*)", url).group(1) uname = str(self.REQUEST.AUTHENTICATED_USER) # Find proxy for course's group folder. proxy_url = self.__url_to_proxy(self.fle_users.get_user_info(uname).get_webtop(), course_id) if not proxy_url: # Object is in the GroupFolder but the user's Webtop does not have # a GroupFolderProxy for that GroupFolder: return empty strings # to signal that we don't want to display this search result. return '', '' if meta_type == 'WebtopLink': return view_url, proxy_url if meta_type == 'GroupFolder': return proxy_url, proxy_url[:proxy_url.rfind('/')] else: return proxy_url + '/' + view_url[view_url.find('/gf/')+4:], \ proxy_url def __url_to_proxy(self, ob, course_id): # Is right GroupFolderProxy in this folder? for proxy in ob.get_children('GroupFolderProxy'): if proxy.get_course_this_belongs_to().get_id() == course_id: return proxy.absolute_url() # If not, search recursively in subfolders. for folder in ob.get_children('WebtopFolder'): url = self.__url_to_proxy(folder, course_id) if url: return url return None Globals.InitializeClass(Webtop) # EOF