成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

odoo打包下載

JohnLui / 2124人閱讀

摘要:視圖中下載按鈕的編輯附件打包下載中獲取需要下載的文件的,并返回字符串集合打包下載的方法中的打包下載引用和方法,如下代碼

view 視圖中下載按鈕的編輯
    
        附件打包下載
        
        
        code
        
            if records:
                action = {
                    "name": "Visit Webpage",
                    "type": "ir.actions.act_url",
                    "url": "/document/zip/"+str(records.download_zip()),
                    "target": "self",
                }
        
    
model 中獲取需要下載的文件的ID,并返回字符串集合 打包下載的方法
@api.multi
def download_zip(self):
    dones = self.env["ir.attachment"].search([("res_model", "=", "activity.event"), ("res_id", "=", self.id)])
    file_ids = ""
    for x in dones:
        file_ids = file_ids + str(x.id) + ","
    print(file_ids)
    return {
        file_ids
    }
controller.py中的打包下載引用和方法,如下代碼
# -*- coding: utf-8 -*-
import base64
import io
import jinja2
import json
import logging
import os
import sys
import zipfile
import time

import werkzeug
import werkzeug.exceptions
import werkzeug.utils
import werkzeug.wrappers
import werkzeug.wsgi
from odoo import http
from odoo.http import content_disposition, dispatch_rpc, request, 
    serialize_exception as _serialize_exception, Response
from odoo.exceptions import AccessError, UserError, AccessDenied
from odoo.models import check_method_name
from odoo.service import db, security

_logger = logging.getLogger(__name__)

if hasattr(sys, "frozen"):
    # When running on compiled windows binary, we don"t have access to package loader.
    path = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "views"))
    loader = jinja2.FileSystemLoader(path)
else:
    loader = jinja2.PackageLoader("odoo.addons.web", "views")

env = jinja2.Environment(loader=loader, autoescape=True)
env.filters["json"] = json.dumps

# 1 week cache for asset bundles as advised by Google Page Speed
BUNDLE_MAXAGE = 60 * 60 * 24 * 7

DBNAME_PATTERN = "^[a-zA-Z0-9][a-zA-Z0-9_.-]+$"

#----------------------------------------------------------
# Odoo Web helpers
#----------------------------------------------------------

db_list = http.db_list

db_monodb = http.db_monodb

class DownloadAll(http.Controller):

    def _get_file_response(self, id, filename=None, field="datas", share_id=None, share_token=None):
        """
        returns the http response to download one file.

        """
        status, headers, content = request.registry["ir.http"].binary_content(
            id=id, field=field, filename=filename, related_id=share_id,
            access_token=share_token, access_mode="documents_share", download=True)

        if status == 304:
            response = werkzeug.wrappers.Response(status=status, headers=headers)
        elif status == 301:
            return werkzeug.utils.redirect(content, code=301)
        elif status != 200:
            response = request.not_found()
        else:
            content_base64 = base64.b64decode(content)
            headers.append(("Content-Length", len(content_base64)))
            response = request.make_response(content_base64, headers)

        return response

    def _make_zip(self, name, attachments):
        """returns zip files for the Document Inspector and the portal.

        :param name: the name to give to the zip file.
        :param attachments: files (ir.attachment) to be zipped.
        :return: a http response to download a zip file.
        """
        stream = io.BytesIO()
        try:
            with zipfile.ZipFile(stream, "w") as doc_zip:
                for attachment in attachments:
                    if attachment.type in ["url", "empty"]:
                        continue
                    filename = attachment.datas_fname
                    doc_zip.writestr(filename, base64.b64decode(attachment["datas"]),
                                     compress_type=zipfile.ZIP_DEFLATED)
        except zipfile.BadZipfile:
            _logger.exception("BadZipfile exception")

        content = stream.getvalue()
        headers = [
            ("Content-Type", "zip"),
            ("X-Content-Type-Options", "nosniff"),
            ("Content-Length", len(content)),
            ("Content-Disposition", content_disposition(name))
        ]
        return request.make_response(content, headers)

    @http.route(["/document/zip/"], type="http", auth="public")
    def _get_zip(self, file_ids=None, *args, **kwargs):
        """route to get the zip file of the selection in the document"s Kanban view (Document inspector).
        :param file_ids: if of the files to zip.
        :param zip_name: name of the zip file.
        """
        file_ids = file_ids[2:-3]
        print(file_ids)
        timestamp = time.strftime("%Y%m%d%H%M%S",time.localtime(time.time()))
        zip_name = "activity-" + timestamp + ".zip"
        ids_list = [int(x) for x in file_ids.split(",")]
        print(ids_list)
        env = request.env
        return self._make_zip(zip_name, env["ir.attachment"].browse(ids_list))

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/43329.html

相關(guān)文章

  • Odoo 中添加自定義頁(yè)面

    摘要:一般情況下都是在中繼承后在其末尾添加相關(guān)資源路徑除了資源需要引入外,我們編寫(xiě)的頁(yè)面模板也許要引入,打開(kāi)并在底部添加我們的自定義頁(yè)面文件大功告成,一個(gè)最簡(jiǎn)單的自定義頁(yè)面已經(jīng)完成了,安裝模塊然后運(yùn)行看看效果吧。 前些天群里的小伙伴問(wèn)了些關(guān)于在 Odoo 管理后臺(tái)自定義頁(yè)面和 Widget 的問(wèn)題,那我就來(lái)寫(xiě)一篇簡(jiǎn)短的內(nèi)容,教大家如何創(chuàng)建自定義頁(yè)面并引用第三方庫(kù)。如果大家有看我之前寫(xiě)的基礎(chǔ)教...

    Jackwoo 評(píng)論0 收藏0
  • Odoo 基礎(chǔ)教程系列」第一篇——環(huán)境準(zhǔn)備

    摘要:安裝好后,在中執(zhí)行查看版本信息,應(yīng)該會(huì)看到輸出如下信息版本號(hào)可能會(huì)不同如果提示未找到,則需要手動(dòng)將用戶基礎(chǔ)目錄下的添加到中。相關(guān)文章基礎(chǔ)教程系列第篇開(kāi)天坑啦 showImg(https://segmentfault.com/img/bV4GZu?w=1262&h=911); 之前說(shuō)好的 「Odoo 基礎(chǔ)教程系列」終于來(lái)了(撒花)~剛過(guò)完年重新投入到工作中,一下子事情有點(diǎn)多都要忙不過(guò)來(lái)了...

    szysky 評(píng)論0 收藏0
  • Odoo 中生成唯一不重復(fù)的序列號(hào)

    摘要:最近在做的項(xiàng)目中有一個(gè)需求是要讓某個(gè)字段值根據(jù)記錄產(chǎn)生的日期和一定的組合規(guī)則按順序生成一個(gè)序列號(hào),這個(gè)序列號(hào)不可重復(fù),這原本是一個(gè)很常見(jiàn)的需求,沒(méi)有多想就寫(xiě)好了。 showImg(https://segmentfault.com/img/remote/1460000013229918?w=1000&h=667); 最近在做的項(xiàng)目中有一個(gè)需求是要讓某個(gè)字段值根據(jù)記錄產(chǎn)生的日期和一定的組合...

    wujl596 評(píng)論0 收藏0
  • Odoo 基礎(chǔ)教程系列」第二篇——從 Todo 應(yīng)用開(kāi)始(1)

    摘要:雖然這是個(gè)很簡(jiǎn)單的應(yīng)用,但是希望大家可以動(dòng)手一起操作,從最簡(jiǎn)單的開(kāi)始上手學(xué)習(xí)如何使用這個(gè)框架。則是在和之間,負(fù)責(zé)響應(yīng)用戶操作,從中獲取數(shù)據(jù)進(jìn)行處理并返回到中。 showImg(https://segmentfault.com/img/bV66tE?w=728&h=410); 在第一篇教程發(fā)布之后差不多一個(gè)月的今天,終于完成了第二篇內(nèi)容,這個(gè)發(fā)布周期拖得實(shí)在是有點(diǎn)太長(zhǎng)了,我都覺(jué)得不好意思...

    UCloud 評(píng)論0 收藏0
  • 搶灘中小企業(yè)云市場(chǎng)卡位戰(zhàn),SAP 、Odoo等國(guó)外巨頭誰(shuí)能勝出

    摘要:年月日,在中國(guó)新年前夕,發(fā)布了中國(guó)加速計(jì)劃,計(jì)劃在未來(lái)五年,持續(xù)加大對(duì)中國(guó)中小企業(yè)市場(chǎng)的投入。一向以高端市場(chǎng)為傲的成為中國(guó)中小企業(yè)市場(chǎng)的闖局者。2019年1月31日,在中國(guó)新年前夕,SAP發(fā)布了中國(guó)加速計(jì)劃,計(jì)劃在未來(lái)五年,持續(xù)加大對(duì)中國(guó)中小企業(yè)市場(chǎng)的投入。一向以高端市場(chǎng)為傲的SAP成為中國(guó)中小企業(yè)市場(chǎng)的闖局者。無(wú)獨(dú)有偶。Oracle此前的定位主要是企業(yè)級(jí)高端市場(chǎng),但云計(jì)算給Oracle進(jìn)入...

    MorePainMoreGain 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<