Пример #1
0
    def post(self, request, *args, **kwargs):
        user = request.user
        pk = self.kwargs['pk']
        form = self.form_class(request.POST)
        repo = Repo.objects.get(user=user, main=True)
        if form.is_valid():
            title = request.POST['title']
            permalink = request.POST['permalink']
            content = request.POST['content']

            save_page_database(repo, title, permalink, content, pk)

            # Create header content for the markdown file
            head_content = page_header_content(title, permalink)

            # Convert the body content to markdown
            body_content = convert_content(content)

            # Write the content into files
            write_page_file(title.lower(), user, repo, head_content,
                            body_content)

            # Push the code online
            push_online(user, repo)
        return HttpResponseRedirect(reverse('page-update', args=[pk]))
Пример #2
0
    def post(self, request, *args, **kwargs):
        user = request.user
        pk = self.kwargs['pk']
        form = self.form_class(request.POST)
        repo = Repo.objects.get(user=user, main=True)
        if form.is_valid():
            author = request.POST['author']
            comments = request.POST['comments']
            date = request.POST['date']
            time = request.POST['time']
            layout = request.POST['layout']
            title = request.POST['title']
            content = request.POST['content']
            category = request.POST['category']

            # This is a turnaround... I don't know why it happened.
            # Checkbox produces 'on' as the result when selected.
            comments = assign_boolean_to_comments(comments)

            # save stuff to the post database
            post = save_post_database(repo, author, comments, date, time, layout, title, content, pk)

            # save stuff to the post_category database
            save_post_category_database(post, category, pk)

            file_name = create_file_name(date, title)

            # Create header content for the markdown file
            head_content = header_content(author, comments, date, time, layout, title)

            # Convert the body content to markdown
            body_content = convert_content(content)

            # Write the content into files
            write_file(file_name, head_content, body_content)

            # Move file to correct location
            move_file(file_name, user, repo)

            # send the changes online
            push_online(user, repo)
        return HttpResponseRedirect(reverse('home'))