Git Product home page Git Product logo

Comments (4)

jhpyle avatar jhpyle commented on July 4, 2024

I added a function variables_as_json() that causes an HTTP response to be returned that contains the interview variables in JSON format. This is not a perfect representation of the interview variables because the interview variables can contain objects that are not JSON serializable, like Python sets, datetime.datetime objects, and docassemble objects. The variables_as_json() function does the best it can, which should be good enough for most simple API applications.

It is probably better to be selective about which variables to make available through an API, though. The documentation for response() contains an example that uses json.dumps() to return a JSON representation of particular variables.

I have not created a general-purpose "answer file" system because there are so many things that could go wrong if users could upload arbitrary data into an interview. There are better solutions to the problem of sharing variables between interviews.

For example, if you have a suite of family law interviews, you can package them as a single interview with up-front questions that determine which interview to run. The include feature facilitates the incorporation of sub-interviews.

Another way to transfer variables from one interview to another is through the interview_url() and url_args features. Interview 1 can contain a question with a hyperlink to Interview 2 (using the i parameter to interview_url()), where relevant variables are passed as URL parameters to Interview 2. Then both interviews will share the same session key.

Another way for interviews to interact with one another is through the use of write_record() and read_record(). Authors can create keys based on the user's e-mail, which can be retrieved with user_info(). Each interview, when it starts, could use read_record() to query whether any global information already exists. The advantage of this method is that the data are Python-serialized rather than JSON-serialized, so Python objects can be shared.

from docassemble.

jhpyle avatar jhpyle commented on July 4, 2024

I also added a function all_variables() that returns the variables as a Python dictionary in a format suitable for JSON serializing.

from docassemble.

tbrooke avatar tbrooke commented on July 4, 2024

Thanks I will try these

from docassemble.

jhpyle avatar jhpyle commented on July 4, 2024

I believe this issue has been addressed, so I am closing it.

from docassemble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.