Example #1
0
 def _to_json(self, value):
     if isinstance(value, Mapping):
         return dict(((k, self._to_json(v)) for k, v in value.items()))
     elif isinstance(value, (list, tuple)):
         return [self._to_json(v) for v in value]
     elif isinstance(value, date):
         return iso8601(value)
     else:
         return value
Example #2
0
 def _to_string(self, value):
     if isinstance(value, Mapping):
         raise BuildError('A dictionary found when coverting to string')
     elif isinstance(value, (list, tuple)):
         return ', '.join(self._to_string(v) for v in value)
     elif isinstance(value, date):
         return iso8601(value)
     else:
         return to_string(value)
Example #3
0
    def _urls(self, request):
        latest_lastmod = None
        all_items_lastmod = True  # track if all items have a lastmod
        count = 0
        for item in self.items(request):
            loc = self._get('loc', item)
            priority = self._get('priority', item)
            # No location or priority set to 0
            if not loc or priority == 0 or priority == '0':
                continue
            count += 1
            if count > self.limit:
                request.error('Maximum number of sitemap entries reached')
                break

            lastmod = self._get('lastmod', item)
            if lastmod:
                if isinstance(lastmod, str):
                    lastmodv = parse_date(lastmod)
                else:
                    lastmodv = lastmod
                    lastmod = iso8601(lastmod)

                if (all_items_lastmod and
                    (latest_lastmod is None or lastmodv > latest_lastmod)):
                    latest_lastmod = lastmodv
            else:
                all_items_lastmod = False

            values = [self._xml('loc', loc), self._xml('lastmod', lastmod)]

            for tag in self.extra_item_tags:
                values.append(self._xml(tag, self._get(tag, item)))

            yield self._xml(self.item_tag, ''.join(values))

        if all_items_lastmod and latest_lastmod:
            latest_lastmod = iso8601(latest_lastmod)
        else:
            latest_lastmod = None
        request.cache.latest_lastmod = latest_lastmod
Example #4
0
    def _urls(self, request):
        latest_lastmod = None
        all_items_lastmod = True  # track if all items have a lastmod
        count = 0
        for item in self.items(request):
            loc = self._get('loc', item)
            priority = self._get('priority', item)
            # No location or priority set to 0
            if not loc or priority == 0 or priority == '0':
                continue
            count += 1
            if count > self.limit:
                request.error('Maximum number of sitemap entries reached')
                break

            lastmod = self._get('lastmod', item)
            if lastmod:
                if isinstance(lastmod, str):
                    lastmodv = parse_date(lastmod)
                else:
                    lastmodv = lastmod
                    lastmod = iso8601(lastmod)

                if (all_items_lastmod and
                        (latest_lastmod is None or lastmodv > latest_lastmod)):
                    latest_lastmod = lastmodv
            else:
                all_items_lastmod = False

            values = [self._xml('loc', loc), self._xml('lastmod', lastmod)]

            for tag in self.extra_item_tags:
                values.append(self._xml(tag, self._get(tag, item)))

            yield self._xml(self.item_tag, ''.join(values))

        if all_items_lastmod and latest_lastmod:
            latest_lastmod = iso8601(latest_lastmod)
        else:
            latest_lastmod = None
        request.cache.latest_lastmod = latest_lastmod