<commit_before>from oembed.providers import DjangoProvider
import oembed

from lakaxita.attachments.models import File


class FileProvider(DjangoProvider):
    resource_type = 'rich'

    class Meta:
        model = File
        named_view = 'attachments:file'
        fields_to_match = {'pk': 'pk'}

    def title(self, obj):
        return obj.name

    def request_resource(self, url, **kwargs):
        obj = self.get_object(url)
        self.resource_type = obj.type
        return super(FileProvider, self).request_resource(url, **kwargs)

oembed.site.register(FileProvider)
<commit_msg>render oembed template depending on the resource type<commit_after>from oembed.providers import DjangoProvider
import oembed

from lakaxita.attachments.models import File


class FileProvider(DjangoProvider):
    provides = True
    resource_type = 'rich'

    class Meta:
        model = File
        named_view = 'attachments:file'
        fields_to_match = {'pk': 'pk'}
        resource_template_names = {
                'video': 'oembed/provider/video.yammy',
                'audio': 'oembed/provider/audio.yammy',
                'rich': 'oembed/provider/rich.yammy',
                }

    def title(self, obj):
        return obj.name

    def request_resource(self, url, **kwargs):
        obj = self.get_object(url)
        self.resource_type = obj.type
        self._meta.template_name = self._meta.resource_template_names.get(
                self.resource_type,
                self._meta.template_name,
                )
        return super(FileProvider, self).request_resource(url, **kwargs)

oembed.site.register(FileProvider)

{'fraction_non_alphanumeric': 0.09762050030506407, 'fraction_numerical': 0.0, 'mean_word_length': 2.6607142857142856, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2352992', 'n_tokens_mistral': 485, 'n_tokens_neox': 468, 'n_words': 102}