# -*- coding: utf-8 # $Id$ # # Copyright 2001 - 2005 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 """ Portfolio - A place for blog and assignments. """ __version__ = "$Revision$"[11:-2] import Globals import WebtopFolder import Blog from WebtopItem import WebtopItem from AccessControl import ClassSecurityInfo from common import perm_view, perm_edit, perm_manage, perm_add_lo from common import translate import time from zope.interface import implements from interfaces import IWebtopItem, IPortfolio, IStatistics from zope.component import adapter, getUtility from zope.app.container.interfaces import IObjectAddedEvent class Portfolio( Blog.Blog, WebtopFolder.WebtopFolder, ): """ Portfolio holds assignments and blog """ meta_type = "Portfolio" implements(IWebtopItem, IPortfolio) security = ClassSecurityInfo() security.declareObjectPublic() portfolio_top = 1 def __init__(self, parent, name): """ set id """ WebtopItem.__init__(self, parent, name) self.id = 'portfolio' security.declareProtected(perm_view, 'index_html') def index_html(self, REQUEST=None): """ index_page """ getUtility(IStatistics)._viewedObject(REQUEST, self.getRelativeURL(self)) url = self.absolute_url() if 'subgroups' in url: return self.wt_index_html() return self.portfolio_index() security.declareProtected(perm_view, 'get_icon') def get_icon(self): """ icon """ return getattr(self.images, 'folder_gif.gif') security.declareProtected(perm_view, 'get_icon_tag') def get_icon_tag(self): """ get icon tag """ return """""" % self.fle_root().absolute_url() def get_icon_path(self): """ return icon path """ return "folder_gif.gif" security.declareProtected(perm_view, 'get_name') def get_name(self): """ always portfolio """ return "Portfolio" security.declareProtected(perm_view, 'getAssignments') def getAssignments(self): """ return a list of assignments (folder?) """ return self.objectValues('AssignmentProxy') security.declareProtected(perm_edit, 'createAssignmentProxy') def createAssignmentProxy(self, a, c): """ sets AssignmentProxy object """ proxy = AssignmentProxy(self, a, c) proxy.id = a self._setObject(a, proxy) return proxy.__of__(self) Globals.InitializeClass(Portfolio) class AssignmentProxy( WebtopFolder.WebtopFolder, ): """ Assignment folder where user can submit it's work. """ meta_type = "AssignmentProxy" security = ClassSecurityInfo() security.declareObjectPublic() def __init__(self, parent, assignment_id, course_id): """ Construct AssignmentProxy """ WebtopItem.__init__(self, parent, '') self.__assignment_id = assignment_id self.__course_id = course_id security.declareProtected(perm_view, 'index_html') def index_html(self, REQUEST): """ index html """ getUtility(IStatistics)._viewedObject(REQUEST, self.getRelativeURL(self)) return self.hw_index_html() def __get_assignments(self): """ return assignments folder """ try: return self.courses.get_child(self.__course_id).kodutood except KeyError: return None def __get_assignment(self): """ return assignment """ return getattr(self.__get_assignments(), self.__assignment_id, None) security.declareProtected(perm_view, 'get_assignment') def get_assignment(self): """ return assignment """ return self.__get_assignment() security.declareProtected(perm_view, 'get_name') def get_name(self): """ return assignment id """ as = self.__get_assignment() try: return as.getTitle() except AttributeError: pass if not as or as.meta_type == 'AssignmentProxy': # trigger folder deletion here if folder is empty if len(self.objectValues()) == 0: self.delete_me() return "deleted assignment" else: if as.getRawType() == 2: # groupwork groups = as.getGroups() try: if self.is_subgroup_id() not in groups: if len(self.objectValues()) == 0: self.delete_me() return "" return "deleted assignment" except AttributeError: #print "is_subgroup_id failed %s" % self.absolute_url() return "" return as.getTitle() security.declareProtected(perm_view, 'get_description') def get_description(self): """ return assignment description """ as = self.__get_assignment() if not as or as.meta_type == 'AssignmentProxy': return "deleted assignment" else: return as.kirjeldus security.declareProtected(perm_view, 'get_assignment_material') def get_assignment_material(self): """ return assignment material if set """ as = self.__get_assignment() if not as or as.meta_type == 'AssignmentProxy': return "" if as.juhend == "": return "" tulem = "" elem = as.juhend.split("/") koht = self.fle_root() try: for obj in elem: if len(obj)>0: koht = getattr(koht, obj) obj_nimi = koht.get_name() tulem += ""+obj_nimi+"" except AttributeError: as.juhend = "" tulem = "" return tulem security.declareProtected(perm_view, 'get_assignment_deadline') def get_assignment_deadline(self, REQUEST): """ return assignment deadline """ as = self.__get_assignment() if not as or as.meta_type == 'AssignmentProxy': return "" if as.getRawType() == 0: return "" if str(as.loppaeg) == 'None': as.loppaeg = time.time() message = translate(self, "Deadline:", target=self.giveLanguage(REQUEST))+" "+time.strftime(translate(self,'timestamp_format',default="%H:%M %Y-%m-%d", target=self.giveLanguage(REQUEST)), time.localtime(as.loppaeg)) if hasattr(as, 'lockFolder') and as.lockFolder(): message += "
"+translate(self,"Folder will be locked after deadline.", target=self.giveLanguage(REQUEST)) return message security.declareProtected(perm_view, 'get_icon') def get_icon(self): """ icon """ return getattr(self.images, 'folder_gif.gif') security.declareProtected(perm_view, 'list_contents') def hw_list_contents(self, REQUEST, jnr): """ list contents + other webtop content if needed """ my_list = self.list_contents_request2(REQUEST) other_list = [] hw = self.__get_assignment() # hw, hw==self, isinstance(hw, AssignmentProxy) if isinstance(hw, AssignmentProxy): return my_list hwID = hw.getAssignmentID() if hwID: users = hw.getReviewers(str(REQUEST.AUTHENTICATED_USER)) for user in users: relurl = "fle_users/"+user+"/webtop/c"+str(jnr)+"/portfolio/"+hwID #u_obj = getattr(self.fle_root(), 'fle_users').get_user_info(user) #portfolio = u_obj.get_course_portfolio(jnr) #o_hw = getattr(portfolio, hwID, None) #if not o_hw: continue other_list += self.list_contents_request2(REQUEST, relative=relurl) return other_list+my_list security.declareProtected(perm_view, 'is_assignment') def is_assignment(self): """ return 1 - this is assignment folder """ return 1 security.declareProtected(perm_view, 'is_folder_locked') def is_folder_locked(self): """ is assignment has deadline then after deadline don't allow users to change content """ hw = self.__get_assignment() try: if hw.lockFolder(): return time.time()>hw.loppaeg except AttributeError: return False security.declareProtected(perm_view, 'quizLink') def quizLink(self, REQUEST, course,userlocation): """ if we need link to quiz solving """ if not self.myOwnWebtop(REQUEST): return "" url = "" asg = self.__get_assignment() if not asg or asg.meta_type == 'AssignmentProxy': return url try: quizID = asg.testiID if not quizID: return "" quiz = getattr(course.testid, quizID) if quiz.kasLubatudLahendada(REQUEST): if quiz.kysiTyyp()==0: url=quiz.absolute_url()+'/qtExplanationQuiz?userLocation='+userlocation elif quiz.kysiTyyp()==1: url = quiz.absolute_url()+'/qtAnsweringForm?userLocation='+userlocation elif quiz.kysiTyyp()==2: url=quiz.absolute_url()+'/qtExerciseForm?userLocation='+userlocation except AttributeError: pass return url security.declareProtected(perm_view, 'wordmapLink') def wordmapLink(self, REQUEST, course,userlocation): """ if we need link to wordmap making """ if not self.myOwnWebtop(REQUEST): return "" url = "" as = self.__get_assignment() if not as or as.meta_type == 'AssignmentProxy': return url try: wmID = as.wmID if not wmID: return "" #wm = getattr(course.wordmaps, wmID) url=self.wmcID except AttributeError: pass return url security.declareProtected(perm_view, 'explainWhy') def explainWhy(self, REQUEST): """ see YlTest """ as = self.__get_assignment() why = "" if not as or as.meta_type == 'AssignmentProxy': return why quizID = as.testiID if not quizID: return why try: quiz = getattr(as.parent().parent().testid, quizID, None) except AttributeError: return why if not quiz: return why why = quiz.explainWhy(REQUEST) return why Globals.InitializeClass(AssignmentProxy) @adapter(IPortfolio, IObjectAddedEvent) def added(obj, event): obj.manage_permission('Change permissions', ('Owner', 'Teacher',), 1)