import vobject from zope.interface import implements from Products.MetadataPortal.widgets import Default from Products.MetadataPortal.waramulib.interfaces import IWidget from Products.MetadataPortal.utils import translate, getLanguage class Authors(Default): """ authors widget """ implements(IWidget) def view(self, f, id, cls, w, tid, lang=None): """ author's vcard viewer """ r = u"" r += self._fieldLabel(cls, id, f.get('printable')) fval = self.context.get(f.get('name'), lang) for vcard in vobject.readComponents(fval): fn = vcard.n.value.given ln = vcard.n.value.family em = vcard.email.value orgs = ', '.join(vcard.org.value) r += '
' r += fn + " " + ln if em: r += " ("+em+")" if orgs: r += " "+orgs r += '
' #r += fval r += '' return r def edit(self, f, id, cls, w, tid, lang=None): """ author's vcard edit """ fval = self.context.get(f.get('name'), lang) lang = getLanguage(self.context.request) r = u"" r += self._fieldLabel(cls, id, f.get('printable')) r += '' r += '''''' r += '
' c = 1 for vcard in vobject.readComponents(fval): fn = vcard.n.value.given ln = vcard.n.value.family em = vcard.email.value orgs = ', '.join(vcard.org.value) r += '
' r += '' r += '' r += '' r += '' r += '' r += '' r += '' r += '' r += '
' r += '
' r += '
'+translate(self, "add a value", lang)+'
' r += '' r += '' return r