Ejemplo n.º 1
0
    def portal_my_dms_file_download(self,
                                    dms_file_id,
                                    access_token=None,
                                    **kw):
        """Process user's consent acceptance or rejection."""
        ensure_db()
        try:
            # If there's a website, we need a user to render the template
            request.uid = request.website.user_id.id
        except AttributeError:
            # If there's no website, the default is OK
            pass
        # operations
        res = self._dms_check_access("dms.file", dms_file_id, access_token)
        if not res:
            if access_token:
                return request.redirect("/")
            else:
                return request.redirect("/my")

        dms_file_sudo = res
        filecontent = base64.b64decode(dms_file_sudo.content)
        content_type = ["Content-Type", "application/octet-stream"]
        disposition_content = [
            "Content-Disposition",
            content_disposition(dms_file_sudo.name),
        ]
        return request.make_response(filecontent,
                                     [content_type, disposition_content])
Ejemplo n.º 2
0
 def download_document(self, model, field, id, filename=None, **kw):
     """
     :param str filename: field holding the file's name, if any
     :returns: :class:`werkzeug.wrappers.Response`
     """
     Model = request.registry[model]
     cr, uid, context = request.cr, request.uid, request.context
     fields = [field]
     res = Model.read(cr, uid, [int(id)], fields, context)[0]
     # filecontent = base64.b64decode(res.get(field) or '')
     filecontent = res.get(field)
     print(filecontent)
     if not filecontent:
         return request.not_found()
     else:
         if not filename:
             filename = '%s_%s' % (model.replace('.', '_'), id)
         headers = [
             ('Content-Type', 'application/xml'),
             ('Content-Disposition', content_disposition(filename)),
             ('charset', 'utf-8'),
         ]
         return request.make_response(filecontent,
                                      headers=headers,
                                      cookies=None)
Ejemplo n.º 3
0
 def download_document(self, file, filename):
     if not file:
         return request.not_found()
     else:
         return request.make_response(
             file, [('Content-Type', 'application/octet-stream'),
                    ('Content-Disposition', content_disposition(filename))])
Ejemplo n.º 4
0
 def download_document(self,model,field,id,filename=None, **kw):
     """ Download link for files stored as binary fields.
      :param str model: name of the model to fetch the binary from
      :param str field: binary field
      :param str id: id of the record from which to fetch the binary
      :param str filename: field holding the file's name, if any
      :returns: :class:`werkzeug.wrappers.Response`
     """
     Model = request.registry[model]
     cr, uid, context = request.cr, request.uid, request.context
     fields = [field]
     res = Model.read(cr, uid, [int(id)], fields, context)[0]
     filecontent = base64.b64decode(res.get(field) or '')
     if not filecontent:
         return request.not_found()
     else:
         if not filename:
             filename = '%s_%s' % (model.replace('.', '_'), id)
     return request.make_response(filecontent,
                         [('Content-Type', 'application/pdf'),
                          ('Content-Disposition', content_disposition(filename))])