AJAX Ordering In AT Content Types

I’ve been struggling with one nagging stupid little bug in my archetypes-based content types. They just wouldn’t sort in the folder contents view.

This normally wouldn’t be that big of a deal. Don’t get me wrong, I hate to have expected features not work, but it isn’t a show stopper for most apps…. Well, it wasn’t until recently, anyway :).

I decided a while back to lash out against my adventurous nature and take a firm stance of doing things The Plone WayTM as much as possible when I develop new products. I reckon Plone has figured most things out, and if I don’t like how it works, or it’s just broken, I’ll fix it.

…And the journey will make me a better person.

For reasons beyond my understanding, I’ve been working on a lot of projects lately that need ordered items within folders. As such, my new docturne, The Plone WayTM wasn’t working for me, and I really needed it to.

A couple of weeks ago I dug and dug and figured the problem was with what interfaces I was implementing. That line of thought was a complete red herring. Awesome :(.

Today I found some time to take another whack at it. I did a bunch of research and came up empty. Then I took a look at the mailing list archives for the product developers list, in preparation to post.

That’s when I found this thread: http://plone.org/support/forums/addons#nabble-td356376|a14300974. SCORE!

Turns out the ordered folder support expects content items to be registered with CMF. I’m not clear on how this happens inside of Plone, but it can be fixed by setting the meta_type attribute in your content type class. You can just set it to whatever the portal_type is. For all the details, see Issue #414 in Faculty Staff Directory

SO, my problem has been solved, thanks to WebLion, and diligent research!

I’ve also updated the addcontent contenttype template in ZopeSkel’s trunk, [77394]. This should help people get this feature into their code, even though I really don’t know why it’s necessary.

Side Note: if you use a front-end to monitor the mailing lists you really should access them through GMANE, using the news reader interface. It gives you access to the entire archive, and you can easily reply or make new posts. I like better than nabble, except for linking to threads :).


Where’s Robert Stack when you need him?

When I changed ZopeSkel to reflect this issue, I got a note from Wichert Akkerman responding to the commit notice (I <3 SVN commit hooks). He told me that the portal_type attribute was completely unnecessary. He said that GenericSetup should handle setting the portal_type attribute. I thought about it a bit I realized that that made perfect sense, and I recalled thinking it was a little weird to specify it in the code, but never questioned it, because I saw the same thing in Martin Aspeli’s Professional Plone Development (chapter 10, page 196). *shrug*.

It’s still my favorite book ever.

Update Update!

This wasn’t the end of it. :) See http://plone.org/support/forums/core#nabble-td2948892

This entry was posted in plone. Bookmark the permalink.

7 Responses to AJAX Ordering In AT Content Types

  1. Joel Davis says:

    Holy cow. Thanks for this nugget. I saw the lede of this article on twitter and it sounded a little familiar. I discovered that I had this problem last week and I thought my browser was just being buggy. With this fix in place, everything is working.

    One note, after adding the meta_type declaration in my content type’s .py file, I restarted zope but that didn’t fix things for objects that were previously created. I ran clear and rebuild on the portal_catolg and confirmed that the meta_type of my objects had changed, but still no luck. I had to actually delete the old objects and re-add them to the site. I’m sure there’s a better way, but the good news is that when I drag the new objects up and down in “contents” view, the order actually holds after a page refresh. Thanks!

    • jjmojojjmojo says:

      Yeah I ran into the same problem, and tried the catalog first too. :) I think what needs to happen is the meta_type attribute just needs to be set “physically” via a python script. Then at the end of the request (or after an explicit commit), the changes will stick. You could also try exporting the content and then re-importing it.

      I think this may be a good excuse for me to look into what my options are for implementing migration scripts in my products. May be as easy as adding a function to Extensions/Instally.py called “upgrade” but I need to see if theres another or better way.

    • jjmojojjmojo says:

      I should have mentioned this in my post, I’m inheriting from Products.ATContentTypes.content.folder.ATFolder (and Products.ATContentTypes.base.ATCTContent for the non-folderish types), so theoretically my content types should have already subclassed OrderedBaseFolder.
      time passes…
      I just took another look at the inheritance list that DocFinderTab reports, and OrderedBaseFolder is there, several levels deep, but it’s there. *shrug* It’s another piece of the puzzle for sure.

  2. Anthony says:

    We had a problem getting our content type objects to follow the plone order in our custom content type folders and I found a blog post that said that content_meta_type in profiles/types/[contenttype].xml cannot have spaces. I wish I had saved that link, because I cannot find it now. Anyway, I took the spaces out (ex. “Financial Aid Folder” became “FinancialAidFolder”) and all was well.

    • jjmojojjmojo says:

      I don’t know if that’s entirely true. I’ve got some working content types right now that have the content_meta_type property set to something like “Notebook Task”. I know that you can’t have spaces in the name of the file (e.g. Notebook Task.xml won’t work but Notebook_Task.xml or NotebookTask.xml will).

      Did you build the content type with ArchGenXML?

  3. Anthony says:

    I don’t think so. It was based on sample code given to us by a consultant that happened to be for non-folderish objects. I just copied and modified to make a folder type. I looked mostly at the PPD book for guidance on that.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s