How to use the docassemble.base.functions.server 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_base / docassemble / base / core.py View on Github external
def _make_pdf_thumbnail(self, page):
        """Creates a page image for the first page of a PDF file."""
        if not hasattr(self, 'file_info'):
            self.retrieve()
        max_pages = 1 + int(self.file_info['pages'])
        formatter = '%0' + str(len(str(max_pages))) + 'd'
        the_path = self.file_info['path'] + 'screen-' + (formatter % int(page)) + '.png'
        if not os.path.isfile(the_path):
            server.fg_make_png_for_pdf(self, 'screen', page=page)
    def pngs_ready(self):
github jhpyle / docassemble / docassemble_base / docassemble / base / core.py View on Github external
if 'number' in kwargs and kwargs['number'] is not None:
            self.number = kwargs['number']
            self.ok = True
        if not hasattr(self, 'filename'):
            if hasattr(self, 'extension'):
                self.filename = kwargs.get('filename', 'file.' + self.extension)
            else:
                self.filename = kwargs.get('filename', 'file.txt')
        if not hasattr(self, 'number'):
            yaml_filename = None
            uid = None
            if hasattr(docassemble.base.functions.this_thread, 'current_info'):
                yaml_filename = docassemble.base.functions.this_thread.current_info.get('yaml_filename', None)
                uid = docassemble.base.functions.this_thread.current_info.get('session', None)
                #logmessage("yaml_filename is " + str(yaml_filename) + " and uid is " + str(uid))
            self.number = server.get_new_file_number(uid, self.filename, yaml_file_name=yaml_filename)
            self.ok = True
            self.extension, self.mimetype = server.get_ext_and_mimetype(self.filename)
        self.retrieve()
        the_path = self.path()
        if not (os.path.isfile(the_path) or os.path.islink(the_path)):
            sf = SavedFile(self.number, extension=self.extension, fix=True)
            sf.save()
    def retrieve(self):
github jhpyle / docassemble / docassemble_base / docassemble / base / filter.py View on Github external
extra_class = ' dawideimage'
        else:
            extra_class = ''
        if file_info.get('extension', '') in ['png', 'jpg', 'gif', 'svg', 'jpe', 'jpeg']:
            return('<img src="' + the_url + '" style="' + width_string + '">')
        elif file_info['extension'] in ('pdf', 'docx', 'rtf', 'doc', 'odt'):
            if file_info['extension'] in ('docx', 'rtf', 'doc', 'odt') and not os.path.isfile(file_info['path'] + '.pdf'):
                server.fg_make_pdf_for_word_path(file_info['path'], file_info['extension'])
                server.fg_make_png_for_pdf_path(file_info['path'] + ".pdf", 'screen', page=1)
            if 'pages' not in file_info:
                try:
                    reader = PyPDF2.PdfFileReader(open(file_info['path'] + '.pdf', 'rb'))
                    file_info['pages'] = reader.getNumPages()
                except:
                    file_info['pages'] = 1
            image_url = server.url_finder(file_reference, size="screen", page=1, _question=question)
            if image_url is None:
                return ('[ERROR: File reference ' + text_type(file_reference) + ' cannot be displayed]')
            if 'filename' in file_info:
                title = ' title="' + file_info['filename'] + '"'
            else:
                title = ''
            if alt_text == '':
                the_alt_text = 'alt=' + json.dumps(word("Thumbnail image of document")) + ' '
            else:
                the_alt_text = alt_text
            output = '<a href="' + the_url + '" class="daimageref" title=""><img src="' + image_url + '" style="' + width_string + '"></a>'
            if 'pages' in file_info and file_info['pages'] &gt; 1:
                output += " (" + text_type(file_info['pages']) + " " + word('pages') + ")"
            return(output)
        else:
            return('<a href="' + the_url + '" class="daimageref">' + file_info['filename'] + '</a>')
github jhpyle / docassemble / docassemble_base / docassemble / base / util.py View on Github external
else:
            success = False
        if success:
            for the_attachment in attachment_list:
                if isinstance(the_attachment, DAStaticFile):
                    the_path = the_attachment.path()
                    with open(the_path, 'rb') as fp:
                        the_basename = os.path.basename(the_path)
                        extension, mimetype = server.get_ext_and_mimetype(the_basename)
                        msg.attach(attachment_name(the_basename, filenames_used), mimetype, fp.read())
                    continue
                if the_attachment.ok:
                    if the_attachment.has_specific_filename:
                        file_info = server.file_finder(str(the_attachment.number), filename=the_attachment.filename)
                    else:
                        file_info = server.file_finder(str(the_attachment.number))
                    if 'fullpath' in file_info:
                        failed = True
                        with open(file_info['fullpath'], 'rb') as fp:
                            msg.attach(attachment_name(the_attachment.filename, filenames_used), file_info['mimetype'], fp.read())
                            failed = False
                        if failed:
                            success = False
                    else:
                        success = False
    if success:
        try:
            logmessage("send_email: starting to send")
            server.send_mail(msg)
            logmessage("send_email: finished sending")
        except Exception as errmess:
            logmessage("send_email: sending mail failed with error of " + " type " + str(errmess.__class__.__name__) + ": " + text_type(errmess))
github jhpyle / docassemble / docassemble_base / docassemble / base / core.py View on Github external
def url_for(self, **kwargs):
        """Returns a URL to the static file."""
        the_args = dict()
        for key, val in kwargs.iteritems():
            the_args[key] = val
        the_args['_question'] = docassemble.base.functions.this_thread.current_question
        return server.url_finder(self.filename, **the_args)
    def __str__(self):
github jhpyle / docassemble / docassemble_base / docassemble / base / util.py View on Github external
if isinstance(exclude_privileges, DAObject) and hasattr(exclude_privileges, 'elements'):
                exclude_privileges = exclude_privileges.elements
            else:
                exclude_privileges = [exclude_privileges]
    else:
        exclude_privileges = list()
    for user_id, access_time in this_thread.internal['accesstime'].items():
        if user_id == -1:
            if 'anonymous' in exclude_privileges:
                continue
            if include_privileges is None or 'anonymous' in include_privileges:
                if max_time is None or max_time &lt; access_time:
                    max_time = access_time
                    break
        else:
            user_object = server.get_user_object(user_id)
            if user_object is not None and hasattr(user_object, 'roles'):
                if len(user_object.roles) == 0:
                    if 'user' in exclude_privileges:
                        continue
                    if include_privileges is None or 'user' in include_privileges:
                        if max_time is None or max_time &lt; access_time:
                            max_time = access_time
                            break
                else:
                    for role in user_object.roles:
                        if (include_cron is False and role.name == 'cron') or role.name in exclude_privileges:
                            continue
                        if include_privileges is None or role.name in include_privileges:
                            if max_time is None or max_time &lt; access_time:
                                max_time = access_time
                                break
github jhpyle / docassemble / docassemble_base / docassemble / base / util.py View on Github external
def set(self, key, value):
        """Writes an object to the data store under the given key."""
        the_key = self._get_base_key() + ':' + key
        server.server_sql_set(the_key, value, encrypted=self.is_encrypted(), secret=this_thread.current_info.get('secret', None), the_user_id=this_thread.current_info['user']['the_user_id'])
    def delete(self, key):
github jhpyle / docassemble / docassemble_base / docassemble / base / util.py View on Github external
def status(self):
        if self.sid is None:
            return 'not-configured'
        the_json = server.server_redis.get('da:faxcallback:sid:' + self.sid)
        if the_json is None:
            return 'no-information'
        info = json.loads(the_json)
        return info['FaxStatus']
    def info(self):
github jhpyle / docassemble / docassemble_base / docassemble / base / util.py View on Github external
def send_sms(to=None, body=None, template=None, task=None, attachments=None, config='default'):
    """Sends a text message and returns whether sending the text was successful."""
    if server.twilio_config is None:
        logmessage("send_sms: ignoring because Twilio not enabled")
        return False
    if config not in server.twilio_config['name']:
        logmessage("send_sms: ignoring because requested configuration does not exist")
        return False
    tconfig = server.twilio_config['name'][config]
    if 'sms' not in tconfig or tconfig['sms'] in [False, None]:
        logmessage("send_sms: ignoring because SMS not enabled")
        return False
    if attachments is None:
        attachments = []
    elif attachments is not list:
        attachments = [attachments]
    if type(to) is not list:
        to = [to]
    if len(to) == 0:
github jhpyle / docassemble / docassemble_base / docassemble / base / core.py View on Github external
def url_for(self, **kwargs):
        """Returns a URL to the static file."""
        the_args = dict()
        for key, val in kwargs.iteritems():
            the_args[key] = val
        the_args['_question'] = docassemble.base.functions.this_thread.current_question
        return server.url_finder(self.filename, **the_args)
    def __str__(self):