<commit_before>from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse_lazy
from django.utils.feedgenerator import Atom1Feed

from . import app_settings
from .models import Name


class NameAtomFeedType(Atom1Feed):
    """Create an Atom feed that sets the Content-Type response
    header to application/xml.
    """
    mime_type = 'application/xml'

    def root_attributes(self):
        attrs = super(NameAtomFeedType, self).root_attributes()
        attrs['xmlns:georss'] = 'http://www.georss.org/georss'
        return attrs

    def add_item_elements(self, handler, item):
        super(NameAtomFeedType, self).add_item_elements(handler, item)
        if item.get('location'):
            handler.addQuickElement('georss:point', item['location'])


class NameAtomFeed(Feed):
    feed_type = NameAtomFeedType
    link = reverse_lazy("name_feed")
    title = "Name App"
    subtitle = "New Name Records"
    author_name = app_settings.NAME_FEED_AUTHOR_NAME
    author_email = app_settings.NAME_FEED_AUTHOR_EMAIL
    author_link = app_settings.NAME_FEED_AUTHOR_LINK

    def items(self):
        return Name.objects.order_by('-date_created')[:20]

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

    def item_description(self, obj):
        return 'Name Type: {0}'.format(obj.get_name_type_label())

    def item_link(self, obj):
        return obj.get_absolute_url()

    def item_location(self, obj):
        if obj.has_locations() and obj.location_set.current_location:
            return obj.location_set.current_location.geo_point()

    def item_extra_kwargs(self, obj):
        return dict(location=self.item_location(obj))<commit_msg>Add a better docblock.<commit_after>from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse_lazy
from django.utils.feedgenerator import Atom1Feed

from . import app_settings
from .models import Name


class NameAtomFeedType(Atom1Feed):
    """Custom Atom Feed Type for Name objects.

    This will set the Content-Type header to application/xml, and
    add a georss:point element to any entry that has a current location
    set.
    """
    mime_type = 'application/xml'

    def root_attributes(self):
        attrs = super(NameAtomFeedType, self).root_attributes()
        attrs['xmlns:georss'] = 'http://www.georss.org/georss'
        return attrs

    def add_item_elements(self, handler, item):
        super(NameAtomFeedType, self).add_item_elements(handler, item)
        if item.get('location'):
            handler.addQuickElement('georss:point', item['location'])


class NameAtomFeed(Feed):
    """Atom Feed for Name objects."""
    feed_type = NameAtomFeedType
    link = reverse_lazy("name_feed")
    title = "Name App"
    subtitle = "New Name Records"

    author_name = app_settings.NAME_FEED_AUTHOR_NAME
    author_email = app_settings.NAME_FEED_AUTHOR_EMAIL
    author_link = app_settings.NAME_FEED_AUTHOR_LINK

    def items(self):
        return Name.objects.order_by('-date_created')[:20]

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

    def item_description(self, obj):
        return 'Name Type: {0}'.format(obj.get_name_type_label())

    def item_link(self, obj):
        return obj.get_absolute_url()

    def item_location(self, obj):
        if obj.has_locations() and obj.location_set.current_location:
            return obj.location_set.current_location.geo_point()

    def item_extra_kwargs(self, obj):
        return dict(location=self.item_location(obj))
{'fraction_non_alphanumeric': 0.09759547383309759, 'fraction_numerical': 0.002828854314002829, 'mean_word_length': 3.634338138925295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '4687569', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1083, 'n_words': 242}