def description_from_content(self): """ Returns the first block or sentence of the first content-like field. """ description = "" # Use the first RichTextField, or TextField if none found. for field_type in (RichTextField, models.TextField): if not description: for field in self._meta.fields: if isinstance(field, field_type) and \ field.name != "description": description = getattr(self, field.name) if description: from mezzanine.core.templatetags.mezzanine_tags \ import richtext_filters description = richtext_filters(description) break # Fall back to the title if description couldn't be determined. if not description: description = str(self) # Strip everything after the first block or sentence. ends = ("</p>", "<br />", "<br/>", "<br>", "</ul>", "\n", ". ", "! ", "? ") for end in ends: pos = description.lower().find(end) if pos > -1: description = TagCloser(description[:pos]).html break else: description = truncatewords_html(description, 100) return description
def description_from_content(self): """ Returns the first block or sentence of the first content-like field. """ description = "" # Use the first RichTextField, or TextField if none found. for field_type in (RichTextField, models.TextField): if not description: for field in self._meta.fields: if (isinstance(field, field_type) and field.name != "description"): description = getattr(self, field.name) if description: from mezzanine.core.templatetags.mezzanine_tags \ import richtext_filters description = richtext_filters(description) break # Fall back to the title if description couldn't be determined. if not description: description = str(self) # Strip everything after the first block or sentence. ends = ("</p>", "<br />", "<br/>", "<br>", "</ul>", "\n", ". ", "! ", "? ") for end in ends: pos = description.lower().find(end) if pos > -1: description = TagCloser(description[:pos]).html break else: description = truncatewords_html(description, 100) return description
def post(self, request, *args, **kwargs): # pylint: disable=unused-argument newspost_slug = request.POST.get('newspost_slug') try: newspost = NewsPost.objects.get(slug=newspost_slug) except NewsPost.DoesNotExist: error_message = 'News post item for "{}" could not be found'.format(newspost_slug) result = dict(error=error_message) else: # adapt to dict user_name = newspost.user.get_full_name() publish_date = date(newspost.publish_date, 'F dS, Y') content = safe(richtext_filters(newspost.content)) result = dict( error=None, title=newspost.title, content=content, user=user_name, publish_date=publish_date) return JsonResponse(result, safe=True)
def items(self): if not self._public: return [] blog_posts = BlogPost.objects.published().select_related("user") if self.tag: tag = get_object_or_404(Keyword, slug=self.tag) blog_posts = blog_posts.filter(keywords__in=tag.assignments.all()) if self.category: category = get_object_or_404(BlogCategory, slug=self.category) blog_posts = blog_posts.filter(categories=category) if self.username: author = get_object_or_404(User, username=self.username) blog_posts = blog_posts.filter(user=author) limit = settings.BLOG_RSS_LIMIT if limit is not None: blog_posts = blog_posts[:settings.BLOG_RSS_LIMIT] blog_posts_filter = [] for post in blog_posts: post.content = mezzanine_tags.richtext_filters(post.content) blog_posts_filter.append(post) return blog_posts_filter
def item_description(self, item): description = richtext_filters(item.content) absolute_urls_name = "mezzanine.utils.html.absolute_urls" if absolute_urls_name not in settings.RICHTEXT_FILTERS: description = absolute_urls(description) return description
def generate_from_posts(posts): book = epub.EpubBook() # add metadata book.set_title('Articles de Vincent Jousse') book.set_language('fr') book.add_author('Vincent Jousse') chapters = [] for post in posts: c1 = epub.EpubHtml(title=post.title, file_name='%s.xhtml' % post.slug, lang='fr') c1.content = u'<html><head></head><body><h1>%s</h1>%s</body></html>' % ( post.title, mezzanine_tags.richtext_filters(post.content)) book.add_item(c1) chapters.append(c1) book.toc = tuple(chapters) # add navigation files book.add_item(epub.EpubNcx()) book.add_item(epub.EpubNav()) # define css style style = ''' @namespace epub "http://www.idpf.org/2007/ops"; body { font-family: Cambria, Liberation Serif, Bitstream Vera Serif, Georgia, Times, Times New Roman, serif; } h2 { text-align: left; text-transform: uppercase; font-weight: 200; } ol { list-style-type: none; } ol > li:first-child { margin-top: 0.3em; } nav[epub|type~='toc'] > ol > li > ol { list-style-type:square; } nav[epub|type~='toc'] > ol > li > ol > li { margin-top: 0.3em; } ''' # add css file nav_css = epub.EpubItem(uid="style_nav", file_name="style/nav.css", media_type="text/css", content=style) book.add_item(nav_css) # create spine book.spine = ['nav'] + chapters tf = tempfile.NamedTemporaryFile() # create epub file epub.write_epub(tf.name, book, {}) return tf
def item_description(self, item): return richtext_filters(item.content)
def item_description(self, item): return richtext_filters(item.content)
def item_description(self, item): description = richtext_filters(item.content) absolute_urls_name = "mezzanine.utils.html.absolute_urls" if absolute_urls_name not in settings.RICHTEXT_FILTERS: description = absolute_urls(description) return description
def get_page(slug, attr): # page = richtext_filter(get_object_translation(getattr(RichTextPage.objects.get(pk=int(pk)), attr))) page = get_object_translation(RichTextPage.objects.get(slug=slug)) return richtext_filters(page.content)
def item_description(self, item): copy_info = "\n原文:[" + \ super(PostsRSS, self).item_title(item) + "](" + \ super(PostsRSS, self).item_link(item) + ")" return richtext_filters( item.content[0:600]) + richtext_filters(copy_info)
def post(self, request, *args, **kwargs): text = self.request.POST.get('text', u"") return HttpResponse(richtext_filters(text), content_type='text/html')
def generate_from_posts(posts): book = epub.EpubBook() # add metadata book.set_title('Articles de Vincent Jousse') book.set_language('fr') book.add_author('Vincent Jousse') chapters = [] for post in posts: c1 = epub.EpubHtml(title=post.title, file_name='%s.xhtml' % post.slug, lang='fr') c1.content=u'<html><head></head><body><h1>%s</h1>%s</body></html>' % (post.title, mezzanine_tags.richtext_filters(post.content)) book.add_item(c1) chapters.append(c1) book.toc = tuple(chapters) # add navigation files book.add_item(epub.EpubNcx()) book.add_item(epub.EpubNav()) # define css style style = ''' @namespace epub "http://www.idpf.org/2007/ops"; body { font-family: Cambria, Liberation Serif, Bitstream Vera Serif, Georgia, Times, Times New Roman, serif; } h2 { text-align: left; text-transform: uppercase; font-weight: 200; } ol { list-style-type: none; } ol > li:first-child { margin-top: 0.3em; } nav[epub|type~='toc'] > ol > li > ol { list-style-type:square; } nav[epub|type~='toc'] > ol > li > ol > li { margin-top: 0.3em; } ''' # add css file nav_css = epub.EpubItem(uid="style_nav", file_name="style/nav.css", media_type="text/css", content=style) book.add_item(nav_css) # create spine book.spine = ['nav'] + chapters tf = tempfile.NamedTemporaryFile() # create epub file epub.write_epub(tf.name, book, {}) return tf
def item_description(self, item): copy_info = "\n原文:[" + \ super(PostsRSS, self).item_title(item) + "](" + \ super(PostsRSS, self).item_link(item) + ")" + "<br />更多精彩内容,欢迎搜索并关注我的微信公众号: Phodal" return richtext_filters(item.content[0:600]) + richtext_filters(copy_info)