librelist archives

« back to archive

Adding database models in plugins

Adding database models in plugins

From:
LeafStorm
Date:
2010-01-14 @ 23:22
Is it possible to write a plugin that adds a data type to the Zine
database - for example, quotes or links? If so, can you demonstrate
how this is done?

-- LeafStorm
"There are 10 types of people in the world - those who understand
binary and those who don't."

Re: [zine] Adding database models in plugins

From:
Armin Ronacher
Date:
2010-01-15 @ 01:13
Hi,

Am 15.01.2010 00:22, schrieb LeafStorm:
> Is it possible to write a plugin that adds a data type to the Zine
> database - for example, quotes or links? If so, can you demonstrate
> how this is done?
It is not possible in current versions of Zine, but if everything goes
according to plan that is merged in with the next version.  You can
already play with the code at Georg's repository:

  http://bitbucket.org/birkenfeld/zine-main-migrations/

Check the eric_the_fish plugin in the external-plugins folder which uses
the database.  There however are some things that need to be adjusted
before release there, so the code in that repository is subject to change.

Feel free to provide early feedback however :)


Regards,
Armin

Re: [zine] Adding database models in plugins

From:
LeafStorm
Date:
2010-01-15 @ 02:54
I looked through the code, and it looks pretty good. I could mostly
understand the Eric the Fish plugin's migrations, but you will
probably want to write some sort of documentation describing the
process of migrations in more detail, as SQLAlchemy isn't really my
forte, and the obviousness is likely to decrease exponentially for
anything more complicated than Eric the Fish.

Another thing is that you might want to rethink the idea of having the
migrations yield HTML for progress updates. Yielding straight HTML
markup looks a bit kludgy, and I saw a bit of difference in the way
the HTML was written between the core migrations and the Eric the Fish
migration. I'm not sure what the best way to handle this would be -
possibly some sort of thing like:

yield Status('Adding fortunes to the database')
for fortune in FORTUNES:
  yield Item(fortune)
  session.add(Fortune(fortune))
session.commit()

-- LeafStorm
"There are 10 types of people in the world - those who understand
binary and those who don't."


On Thu, Jan 14, 2010 at 8:13 PM, Armin Ronacher
<armin.ronacher@active-4.com> wrote:
> Hi,
>
> Am 15.01.2010 00:22, schrieb LeafStorm:
>> Is it possible to write a plugin that adds a data type to the Zine
>> database - for example, quotes or links? If so, can you demonstrate
>> how this is done?
> It is not possible in current versions of Zine, but if everything goes
> according to plan that is merged in with the next version.  You can
> already play with the code at Georg's repository:
>
>  http://bitbucket.org/birkenfeld/zine-main-migrations/
>
> Check the eric_the_fish plugin in the external-plugins folder which uses
> the database.  There however are some things that need to be adjusted
> before release there, so the code in that repository is subject to change.
>
> Feel free to provide early feedback however :)
>
>
> Regards,
> Armin
>