|
Project Information
|
What is it?A revolutionary approach to web applications using django. Code your views using linear flow logic, maintaining the state across requests. Similar to UnCommon web, Seaside and Borges Since its just another django app, you can still write some views in the traditional style, and use all the features of django web framework. the other home of this project is http://woobiz.com.ar/en/articles/stateful-django The kind of code you end up writing:A counter: class Counter(StatefulView):
def main(self):
for c in count():
yield Page("you've been here %s times before" % c)A wizard (kind of): class NameForm(forms.Form):
name = forms.CharField(max_length=100)
class LanguageForm(forms.Form):
langs = [(x,x) for x in ['python','perl','ruby','php','prolog']]
lang = forms.ChoiceField(choices=langs, initial='python', widget=forms.RadioSelect)
class Wizard(StatefulView):
def main(self):
started = datetime.now()
form = NameForm()
name = None
while not name:
input, a, kw = yield show_page('ask_name.html', {'form': form,})
form = NameForm(input.GET)
if form.is_valid():
name = form.cleaned_data['name']
form = LanguageForm()
input, a, kw = yield show_page('ask_language.html', {'form': form, 'name':name})
form = LanguageForm(input.GET)
if form.is_valid():
lang = form.cleaned_data['lang']
if lang == 'python':
yield Page("Cool, now refresh and see how much time you spent in this wizard")
else:
yield FinalPage("well %s, i guess you should look for a %s framework then..." % (name,lang))
else:
yield FinalPage("hey, you are not going with the flow you know, goodbye %s." % name)
delta = datetime.now() - started
yield FinalPage("You spent %s seconds, bye %s !!" % (delta.seconds, name))
Implementation facts:
Installation, requirements and usageQuick and dirtyJust checkout trunk, edit reelevant paths in settings.py and run: python manage.py runserver <host>:<port> then play around with example_app/views.py Long version
from django_stateful.views import StatefulView, Page, FinalPage, show_page
yield Page("here's something the server wants to say") yield show_page('template.html', {'foo': foo, 'bar':bar}) input, args, kwargs = yield show_page('ask_for_input.html', {'form': form})
from django.conf.urls.defaults import *
from my_project.views import MyCustomView
urlpatterns = patterns('',
url(r'^my_custom_view/$', MyCustomView.handle),
)
|