Example #1
0
    def save(self, *args, **kwargs):
        self.body = self.body_html
        self.summary = self.summary_html

        self.body_html = sanitizeHtml(self.body_html)
        self.summary_html = sanitizeHtml(self.summary_html)
        if self.tags_string == "":
            self.tags_string = "Untagged"
        super(UserChapter, self).save(*args, **kwargs)
Example #2
0
    def save(self, *args, **kwargs):

        # Check if contents have changed... if not, silently ignore save
        if self.article and self.article.current_revision:
            if self.article.current_revision.contents == self.contents:
                return
            else:
                import datetime
                self.article.modified_on = datetime.datetime.now()
                self.article.save()

        # Increment counter according to previous revision
        previous_revision = Revision.objects.filter(article=self.article).order_by('-counter')
        if previous_revision.count() > 0:
            if previous_revision.count() > previous_revision[0].counter:
                self.counter = previous_revision.count() + 1
            else:
                self.counter = previous_revision[0].counter + 1
        else:
            self.counter = 1
        self.previous_revision = self.article.current_revision


        # Create pre-parsed contents - no need to parse on-the-fly
        #ext = WIKI_MARKDOWN_EXTENSIONS
        #ext += ["wikilinks(base_url=%s/)" % reverse('wiki_view', args=('',))]

        self.contents = sanitizeHtml(self.contents)
        self.contents_parsed = self.contents

        #self.contents_parsed = markdown(self.contents_parsed,
        #                                extensions=ext,
        #                                safe_mode='escape',)
        super(Revision, self).save(*args, **kwargs)
Example #3
0
def user_chapter(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = UserChapterForm(request.POST, request.FILES)
            if form.is_valid():
                title = form.cleaned_data['title']
                summary_html = form.cleaned_data['summary']
                content = form.cleaned_data['content']
                photo = form.cleaned_data['photo']
                tags_string = form.cleaned_data['tags_string']
                
                highest_index = Chapter.objects.aggregate(Max('index'))
                index = highest_index['index__max']+1
                
                user_chapter = UserChapter(title=title,
                                       summary=summary_html,
                                       summary_html=sanitizeHtml(summary_html),
                                       body=content,
                                       body_html=sanitizeHtml(content),
                                       pub_date=datetime.now(),
                                       index=index,
                                       author=request.user,
                                       picture=photo,
                                       tags_string=tags_string)
                user_chapter.save()
                return HttpResponseRedirect('/book/user_chapter/thanks/')
            else:
                data = {'title':request.POST['title'],
                        'summary':request.POST['summary'],
                        'content':request.POST['content'],
                        'photo':request.FILES['photo'],
                        'tags_string':request.FILES['tags_string']}
                form = UserChapterForm(data)
                return render_to_response('book/user_chapter.html', 
                                        {'form': form,},
                                        context_instance = RequestContext(request))
        else:
            form = UserChapterForm()
    
        return render_to_response('book/user_chapter.html', 
                                {'form': form,},
                                context_instance = RequestContext(request))
    else:
       return HttpResponseRedirect('/accounts/login/?next=/book/user_chapter/')