def rendered_content(self): video_url = self.video_url for source, pattern in VideoEntry.embed_patterns: id = re.findall(pattern, video_url) if id: embed = VideoEntry.embed_codes[source] html = embed.replace('{{!ID}}', id[0]) break else: html = 'Video: <a href="video_url">%s</a>' % video_url if self.description: html += markup(self.description) return html
def entry_detail(request, date, slug): """Display one entry with the given slug and date. """ try: today = datetime.strptime(date, "%Y/%b/%d") tomorrow = today + timedelta(days=1) except: raise Http404 try: entry = EntryType.objects(publish_date__gte=today, publish_date__lt=tomorrow, slug=slug)[0] except IndexError: raise Http404 # Select correct form for entry type form_class = Comment.CommentForm if request.method == 'POST': form = form_class(request.user, request.POST) if form.is_valid(): # Get necessary post data from the form comment = HtmlComment(**form.cleaned_data) if request.user.is_authenticated(): comment.is_admin = True # Update entry with comment q = EntryType.objects(id=entry.id) comment.rendered_content = markup(comment.body, escape=True, small_headings=True) q.update(push__comments=comment) return HttpResponseRedirect(entry.get_absolute_url()+'#comments') else: form = form_class(request.user) # Check for comment expiry comments_expired = False if entry.comments_expiry_date: if entry.comments_expiry_date < datetime.now(): comments_expired = True context = { 'entry': entry, 'form': form, 'comments_expired': comments_expired, 'datenow': datetime.now(), } return render_to_response(_lookup_template('entry_detail'), context, context_instance=RequestContext(request))
def rendered_content(self): url = self.image_url html = '<img src="%s" />' % url if self.description: html += markup(self.description) return html
def rendered_content(self): if self.description: return markup(self.description, no_follow=False) return '<p>Link: <a href="%s">%s</a></p>' % (self.link_url, self.link_url)
def save(self): """Convert any markup to HTML before saving. """ self.rendered_content = markup(self.content) super(TextEntry, self).save()