How to use dpcassemble as a black box?
Hi, I try to design a questionnaire system for my course design, I want to use the docassemble as a black box, because it's tough for me to understand the structure of the code. I already install the docassemble packages in python 2.7.10, but I don't know which function to 1. use to prase the yaml files, 2. generate the web questionnaire page, and 3. store the answers of the questionnaires to db. I will be appreciate it if you can tell me how to call the functions and their input and output. Sincerely, Peiran
Hi Peiran, The best way to use docassemble as a black box is through the web API. https://docassemble.org/docs/api.html There hasn't been a lot of demand for running the docassemble.base Python module without the web application, so I have not yet written documentation for that, but here is some Python code that should help you get started: import pprint import docassemble.base.parse interview_source = docassemble.base.parse.interview_source_from_string('docassemble.demo:data/questions/questions.yml') interview_source.update() interview = interview_source.get_interview() user_dict = docassemble.base.parse.get_initial_dict() interview_status = docassemble.base.parse.InterviewStatus(current_info=dict(url=None, user=dict(is_authenticated=False, is_anonymous=True))) interview.assemble(user_dict, interview_status) print "First question:" pprint.pprint(interview_status.as_data()) print "Choosing English..." exec("x.language = 'en'", user_dict) print "Re-assembling..." interview.assemble(user_dict, interview_status) print "Second question:" pprint.pprint(interview_status.as_data()) print "Pressing Continue..." exec("user_saw_initial_screen = True", user_dict) interview.assemble(user_dict, interview_status) print "Third question:" pprint.pprint(interview_status.as_data()) The layout of the data structure returned by interview_status.as_data() varies from question to question but it is pretty self-explanatory. As for storing the user_dict to a database, that is up to you (see docassemble.webapp for one way to do it). If you call docassemble.base.parse.pickleable_objects(user_dict) you will get a version of the user_dict that can be serialized with Python's pickle module. On Tue, Feb 27, 2018 at 9:46 PM, Peiran Quan <quanpr64@gmail.com> wrote:
Hi, I try to design a questionnaire system for my course design, I want to use the docassemble as a black box, because it's tough for me to understand the structure of the code. I already install the docassemble packages in python 2.7.10, but I don't know which function to 1. use to prase the yaml files, 2. generate the web questionnaire page, and 3. store the answers of the questionnaires to db. I will be appreciate it if you can tell me how to call the functions and their input and output. Sincerely, Peiran _______________________________________________ Docassemble mailing list docassemble@python.org https://mail.python.org/mm3/mailman3/lists/docassemble.python.org/ _______________________________________________ Docassemble mailing list docassemble@python.org https://mail.python.org/mm3/mailman3/lists/docassemble.python.org/
participants (2)
-
Jonathan Pyle
-
Peiran Quan