Welcome to Squishdot Websites Squishdot How-To
 about
 search
 post article
 Documentation
 Mailing Lists
 Bug Tracking
 Development
 Installation
 Upgrading
 Download
 admin
 rdf

 main
 parent
 thread


formatting date_posted & search sort order
by on Thursday October 17, 02:22AM, 2002
Editors Note - Please do NOT follow the advice in this posting. There are much simpler ways to achieve your aims when it comes to anything date related! Either ask on or post a question on this site.

How helpful is that?

It took me about 24 hours to figure out. I wasn't sure I got it right. Really, I thought, it must be easier.

But maybe not. Read all about it: Squishdot Dates & Sort Order

For the benefit of other Squish users, here's the abbreviated version.

NOTE: If you only want to change the date format and don't care about making the search returns sort in chronological order, just modify the date format itself in the DTML methods, using "fmstr" as has been documented elsewhere and is also discussed below.

I have close to the current version, Squishdot 1.4.0 (current is 1.4.1). I'm using a plain vanilla site: after one quick look at the "Blue Heaven" version of Squish and the code that creates it, I decided not to spend time modifying the embedded design elements. I prefer working up from simple code as I learn my way around. Also, I'm not a programmer -- though I'm not averse to dipping into the different levels of code.

I found references to various patches. One that returns the date formatted for different locales is mentioned on the site, but the link to the patch in the archives is broken. One that allows for variable date formats can be found in the , but I couldn't figure out how to use it, or whether it would help with the problem sorting search returns. There's also mention of a new date method added in v. 1.3.0 that supposedly allows you to adjust the date_posted format, but it wasn't explained and didn't seem to work for what I needed. Nothing that I found made much sense to me.

There may be smarter and simpler ways to do this, but here's what worked for me.

 

1. Change the date_posted string to a format that will sort on the numerical values of year.month.day.time instead of alphabetically by day of week.

The default format of date_posted is set in a massive python script, Posting.py, and gives you something like:

Saturday October 12, @09:21PM

Because the search works on formatted date strings, you can't adjust the sort order without going into this script and changing the formatting there -- unless you want them organized by day of the week. Not helpful! Presumably, this is stored in a ZCatalogue, and the actual date value must be in there someplace, too, but where this lives and how to get into it aren't obvious. I tried sorting on "date" instead, which is defined in Postings.py immediately after "date_posted," but couldn't make out any order whatsoever in the results it returned (!).

In order to sort by date, as far as I could figure out, I needed something like:

2002.10.12 :: 21:21 (Saturday October 12 : 09:21 PM)

This is kind of overkill, but gives the date/time in a format that's accurately sortable, first, followed by the same info in more user-friendly (human readable) form. To do this, I went into Posting.py and changed:

FROM:

    security.declareProtected(View, 'date_posted')
    def date_posted(self,fmstr='%A %B %d, @%I:%M%p'):     
        # """ date when article was posted """     
        ltime = localtime(self.created)         
        return strftime(fmstr,ltime)  

TO:

    security.declareProtected(View, 'date_posted')
    def date_posted(self,fmstr='%Y.%m.%d :: %H:%M (%A %B %d : %I:%M %p)'):     
        # """ date when article was posted """     
        ltime = localtime(self.created)         
        return strftime(fmstr,ltime)  

The bit you need to change is this: "fmstr='%A %B %d, @%I:%M%p'," where "%A" gives you the day of the week, "%B" gives you the month by name, "%d" gives you the date, "%I:%M" gives you the time on a 12 hr. clock, and "%p" either AM or PM.

In my modified version, "fmstr='%Y.%m.%d :: %H:%M (%A %B %d : %I:%M %p)'," "%Y" gives you the year, "%m" gives you the month by number, and "%d" again gives the date. "%H:%M" gives the time in a 24 hr. clock.

For a detailed list of these options, see the entry for "strftime" in Time access and conversions in the Python Library Reference.

 

2. Modify the search results loop in showSearchResults to sort postings by date posted, in reverse order, and insert the date in the results so users can see it.

Adding the sort to the search results is the easiest part:

FROM:

TO:

Next, insert the date in the returned results. I also removed itals from the formatting of the author name and put the date below the main search results for each item. Finally, I adjusted font styles for scannability, reducing the font size, changing the color to grey, and adjusting left-hand padding so it would align with the text above, to the right of the icon:

FROM:

by

TO:

by

 

3. Re-catalogue all the postings so the new date_format string replaces the old in the catalogue of postings.

Otherwise, you'll have the new format for postings added from now on but the old format for all previous postings.

Go to the "Options" tab on your Squishdot site and click on "Re-catalog All Postings." Note that it says: "This can be resource expensive." If you have a lot of postings, recataloguing them all will take a long time.

 

4. Adjust formatting of date/time on the postings preview page.

One small step and you're done.

The DTML method, previewPosting, reads the date/time straight off the ZopeTime clock and formats it for the preview, so you need to adjust the date formatting there if you want it to correspond to the new formatting. Because this only affects how the date/time is rendered on the preview page, I left out the portion needed for the search results sort and used only the more legible portion, with a minor adjustment:

2002 October 13 (Sunday) : 05:39 PM

FROM:

  , @ by

TO:

   ( ) : by

Careful readers will notice that a lot of time has elapsed between when I started this process and now!

 

5. Optional: Streamline the date format everywhere else!

Finally, you might not -- after all this! -- want the very number-crunchy version of the date-time to appear anywhere but in the search results. To do this, AND if that's all care about, you can go into the DTML methods and modify the formatting of the date_format there by changing:

TO whatever you want, but this one is nice:

giving you:

2002 October 13 (Sunday) : 10:02 PM

You need to change it in index_html and posting_html (and, depending, might need to adjust the formatting in previewPosting to match).

Phew! I did catch some sleep in between.

I was hoping something useful might come out of the Squishdot customization contest at FreeZope, for example. They were supposed to post the winners on the 11th, but nothing's up yet. Gee, I wonder why? The results will undoubtedly be posted soon. . . . But given the state of the code and attitude of the developers, you'd have to be crazy to try to customi -- oh, what have I been doing with my life? =}

have fun,

::laura

Related Links

The Fine Print: The following comments are owned by whoever posted them.
( Reply )

:-(
by on Thursday October 17, 04:56PM, 2002
Hey Laura,

Thanks for ranting at me :-(

After getting crap from both you and some guy called Shad Young on the list, I think I'll throw in the towel. It seems no matter what you do for people for free, they want more and bitch at you if you can't deliver.

Really, for free software, surely using google (or even the search on Squishdot.org) can't be _that_ much to ask for?

The issue _has_ been done to death. If you want to sort, add an index called 'date', if you want to format, use 'date_posted' and supply a format string.

I'm sorry you've ahd a bad experience, I hope things go better for you in the future :-S
[ Reply to this ]
  • Re: :-( => more on sorting by date & why
    by on Sunday October 20, 11:19PM, 2002

    Sorry, Chris, that you read my posting as a rant. I mostly intended to document the changes I made in order to contribute, to give back to Squish, and possibly assist other users.

    I did take the time --- a lot of time --- to search via Google and the mailing list archives, and didn't find the solutions I was looking for. Curious timing. I see that now there's been a small flurry of attention to sorting by date, much of it apparently unrelated to my posting. Find answers over at zopezen here and in the Squishdot mailing list archives .

    Yes, I was also tearing my hair out at the difficulty of figuring out how to do what I needed to do. But Squishdot is really valuable! As I said in the longer version of my article, we need tools for threaded discussion in Zope. I used Squishdot for a reason, as have many others: it has a lot of great features. But by now it seems to need some serious refactoring, that's all. It's difficult to modify and find your way around the code, especially for non-programmers.

    But the fact that I've spent as much time as I have trying, usually with success, is a testament to its value. I've learned a lot working with Squishdot --- and I'm still using it! I can only imagine how difficult it is to manage a project as complex as Squishdot. Sorry that didn't come through.

    Thanks for all your efforts and successes with Squishdot, Chris, and for your reply.

    ::laura


    [ Reply to this ]
    • Re: :-( => more on sorting by date & why
      by on Monday October 28, 07:11AM, 2002

      Rant Rant Rant Rant.

      Get a life


      [ Reply to this ]

 
The Fine Print: The following comments are owned by whoever posted them.
( Reply )

Powered by Zope  Squishdot Powered
  "Any system that depends on reliability is unreliable." -- Nogg's Postulate
All trademarks and copyrights on this page are owned by their respective companies. Comments are owned by the Poster. The Rest ©1999 , ©2000-2002 .