def get_snippets(self, name): snippets = [] object_list = Snippet.objects_pub.filter(snippet_groups__slug=name) for obj in object_list: snippet = snippet_factory.get_snippet_for_obj(obj) snippets.append(snippet) return snippets
def get_snippet(self, slug): try: obj = Snippet.objects_pub.get(slug=slug) except Snippet.DoesNotExist: return '' snippet = snippet_factory.get_snippet_for_obj(obj) return snippet
def snippet_shortcode(value): search = re.findall(r'\[snippet (\w+)\]', value) if search: names = list(search) object_list = Snippet.objects.filter(publish=True, slug__in=names) snippet_dict = {} for obj in object_list: snippet = snippet_factory.get_snippet_for_obj(obj) snippet_dict[obj.slug] = snippet for name in names: shortcode = '[snippet %s]' % name text = unicode(snippet_dict.get(name, '')) value = value.replace(shortcode, text) return value