[albatross-users] Re: Some questions and my albatross wrapper....

Cameron Blackwood korg at darkqueen.org
Sun Feb 26 12:23:37 EST 2006



If I may be rude and reply to my own message.... :)

"Cameron Blackwood" (thats ME!) writes:
  | 
  | Hi everyone. Im an on again, off again albatross user and Ive been
  | working on a 'wrapper class' to make my albatross programming easier.
  | 


  | 
  | For loops with var="foo"?
  | -------------------------

Im so glad you liked this idea :)  *does happy dance*
Iter.value() has always been an annoying point for al-for's for me.




  | 
  | My wrapper class
  | ================

Im not proud of this code but......

   http://darkqueen.org/docs/code/korg_web/



You should be able to:

  * extract the tarball

  * have a look at the sample pages and templates in korg_web/stuff

    (korg_web/stuff/template_ten.html is the only non standard template)

    (korg_web/stuff/pages.py
     korg_web/stuff/obj_a/pages.py
     korg_web/stuff/obj_a/obj_a/pages.py
     have the page code.)

  * edit the test.py to add albatross to your path (if it isnt site-installed)

  * [ note: the first arg of TestApp is your content directory. If you
    use this with your own application you need to change this :)]

  * run <tt>python test.py</tt> and point a web browser to
    http://localhost:7722/


And no, I dont like the name either.... :) this is a way alpha release
and to be honest, if people like any of the ideas, then id rather they
rolled them into albatross rather than using my code. :) :) :) :)




  |
  | Why a wrapper class?

Because to make a change:

    * copy an existing template_???.html to template_myfoo.html 
    * create a class  myfoo  in the pages.py 
    * edit an existing page class so you can goto the new page (see
      index class in stuff/pages.py)
    * restart the app

Easy. All done via the files. 

If you add the page to stuff/obj_a then the page appears as
stuff/obj_a/myfoo as you'd expect. :)

Combined with the hiding of ctx.locals, I find the code more readable.

This makes coming back to any project using it easier. (IMHO)






There was a question about the security of.....

  | 
  |   * command buttons
  |     Smarter wrapping of <input type="submit"> buttons so you can do
  |     template code like this:
  | 
  |       <al-for iter="i" expr="ten_list">
  |          <al-value expr="i.value()">::
  |          <alx-kwbutton label="inc this number" op="add" args="[i.index(), 1
  | ]">
  | 
  |     which will make a button with the label and call a method 'add'
  |     with the arguments specified if you click it.

Let me explain a bit more about how that works....

When your dtml code marks up something like:

  |   <alx-kwbutton label="inc this number" op="add" args="[i.index(), 1]">

The tag creates a button_id (the name="xxx" setting on the submit button).

The function op and args are stored in a dictionary in the context under
that button_id.

When the page is processed, the dictionary keys (button_id's) are looked
up in the submitted inputs and any that are selected then the op and
args are placed in the 'commands to run' queue.

Then process_page() is call (so you can edit/check/add/remove them
if you want).

Then the 'commands to run' queue calls all the specified (by op)
methods with the specified arguments.

So, these buttons _cant_ execute anything that you didnt put in your
dtml code. Only the functions/args that you marked up are available in
the dictionary, so the user can _only_ send button_id's that you
created, not call random methods with arguments that you dont want.

(Obviously you dont want the context stored in the browser, but my
wrapper code uses session files, so that isnt an issue for me.)

Again, Im a sysadmin, not a webdev, so sanity checking, comments or
pointing out the better way to do this is always welcome.


cheers,
cam


--
 / `Rev Dr'   cam  at darkqueen.org            Roleplaying, virtual goth \
<   http://darkqueen.org        Poly, *nix, Python, C/C++, genetics, ATM  >
 \  [+61 3] 9809 1523[h]         skeptic, Evil GM(tm). Sysadmin for hire /
                      ---------- Random Quote ----------
Q:	Why do ducks have big flat feet?
A:	To stamp out forest fires.

Q:	Why do elephants have big flat feet?
A:	To stamp out flaming ducks.



More information about the Albatross-users mailing list