How to use docassemble - 10 common examples

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 / users / views.py View on Github external
email_addresses.append(part_two)

        the_role_id = None

        for role in Role.query.order_by('id'):
            if role.id == int(invite_form.role_id.data) and role.name != 'admin' and role.name != 'cron':
                the_role_id = role.id

        if the_role_id is None:
            the_role_id = user_role.id

        has_error = False
        for email_address in email_addresses:
            user, user_email = user_manager.find_user_by_email(email_address)
            if user:
                flash(word("A user with that e-mail has already registered") + " (" + email_address + ")", "error")
                has_error = True
                continue
            else:
                user_invite = MyUserInvitation(email=email_address, role_id=the_role_id, invited_by_user_id=current_user.id)
                db.session.add(user_invite)
                db.session.commit()
            token = user_manager.generate_token(user_invite.id)
            accept_invite_link = url_for('user.register',
                                         token=token,
                                         _external=True)

            user_invite.token = token
            db.session.commit()
            #docassemble.webapp.daredis.clear_user_cache()
            try:
                logmessage("Trying to send e-mail to " + text_type(user_invite.email))
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / server.py View on Github external
# cur.execute("SELECT filename FROM uploads where indexno=%s and key=%s", [file_number, session['uid']])
    # for d in cur:
    #     result['path'] = get_path_from_file_number(file_number)
    #     result['filename'] = d[0]
    #     result['extension'], result['mimetype'] = get_ext_and_mimetype(result['filename'])
    #     result['fullpath'] = result['path'] + '.' + result['extension']
    #     break
    # conn.commit()
    if 'path' not in result:
        logmessage("path is not in result for " + str(file_number))
        return result
    filename = result['path'] + '.' + result['extension']
    if os.path.isfile(filename):
        add_info_about_file(filename, result)
    else:
        logmessage("Filename DID NOT EXIST.")
    return(result)
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / server.py View on Github external
audio_file = SavedFile(new_file_number, extension='mp3', fix=True)
            audio_file.fetch_url(url)
            if audio_file.size_in_bytes() > 100:
                call_array = [daconfig['pacpl'], '-t', 'ogg', audio_file.path + '.mp3']
                result = call(call_array)
                if result != 0:
                    logmessage("Failed to convert downloaded mp3 (" + path + ") to ogg")
                    abort(404)
                entry.upload = new_file_number
                audio_file.finalize()
                db.session.commit()
            else:
                logmessage("Download from voicerss (" + path + ") failed")
                abort(404)
    if not entry.upload:
        logmessage("Upload file number was not set")
        abort(404)
    if not audio_file:
        audio_file = SavedFile(entry.upload, extension='mp3', fix=True)
    the_path = audio_file.path + '.' + file_format
    if not os.path.isfile(the_path):
        logmessage("Could not serve speak file because file (" + the_path + ") not found")
        abort(404)
    return(send_file(the_path, mimetype=audio_mimetype_table[file_format]))
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / server.py View on Github external
result['filename'] = upload.filename
        result['extension'], result['mimetype'] = get_ext_and_mimetype(result['filename'])
        result['savedfile'] = SavedFile(file_number, extension=result['extension'], fix=True)
        result['path'] = result['savedfile'].path
        result['fullpath'] = result['path'] + '.' + result['extension']
    # cur = conn.cursor()
    # cur.execute("SELECT filename FROM uploads where indexno=%s and key=%s", [file_number, session['uid']])
    # for d in cur:
    #     result['path'] = get_path_from_file_number(file_number)
    #     result['filename'] = d[0]
    #     result['extension'], result['mimetype'] = get_ext_and_mimetype(result['filename'])
    #     result['fullpath'] = result['path'] + '.' + result['extension']
    #     break
    # conn.commit()
    if 'path' not in result:
        logmessage("path is not in result for " + str(file_number))
        return result
    filename = result['path'] + '.' + result['extension']
    if os.path.isfile(filename):
        add_info_about_file(filename, result)
    else:
        logmessage("Filename DID NOT EXIST.")
    return(result)
github jhpyle / docassemble / docassemble_base / docassemble / base / pandoc.py View on Github external
def update_references(filename):
    initialize_libreoffice()
    subprocess_arguments = [LIBREOFFICE_PATH, '--headless', '--invisible', 'macro:///Standard.Module1.PysIndexer(' + filename + ')']
    tries = 0
    while tries < 5:
        docassemble.base.functions.server.applock('obtain', 'libreoffice')
        p = subprocess.Popen(subprocess_arguments, cwd=tempfile.gettempdir())
        result = p.wait()
        docassemble.base.functions.server.applock('release', 'libreoffice')
        if result == 0:
            break
        logmessage("update_references: call to LibreOffice returned non-zero response")
        tries += 1
        time.sleep(0.5 + tries*random.random())
    if result != 0:
        return False
    return True
github jhpyle / docassemble / docassemble_base / docassemble / base / pandoc.py View on Github external
if use_libreoffice:
            initialize_libreoffice()
            #logmessage("Trying libreoffice with " + repr(subprocess_arguments))
            docassemble.base.functions.server.applock('obtain', 'libreoffice')
            p = subprocess.Popen(subprocess_arguments, cwd=tempdir)
            result = p.wait()
            docassemble.base.functions.server.applock('release', 'libreoffice')
        if os.path.isfile(to_file):
            break
        result = 1
        tries += 1
        time.sleep(0.5 + tries*random.random())
        if use_libreoffice:
            logmessage("Retrying libreoffice with " + repr(subprocess_arguments))
        else:
            logmessage("Retrying convertapi")
        continue
    if result == 0:
        if password:
            pdf_encrypt(to_file, password)
        shutil.copyfile(to_file, out_file)
    if tempdir is not None:
        shutil.rmtree(tempdir)
    if result != 0:
        return False
    return True
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / server.py View on Github external
logmessage("Failed to convert downloaded mp3 (" + path + ") to ogg")
                    abort(404)
                entry.upload = new_file_number
                audio_file.finalize()
                db.session.commit()
            else:
                logmessage("Download from voicerss (" + path + ") failed")
                abort(404)
    if not entry.upload:
        logmessage("Upload file number was not set")
        abort(404)
    if not audio_file:
        audio_file = SavedFile(entry.upload, extension='mp3', fix=True)
    the_path = audio_file.path + '.' + file_format
    if not os.path.isfile(the_path):
        logmessage("Could not serve speak file because file (" + the_path + ") not found")
        abort(404)
    return(send_file(the_path, mimetype=audio_mimetype_table[file_format]))
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / wsgi_restart.py View on Github external
def main():
    from docassemble.base.config import daconfig
    webapp_path = daconfig.get('webapp', '/usr/share/docassemble/webapp/docassemble.wsgi')
    wsgi_file = webapp_path
    if os.path.isfile(wsgi_file):
        with open(wsgi_file, 'a'):
            os.utime(wsgi_file, None)
            sys.stderr.write("Restarted WSGI.\n")
    sys.exit(0)
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / create_tables.py View on Github external
def main():
    with app.app_context():
        if daconfig.get('use alembic', True):
            packagedir = pkg_resources.resource_filename(pkg_resources.Requirement.parse('docassemble.webapp'), 'docassemble/webapp')
            if not os.path.isdir(packagedir):
                sys.exit("path for running alembic could not be found")
            from alembic.config import Config
            from alembic import command
            alembic_cfg = Config(os.path.join(packagedir, 'alembic.ini'))
            alembic_cfg.set_main_option("sqlalchemy.url", alchemy_connection_string())
            alembic_cfg.set_main_option("script_location", os.path.join(packagedir, 'alembic'))
            if not db.engine.has_table(dbtableprefix + 'alembic_version'):
                sys.stderr.write("Creating alembic stamp\n")
                command.stamp(alembic_cfg, "head")
            if db.engine.has_table(dbtableprefix + 'user'):
                sys.stderr.write("Running alembic upgrade\n")
                command.upgrade(alembic_cfg, "head")
        #db.drop_all()
        try:
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / server.py View on Github external
else:
        package_entry = Package.query.filter_by(name=packagename).first()
        if package_entry is not None:
            if package_entry.type == 'zip' and package_entry.upload is not None:
                SavedFile(package_entry.upload).delete()
            package_entry.version += 1
            package_entry.giturl = giturl
            package_entry.upload = None
            package_entry.limitation = None
            package_entry.type = 'git'
            db.session.commit()
    ok, logmessages = docassemble.webapp.update.check_for_updates()
    if ok:
        trigger_update(except_for=hostname)
        restart_wsgi()
        flash(word("Install successful"), 'success')
    else:
        flash(word("Install not successful"), 'error')
    flash('pip log: ' + str(logmessages), 'info')
    # pip_log = tempfile.NamedTemporaryFile()
    # commands = ['install', '--quiet', '--egg', '--src=' + tempfile.mkdtemp(), '--upgrade', '--log-file=' + pip_log.name, 'git+' + giturl + '.git#egg=' + packagename]
    # returnval = pip.main(commands)
    # if returnval > 0:
    #     with open(pip_log.name) as x: logfilecontents = x.read()
    #     flash("pip " + " ".join(commands) + "<pre>" + str(logfilecontents) + "</pre>", 'error')
    return