Re: Thoughts on comments package
Ted Leung <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.user |
|---|---|
| Message-ID | <[email protected]> |
On Feb 12, 2004, at 7:45 PM, Wari Wahab wrote:
>> As you do this, keep in mind that we'll need a way to produce error
>> replies as well.
>
> I thought errors are as easy as:
>
> renderer.addHeader('Status', '404 Not Found')
> renderer.setContent( {'title': 'The page you are looking for is not
> available','body': 'Somehow I cannot find the page you want.'+
> 'Go Back to <a href="%s">%s</a>?' %
> (config["base_url"],
> config["blog_title"])})
> # Log it as failure
> tools.run_callback("logrequest", {'filename':config.get('logfile',''),
> 'return_code': '404',
> 'request': self._request})
> renderer.render()
>
> Can be made easier by putting these three lines in a method of a
> BasicRenderer I guess.
It seems like a waste for a trackback handler to run all the way
through the
pyblosxom pipeline in order to report a failure.
>
>> Another thing about the current architecture is that it makes it very
>> difficult for me to provide comment preview, which is something that
>> people really would like to have. To do preview, people submit the
>> form, but we don't have a way of injecting that back into pyblosxom
>> because it's a cgi script -- I didn't write the comment data to disk,
>> because it was a preview, but then the pyblosxom script exits and the
>> data was lost.
>
> But Ted, you of all people should know how one can do this without even
> using cookies. It's the same technique done in most Wiki implementation
> and even Movable Type comment system uses this same way without cookies
> or sessions whatsoever.
>
> 1. You have a comment form with a preview and post button
> 2. On post, you just post. End
> 3. On preview, you set up the comment rendered in it's glory HTML,
> 3.1 you also set up a bunch of hidden fields in a form containing
> the
> data that was entered
> 3.2 and in that same page, you have that same bunch of widgets that
> allows users to modify what they entered
> 3.4 put in a [preview/post] button, if you have hidden fields, you
> need one button, because you can compare and set the preview or
> post logic, no hidden fields means two buttons.
> 4. Rinse
> 5. Lather
> 6. Repeat step 2
>
> Granted a lot of work had to be done on step 3 because you would have
> three data formats to work with, which is
> * The rendered HTML for comments
> * The original data in the hidden fields
> * The almost original (escape all & to $amps;) data in the TEXTAREA
> form to be displayed to the user
>
> I don't think this is impossible, a bit hard? Yes. Primitive? Also
> true,
> this was done before netscape invented cookies. MovableType has been
> working without cookies (during comment submission, not the MT ui), and
> greymatter works in similar ways as well.
>
> You can take a look at Will's registry plugin to see how he implements
> previews, although he did not have a form in the preview page, one
> could
> at least press the back button and modify from there. Once the user
> clicks [OK], is the time when all that input is written to disk.
>
>> I know how to fix this problem in the Java servlet environment -- I'd
>> just stick the data in the session, but in the CGI environment, I
>> haven't thought of a clean way to solve this problem.
>
> What are sessions? Basically data that's serialized to memory or disk
> that may or may not expire within the next few minutes. Extremely
> complex sessions mechanism can work Amazon.com, helping you to buy a
> tech book and recommending you to some other related ones, while simple
> ones are used as short term memory, and your case, the preview data to
> be commited.
>
> Sessions require some ID, this being cookies, or a simple ?ID=foobar.
> Ultimately, a background process will clean up unused or expired
> sessions.
>
> So let's talk about this and it's implications in Pyblosxom. We do not
> have a cookie mechanism, but could probably be fixable using plugins.
> With a cookie, one could implement sessions, and store data in a DB
> file. That would allow one to have fast access to information. Even if
> Pyblosxom is a CGI, you can get data about the user based on his
> session
> info.
>
> This of course requires some work doing up some form of session objects
> that does all the hard work in the background. Expiration of sessions
> can be done everytime pyblosxom fires up, or just by using a simple
> cron
> job to do the dirty work.
>
> Then, it'll be as easy as sticking the data into the session. It's not
> that hard, lot's of programs out there has done it before, and not only
> that, there are a few session objects available for python out there in
> sourceforge, so you don't have to do the work of implementing your own.
>
> Java makes it easy because the classes are there for you so that you
> can
> concentrate on just the business logic. It still has to do the same old
> hard work of keeping data in memory, or dumping it in Oracle database.
>
> I do believe that you know all these things and I really shouldn't
> explain to you about this, only that technologies exists to make you
> forget about the details, no matter how simple it is.
Actually, thanks for the reminder. I came to web programming late and
went directly to Java, so I tend to not think of things that are second
nature to people that have had to wrestle with CGI scripts. I guess I
can
try to do the hidden field thing. I can make the comment renderer
look for those fields and fake an entry for preview. But it's nasty
ugly.
Don't worry - I'm not advocating building a session mechanism. But I do
think that trying to combine everything into one mega handler (as was
being
proposed) is going to have some interesting challenges if we want to try
and handle everything that we can do now.
----
Ted Leung Blog: http://www.sauria.com/blog
PGP Fingerprint: 1003 7870 251F FA71 A59A CEE3 BEBA 2B87 F5FC 4B42
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click