Example #1
0
    def save(self, *args, **kwargs):
        # If this is a major commit update the html content in the post.
        if self.update_major:
            # If first revision, markup content
            # Else it is a bit more tricky. In order to synchronise comments
            # to commentable html tags we have to go through a few hoops.
            if not self.content_markup:
                self.content_markup = str(cwmarkdown(self.content))
            else:
                self.content_markup = str(cwmarkdown(self.content, previous_content=self.content_markup, post=self, comments=self.comments))

            if self.content and self.pk:
                # Note: Any change here needs to be reflected in save_related in admin.py
                # Add Root Node & Section Node & any manual tags by Default - Language, Subsection in this case
                default_tags = []
                if self.include_tags:
                    default_tags = [tag.name for tag in self.include_tags.all()]
                default_tags.extend([self.node.name.lower(), self.node.parent.name.lower()])
                contTags = Set(default_tags)

                # Find any tags from content and auto-add
                for tag in Tag.objects.all():
                    if re.search( tag.name, self.content, re.M|re.I):
                        contTags.add(tag)

                # Remove any tags which are from exclude tags
                if self.exclude_tags:
                    exclude_tags = [exclude_tag.name for exclude_tag in self.exclude_tags.all()]
                    contTags = Set([tag for tag in contTags if tag not in exclude_tags])

                # Finally clear tags completely and readd
                self.tags.clear()
                for tag in contTags:
                    self.tags.add(tag)

        if not self.slug:
            self.slug = slugify(self.title)

        super(Post, self).save(*args, **kwargs)
        
        # Finally, save a revision - commit
        print self.id
        PostRevision.objects.create_post_revision(post=self, content=self.content, comment=self.update_comment)
Example #2
0
 def post(self, request, *args, **kwargs):
     logger.info('%s, this is the ajax_get function from %s' % (self.__class__.__name__, self.__module__))
     #self.object = self.get_object()
     #context = super(PostEditView, self).get_context_data(**kwargs)
     content = request.POST.get('foo')
     print request
     print request.POST
     print "content", content
     preview = cwmarkdown(content)
     print "preview", preview
     return HttpResponse(preview)
     return render_to_resp(self.template_name, context, context_instance=RequestContext(request), mimetype='application/javascript')
def editor_render(content, safe=False):
    """Render this content for display."""
    return cwmarkdown(content)