Code linting
This commit is contained in:
parent
3ee4b91265
commit
0a9ae13c69
5 changed files with 37 additions and 42 deletions
|
|
@ -9,4 +9,4 @@ class BlogApp(CMSApp):
|
||||||
urls = ["djangocms_blog.urls"]
|
urls = ["djangocms_blog.urls"]
|
||||||
app_name = 'djangocms_blog'
|
app_name = 'djangocms_blog'
|
||||||
|
|
||||||
apphook_pool.register(BlogApp)
|
apphook_pool.register(BlogApp)
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
|
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from heapq import nlargest
|
from heapq import nlargest
|
||||||
from itertools import repeat, ifilter
|
from itertools import repeat, ifilter
|
||||||
|
|
||||||
|
|
||||||
class Counter(dict):
|
class Counter(dict):
|
||||||
'''Dict subclass for counting hashable objects. Sometimes called a bag
|
"""
|
||||||
|
Dict subclass for counting hashable objects. Sometimes called a bag
|
||||||
or multiset. Elements are stored as dictionary keys and their counts
|
or multiset. Elements are stored as dictionary keys and their counts
|
||||||
are stored as dictionary values.
|
are stored as dictionary values.
|
||||||
|
|
||||||
>>> Counter('zyzygy')
|
>>> Counter('zyzygy')
|
||||||
Counter({'y': 3, 'z': 2, 'g': 1})
|
Counter({'y': 3, 'z': 2, 'g': 1})
|
||||||
|
"""
|
||||||
'''
|
|
||||||
|
|
||||||
def __init__(self, iterable=None, **kwds):
|
def __init__(self, iterable=None, **kwds):
|
||||||
'''Create a new, empty Counter object. And if given, count elements
|
"""
|
||||||
|
Create a new, empty Counter object. And if given, count elements
|
||||||
from an input iterable. Or, initialize the count from another mapping
|
from an input iterable. Or, initialize the count from another mapping
|
||||||
of elements to their counts.
|
of elements to their counts.
|
||||||
|
|
||||||
|
|
@ -25,26 +25,26 @@ class Counter(dict):
|
||||||
>>> c = Counter({'a': 4, 'b': 2}) # a new counter from a mapping
|
>>> c = Counter({'a': 4, 'b': 2}) # a new counter from a mapping
|
||||||
>>> c = Counter(a=4, b=2) # a new counter from keyword args
|
>>> c = Counter(a=4, b=2) # a new counter from keyword args
|
||||||
|
|
||||||
'''
|
"""
|
||||||
self.update(iterable, **kwds)
|
self.update(iterable, **kwds)
|
||||||
|
|
||||||
def __missing__(self, key):
|
def __missing__(self, key):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def most_common(self, n=None):
|
def most_common(self, n=None):
|
||||||
'''List the n most common elements and their counts from the most
|
"""List the n most common elements and their counts from the most
|
||||||
common to the least. If n is None, then list all element counts.
|
common to the least. If n is None, then list all element counts.
|
||||||
|
|
||||||
>>> Counter('abracadabra').most_common(3)
|
>>> Counter('abracadabra').most_common(3)
|
||||||
[('a', 5), ('r', 2), ('b', 2)]
|
[('a', 5), ('r', 2), ('b', 2)]
|
||||||
|
|
||||||
'''
|
"""
|
||||||
if n is None:
|
if n is None:
|
||||||
return sorted(self.iteritems(), key=itemgetter(1), reverse=True)
|
return sorted(self.iteritems(), key=itemgetter(1), reverse=True)
|
||||||
return nlargest(n, self.iteritems(), key=itemgetter(1))
|
return nlargest(n, self.iteritems(), key=itemgetter(1))
|
||||||
|
|
||||||
def elements(self):
|
def elements(self):
|
||||||
'''Iterator over elements repeating each as many times as its count.
|
"""Iterator over elements repeating each as many times as its count.
|
||||||
|
|
||||||
>>> c = Counter('ABCABC')
|
>>> c = Counter('ABCABC')
|
||||||
>>> sorted(c.elements())
|
>>> sorted(c.elements())
|
||||||
|
|
@ -53,7 +53,7 @@ class Counter(dict):
|
||||||
If an element's count has been set to zero or is a negative number,
|
If an element's count has been set to zero or is a negative number,
|
||||||
elements() will ignore it.
|
elements() will ignore it.
|
||||||
|
|
||||||
'''
|
"""
|
||||||
for elem, count in self.iteritems():
|
for elem, count in self.iteritems():
|
||||||
for _ in repeat(None, count):
|
for _ in repeat(None, count):
|
||||||
yield elem
|
yield elem
|
||||||
|
|
@ -66,7 +66,7 @@ class Counter(dict):
|
||||||
'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
|
'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
|
||||||
|
|
||||||
def update(self, iterable=None, **kwds):
|
def update(self, iterable=None, **kwds):
|
||||||
'''Like dict.update() but add counts instead of replacing them.
|
"""Like dict.update() but add counts instead of replacing them.
|
||||||
|
|
||||||
Source can be an iterable, a dictionary, or another Counter instance.
|
Source can be an iterable, a dictionary, or another Counter instance.
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ class Counter(dict):
|
||||||
>>> c['h'] # four 'h' in which, witch, and watch
|
>>> c['h'] # four 'h' in which, witch, and watch
|
||||||
4
|
4
|
||||||
|
|
||||||
'''
|
"""
|
||||||
if iterable is not None:
|
if iterable is not None:
|
||||||
if hasattr(iterable, 'iteritems'):
|
if hasattr(iterable, 'iteritems'):
|
||||||
if self:
|
if self:
|
||||||
|
|
@ -85,7 +85,7 @@ class Counter(dict):
|
||||||
for elem, count in iterable.iteritems():
|
for elem, count in iterable.iteritems():
|
||||||
self[elem] = self_get(elem, 0) + count
|
self[elem] = self_get(elem, 0) + count
|
||||||
else:
|
else:
|
||||||
dict.update(self, iterable) # fast path when counter is empty
|
dict.update(self, iterable) # fast path when counter is empty
|
||||||
else:
|
else:
|
||||||
self_get = self.get
|
self_get = self.get
|
||||||
for elem in iterable:
|
for elem in iterable:
|
||||||
|
|
@ -118,13 +118,13 @@ class Counter(dict):
|
||||||
# c += Counter()
|
# c += Counter()
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
'''Add counts from two counters.
|
"""Add counts from two counters.
|
||||||
|
|
||||||
>>> Counter('abbb') + Counter('bcc')
|
>>> Counter('abbb') + Counter('bcc')
|
||||||
Counter({'b': 4, 'c': 2, 'a': 1})
|
Counter({'b': 4, 'c': 2, 'a': 1})
|
||||||
|
|
||||||
|
|
||||||
'''
|
"""
|
||||||
if not isinstance(other, Counter):
|
if not isinstance(other, Counter):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
result = Counter()
|
result = Counter()
|
||||||
|
|
@ -135,12 +135,12 @@ class Counter(dict):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def __sub__(self, other):
|
def __sub__(self, other):
|
||||||
''' Subtract count, but keep only results with positive counts.
|
""" Subtract count, but keep only results with positive counts.
|
||||||
|
|
||||||
>>> Counter('abbbc') - Counter('bccd')
|
>>> Counter('abbbc') - Counter('bccd')
|
||||||
Counter({'b': 2, 'a': 1})
|
Counter({'b': 2, 'a': 1})
|
||||||
|
|
||||||
'''
|
"""
|
||||||
if not isinstance(other, Counter):
|
if not isinstance(other, Counter):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
result = Counter()
|
result = Counter()
|
||||||
|
|
@ -151,12 +151,12 @@ class Counter(dict):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def __or__(self, other):
|
def __or__(self, other):
|
||||||
'''Union is the maximum of value in either of the input counters.
|
"""Union is the maximum of value in either of the input counters.
|
||||||
|
|
||||||
>>> Counter('abbb') | Counter('bcc')
|
>>> Counter('abbb') | Counter('bcc')
|
||||||
Counter({'b': 3, 'c': 2, 'a': 1})
|
Counter({'b': 3, 'c': 2, 'a': 1})
|
||||||
|
|
||||||
'''
|
"""
|
||||||
if not isinstance(other, Counter):
|
if not isinstance(other, Counter):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
_max = max
|
_max = max
|
||||||
|
|
@ -168,12 +168,12 @@ class Counter(dict):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def __and__(self, other):
|
def __and__(self, other):
|
||||||
''' Intersection is the minimum of corresponding counts.
|
""" Intersection is the minimum of corresponding counts.
|
||||||
|
|
||||||
>>> Counter('abbb') & Counter('bcc')
|
>>> Counter('abbb') & Counter('bcc')
|
||||||
Counter({'b': 1})
|
Counter({'b': 1})
|
||||||
|
|
||||||
'''
|
"""
|
||||||
if not isinstance(other, Counter):
|
if not isinstance(other, Counter):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
_min = min
|
_min = min
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,8 @@ except ImportError:
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
from parler.managers import TranslationManager
|
from parler.managers import TranslationManager
|
||||||
|
|
||||||
from .settings import BLOG_TAGCLOUD_MIN, BLOG_TAGCLOUD_MAX
|
|
||||||
|
|
||||||
|
|
||||||
class TaggedFilterItem(object):
|
class TaggedFilterItem(object):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,15 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from sitemap import BlogSitemap
|
from django.contrib.sitemaps import Sitemap
|
||||||
|
|
||||||
|
from ..models import Post
|
||||||
|
|
||||||
|
|
||||||
|
class BlogSitemap(Sitemap):
|
||||||
|
changefreq = "never"
|
||||||
|
priority = 0.5
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return Post.objects.published()
|
||||||
|
|
||||||
|
def lastmod(self, obj):
|
||||||
|
return obj.date_modified
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from django.contrib.sitemaps import Sitemap
|
|
||||||
|
|
||||||
from ..models import Post
|
|
||||||
|
|
||||||
|
|
||||||
class BlogSitemap(Sitemap):
|
|
||||||
changefreq = "never"
|
|
||||||
priority = 0.5
|
|
||||||
|
|
||||||
def items(self):
|
|
||||||
return Post.objects.published()
|
|
||||||
|
|
||||||
def lastmod(self, obj):
|
|
||||||
return obj.date_modified
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue