def article_edit(request, article_id): """If the user has rights, he will be able to edit and save. Otherwise, he will be redirected to need_login page.""" article = Article.get_by_id(int(article_id)) if users.get_current_user().email() != article.author: return HttpResponseRedirect('/need_login/') else: if request.method == 'GET': c = {} c.update(csrf(request)) # Give user details to template. _user_manage(c) post_url = '/article/edit/' + article_id + '/' # Set post url. c['form'] = {'action': post_url} # Get the article and populate the form. c['article'] = article return render_to_response('edit_article.html', c) elif request.method == 'POST': # Modify the article. article.title = request.POST.get('title', 'untitled') article.body = request.POST.get('new_content', 'no content') # Save it. article.put() return HttpResponseRedirect('/article/' + article_id + '/')
def article_delete(request, article_id): """We check if the user has rights to delete, and we delete.""" article = Article.get_by_id(int(article_id)) if users.get_current_user().email() != article.author: return HttpResponseRedirect('/need_login/') else: article.delete() return HttpResponseRedirect('/article/all/')
def article_detail(request, article_id): """Shows one article.""" # Get the article. article = Article.get_by_id(int(article_id)) # Fill the context. c = {} c['article'] = article # Deal with login. _user_manage(c) return render_to_response("article.html", c)