WizardStep.py :  » Web-Frameworks » Aquarium » aquarium-2.3 » aquarium » screen » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Aquarium 
Aquarium » aquarium 2.3 » aquarium » screen » WizardStep.py
class WizardStep:
    """Provides convenience methods for wizard steps. You -must- setup a bean
    in your subclass"""

    bean = None
    goingBackwards = False

    def callWizard(self, action):
        self.wizard(callingStep=self, action=action)

    def __call__(self, *args, **kargs):
        self.formValues = {}
        self.errorMessages = {}

        self.initWizard()
        self.bean.stepList = self.wizard.steps
        self.callWizard("Show")

    def run(self):
        """This method is called when it is time for us to run."""

        self.executeAction()
        self.forward(self.getName() + "_view")

    def forward(self, where):
        _ = self._ctx._
        if self.errorMessages:
            self.setError(_("""\
An error was found in your data.  See below for more information."""),
                    errors=self.errorMessages)
        self.bean.defaults = [
            self.getPreviousData() or {},
            self.formValues or {},
            self.getDefaults(),
        ]

        self._ctx.iLib.forward(where, self.bean)

    def initWizard(self):
        self.wizard = self._ctx.iLib.aquariumFactory(
            "screen." + self.wizardName)

    def getDefaults(self):
        return {}

    def review(self):
        return ""

    def doNextAction(self):
        """Tells the wizard to take us to the next step."""

        nextMethod = lambda: self.callWizard("Next")
        self.validateAndProcess(nextMethod)

    def doPrevAction(self):
        """Tells the wizard to take us to the previous step."""

        self.goingBackwards = True
        prevMethod = lambda: self.callWizard("Prev")
        self.validateAndProcess(prevMethod)

        # If we are executing this code, validation failed, we allow
        # going previous without processing the data, we hold on to
        # it in the session so that we can show it later.
        self._ctx.session["wizard" + self.getName()] = self._ctx.form
        prevMethod()

    def getPreviousData(self):
        prevData = self._ctx.session.get("wizard" + self.getName())
        if prevData:
            del self._ctx.session["wizard" + self.getName()]
        return prevData

    def doCancelAction(self):
        """Tells the wizard to cancel."""

        self.callWizard("Cancel")

    def validateAndProcess(self, successCallback):
        if self.validate():
            self.process()
            successCallback()

    def validate(self):
        """You should override this with a validator that actually does
        something. On success it should populate self.formValues with
        the return data from FormValid. On failure it should populate
        self.formValues with self._ctx.form
        """

        self.formValues = self._ctx.form
        self.errorMessages = {}

        return True

    def process(self):
        """Override this method so that you can actually process the data.
        Most likely this means to save the data.

        Note that if you are reading from self._ctx.form in here (instead
        of self.formValues) you are probably doing something wrong.
        """

        pass
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.