def test_safeslug(self): examples = ( ("This is a Test", "this-is-a-test"), ("this is a test", "this-is-a-test"), ("This is another-- test", "this-is-another-test"), ( 'A real example: Hello World in C++ -- "a new approach*"!', "a-real-example-hello-world-in-c++-a-new-approach", ), ) for value, expected in examples: assert helpers.safeslug(value) == expected examples = ((u"Hänsel und Gretel", "haensel-und-gretel"), (u"fácil € ☺", "facil-eur")) for value, expected in examples: assert helpers.safeslug(value) == expected from unicodedata import normalize setattr(helpers, "normalize", normalize) helpers.translitcodec = None assert helpers.safeslug(u"Hänsel und Gretel") == "hansel-und-gretel"
def test_safeslugwithrussian(self): examples = [(u"Nothing happens", "nothing-happens"), (u"русский", "russkii")] for value, expected in examples: assert helpers.safeslug(value) == expected helpers.unidecode = None assert helpers.safeslug(u"русский") == ""
def test_safeslugwithrussian(self): examples = [(u'Nothing happens', 'nothing-happens'), (u'русский', 'russkii')] for value, expected in examples: assert helpers.safeslug(value) == expected helpers.unidecode = None assert helpers.safeslug(u'русский') == ''
def recurse(category, tree): yield category, sorted(list(fetch(tree)), key=lambda k: k.date, reverse=True) for subtree in iteritems(tree[0]): for item in recurse(category + "/" + safeslug(subtree[0]), subtree[1]): yield item
def tweet(entry, conf, dryrun=False): """Send a tweet with the title, link and tags from an entry. The first time you need to authorize Acrylamid but than it works without any interaction.""" key = "6k00FRe6w4SZfqEzzzyZVA" secret = "fzRfQcqQX4gcZziyLeoI5wSbnFb7GGj2oEh10hnjPUo" creds = os.path.expanduser('~/.twitter_oauth') if not os.path.exists(creds): twitter.oauth_dance("Acrylamid", key, secret, creds) oauth_token, oauth_token_secret = twitter.read_token_file(creds) t = twitter.Twitter( auth=twitter.OAuth(oauth_token, oauth_token_secret, key, secret)) tweet = u"New Blog Entry: {0} {1} {2}".format( entry.title, helpers.joinurl(conf['www_root'], entry.permalink), ' '.join([u'#' + helpers.safeslug(tag) for tag in entry.tags])) print(' ', bold(blue("tweet ")), end='') print('\n'.join(wrap(tweet.encode('utf8'), subsequent_indent=' ' * 13))) if not dryrun: try: t.statuses.update(status=tweet.encode('utf8')) except twitter.api.TwitterError as e: try: log.warn("%s" % json.loads(e.response_data)['error']) except (ValueError, TypeError): log.warn("Twitter: something went wrong...")
def context(self, env, request): class Link: def __init__(self, title, href): self.title = title self.href = href if href.endswith('/') else href + '/' def tagify(tags): href = lambda t: expand(self.path, {'name': safeslug(t)}) return [Link(t, href(t)) for t in tags] tags = defaultdict(list) for e in request['entrylist']: for tag in e.tags: tags[tag.lower()].append(e) env.tt.register('tagify', tagify) env.tag_cloud = Tagcloud(tags, self.conf['tag_cloud_steps'], self.conf['tag_cloud_max_items'], self.conf['tag_cloud_start_index'], self.conf.get('tag_cloud_shuffle', False)) self.tags = {} for k, v in tags.iteritems(): self.tags[safeslug(k)] = v return env
def tweet(entry, conf, dryrun=False): """Send a tweet with the title, link and tags from an entry. The first time you need to authorize Acrylamid but than it works without any interaction.""" key = "6k00FRe6w4SZfqEzzzyZVA" secret = "fzRfQcqQX4gcZziyLeoI5wSbnFb7GGj2oEh10hnjPUo" creds = os.path.expanduser('~/.twitter_oauth') if not os.path.exists(creds): twitter.oauth_dance("Acrylamid", key, secret, creds) oauth_token, oauth_token_secret = twitter.read_token_file(creds) t = twitter.Twitter(auth=twitter.OAuth(oauth_token, oauth_token_secret, key, secret)) tweet = u"New Blog Entry: {0} {1} {2}".format(entry.title, helpers.joinurl(conf['www_root'], entry.permalink), ' '.join([u'#' + helpers.safeslug(tag) for tag in entry.tags])) print(' ', bold(blue("tweet ")), end='') print('\n'.join(wrap(tweet.encode('utf8'), subsequent_indent=' '*13))) if not dryrun: try: t.statuses.update(status=tweet.encode('utf8')) except twitter.api.TwitterError as e: try: log.warn("%s" % json.loads(e.response_data)['error']) except (ValueError, TypeError): log.warn("Twitter: something went wrong...")
def safeslug(self): examples = ( ('This is a Test', 'this-is-a-test'), ('this is a test', 'this-is-a-test'), ('This is another-- test', 'this-is-another-test'), ('A real example: Hello World in C++ -- "a new approach*"!', 'a-real-example-hello-world-in-c++-a-new-approach')) for value, expected in examples: assert helpers.safeslug(value) == expected examples = ((u'Hänsel und Gretel', 'haensel-und-gretel'), (u'fácil € ☺', 'facil-eu'), (u'русский', 'russkii')) for value, expected in examples: assert helpers.safeslug(value) == expected
def safeslug(self): examples = (('This is a Test', 'this-is-a-test'), ('this is a test', 'this-is-a-test'), ('This is another-- test', 'this-is-another-test'), ('A real example: Hello World in C++ -- "a new approach*"!', 'a-real-example-hello-world-in-c++-a-new-approach')) for value, expected in examples: assert helpers.safeslug(value) == expected examples = ((u'Hänsel und Gretel', 'haensel-und-gretel'), (u'fácil € ☺', 'facil-eu'), (u'русский', 'russkii')) for value, expected in examples: assert helpers.safeslug(value) == expected
def generate(self, conf, env, data): """Creates paged listing by tag.""" for tag in self.tags: data["entrylist"] = [entry for entry in self.tags[tag]] for res in Paginator.generate(self, conf, env, data, tag=tag, name=safeslug(tag)): yield res
def recurse(category, tree): yield category, sorted(list(fetch(tree)), key=lambda k: k.date, reverse=True) for subtree in iteritems(tree[0]): for item in recurse(category + '/' + safeslug(subtree[0]), subtree[1]): yield item
def test_safeslug(self): examples = (('This is a Test', 'this-is-a-test'), ('this is a test', 'this-is-a-test'), ('This is another-- test', 'this-is-another-test'), ('A real example: Hello World in C++ -- "a new approach*"!', 'a-real-example-hello-world-in-c++-a-new-approach')) for value, expected in examples: assert helpers.safeslug(value) == expected examples = ((u'Hänsel und Gretel', 'haensel-und-gretel'), (u'fácil € ☺', 'facil-eur')) for value, expected in examples: assert helpers.safeslug(value) == expected from unicodedata import normalize setattr(helpers, 'normalize', normalize) helpers.translitcodec = None assert helpers.safeslug(u'Hänsel und Gretel') == 'hansel-und-gretel'
def generate(self, conf, env, data): """Creates paged listing by tag.""" for tag in self.tags: data['entrylist'] = [entry for entry in self.tags[tag]] for res in Paginator.generate(self, conf, env, data, tag=tag, name=safeslug(tag)): yield res
def test_safeslug(self): examples = ( ('This is a Test', 'this-is-a-test'), ('this is a test', 'this-is-a-test'), ('This is another-- test', 'this-is-another-test'), ('A real example: Hello World in C++ -- "a new approach*"!', 'a-real-example-hello-world-in-c++-a-new-approach')) for value, expected in examples: assert helpers.safeslug(value) == expected examples = ((u'Hänsel und Gretel', 'haensel-und-gretel'), (u'fácil € ☺', 'facil-eur')) for value, expected in examples: assert helpers.safeslug(value) == expected from unicodedata import normalize setattr(helpers, 'normalize', normalize) helpers.translitcodec = None assert helpers.safeslug(u'Hänsel und Gretel') == 'hansel-und-gretel'
def _populate_tags(self, request): tags = defaultdict(list) tmap = defaultdict(int) for e in request['entrylist']: for tag in e.tags: tags[tag.lower()].append(e) tmap[tag] += 1 # map tags to the most counted tag name for name in tags.keys()[:]: key = max([(tmap[key], key) for key in tmap if key.lower() == name])[1] rv = tags.pop(key.lower()) tags[key] = rv self.tags = dict([(safeslug(k), v) for k, v in tags.iteritems()]) return tags
def tagify(tags): href = lambda t: expand(self.path, {'name': safeslug(t)}) return [Link(t, href(t)) for t in tags] if isinstance(tags, (list, tuple)) \ else Link(tags, href(tags))
def slug(self): """ascii safe entry title""" slug = self.props.get('slug', None) if not slug: slug = safeslug(self.title) return slug
def populate_tags(self, request): tags = fetch(request['entrylist']) self.tags = dict([(safeslug(k), v) for k, v in iteritems(tags)]) return tags
def tagify(tags): href = lambda t: expand(self.path, {"name": safeslug(t)}) return [Link(t, href(t)) for t in tags]
def _populate_tags(self, request): tags = fetch(request["entrylist"], skip=lambda x: x.draft) self.tags = dict([(safeslug(k), v) for k, v in tags.iteritems()]) return tags
def populate_tags(self, request): tags = fetch(request['entrylist'] + request['translations']) self.tags = dict([(safeslug(k), v) for k, v in tags.iteritems()]) return tags
def slug(self): """ascii safe entry title""" return safeslug(self.title)
def tagify(tags): href = lambda t: expand(self.path, {"name": safeslug(t)}) return [Link(t, href(t)) for t in tags] if isinstance(tags, (list, tuple)) else Link(tags, href(tags))
def tagify(tags): href = lambda t: expand(self.path, {'name': safeslug(t)}) return [Link(t, href(t)) for t in tags]