_______ _________ _______ _______ _______ ______ _________
( )\__ __/( ____ \( ____ )( ___ )( __ \ \__ _/
| () () | ) ( | ( \/| ( )|| ( ) || ( \ ) ) (
| || || | | | | | | (____)|| | | || | ) | | |
| |(_)| | | | | | | __)| | | || | | | | |
| | | | | | | | | (\ ( | | | || | ) | | |
| ) ( |___) (___| (____/\| ) \ \__| (___) || (__/ )|\_) )
|/ \|\_______/(_______/|/ \__/(_______)(______/ (____/
-----------------------------------------------------------------
-> What the user of the framework (a developper) will write :
class Person(microdj.Magic):
name = ""
age = 0
sexe = ""
-> The framework will be able to :
-
Generates instance attributes for all static attributes
-
an init method with all attributes as keyword arguments so the user can writes : p1 = Person(name="toto") p2 = Person(name="titi", age=3)
-
The html code that represents a form to create Person objects (this is what django.admin do)
-
The html code that represents a list of all Person objects (this is what django.admin do also)
-
Saving/loading all Person objects in a file (we will not use a database, but serialization)
-
A simple http server in python with a tiny url dispatcher
my_url/person my_url/admin ...
-
A rendering method using a template engine (for example Jinja)
-
Your propositions are welcome ...
python microdj startapp app_name
This wil creates a folder called app_name with :
database/ : the database folder that contains all serialized objects
templates/ : the templates folder that contains all templates files
models.py : models file that contains user's classes
views.py : views file that contains user's views
urls.py : urls file that will be used by the dispatcher
__init__.py : an empty init file to tels to python that this is a module
To clean the app use :
python microdj delapp app_name
class YourClassName(microdj.Magic):
attribute1 = default_value
attribute2 = default_value
........
create instances of your class using :
instance1 = YourClassName(attribute1=value, attribute2=value, ....)
Don't forget to save created objects using :
YourClassName.save()
python microdj syncdb app_name
This will creates a file "class_name.db" in the database folder for each Class (that has Meta_Magic as metaclass) you have in your model.
To clean the database use :
python microdj cleandb app_name
python microdj genadmin app_name
We use jinja2 templates engine : http://jinja.pocoo.org/docs/dev/
Return a response using a template :
def index(req):
return microdj.render("template_name.html", { "key" : var })
Return a simple text response :
def index(req):
return "balbalbalba"
Don't forget to load the needed classes :
YourClassName.load()
urls = {
'path1' : views.view1,
'path2' : views.view2,
.....
}
python microdj runserver app_name port_number