Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

One Time Forms Input #500

Open
beblank opened this Issue · 12 comments

3 participants

@beblank

How to make the forms input just 1 time
if already filled then show the filled forms
i know theres a onOpenDocument event
i tried some solution from
#456

but the /EditDocument shows error


Traceback (innermost last):
Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module Shared.DC.Scripts.Bindings, line 322, in __call__
Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
Module Products.CMFCore.FSPageTemplate, line 237, in _exec
Module Products.CMFCore.FSPageTemplate, line 177, in pt_render
Module Products.PageTemplates.PageTemplate, line 79, in pt_render
Module zope.pagetemplate.pagetemplate, line 132, in pt_render
Module zope.pagetemplate.pagetemplate, line 240, in __call__
Module zope.tal.talinterpreter, line 271, in __call__
Module zope.tal.talinterpreter, line 343, in interpret
Module zope.tal.talinterpreter, line 888, in do_useMacro
Module zope.tal.talinterpreter, line 343, in interpret
Module zope.tal.talinterpreter, line 533, in do_optTag_tal
Module zope.tal.talinterpreter, line 518, in do_optTag
Module zope.tal.talinterpreter, line 513, in no_tag
Module zope.tal.talinterpreter, line 343, in interpret
Module zope.tal.talinterpreter, line 852, in do_condition
Module zope.tal.talinterpreter, line 343, in interpret
Module zope.tal.talinterpreter, line 533, in do_optTag_tal
Module zope.tal.talinterpreter, line 518, in do_optTag
Module zope.tal.talinterpreter, line 513, in no_tag
Module zope.tal.talinterpreter, line 343, in interpret
Module zope.tal.talinterpreter, line 946, in do_defineSlot
Module zope.tal.talinterpreter, line 343, in interpret
Module zope.tal.talinterpreter, line 583, in do_setLocal_tal
Module zope.tales.tales, line 696, in evaluate
URL: file:/hosting/emtres/Plone/buildout-cache/eggs/Products.CMFPlomino-1.18.3-py2.7.egg/Products/CMFPlomino/skins/cmfplomino_templates/EditDocument.pt
Line 71, Column 0
Expression: 
Names:
{'container': ,
 'context': ,
 'default': ,
 'here': ,
 'loop': {},
 'nothing': None,
 'options': {'args': ()},
 'repeat': ,
 'request': ,
 'root': ,
 'template': ,
 'traverse_subpath': [],
 'user': }
Module Products.PageTemplates.ZRPythonExpr, line 48, in __call__
__traceback_info__: here.hasItem('Form')
Module PythonExpr, line 1, in 
AttributeError: hasItem 


thanks

@ebrehault
Owner

I am not sure #456 can be used in your case.
What do you want to do exactly ?
If you want to forbid that any new document is created using a given form if there is already one document existing, that's easy, you add this in your onBeforeCreateDocument event:

db = context.getParentDatabase()
existingdocs = db.getIndex().dbsearch({'Form': 'my_singleton_form'})
if len(existingdocs) > 0:
    return "Sorry, you cannot create another doc with this form."
@beblank

what i need to do is
if there's an existing document then show existing document edit mode

thanks

@beblank

tried that and nothing happened
no notification and still creating new document

@ebrehault
Owner

ok, well then the best approach is to create an action or an agent that will check if the doc exists and then redirect either to the /OpenForm url or to the /EditDocument url

@beblank

sorry it works
i still using admin when tried it
i change some script

db = context.getParentDatabase()
existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1'})
if len(existingdocs) > 0:
olddoc = existingdocs[0].getObject()
return open_url(context.REQUEST.response.redirect(olddoc.doc_url()+'/OpenDocument'), false)

but it show error
how to fix it

thanks

@fulv
Owner

Don't do open_url. You want to set the REDIRECT key on the request, and then just return the URL as a string. The agent will do the redirect for you:

context.REQUEST.set('REDIRECT', 'True')
return olddoc.doc_url()+'/OpenDocument'
@beblank

so the script would be just like this?


db = context.getParentDatabase()
existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1'})
if len(existingdocs) > 0:
olddoc = existingdocs[0].getObject()
context.REQUEST.set('REDIRECT', 'True')
return olddoc.doc_url()+'/OpenDocument'

it won't redirect the url
just show as a string

Validation failed
return url
go back button

why not using open_url ?

now the problem is every user can't add another forms data because it ends up shows old data
so i have and idea to check the user.
i created a user field which is computed to currentUser


db = context.getParentDatabase()
current_user_id = db.getCurrentUser().id
existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1'})
length = len(existingdocs)
for i in existingdocs(0,length)
    if (forms.user[i] == current_user_id)
        olddoc = existingdocs[i].getObject()
        context.REQUEST.set('REDIRECT', 'True')
        return olddoc.doc_url()+'/OpenDocument'

how to access all the user field array?

thanks

@ebrehault
Owner

The user id is stored in the Plomino_Authors field (which is a list), so the right way to do it is:

db = context.getParentDatabase()
existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1', 'Plomino_Authors': [db.getCurrentUser().getMemberid()]})
if len(existingdocs) > 0:
    blabla
@beblank

db = context.getParentDatabase()
existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1', 'Plomino_Authors': [db.getCurrentUser().getMemberid()]})
if len(existingdocs) > 0:
    return 'test'

formula error
and noting happend

@beblank

how to to this the other way?
how can i search a value from field of form?
it should be easy to do this when i get the value

@beblank

ok i get it working
thanks

@beblank

db = context.getParentDatabase()
currentUser = db.getCurrentUser().getMemberid()
existingdocs = db.getIndex().dbsearch({'Form': 'DataUmum2013P1', 'UserField': currentUser})
if len(existingdocs) > 0:
return 'test'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.