<commit_before># -*- coding: utf-8 -*-

import json

from odoo import fields, models, api, _
from odoo.exceptions import UserError


class MusicAlbum(models.Model):
    _name = 'oomusic.album'
    _description = 'Music Album'
    _order = 'year desc, name'
    _inherit = ['oomusic.download.mixin', 'oomusic.preference.mixin']

    create_date = fields.Datetime(index=True)

    name = fields.Char('Album', index=True)
    track_ids = fields.One2many('oomusic.track', 'album_id', 'Tracks', readonly=True)
    artist_id = fields.Many2one('oomusic.artist', 'Artist')
    genre_id = fields.Many2one('oomusic.genre', 'Genre')
    year = fields.Char('Year', index=True)
    folder_id = fields.Many2one(
        'oomusic.folder', 'Folder', index=True, required=True)
    user_id = fields.Many2one(
        'res.users', string='User', index=True, required=True, ondelete='cascade',
        default=lambda self: self.env.user
    )
    in_playlist = fields.Boolean('In Current Playlist', compute='_compute_in_playlist')

    star = fields.Selection(
        [('0', 'Normal'), ('1', 'I Like It!')], 'Favorite',
        compute='_compute_star', inverse='_inverse_star', search='_search_star')
    rating = fields.Selection(
        [('0', '0'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5')],
        'Rating', compute='_compute_rating', inverse='_inverse_rating', search='_search_rating'
    )

    image_folder = fields.Binary('Folder Image', related='folder_id.image_folder')
    image_big = fields.Binary("Big-sized Image", related='folder_id.image_big')
    image_medium = fields.Binary("Medium-sized Image", related='folder_id.image_medium')
    image_small = fields.Binary("Small-sized Image", related='folder_id.image_small')
    image_small_cache = fields.Binary("Cache Of Small-sized Image", related='folder_id.image_small_cache')

    def _compute_in_playlist(self):
        playlist = self.env['oomusic.playlist'].search([
            ('current', '=', True)
        ], limit=1).with_context(prefetch_fields=False)
        for album in (self & playlist.playlist_line_ids.mapped('album_id')):
            if all([t.in_playlist for t in album.track_ids]):
                album.in_playlist = True

    @api.multi
    def action_add_to_playlist(self):
        playlist = self.env['oomusic.playlist'].search([('current', '=', True)], limit=1)
        if not playlist:
            raise UserError(_('No current playlist found!'))
        if self.env.context.get('purge'):
            playlist.action_purge()<commit_msg>Album images do not need to be retrieved as sudo<commit_after># -*- coding: utf-8 -*-

import json

from odoo import fields, models, api, _
from odoo.exceptions import UserError


class MusicAlbum(models.Model):
    _name = 'oomusic.album'
    _description = 'Music Album'
    _order = 'year desc, name'
    _inherit = ['oomusic.download.mixin', 'oomusic.preference.mixin']

    create_date = fields.Datetime(index=True)

    name = fields.Char('Album', index=True)
    track_ids = fields.One2many('oomusic.track', 'album_id', 'Tracks', readonly=True)
    artist_id = fields.Many2one('oomusic.artist', 'Artist')
    genre_id = fields.Many2one('oomusic.genre', 'Genre')
    year = fields.Char('Year', index=True)
    folder_id = fields.Many2one(
        'oomusic.folder', 'Folder', index=True, required=True)
    user_id = fields.Many2one(
        'res.users', string='User', index=True, required=True, ondelete='cascade',
        default=lambda self: self.env.user
    )
    in_playlist = fields.Boolean('In Current Playlist', compute='_compute_in_playlist')

    star = fields.Selection(
        [('0', 'Normal'), ('1', 'I Like It!')], 'Favorite',
        compute='_compute_star', inverse='_inverse_star', search='_search_star')
    rating = fields.Selection(
        [('0', '0'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5')],
        'Rating', compute='_compute_rating', inverse='_inverse_rating', search='_search_rating'
    )

    image_folder = fields.Binary(
        'Folder Image', related='folder_id.image_folder', related_sudo=False)
    image_big = fields.Binary(
        'Big-sized Image', related='folder_id.image_big', related_sudo=False)
    image_medium = fields.Binary(
        'Medium-sized Image', related='folder_id.image_medium', related_sudo=False)
    image_small = fields.Binary(
        'Small-sized Image', related='folder_id.image_small', related_sudo=False)
    image_small_cache = fields.Binary(
        'Cache Of Small-sized Image', related='folder_id.image_small_cache', related_sudo=False)

    def _compute_in_playlist(self):
        playlist = self.env['oomusic.playlist'].search([
            ('current', '=', True)
        ], limit=1).with_context(prefetch_fields=False)
        for album in (self & playlist.playlist_line_ids.mapped('album_id')):
            if all([t.in_playlist for t in album.track_ids]):
                album.in_playlist = True

    @api.multi
    def action_add_to_playlist(self):
        playlist = self.env['oomusic.playlist'].search([('current', '=', True)], limit=1)
        if not playlist:
            raise UserError(_('No current playlist found!'))
        if self.env.context.get('purge'):
            playlist.action_purge()
{'fraction_non_alphanumeric': 0.1573720397249809, 'fraction_numerical': 0.008403361344537815, 'mean_word_length': 3.684257602862254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4787940', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1684, 'n_words': 336}