Ejemplo n.º 1
0
def update_post(request, project_url_path, post_url_path):
    form = BlogPostForm(request.POST)
    post = get_object_or_404(BlogPost, url_path=post_url_path)

    # validate the form
    if form.is_valid():
        # update the post
        html = markdown(request.POST['markdown'], safe_mode=True)
        post.title = request.POST['title']
        post.markdown = request.POST['markdown']
        post.summary = html
        post.content = html
        post.save()

        return HttpResponseRedirect(
            reverse(show_post,
                    args=(
                        post.blog.project.url_path,
                        post.url_path,
                    )))
    else:
        return render_to_response('blogs/edit.html', {
            'project': post.blog.project,
            'form': form
        },
                                  context_instance=RequestContext(request))
Ejemplo n.º 2
0
def create_post(request, project_id):
  form = BlogPostForm(request.POST)
  project = get_object_or_404(Project, id = int(project_id))
  
  if request.user not in project.authors.all():
    return HttpResponseRedirect(reverse(projects.show,
                                        args = (project.url_path,)))
  
  # validate the form
  if form.is_valid():
    date = datetime.datetime.utcnow()
    html = markdown(request.POST['markdown'], safe_mode = "escape")
    post = BlogPost(title = request.POST['title'],
                    markdown = request.POST['markdown'],
                    summary = html,
                    content = html,
                    from_feed = False,
                    author = request.user,
                    project = project,
                    date = date)
    post.blog = project.blog
    post.save()
    
    project.blog.most_recent_date = date
    project.blog.save()
    project.calculate_score()
    
    return HttpResponseRedirect(reverse(show_post,
                                        args = (post.blog.project.url_path,
                                                post.url_path,)))
  else:
    return render_to_response('blogs/edit.html', {
        'project': project,
        'form': form
      }, context_instance = RequestContext(request)) 
Ejemplo n.º 3
0
def update_post(request, project_url_path, post_url_path):
    form = BlogPostForm(request.POST)
    post = get_object_or_404(BlogPost, url_path=post_url_path)

    # validate the form
    if form.is_valid():
        # update the post
        html = markdown(request.POST["markdown"], safe_mode=True)
        post.title = request.POST["title"]
        post.markdown = request.POST["markdown"]
        post.summary = html
        post.content = html
        post.save()

        return HttpResponseRedirect(reverse(show_post, args=(post.blog.project.url_path, post.url_path)))
    else:
        return render_to_response(
            "blogs/edit.html", {"project": post.blog.project, "form": form}, context_instance=RequestContext(request)
        )
Ejemplo n.º 4
0
def create_post(request, project_id):
    form = BlogPostForm(request.POST)
    project = get_object_or_404(Project, id=int(project_id))

    if request.user not in project.authors.all():
        return HttpResponseRedirect(
            reverse(projects.show, args=(project.url_path, )))

    # validate the form
    if form.is_valid():
        date = datetime.datetime.utcnow()
        html = markdown(request.POST['markdown'], safe_mode=True)
        post = BlogPost(title=request.POST['title'],
                        markdown=request.POST['markdown'],
                        summary=html,
                        content=html,
                        from_feed=False,
                        author=request.user,
                        project=project,
                        date=date)
        post.blog = project.blog
        post.save()

        project.blog.most_recent_date = date
        project.blog.save()
        project.calculate_score()

        return HttpResponseRedirect(
            reverse(show_post,
                    args=(
                        post.blog.project.url_path,
                        post.url_path,
                    )))
    else:
        return render_to_response('blogs/edit.html', {
            'project': project,
            'form': form
        },
                                  context_instance=RequestContext(request))
Ejemplo n.º 5
0
def update_post(request, project_url_path, post_url_path):
  form = BlogPostForm(request.POST)
  post = get_object_or_404(BlogPost, url_path = post_url_path)
  
  # validate the form
  if form.is_valid():
    # update the post
    html = markdown(request.POST['markdown'], safe_mode = "escape")
    post.title = request.POST['title']
    post.markdown = request.POST['markdown']
    post.summary = html
    post.content = html
    post.save()
    
    return HttpResponseRedirect(reverse(show_post,
                                        args = (post.blog.project.url_path,
                                                post.url_path,)))
  else:
    return render_to_response('blogs/edit.html', {
        'project': post.blog.project,
        'form': form
      }, context_instance = RequestContext(request))