[IMP] website_slides: improve slide.slide (lesson) code and view

PURPOSE

Improve daily use of slide, especially in backend.

SPECIFICATIONS

Make slide type editable in backend, notably at create. This commit makes it
possible for the user to manually define the type of the slide.

Slightly clean slide code about slide data.

LINKS

Task 1978731
PR #33255
This commit is contained in:
qmo-odoo
2019-08-08 08:29:34 +00:00
committed by Thibault Delavallée
parent 340613d068
commit 6e6b635557
2 changed files with 14 additions and 15 deletions
+7 -8
View File
@@ -1,14 +1,13 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import requests
from PIL import Image
import base64
import datetime
import io
import re
import uuid
import requests
from PIL import Image
from werkzeug import urls
from odoo import api, fields, models, _
@@ -612,10 +611,10 @@ class Slide(models.Model):
# --------------------------------------------------
@api.model
def _fetch_data(self, base_url, data, content_type=False, extra_params=False):
def _fetch_data(self, base_url, params, content_type=False):
result = {'values': dict()}
try:
response = requests.get(base_url, params=data)
response = requests.get(base_url, params=params)
response.raise_for_status()
if content_type == 'json':
result['values'] = response.json()
@@ -733,12 +732,12 @@ class Slide(models.Model):
elif google_values['mimeType'].startswith('application/vnd.google-apps'):
values['slide_type'] = get_slide_type(values)
if 'exportLinks' in google_values:
values['datas'] = self._fetch_data(google_values['exportLinks']['application/pdf'], params, 'pdf', extra_params=True)['values']
values['datas'] = self._fetch_data(google_values['exportLinks']['application/pdf'], params, 'pdf')['values']
# Content indexing
if google_values['exportLinks'].get('text/plain'):
values['index_content'] = self._fetch_data(google_values['exportLinks']['text/plain'], params, extra_params=True)['values']
values['index_content'] = self._fetch_data(google_values['exportLinks']['text/plain'], params)['values']
elif google_values['exportLinks'].get('text/csv'):
values['index_content'] = self._fetch_data(google_values['exportLinks']['text/csv'], params, extra_params=True)['values']
values['index_content'] = self._fetch_data(google_values['exportLinks']['text/csv'], params)['values']
elif google_values['mimeType'] == 'application/pdf':
# TODO: Google Drive PDF document doesn't provide plain text transcript
values['datas'] = self._fetch_data(google_values['webContentLink'], {}, 'pdf')['values']
@@ -65,17 +65,17 @@
<group>
<group>
<field name="active" invisible="1"/>
<field name="user_id"/>
<field name="slide_type" readonly="1"/>
<field name="url"
attrs="{'required': [('slide_type', 'in', ('video'))], 'invisible': [('slide_type', 'not in', ('video'))]}" />
<field name="slide_type"/>
<field name="url" attrs="{
'required': [('slide_type', 'in', ('video'))],
'invisible': [('slide_type', 'not in', ('video'))]}" />
<field name="document_id" invisible="1"/>
<field name="mime_type" readonly="1"
attrs="{'invisible': True}"/>
<field string="Attachment" name="datas"
<field name="mime_type" readonly="1" groups="base.group_no_one"/>
<field name="datas" string="Attachment"
attrs="{'invisible': [('slide_type', 'not in', ('document', 'presentation'))]}"/>
</group>
<group>
<field name="user_id"/>
<field name="channel_id"/>
<field name="website_id" groups="website.group_multi_website"/>
<field name="website_url"/>