# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import FileField from Products.Archetypes.public import FileWidget from Products.Archetypes.public import OrderedBaseFolder, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME schema = BaseSchema class Drawer(OrderedBaseFolder): """ E-Portfolio Drawer folder for stuff ;) (files, documents, etc)""" meta_type = "Drawer" archetype_name = "Drawer" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = ('File', 'Image', 'Drawer') security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/drawer_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 = "drawer.gif" 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 deleteObject(self, REQUEST): """ delete object """ id = REQUEST.get("id") self._delObject(id) return REQUEST.RESPONSE.redirect(self.absolute_url()+'/drawer_view') def cutTitle(self, title, lenght): """ cut tail of title """ if len(title)>lenght: return title[:lenght]+'...' return title registerType(Drawer, PROJECT_NAME)