def download_logs(self): """ Downloads the log file """ if tools.config['logfile']: res = send_file(tools.config['logfile'], mimetype="text/plain", as_attachment=True) res.headers['Cache-Control'] = 'no-cache' return res
def _get_manifest(self, company_id): config = self._get_pwa_config(company_id) if config: icons = [] manifest = { "start_url": "/web", "scope": "/web", } if config.pwa_name: manifest.update({'name': config.pwa_name}) if config.pwa_short_name: manifest.update({'short_name': config.pwa_short_name}) if config.pwa_background_color: manifest.update( {'background_color': config.pwa_background_color}) if config.pwa_theme_color: manifest.update({'theme_color': config.pwa_theme_color}) if config.pwa_display: manifest.update({'display': config.pwa_display}) if config.pwa_icon_128: icons.append({ 'src': '/pwa/icon/128/%s' % str(company_id), 'type': "image/png", 'sizes': "128x128", }) if config.pwa_icon_192: icons.append({ 'src': '/pwa/icon/192/%s' % str(company_id), 'type': "image/png", 'sizes': "192x192", }) if config.pwa_icon_512: icons.append({ 'src': '/pwa/icon/512/%s' % str(company_id), 'type': "image/png", 'sizes': "512x512", }) if len(icons) == 0: icons = [{ "src": "/web_flectra/static/img/icons/icon-512x512.png", "type": "image/png", "sizes": "512x512", }] manifest.update({'icons': icons}) return json.dumps(manifest) else: file = get_resource_path('web_flectra', 'static', 'src', 'manifest.json') response = send_file(file, filename='manifest.json', mimetype='application/json') return response
def download_attachment(self, attachment_id): # Check if this is a valid attachment id attachment = request.env['ir.attachment'].sudo().search_read([ ('id', '=', int(attachment_id)) ], ["name", "datas", "mimetype", "res_model", "res_id", "type", "url"]) if attachment: attachment = attachment[0] else: return redirect(self.orders_page) # Check if the user has bought the associated product res_model = attachment['res_model'] res_id = attachment['res_id'] purchased_products = request.env[ 'account.move.line'].get_digital_purchases() if res_model == 'product.product': if res_id not in purchased_products: return redirect(self.orders_page) # Also check for attachments in the product templates elif res_model == 'product.template': template_ids = request.env['product.product'].sudo().browse( purchased_products).mapped('product_tmpl_id').ids if res_id not in template_ids: return redirect(self.orders_page) else: return redirect(self.orders_page) # The client has bought the product, otherwise it would have been blocked by now if attachment["type"] == "url": if attachment["url"]: return redirect(attachment["url"]) else: return request.not_found() elif attachment["datas"]: data = io.BytesIO(base64.standard_b64decode(attachment["datas"])) # we follow what is done in ir_http's binary_content for the extension management extension = os.path.splitext(attachment["name"] or '')[1] extension = extension if extension else mimetypes.guess_extension( attachment["mimetype"] or '') filename = attachment['name'] filename = filename if os.path.splitext( filename)[1] else filename + extension return http.send_file(data, filename=filename, as_attachment=True) else: return request.not_found()
def download_attachment(self, attachment_id): # Check if this is a valid attachment id attachment = request.env['ir.attachment'].sudo().search_read([ ('id', '=', int(attachment_id)) ], [ "name", "datas", "file_type", "res_model", "res_id", "type", "url" ]) if attachment: attachment = attachment[0] else: return redirect(self.orders_page) # Check if the user has bought the associated product res_model = attachment['res_model'] res_id = attachment['res_id'] purchased_products = request.env[ 'account.invoice.line'].get_digital_purchases() if res_model == 'product.product': if res_id not in purchased_products: return redirect(self.orders_page) # Also check for attachments in the product templates elif res_model == 'product.template': template_ids = request.env['product.product'].sudo().browse( purchased_products).mapped('product_tmpl_id').ids if res_id not in template_ids: return redirect(self.orders_page) else: return redirect(self.orders_page) # The client has bought the product, otherwise it would have been blocked by now if attachment["type"] == "url": if attachment["url"]: return redirect(attachment["url"]) else: return request.not_found() elif attachment["datas"]: data = io.BytesIO(base64.standard_b64decode(attachment["datas"])) return http.send_file(data, filename=attachment['name'], as_attachment=True) else: return request.not_found()