Getting Ready to Enter Your Data with Python Scripts
There is a bit of preliminary wiring
There are a few setup steps to prepare to input setup data into your system:
- From the root of your SchoolTool checkout, make a directory called "setup-data"
mkdir setup-dataThis is where you will put your CSV and text files. - Do
cd src/schooltool - You need to create a Python package to contain your scripts. Make a folder. We'll use the name "myschool" in this example. So
mkdir myschool - To make this an official Python package, we also need to
touch myschool/__init__.py - Next, we need to add a little configuration file to let the server know about the package we just created.
cdback down to your root (cd ../../) and thencd schooltool-skel/etc/package-includes/ - With your favorite editor, create a file named "myschool-configure.zcml" containing the following text
<include package="schooltool.myschool" /> - Now, we'll make a simple little test script. Navigate back to your new package:
cd ../../../andcd src/schooltool/myschool - With your favorite text editor, create a file called "students.py" with the following text:
import zope.interface
from schooltool.setupdata.interfaces import ISetupDataPlugin
from schooltool.person.person import Person
class Students(object):
zope.interface.implements(ISetupDataPlugin)
name = 'students'
dependencies = ()
def generate(self, app):
# Making one test user...
person = Person('cbrown', 'Charlie Brown')
# adding him to our ST application instance
app['persons']['cbrown'] = person
- Now, you need another configuration file to tell the server to use your new setup data plugin. So create "configure.zcml" in the "myschool" directory with this text:
<configure xmlns="http://namespaces.zope.org/zope">
<configure
xmlns:zcml="http://namespaces.zope.org/zcml"
zcml:condition="have devmode">
<utility
factory=".students.Students"
provides="schooltool.setupdata.interfaces.ISetupDataPlugin"
name="students"
/>
</configure>
</configure>
- Now, start or restart your server, go to "Setup data" in the "Developer Tools" menu in the upper right hand corner of your browser (if you don't see that, your server isn't configured to run in "dev mode"). Hit the "Generate" button.
- You should see a message like this:
Plugin Name CPU time used (seconds) students 0.07 - If you go to "Persons" under "Navigation" you should see a new user: Charlie Brown.