<commit_before>import mimetypes

from django.contrib.syndication.views import Feed
from django.shortcuts import get_object_or_404
from leaflets.models import Leaflet
# from parties.models import Party
from constituencies.models import Constituency
from tags.models import Tag
from categories.models import Category

class LatestLeafletsFeed(Feed):
    title = "electionleaflets.org latest items"
    link = "/leaflets/"
    description = "The most recently uploaded leaflets"

    def items(self):
        return Leaflet.objects.order_by('-id')[:10]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        return item.description

    def item_enclosure_url(self, item):
        return item.images.all()[0].image.url

    def item_enclosure_length(self, item):
        return item.images.all()[0].image.size

    def item_enclosure_mime_type(self, item):
        type, _ = mimetypes.guess_type(item.images.all()[0].image.url)
        return type
<commit_msg>Sets the title to the constituency name if no title<commit_after>import mimetypes

from django.contrib.syndication.views import Feed
from django.shortcuts import get_object_or_404
from leaflets.models import Leaflet
# from parties.models import Party
from constituencies.models import Constituency
from tags.models import Tag
from categories.models import Category

class LatestLeafletsFeed(Feed):
    title = "electionleaflets.org latest items"
    link = "/leaflets/"
    description = "The most recently uploaded leaflets"

    def items(self):
        return Leaflet.objects.order_by('-id')[:10]

    def item_title(self, item):
        return item.title or item.constituency.name

    def item_description(self, item):
        return item.description

    def item_enclosure_url(self, item):
        return item.images.all()[0].image.url

    def item_enclosure_length(self, item):
        return item.images.all()[0].image.size

    def item_enclosure_mime_type(self, item):
        type, _ = mimetypes.guess_type(item.images.all()[0].image.url)
        return type

{'fraction_non_alphanumeric': 0.08942307692307692, 'fraction_numerical': 0.007692307692307693, 'mean_word_length': 3.772935779816514, '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': '7543767', 'n_tokens_mistral': 627, 'n_tokens_neox': 596, 'n_words': 161}