コード例 #1
0
ファイル: core.py プロジェクト: MechanisM/django-mumblr
def entry_detail(request, date=None, slug=None, permalink=None):
    """Display one entry with the given slug and date.
    """
    if permalink:
        try:
            entry = EntryType.objects(permalink=permalink)[0]
        except IndexError:
            raise Http404
    else:
        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,
    }
    return render_to_response(_lookup_template('entry_detail'), context,
                              context_instance=RequestContext(request))
コード例 #2
0
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,
    }
    return render_to_response(_lookup_template('entry_detail'),
                              context,
                              context_instance=RequestContext(request))
コード例 #3
0
ファイル: core.py プロジェクト: angelomendonca/django-mumblr
    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
コード例 #4
0
    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
コード例 #5
0
ファイル: core.py プロジェクト: angelomendonca/django-mumblr
 def rendered_content(self):
     url = self.image_url
     html = '<img src="%s" />' % url
     if self.description:
         html += markup(self.description)
     return html
コード例 #6
0
ファイル: core.py プロジェクト: angelomendonca/django-mumblr
 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)
コード例 #7
0
ファイル: core.py プロジェクト: angelomendonca/django-mumblr
 def save(self):
     """Convert any markup to HTML before saving.
     """
     self.rendered_content = markup(self.content)
     super(TextEntry, self).save()
コード例 #8
0
 def rendered_content(self):
     url = self.image_url
     html = '<img src="%s" />' % url
     if self.description:
         html += markup(self.description)
     return html
コード例 #9
0
 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)
コード例 #10
0
 def save(self):
     """Convert any markup to HTML before saving.
     """
     self.rendered_content = markup(self.content)
     super(TextEntry, self).save()