|
GettingStarted
Guide to installing Tesla and creating your models. InstallationIt is assumed that you have Python 5 installed on your machine, plus easy_install etc, and that you are familiar with Pylons, SQLAlchemy and Elixir. 1. Download the template.There are two ways to do this: easy_install [-U] Tesla For the development version: easy_install [-U] Tesla==dev This should also install dependencies, if they are not already installed. 2. Check installation works.paster create --list-templates "tesla" and "tesla_auth" should be in the list. Sample Tesla applicationWe'll create a very simple blogging tool, myblog, for our purposes. SQLite database will be used as it's the easiest to get up and running. 1. Create your project.paster create myblog -t tesla You should now have a Pylons app ready to go. Change to the myblog directory. 2. Edit database settings.Open up development.ini and set the SQLAlchemy database URI accordingly : sqlalchemy.default.uri = sqlite:///%{here}s/myblog_development.dbSee here for how to set the SQLAlchemy URI for your database. 3. Create model files.paster model posts Two files should now be created: myblog/models/posts.py and myblog/tests/unit/test_posts.py. 4. Create a model class.Open myblog/model/posts.py and create a simple Entity class: from elixir import *
class BlogPost(Entity):
has_field('title', Unicode(100), required = True)
has_field('content', Unicode)
using_options(tablename = 'posts')The model class needs to be imported into myblog/model/__init__.py so it can be "seen" by the application. Add the following to the bottom of myblog/model/__init__.py: from posts import BlogPost Note: if you want to use the SQLAlchemy autoload feature (which uses reflection on the database schema rather than declaring your columns in code) then open up myblog/lib/database.py and uncomment these lines: #if not metadata.is_bound(): # elixir.delay_setup = True 5. Create the database tables.paster create_sql development.ini [posts] This will create all the database tables for the application if they don't exist yet. You can optionally pass in the name of a single table to be created. 6. Create a sample post.Run paster shell development.ini. You can now type: p = model.BlogPost(title = 'My first post', content = 'yippee!') p.flush() A blog post should now be in the database. 7. Set up your tests.Tesla by default uses an in-memory SQLite database. You can change this in test.ini if needed. Open up myblog/tests/unit/test_posts.py. You should see the following code: from myblog.tests import *
class TestPosts(TestModel):
passLet's add a simple test in here: from myblog.tests import *
class TestPosts(TestModel):
def test_create_post(self):
post = model.BlogPost(name = 'a post', content='blah')
post.flush()
self.failUnlessEqual(model.BlogPost.count(), 1) Then run nosetests to see if the test passes. |
Sign in to add a comment
I assume you mean Python 2.5 installed, not Python 5.
:~/workspace/myapp/myapp$ paster create_sql test.ini An unknown error occurred. <module 'myapp' from '/home/lee/workspace/myapp/myapp/myapp/init.pyc'> has no 'make_app' attribute
I am using -t tesla_auth.
pylons 0.9.6rc2 and tesla 0.2.5
uncommenting this block isn't working for me:
I got an error that 'metadata' didn't exist.So I thought maybe it should be context.metadata and that raises a different error:
I have the following in my development.ini file:
Where/How should I be calling "self.add_engine" to configure engine 'default'?
A fix for the make_app problem can be found here: http://code.google.com/p/tesla-pylons-elixir/issues/detail?id=26&q=has%20no%20'make_app'%20attribute
A fix for the make_app problem can be found here: http://code.google.com/p/tesla-pylons-elixir/issues/detail?id=26&q=has%20no%20'make_app'%20attribute
The Tesla trunk seems to be pretty broken at the current time; the tutorial above will not work at all. Current development (as of this posting) seems to be happening on the 097update branch, with which I was able to successfully get started as described above:
http://tesla-pylons-elixir.googlecode.com/svn/branches/097update
could someone involved in the project please update the trunk to match the branch referred to by rafrombrc. works great from that branch but useless from easy_install.
delaneygillilan:
This project has essentially been abandoned. All resources devoted to this project (i.e. me) have switched to Shabti, a fork of tesla-pylons-elixir which is accessible on http://bitbucket.org/gjhiggins/shabti/
There's more info on Shabti available from http://bel-epa.com/notes/Pylons/Shabti
(Still no easy-install as yet, tho)
HTH,
gjhiggins