Zine

open source content publishing system


Changeset 1319:3cbfda759c44


Ignore:
Timestamp:
07/19/09 17:17:22 (3 years ago)
Author:
s0undt3ch
Branch:
default
Message:

Completed "Eric The Fish" as a plugin database migration example. Now it actually queries the database for the random fortune.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • external-plugins/eric_the_fish/__init__.py

    r1314 r1319  
    4545from zine.privileges import BLOG_ADMIN 
    4646 
    47 # the last thing is importing the FORTUNES list from the fortunes.py file 
    48 # from the same folder. It's just a long list with quotes. 
    49 from zine.plugins.eric_the_fish.fortunes import FORTUNES 
     47# import Zine's database related stuff 
     48from zine.database import db 
     49 
     50# the last thing is importing the Fortunes database mapped object. 
     51from zine.plugins.eric_the_fish.database import Fortune 
    5052 
    5153# because we have an admin panel page we need to store the templates 
     
    5658# here we do the same for the shared files (css, fish images and javascript) 
    5759SHARED_FILES = join(dirname(__file__), 'shared') 
    58  
    59 # here we do the same for our database upgrade's repository 
    60 UPGRADES_REPO = dirname(__file__) 
    6160 
    6261# and that's just the list of skins we have. 
     
    9291    for link_id, url, title, children in navigation_bar: 
    9392        if link_id == 'options': 
    94             children.insert(-3, ('eric_the_fish', url_for('eric_the_fish/config'), 
     93            children.insert(-3, ('eric_the_fish', 
     94                                 url_for('eric_the_fish/config'), 
    9595                                 _('Eric The Fish'))) 
    9696 
     
    119119 
    120120def get_fortune(req): 
    121     """The servicepoint function. Just return one fortune from the list.""" 
    122     return {'fortune': choice(FORTUNES)} 
     121    """The servicepoint function. Just return one fortune from the database.""" 
     122    fortune_ids = db.session.query(Fortune.id).all() 
     123    return {'fortune': db.session.query(Fortune).get(choice(fortune_ids)).text} 
    123124 
    124 def register_repository(): 
    125     print 'registering eric repo' 
    126     get_application().register_upgrade_repository('eric_the_fish', UPGRADES_REPO) 
    127125 
    128126def setup(app, plugin): 
     
    132130    """ 
    133131 
    134     # we need to register eric's database upgrades repository 
    135 #    app.connect_event('register-upgrade-repository', register_repository) 
    136     app.register_upgrade_repository(plugin, UPGRADES_REPO) 
     132    # we need to register eric's database upgrades repository; 
     133    # Basically it should be a folder which itself has another child folder 
     134    # named "versions" where the upgrade script(s) should reside. 
     135    # In "Eric the fish" case we pass the plugin's folder which has that child 
     136    # folder called "versions" 
     137    app.register_upgrade_repository(plugin, dirname(__file__)) 
    137138 
    138139    # we want our fish to appear in the admin panel, so hook into the 
Note: See TracChangeset for help on using the changeset viewer.