Skip to content

Commit

Permalink
Features setting
Browse files Browse the repository at this point in the history
Introduces 3 settings:
- (De)activate scheduled actions
- Set list view as default view for albums and artists
- Set LastFM info fetching manual
  • Loading branch information
DocMarty84 committed May 12, 2018
1 parent 70d4288 commit d572bcc
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 2 deletions.
1 change: 1 addition & 0 deletions __manifest__.py
Expand Up @@ -28,6 +28,7 @@
'views/oomusic_folder_views.xml',
'views/oomusic_genre_views.xml',
'views/oomusic_playlist_views.xml',
'views/oomusic_settings_config.xml',
'views/oomusic_track_views.xml',
'views/oomusic_suggestion_views.xml',
'views/oomusic_transcoder_views.xml',
Expand Down
4 changes: 4 additions & 0 deletions data/oomusic_data.xml
Expand Up @@ -9,5 +9,9 @@
<field name="key">oomusic.lastfm_key</field>
<field name="value">48a48a2bc9c6fc3b4a7df96ef51c6a0f</field>
</record>
<record model="ir.config_parameter" id="features">
<field name="key">oomusic.fm_info</field>
<field name="value">auto</field>
</record>
</data>
</odoo>
1 change: 1 addition & 0 deletions models/__init__.py
Expand Up @@ -4,6 +4,7 @@
from . import oomusic_download
from . import oomusic_album
from . import oomusic_artist
from . import oomusic_config_settings
from . import oomusic_converter
from . import oomusic_folder
from . import oomusic_folder_scan
Expand Down
60 changes: 60 additions & 0 deletions models/oomusic_config_settings.py
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-

from odoo import api, fields, models


class OomusicConfigSettings(models.TransientModel):
_name = 'oomusic.config.settings'
_inherit = 'res.config.settings'

cron = fields.Selection([
('active', 'Active'),
('inactive', 'Inactive'),
], string='Scheduled Actions', help='Activate automatic folder scan and image cache mechanism')
view = fields.Selection([
('kanban', 'Kanban, with thumbnails'),
('tree', 'List, without thumbnails'),
], string='Default Views')
fm_info = fields.Selection([
('auto', 'Fetched automatically'),
('manual', 'Fetched manually'),
], string='LastFM Info')

@api.model
def get_values(self):
res = super(OomusicConfigSettings, self).get_values()
cron = (
self.env.ref('oomusic.oomusic_scan_folder') +
self.env.ref('oomusic.oomusic_build_artists_image_cache') +
self.env.ref('oomusic.oomusic_build_image_cache') +
self.env.ref('oomusic.oomusic_build_lastfm_cache')
).mapped('active')
view = (
self.env.ref('oomusic.action_album') +
self.env.ref('oomusic.action_artist')
).mapped('view_mode')
res['cron'] = 'active' if all([c for c in cron]) else 'inactive'
res['view'] = 'tree' if all([v.split(',')[0] == 'tree' for v in view]) else 'kanban'
res['fm_info'] = self.env['ir.config_parameter'].sudo().get_param('oomusic.fm_info', 'auto')
return res

def set_values(self):
super(OomusicConfigSettings, self).set_values()
# Activate/deactive ir.cron
(
self.env.ref('oomusic.oomusic_scan_folder') +
self.env.ref('oomusic.oomusic_build_artists_image_cache') +
self.env.ref('oomusic.oomusic_build_image_cache') +
self.env.ref('oomusic.oomusic_build_lastfm_cache')
).write({'active': bool(self.cron == 'active')})
# Set view order
if self.view == 'tree':
view_mode_album = 'tree,kanban,form,graph,pivot'
view_mode_artist = 'tree,kanban,form'
else:
view_mode_album = 'kanban,tree,form,graph,pivot'
view_mode_artist = 'kanban,tree,form'
self.env.ref('oomusic.action_album').write({'view_mode': view_mode_album})
self.env.ref('oomusic.action_artist').write({'view_mode': view_mode_artist})
# Set LastFM Info
self.env['ir.config_parameter'].sudo().set_param('oomusic.fm_info', self.fm_info)
8 changes: 7 additions & 1 deletion models/oomusic_lastfm.py
Expand Up @@ -34,8 +34,9 @@ def get_query(self, url, sleep=0.0, force=False):
ConfigParam = self.env['ir.config_parameter'].sudo()
fm_key = ConfigParam.get_param('oomusic.lastfm_key')
fm_cache = int(ConfigParam.get_param('oomusic.lastfm_cache', 112))
fm_info = ConfigParam.get_param('oomusic.fm_info', 'auto')
if not fm_key:
return
return '{}'

url = url_fix(url + '&api_key=' + fm_key + '&format=json').encode('utf-8')
url_hash = hashlib.sha1(url).hexdigest()
Expand All @@ -44,6 +45,11 @@ def get_query(self, url, sleep=0.0, force=False):
Lastfm = self.with_env(self.env(cr=new_cr)).search([('name', '=', url_hash)])
if force or not Lastfm or Lastfm.expiry_date < fields.Datetime.now():
content = '{}'
if fm_info == 'manual' and not force:
Lastfm.env.cr.rollback()
Lastfm.env.cr.close()
content = Lastfm.content or content
return content
try:
time.sleep(sleep)
r = requests.get(url, timeout=3.0)
Expand Down
38 changes: 38 additions & 0 deletions views/oomusic_settings_config.xml
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="oomusic_config_settings_view_form" model="ir.ui.view">
<field name="name">OOMusic Settings</field>
<field name="model">oomusic.config.settings</field>
<field name="arch" type="xml">
<form string="Configure OOMusic" class="oe_form_configuration">
<header>
<button string="Apply" type="object" name="execute" class="oe_highlight"/>
<button string="Cancel" type="object" name="cancel" class="oe_link" special="cancel"/>
</header>
<group string="Features">
<field name="cron" widget="radio"/>
<field name="view" widget="radio"/>
<field name="fm_info" widget="radio"/>
</group>
</form>
</field>
</record>

<record id="action_oomusic_config_settings" model="ir.actions.act_window">
<field name="name">Settings</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">oomusic.config.settings</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
</record>

<menuitem
id="menu_stock_general_settings"
name="Settings"
parent="menu_oomusic_config"
sequence="0"
action="action_oomusic_config_settings"
groups="base.group_system"/>
</data>
</odoo>
2 changes: 1 addition & 1 deletion views/oomusic_transcoder_views.xml
Expand Up @@ -50,5 +50,5 @@
</record>

<!-- Third Level Menu -->
<menuitem id="menu_action_transcoder" parent="menu_oomusic_config" action="action_transcoder" sequence="10" groups="base.group_system"/>
<menuitem id="menu_action_transcoder" parent="menu_oomusic_config" action="action_transcoder" sequence="30" groups="base.group_system"/>
</odoo>

0 comments on commit d572bcc

Please sign in to comment.