from zope.interface import implements from zope.component import getUtility from Products.MetadataPortal.interfaces import iMDPortal, IWaramu from Products.MetadataPortal.waramulib.interfaces import IAttachable from Products.MetadataPortal.utils import translate, getLanguage class Attachments(object): implements(IAttachable) def __init__(self, context): self.context = context def view(self): r = u'' % ('attachments', translate(self, 'Files', getLanguage(self.context.request))) if self.context.getNOfAttachments() > 0: pr = getUtility(iMDPortal, context=self.context) w = getUtility(IWaramu, context=self.context).__of__(pr) loa = w.listAttachments(self.context.getId()) ats = loa.items() ats.sort() r += '
    ' wurl = w.getWaramuWebUrl() for aid, fname in ats: r += '
  1. %s
  2. ' % (wurl, self.context.getId(), aid, fname) r+= '
' else: r += translate(self, 'No files available', getLanguage(self.context.request)) return r def edit(self): r = u'' % ('attachments', 'Files') r += '
\n' if not self.context.isNew(): if self.context.getNOfAttachments() > 0: # fetch a list of attachments pr = getUtility(iMDPortal, context=self.context) w = getUtility(IWaramu, context=self.context).__of__(pr) loa = w.listAttachments(self.context.getId()) ats = loa.items() ats.sort() for aid, fname in ats: r += '
' r += 'X' r += ' '+fname+'' r += '
' r += '
' r += '
\n\t'+translate(self, "add a file", getLanguage(self.context.request))+'\n
' return r