Пример #1
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)) 
Пример #2
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))
Пример #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)
        )
Пример #4
0
def write_post(request, project_id):
    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, )))

    return render_to_response('blogs/edit.html', {
        'project': project,
        'form': BlogPostForm()
    },
                              context_instance=RequestContext(request))
Пример #5
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))
Пример #6
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))
Пример #7
0
def edit_post(request, project_url_path, post_url_path):
    # redirect if the url path is not in the correct format
    resp = force_url_paths(edit_post, project_url_path, post_url_path)
    if resp: return resp

    post = get_object_or_404(BlogPost, url_path=post_url_path)

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

    return render_to_response('blogs/edit.html', {
        'project': post.blog.project,
        'post': post,
        'form': BlogPostForm(instance=post)
    },
                              context_instance=RequestContext(request))