# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import FileField, TextField, ReferenceField from Products.Archetypes.public import FileWidget, RichWidget from Products.Archetypes.public import OrderedBaseFolder, BaseContent, registerType from Products.ATReferenceBrowserWidget.ATReferenceBrowserWidget import ReferenceBrowserWidget from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME schema = BaseSchema class Presentation(OrderedBaseFolder): """ E-Portfolio Presentations""" meta_type = "Presentation" archetype_name = "Presentation" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = ('Sheet','Image') security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/presentation_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/presentation_edit', 'permissions': ('Modify portal content',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Access Denied',), }, ) def __init__(self, id): self.id = id self.largeIcon = "presentation.gif" self.background = "#FFFFFF" self.fontColor = "#000000" self.fontFace = "Arial" def getLargeIcon(self): """ returns large icon name """ return self.largeIcon def getLargeIconById(self, id): """ returns large icon name """ object = getattr(self, id) largeIcon = object.largeIcon if object.getLargeIcon(): if (object.getLargeIcon()=='drawer.gif' and object.meta_type!='Drawer'): if object.meta_type in ['Folder', 'ATFolder']: largeIcon = 'folder.gif' if object.meta_type in ['File', 'ATFile', 'ATImage']: if object.content_type in ['application/pdf']: largeIcon = 'pdffile.gif' elif object.content_type in ['text/html','text/xml','text/javascript','text/css']: largeIcon = 'htmlfile.gif' elif object.content_type in ['application/msword','text/rtf','text/richtext','application/rtf']: largeIcon = 'textfile.gif' elif object.content_type in ['application/vnd.ms-excel']: largeIcon = 'tablefile.gif' elif object.content_type in ['image/jpeg','image/png','image/gif','image/tiff','image/x-ms-bmp']: largeIcon = 'imagefile.gif' elif object.content_type in ['application/zip','application/x-tar']: largeIcon = 'zipfile.gif' return largeIcon def getStyle(self): """ returs background color """ style = 'background: '+str(self.background)+'; color: '+str(self.fontColor)+'; font-family: '+str(self.fontFace) return style def getTextStyle(self): """ returs text style color """ style = 'color: '+str(self.fontColor)+'; font-family: '+str(self.fontFace) return style def getBackground(self): """ returs background color """ return self.background def getFontColor(self): """ returs fontColor color """ return self.fontColor def getFontFace(self): """ returs fontFace color """ return self.fontFace def savePresentation(self,REQUEST): """ saves presentation """ self.background = REQUEST.get('background') self.fontColor = REQUEST.get('fontcolor') self.fontFace = REQUEST.get('fontface') self._p_changed = 1 ob=getattr(self,self.id) ob.setTitle(REQUEST.get('title')) ob.reindexObject() def getColors(self): """Colors""" symbols = ['00','33','66','99','CC','FF'] colors = [] for j in range(0, 6): for k in range(0, 6): colors.append('#'+symbols[0]+symbols[j]+symbols[k]) for k in range(0, 6): colors.append('#'+symbols[5]+symbols[j]+symbols[k]) return colors def getFonts(self): """Fonts""" fonts = ['Arial', 'Arial Black', 'Comic Sans MS', 'Courier', 'Georgia', 'Impact', 'Lucida Console', 'Palatino Linotype', 'Tahoma', 'Times New Roman', 'Verdana', 'MS Sans Serif'] return fonts def makeHTML(self, fullscreen): """make html for presentation""" HTML='' allSheets = self.getFolderContents() if not allSheets: return "You have no Sheets" id = 1 headers = 0 HTML = HTML + '\n' HTML = HTML + '\n' HTML = HTML + '\n' for sheet in allSheets: if id==1: style = "display:block" else: style = "display:none" if fullscreen: size = "height:100%; width:100%" else: size = "height:550px; width:100%" HTML = HTML + '
\n' HTML = HTML + '
\n
\n' HTML = HTML + '
\n' if hasattr(getattr(self, sheet.id),'getBody'): body = str(getattr(self, sheet.id).getBody()) + '\n' splitted_body = body.split('class="Heading"') new_body = '' for piece in splitted_body: new_piece = piece.replace('', '') headers = headers + 1 new_body = new_body + new_piece HTML = HTML + new_body headers = headers - 1 if hasattr(getattr(self, sheet.id),'getImage'): HTML = HTML + str(getattr(self, sheet.id).getImage()) + '\n' if hasattr(getattr(self, sheet.id),'getRefsToLinks'): refsToLinks = getattr(self, sheet.id).getRefsToLinks() if refsToLinks!=[]: HTML = HTML + '
Related links:' refsToLinks = getattr(self, sheet.id).getRefsToLinks() for ref in refsToLinks: HTML = HTML + '\n' HTML = HTML + '
\n' HTML = HTML + '
\n' HTML = HTML + '
\n' HTML = HTML + '
\n' id = id + 1 HTML = HTML + '\n' HTML = HTML + '\n' return HTML def makeLink(self): """make link""" link = 'javascript:window.open(\"'+self.absolute_url()+'/presentation_fullscreen\", \"fullscreen\", \"fullscreen=yes, toolbars=no,resizable=yes,menubar=no,scrollbars=no\"); history.go(0);' return link def manage_afterAdd(self, item, container): """Replaces the left side portlets with the content type's own action portlet.""" OrderedBaseFolder.manage_afterAdd(self, item, container) if not hasattr(item.aq_base, 'left_slots'): self._setProperty('left_slots', ['here/portlet_presentation/macros/portlet','here/portlet_navigation/macros/portlet',], 'lines') registerType(Presentation, PROJECT_NAME) class Sheet(BaseContent): """ E-Portfolio Slide""" meta_type = "Sheet" archetype_name = "Sheet" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema + Schema(( TextField('text', accessor='getBody', required=True, searchable=True, primary=True, validators = ('isTidyHtmlWithCleanup',), default_output_type = 'text/x-html-safe', allowable_content_types = ('text/html',), widget = RichWidget( description = "", description_msgid = "help_slide_body", label = "Slide body", label_msgid = "label_slide_body", rows = 25, i18n_domain = "eportfolio") ), ReferenceField('refsToLinks', accessor = 'getRefsToLinks', relationship = 'References', mutator = 'addRefsToLinks', allowed_types = ('Drawer','File','Image'), multiValued = True, widget = ReferenceBrowserWidget( force_close_on_insert = True, startup_directory = "drawer", label = "Related links", label_msgid = "label_related_links", i18n_domain = "eportfolio", visible = {'view':'visible', 'edit':'visible'},) ), )) actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Access Denied',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Access Denied',), }, ) def __init__(self, id): self.id = id self.largeIcon = "presentation.gif" def getAct(self): """ACT""" action = {'action': 'string:${object_url}/drawer_view', 'permissions': ('View',), 'id': 'esimene', 'name': 'Esimene'} act = getattr(self.aq_parent, 'actions') act = act + (action,) setattr(self.aq_parent, 'actions', act) return self.aq_parent.actions registerType(Sheet, PROJECT_NAME)