[Zope-CMF] error on renaming a custom content type

Florent Guillaume fg@nuxeo.com
Sun, 4 Aug 2002 13:19:54 +0000 (UTC)


I can't see what's wrong offhand.

CMFDefault.Image works ok.

 You should derive from CMFDefault.Image only (and don't call other
classes' __init__, that's not clean, call
CMFDefault.Image.Image.__init__). Start with a minimal empty class
sublcassing Image that just renames the class. Test that it works. Then
add one by one your methods and test at each step.

BTW when you say "errors", be precise. And if there's a traceback,
include it.

Florent

Aaron Payne  <aaron@aaronpayne.com> wrote:
> Hi,
> 
> On Saturday, August 3, 2002, at 10:37  AM, Florent Guillaume wrote:
> >
> > Yes, simply CMFDefault.Image. It should do all you need.
> >
> > If you still see a bug, then there's a problem, and you'll have to post
> > your code so that we can check it.
> >
> > Florent
> 
> After subclassing CMFDefault.Image.Image I still see the errors upon 
> renaming the instance.  I've included my python class code below.
> 
> class Biography(CMFDefault.Image.Image):
>      """
>      A biography object with an image.
>      """
> 
>      meta_type='CMF Biography'
>      _isDiscussable = 1
>      icon = PortalContent.icon
> 
>      # Declarative security
>      security = ClassSecurityInfo()
>      security.declareObjectProtected(CMFCorePermissions.View)
> 
>      def __init__(self
>               , id
>               , title=''
>               , description=''
>               , cmf_member_owner = 1
>               , display_contact_info = 0
>               , bio_email = ''
>               , bio_text = ''
>               , birthday_month = ''
>               , birthday_day = ''
>               , birthday_year = ''
>               , first_name = ''
>               , middle_name = ''
>               , last_name = ''
>               , bio_title = ''
>               , address_1 = ''
>               , address_2 = ''
>               , city  = ''
>               , state  = ''
>               , province  = ''
>               , zip  = ''
>               , country  = ''
>               , phone_number  = ''
>               , website_url = ''
>               , file  = ''
>               , content_type=''
>               , precondition=''
>               , subject=()
>               , contributors=()
>               , format='image/png'
>               , language='en-US'
>               , rights=''
>               ):
>          OFS.Image.File.__init__( self, id, title, file
>                                 , content_type, precondition )
>          DefaultDublinCoreImpl.__init__(self)
>          self.id=id
>          self.setTitle(title)
>          self.setDescription(description)
>          self.cmf_member_owner=cmf_member_owner
>          self.display_contact_info=display_contact_info
>          self.bio_email=bio_email
>          self.bio_text=bio_text
>          self.birthday_month=birthday_month
>          self.birthday_day=birthday_day
>          self.birthday_year=birthday_year
>          self.first_name=first_name
>          self.middle_name=middle_name
>          self.last_name=last_name
>          self.bio_title=bio_title
>          self.address_1=address_1
>          self.address_2=address_2
>          self.city=city
>          self.state=state
>          self.province=province
>          self.zip=zip
>          self.country=country
>          self.phone_number=phone_number
>          self.website_url=website_url
>          self.content_type = content_type
>          self.precondition = precondition
>          self.subject = subject
>          self.contributors = contributors
>          self.format = format
>          self.language = language
>          self.rights = rights
> 
>      security.declareProtected(BiographyPermissions.ChangeBiography, 
> 'edit')
>      def edit(self
>               , title=None
>               , description=None
>               , cmf_member_owner = None
>               , display_contact_info = None
>               , bio_email = None
>               , bio_text = None
>               , birthday_month = None
>               , birthday_day = None
>               , birthday_year = None
>               , first_name = None
>               , middle_name = None
>               , last_name = None
>               , bio_title = None
>               , address_1 = None
>               , address_2 = None
>               , city  = None
>               , state  = None
>               , province  = None
>               , zip  = None
>               , country  = None
>               , phone_number  = None
>               , website_url = None
>               , content_type = None
>               , precondition = None
>               , subject = None
>               , contributors = None
>               , format = None
>               , language = None
>               , rights = None
>              ):
>          """\
>          """
>          if title is not None:
>              self.setTitle(title)
>          if description is not None:
>              self.setDescription(description)
>          if cmf_member_owner is not None:
>              self.cmf_member_owner = cmf_member_owner
>          if display_contact_info is not None:
>              self.display_contact_info = display_contact_info
>          if bio_email is not None:
>              self.bio_email = bio_email
>          if bio_text is not None:
>              self.bio_text = bio_text
>          if birthday_month is not None:
>              self.birthday_month = birthday_month
>          if birthday_day is not None:
>              self.birthday_day = birthday_day
>          if birthday_year is not None:
>              self.birthday_year = birthday_year
>          if first_name is not None:
>              self.first_name = first_name
>          if middle_name is not None:
>              self.middle_name = middle_name
>          if last_name is not None:
>              self.last_name = last_name
>          if bio_title is not None:
>              self.bio_title = bio_title
>          if address_1 is not None:
>              self.address_1 = address_1
>          if address_2 is not None:
>              self.address_2 = address_2
>          if city is not None:
>              self.city = city
>          if state is not None:
>              self.state = state
>          if province is not None:
>              self.province = province
>          if zip is not None:
>              self.zip = zip
>          if country is not None:
>              self.country = country
>          if phone_number is not None:
>              self.phone_number = phone_number
>          if website_url is not None:
>              self.website_url = website_url
>          if content_type  is not None:
>              self.content_type = content_type
>          if precondition is not None:
>              self.precondition = precondition
>          if subject is not None:
>              self.subject = subject
>          if contributors is not None:
>              self.contributors = contributors
>          if format is not None:
>              self.format = format
>          if language is not None:
>              self.language = language
>          if rights is not None:
>              self.rights = rights
> 
>          self.reindexObject()
>      edit = WorkflowAction(edit)
> 
> 
>      def SearchableText(self):
>          """
>              SeachableText is used for full text seraches of a portal.
>              It should return a concatanation of all useful text.
>          """
>          return "%s %s %s %s %s %s %s %s %s %s %s %s" %  \
>                 (self.title, self.description, self.bio_text, 
> self.first_name,
>                  self.middle_name, self.last_name, self.bio_title, 
> self.city,
>                  self.state, self.province, self.country, 
> self.website_url)
> 
>      def manage_afterAdd(self, item, container):
>          """Both of my parents have an afterAdd method"""
>          OFS.Image.Image.manage_afterAdd(self, item, container)
>          PortalContent.manage_afterAdd(self, item, container)
> 
>      def manage_beforeDelete(self, item, container):
>          """Both of my parents have a beforeDelete method"""
>          PortalContent.manage_beforeDelete(self, item, container)
>          OFS.Image.Image.manage_beforeDelete(self, item, container)
> 
>      def _isNotEmpty(self, file):
>          """ Do various checks on 'file' to try to determine non 
> emptiness. """
>          if not file:
>              return 0                    # Catches None, Missing.Value, ''
>          elif file and (type(file) is type('')):
>              return 1
>          elif getattr(file, 'filename', None):
>              return 1
>          elif not hasattr(file, 'read'):
>              return 0
>          else:
>              file.seek(0,2)              # 0 bytes back from end of file
>              t = file.tell()             # Report the location
>              file.seek(0)                # and return pointer back to 0
>              if t: return 1
>              else: return 0
> 
>      def editimage(self, precondition='', file=''):
>          """ Update image. """
>          if precondition: self.precondition = precondition
>          elif self.precondition: del self.precondition
> 
>          if self._isNotEmpty(file):
>              self.manage_upload(file)
> 
>          self.setFormat(self.content_type)
>      editimage = WorkflowAction(editimage)
-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg@nuxeo.com