コード例 #1
0
        def onsubmit(self,
                     username: luban.decorators.notemptystr = None,
                     password: luban.decorators.notemptystr = None,
                     context: luban.decorators.notemptystr = None,
                     **kwds):
            db = self.controller.db
            q = db.query(User).filter_by(username=username)
            select_form = luban.a.select(id='login-form', type='form')
            if q.count() == 0:
                actions = [select_form.clearErrors()]
                showerror = select_form\
                            .find(name='username', type='formfield')\
                            .showError(message='username does not exist')
                actions.append(showerror)
                return actions

            user = q.one()

            hashed = hashfunc(password)

            if user.password == hashed:
                token = luban.session['token'] = luban.uuid()
                action = luban.session[context]['onsuccess']
                from luban.ui.actions.Loading import Loading
                if isinstance(action, Loading):
                    action.params['token'] = token
                return action

            actions = [select_form.clearErrors()]
            showerror = select_form\
                        .find(name='password', type='formfield')\
                        .showError(message='incorrect password')
            actions.append(showerror)
            return actions
コード例 #2
0
        def newhandler(self, *args, **kwds):

            if not requirement.check_requirement(self, *args, **kwds):
                frame = f(self, *args, **kwds)
            else:
                # create a unique context
                context_id = luban.uuid()
                # this is to build the action to load the real functionality.
                # we need it after user successfully fullfill the requirement
                # it always need to be a load action.
                # "actor" should be the name of the actor
                # "routine" should be the name of this routine
                # "replaceinterface" is required to replace the requirement solicitation inteface with the actual interface
                actor = actorname or getactorname(
                    inspect.getmodule(f).__name__,
                    self.controller.actor_packages)
                routine = f.__name__
                args = (actor, routine) + args
                kwds = dict(kwds)
                kwds['returntype'] = 'replaceinterface'
                # token is necessary for accessing protected area of the app
                # see also luban.workflows.login.authentication_portal
                onsuccess = onsuccess_action or luban.a.load(*args, **kwds)

                # create a
                luban.session[context_id] = {'onsuccess': onsuccess}
                frame = requirement.fullfill_requirement(context=context_id)
            return frame
コード例 #3
0
    def _createTabsForDemoPanelAndCodeViewer(self, func, deps=None):
        '''create a "tabs" widget with one tab for demo, another tab for code

        func: the function that creates a document for the demo
        deps: the functions that "func" depends on. we need to show code for
          all of them to give a complet view. It is good that func and deps
          are in the same actor.
        '''
        tabs = luban.e.tabs()
        demotab = tabs.tab(label='Demo')
        demotab.id = luban.uuid()
        demotab.Class = 'demo'
        funcname = func.__func__.__name__
        demotab.onselect = luban.a.select(element=demotab).replaceContent(
            newcontent=luban.a.load(actor=self.name, routine=funcname))

        codetab = tabs.tab(label='Code')
        codetab.Class = 'code'

        demotab.append(func())

        lines = getSourceLines(func)
        blocks = [lines]

        if deps:
            for dep in deps:
                blocks.append(getSourceLines(dep))

        codedoc = createCodeDoc(blocks)
        codetab.append(codedoc)
        # codetab.onselect = select(element=codetab).replaceContent(codedoc)
        return tabs
コード例 #4
0
    def createDemoPanel(self, **kwds):
        container = luban.e.document()

        doc = container.document(title='the document to replace',
                                 id=luban.uuid())
        newdoc = luban.e.document(title='new document')

        button = container.button(label='click me')
        button.onclick = luban.a.select(element=doc).replaceBy(
            newelement=newdoc)
        return container
コード例 #5
0
    def createDemoPanel(self, **kwds):
        container = luban.e.document()

        doc = container.document(
            title='the document to which a new element will be appended',
            id=luban.uuid())

        newelem = luban.e.paragraph(text='new element')

        button = container.button(label='click me')
        button.onclick = luban.a.select(element=doc).append(newelement=newelem)
        return container
コード例 #6
0
    def createDemoPanel(self, **kwds):
        container = luban.e.document()

        textfield = container.formtextfield(label='text',
                                            value='value',
                                            id=luban.uuid())

        button = container.button(label='click me')
        button.onclick = luban.a.select(element=textfield).setAttr(
            label='new text',
            value='new value',
        )
        return container
コード例 #7
0
ファイル: replaceContent.py プロジェクト: yxqd/luban
 def createDemoPanel(self, **kwds):
     container = luban.e.document()
     
     doc = container.document(
         title = 'the document for which the interior with be replaced', 
         id=luban.uuid())
     doc.paragraph(text='interior')
     
     newdoc = luban.e.document(title = 'new interior')
     
     button = container.button(label = 'click me')
     button.onclick = luban.a.select(element = doc).replaceContent(newcontent = newdoc)
     return container
コード例 #8
0
ファイル: hideshow.py プロジェクト: yxqd/luban
 def createDemoPanel(self, **kwds):
     container = luban.e.document()
     
     doc = container.document(
         title = 'the document to show/hide', 
         id=luban.uuid())
     
     b1 = container.button(label = 'click to hide')
     b1.onclick = luban.a.select(element = doc).hide()
     
     b2 = container.button(label = 'click to show')
     b2.onclick = luban.a.select(element = doc).show()
     
     return container
コード例 #9
0
    def default(self):
        frame = luban.e.frame(title="test hideshow extension")
        container = frame.document(title="hide/show")

        doc = container.document(title='the document to show/hide',
                                 id=luban.uuid())

        b1 = container.button(label='click to hide')
        b1.onclick = luban.a.select(element=doc).hide(speed='slow')

        b2 = container.button(label='click to show')
        b2.onclick = luban.a.select(element=doc).show(speed='slow')

        return luban.a.establishInterface(frame)
コード例 #10
0
ファイル: oncomplete.py プロジェクト: yxqd/luban
 def createDemoPanel(self, **kwds):
     uploadid = str(luban.uuid())
     # create uploader
     oncomplete = luban.a.load(
         actor=self.name,
         routine='onUpload',
         filename=luban.event.filename,
         uploadid=uploadid,
     )
     onfail = luban.a.alert(luban.event.reason)
     uploader = luban.e.uploader(
         label='Upload',
         id=uploadid,
         oncomplete=oncomplete,
         onfail=onfail,
     )
     return uploader