How to use the docassemble.webapp function in docassemble

To help you get started, we’ve selected a few docassemble examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / server.py View on Github external
sys.exit(1)

#USE_PROGRESS_BAR = daconfig.get('use_progress_bar', True)
SHOW_LOGIN = daconfig.get('show_login', True)
#USER_PACKAGES = daconfig.get('user_packages', '/var/lib/docassemble/dist-packages')
#sys.path.append(USER_PACKAGES)
#if USE_PROGRESS_BAR:
initial_dict = dict(_internal=dict(progress=0, tracker=0, steps_offset=0, answered=set(), answers=dict(), objselections=dict()), url_args=dict())
#else:
#    initial_dict = dict(_internal=dict(tracker=0, steps_offset=0, answered=set(), answers=dict(), objselections=dict()), url_args=dict())
if 'initial_dict' in daconfig:
    initial_dict.update(daconfig['initial_dict'])
LOGFILE = daconfig.get('flask_log', '/tmp/flask.log')
#APACHE_LOGFILE = daconfig.get('apache_log', '/var/log/apache2/error.log')

connect_string = docassemble.webapp.database.connection_string()
alchemy_connect_string = docassemble.webapp.database.alchemy_connection_string()

mail = Mail(app)

def my_default_url(error, endpoint, values):
    return url_for('index')

app.handle_url_build_error = my_default_url

engine = create_engine(alchemy_connect_string, convert_unicode=True)
metadata = MetaData(bind=engine)
store = SQLAlchemyStore(engine, metadata, 'kvstore')

kv_session = KVSessionExtension(store, app)

error_file_handler = logging.FileHandler(filename=LOGFILE)
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / cloud_register.py View on Github external
def main():
    from docassemble.base.config import hostname
    roles = os.environ.get('CONTAINERROLE', None)
    if roles is None:
        return
    import docassemble.webapp.cloud
    cloud = docassemble.webapp.cloud.get_cloud()
    if cloud is not None:
        roles = re.sub(r'^:+|:+$', r'', roles)
        role_list = roles.split(":")
        if 'all' in role_list:
            role_list = ['sql', 'redis', 'rabbitmq']
        for role in role_list:
            if role in ['sql', 'log', 'redis', 'rabbitmq']:
                key = cloud.get_key('hostname-' + role)
                if role == 'rabbitmq':
                    key.set_contents_from_string(socket.gethostname())
                    key_two = cloud.get_key('ip-rabbitmq')
                    key_two.set_contents_from_string(socket.gethostbyname_ex(hostname)[2][0])
                else:
                    key.set_contents_from_string(hostname)
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / file_access.py View on Github external
import xml.etree.ElementTree as ET
import docassemble.base.functions
from docassemble.webapp.users.models import UserDictKeys, UserRoles
from docassemble.webapp.core.models import Uploads, UploadsUserAuth, UploadsRoleAuth
from docassemble.webapp.files import SavedFile, get_ext_and_mimetype
from flask_login import current_user
from sqlalchemy import or_, and_
import docassemble.base.config
from io import open
from six import text_type
import sys
from docassemble.base.generate_key import random_lower_string


import docassemble.webapp.cloud
cloud = docassemble.webapp.cloud.get_cloud()

def url_if_exists(file_reference, **kwargs):
    parts = file_reference.split(":")
    from flask import url_for
    base_url = url_for('rootindex', _external=kwargs.get('_external', False)).rstrip('/')
    if len(parts) == 2:
        if cloud and docassemble.base.config.daconfig.get('use cloud urls', False):
            m = re.search(r'^docassemble.playground([0-9]+)$', parts[0])
            if m:
                user_id = m.group(1)
                if re.search(r'^data/sources/', parts[1]):
                    section = 'playgroundsources'
                    filename = re.sub(r'^data/sources/', '', parts[1])
                    filename = re.sub(r'[^A-Za-z0-9\-\_\. ]', '', filename)
                    key = str(section) + '/' + str(user_id) + '/' + filename
                    cloud_key = cloud.get_key(key)
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / server.py View on Github external
#USE_PROGRESS_BAR = daconfig.get('use_progress_bar', True)
SHOW_LOGIN = daconfig.get('show_login', True)
#USER_PACKAGES = daconfig.get('user_packages', '/var/lib/docassemble/dist-packages')
#sys.path.append(USER_PACKAGES)
#if USE_PROGRESS_BAR:
initial_dict = dict(_internal=dict(progress=0, tracker=0, steps_offset=0, answered=set(), answers=dict(), objselections=dict()), url_args=dict())
#else:
#    initial_dict = dict(_internal=dict(tracker=0, steps_offset=0, answered=set(), answers=dict(), objselections=dict()), url_args=dict())
if 'initial_dict' in daconfig:
    initial_dict.update(daconfig['initial_dict'])
LOGFILE = daconfig.get('flask_log', '/tmp/flask.log')
#APACHE_LOGFILE = daconfig.get('apache_log', '/var/log/apache2/error.log')

connect_string = docassemble.webapp.database.connection_string()
alchemy_connect_string = docassemble.webapp.database.alchemy_connection_string()

mail = Mail(app)

def my_default_url(error, endpoint, values):
    return url_for('index')

app.handle_url_build_error = my_default_url

engine = create_engine(alchemy_connect_string, convert_unicode=True)
metadata = MetaData(bind=engine)
store = SQLAlchemyStore(engine, metadata, 'kvstore')

kv_session = KVSessionExtension(store, app)

error_file_handler = logging.FileHandler(filename=LOGFILE)
error_file_handler.setLevel(logging.DEBUG)
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / backend.py View on Github external
def cloud_custom(provider, config):
    config_id = str(provider) + str(config)
    if config_id in cloud_cache:
        return cloud_cache[config_id]
    the_config = daconfig.get(config, None)
    if the_config is None or type(the_config) is not dict:
        logmessage("cloud_custom: invalid cloud configuration")
        return None
    cloud_cache[config_id] = docassemble.webapp.cloud.get_custom_cloud(provider, the_config)
    return cloud_cache[config_id]
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / cloud.py View on Github external
def get_custom_cloud(provider, config):
    if provider is None or config is None:
        return None
    if provider == 's3':
        import docassemble.webapp.amazon
        cloud = docassemble.webapp.amazon.s3object(config)
    elif provider == 'azure':
        import docassemble.webapp.microsoft
        cloud = docassemble.webapp.microsoft.azureobject(config)
    else:
        cloud = None
    return cloud
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / setup.py View on Github external
app.config['USER_AFTER_RESET_PASSWORD_ENDPOINT'] = 'user.login'
app.config['USER_INVITE_URL'] = '/user/invite'
app.config['USER_ENABLE_INVITATION'] = True
app.config['USER_INVITE_EMAIL_TEMPLATE'] = 'flask_user/emails/invite'
app.config['FAVICON_MASK_COLOR'] = daconfig.get('favicon mask color', '#698aa7')
app.config['FAVICON_THEME_COLOR'] = daconfig.get('favicon theme color', '#83b3dd')

if not daconfig.get('allow registration', True):
    app.config['USER_REQUIRE_INVITATION'] = True
app.config['MAX_CONTENT_LENGTH'] = daconfig.get('maximum content length', 16 * 1024 * 1024)
app.config['USE_X_SENDFILE'] = daconfig.get('xsendfile', True) if daconfig.get('web server', 'nginx') == 'apache' else False
#if daconfig.get('behind https load balancer', False):
#    app.config['PREFERRED_URL_SCHEME'] = 'https'
#app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
connect_string = docassemble.webapp.database.connection_string()
alchemy_connect_string = docassemble.webapp.database.alchemy_connection_string()
app.config['SQLALCHEMY_DATABASE_URI'] = alchemy_connect_string
app.secret_key = daconfig.get('secretkey', '38ihfiFehfoU34mcq_4clirglw3g4o87')
app.config['MAILGUN_API_URL'] = daconfig['mail'].get('mailgun api url', 'https://api.mailgun.net/v3/%s/messages.mime') % daconfig['mail'].get('mailgun domain', 'NOT_USING_MAILGUN')
app.config['MAILGUN_API_KEY'] = daconfig['mail'].get('mailgun api key', None)
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
app.config['ENABLE_MANAGE_ACCOUNT'] = daconfig.get('user can delete account', True)
app.config['ENABLE_DELETE_SHARED'] = daconfig.get('delete account deletes shared', False)
app.config['ENABLE_DELETE_ACCOUNT'] = daconfig.get('admin can delete account', True)
app.config['SESSION_COOKIE_SECURE'] = daconfig.get('use https', False) or daconfig.get('behind https load balancer', False)
app.config['REMEMBER_COOKIE_SECURE'] = app.config['SESSION_COOKIE_SECURE']
if 'session lifetime seconds' in daconfig:
    app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(seconds=daconfig['session lifetime seconds'])
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / server.py View on Github external
#USE_PROGRESS_BAR = daconfig.get('use_progress_bar', True)
SHOW_LOGIN = daconfig.get('show_login', True)
#USER_PACKAGES = daconfig.get('user_packages', '/var/lib/docassemble/dist-packages')
#sys.path.append(USER_PACKAGES)
#if USE_PROGRESS_BAR:
initial_dict = dict(_internal=dict(progress=0, tracker=0, steps_offset=0, answered=set(), answers=dict(), objselections=dict()), url_args=dict())
#else:
#    initial_dict = dict(_internal=dict(tracker=0, steps_offset=0, answered=set(), answers=dict(), objselections=dict()), url_args=dict())
if 'initial_dict' in daconfig:
    initial_dict.update(daconfig['initial_dict'])
LOGFILE = daconfig.get('flask_log', '/tmp/flask.log')
#APACHE_LOGFILE = daconfig.get('apache_log', '/var/log/apache2/error.log')

connect_string = docassemble.webapp.database.connection_string()
alchemy_connect_string = docassemble.webapp.database.alchemy_connection_string()

mail = Mail(app)

def my_default_url(error, endpoint, values):
    return url_for('index')

app.handle_url_build_error = my_default_url

engine = create_engine(alchemy_connect_string, convert_unicode=True)
metadata = MetaData(bind=engine)
store = SQLAlchemyStore(engine, metadata, 'kvstore')

kv_session = KVSessionExtension(store, app)

error_file_handler = logging.FileHandler(filename=LOGFILE)
error_file_handler.setLevel(logging.DEBUG)
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / cron.py View on Github external
interview_status.do_sleep()
                                    elif interview_status.question.question_type == "response" and interview_status.questionText == 'null':
                                        release_lock(key, filename)
                                        interview_status.do_sleep()
                                    else:
                                        if save_status != 'ignore':
                                            save_user_dict(key, the_dict, filename, encrypt=False, manual_user_id=cron_user_id, steps=steps, max_indexno=indexno)
                                        release_lock(key, filename)
                                        interview_status.do_sleep()
                                        if interview_status.question.question_type == "response":
                                            if hasattr(interview_status.question, 'all_variables'):
                                                if hasattr(interview_status.question, 'include_internal'):
                                                    include_internal = interview_status.question.include_internal
                                                else:
                                                    include_internal = False
                                                sys.stdout.write(docassemble.webapp.backend.dict_as_json(the_dict, include_internal=include_internal).encode('utf8') + "\n")
                                            elif not hasattr(interview_status.question, 'binaryresponse'):
                                                if interview_status.questionText != 'Empty Response':
                                                    try:
                                                        sys.stdout.write(interview_status.questionText.rstrip() + "\n")
                                                    except:
                                                        sys.stdout.write("Unable to write output to standard error\n")
                                except Exception as err:
                                    release_lock(key, filename)
                                    sys.stderr.write("Cron error: " + text_type(key) + " " + text_type(filename) + " " + text_type(err.__class__.__name__) + ": " + text_type(err) + "\n")
                                    if hasattr(err, 'traceback'):
                                        error_trace = text_type(err.traceback)
                                        if hasattr(err, 'da_line_with_error'):
                                            error_trace += "\nIn line: " + text_type(err.da_line_with_error)
                                    else:
                                        error_trace = None
                                    error_notification(err, trace=error_trace)
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / db_object.py View on Github external
def init_sqlalchemy():
    global db
    global UserMixin
    import sqlalchemy
    import docassemble.webapp.database
    url = docassemble.webapp.database.alchemy_connection_string()
    if url.startswith('postgresql'):
        db = sqlalchemy.create_engine(url, client_encoding='utf8')
    else:
        db = sqlalchemy.create_engine(url)
    #meta = sqlalchemy.MetaData(bind=con, reflect=True)
    from sqlalchemy.orm import sessionmaker, relationship, backref
    Session = sessionmaker(bind=db)
    from sqlalchemy.ext.declarative import declarative_base
    db.Model = declarative_base()
    db.Column = sqlalchemy.Column
    db.Integer = sqlalchemy.Integer
    db.String = sqlalchemy.String
    db.Boolean = sqlalchemy.Boolean
    db.Text = sqlalchemy.Text
    db.DateTime = sqlalchemy.DateTime
    db.func = sqlalchemy.func