1
0
Fork 0
forked from github/pelican

Custom bicycle 'update_dict' was replaced with 'collections.defaultdict'.

This commit is contained in:
Alexander Artemenko 2010-12-26 23:59:30 +03:00
commit 01b4c06916
2 changed files with 5 additions and 16 deletions

View file

@ -8,7 +8,7 @@ import os
from jinja2 import Environment, FileSystemLoader
from jinja2.exceptions import TemplateNotFound
from pelican.utils import update_dict, copytree, process_translations, open
from pelican.utils import copytree, process_translations, open
from pelican.contents import Article, Page, is_valid_content
from pelican.readers import read_file
@ -81,8 +81,8 @@ class ArticlesGenerator(Generator):
self.articles = [] # only articles in default language
self.translations = []
self.dates = {}
self.tags = {}
self.categories = {}
self.tags = defaultdict(list)
self.categories = defaultdict(list)
super(ArticlesGenerator, self).__init__(*args, **kwargs)
def generate_feeds(self, writer):
@ -178,14 +178,14 @@ class ArticlesGenerator(Generator):
if hasattr(article, 'tags'):
for tag in article.tags:
update_dict(self.tags, tag, article)
self.tags[tag].append(article)
all_articles.append(article)
self.articles, self.translations = process_translations(all_articles)
for article in self.articles:
# only main articles are listed in categories, not translations
update_dict(self.categories, article.category, article)
self.categories[article.category].append(article)
# sort the articles by date

View file

@ -7,17 +7,6 @@ from codecs import open as _open
from itertools import groupby
from operator import attrgetter
def update_dict(mapping, key, value):
"""Update a dict intenal list
:param mapping: the mapping to update
:param key: the key of the mapping to update.
:param value: the value to append to the list.
"""
if key not in mapping:
mapping[key] = []
mapping[key].append(value)
def get_date(string):
"""Return a datetime object from a string.