Example #1
0
    def post(self):
        article = self.request.POST.get('id')
        instance = Article.get(article) if article else None

        data = ArticleForm(data=self.request.POST, instance=instance)
        if data.is_valid():
            entity = data.save(commit=False)
            if hasattr(self.request.POST.get('img'), 'file'):
                entity.img = Blob(self.request.POST.get('img').file.read())
            entity.put()
            self.redirect_to("new", message='Статья успешно сохранена!')
        else:
            self.response.out.write(render('templates/article.html', {'form': data}))
Example #2
0
def create_article(request):

    articles = Article.all()

    if request.method == "POST":
        form = ArticleForm(request.POST)

        if form.is_valid():
            article = Article(title=form.cleaned_data['title'],
                              body=form.cleaned_data['body'])
            article.put()
            messages.success(request, 'Article created successful')
            return redirect('create_article')

    return render_to_response('create_article.html', dict(articles=articles))
Example #3
0
def update_article(request, article_id):

    article = Article.get_by_id(int(article_id))
    articles = Article.all()

    if request.method == "POST":
        form = ArticleForm(request.POST)

        if form.is_valid():
            article.title = form.cleaned_data['title']
            article.body = form.cleaned_data['body']
            article.put()
            messages.success(request, 'Article updated successfully')
            return redirect('create_article')

    return render_to_response('create_article.html', dict(articles=articles, article=article, form_action="edit"))
Example #4
0
File: views.py Project: 3241966/PMS
def admin(request,article,success=False,status=None):
	try:
		article = NewsArticle.objects.get(id=article)
	except NewsArticle.DoesNotExist:
		return HttpResponseNotFound()

	if request.method == "POST" and not success:
		form = ArticleForm(request.POST,instance=article)
		if form.is_valid():
			form.save()
			success=True
			status = 'News updated'
	else:
		form = ArticleForm(instance=article)

	return render_to_response("news_adminform.html",{'form' : form,'success' : success,'article' : article,'status' : status},context_instance=RequestContext(request))
Example #5
0
def submit_link_detail(request):
    if request.method == "POST":
        form = ArticleForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = request.user
            obj.save()
            Vote.objects.record_vote(obj, request.user, +1)
            if "actstream" in settings.INSTALLED_APPS:
                action.send(request.user, verb='submitted', target=obj)
            return redirect("/")
        else:
            form = ArticleForm(request.POST)
            return render(request, "djig/submit_link.html", {
                "form"          : form,
            })
    else:
        return HttpResponse("You should POST to this page, not GET it.")
Example #6
0
File: views.py Project: 3241966/PMS
def create(request):
	success = False
	try:
		if request.method == "POST":
			form = ArticleForm(request.POST)
			if form.is_valid():
				try:
					article = form.save(commit=False)
					article.user = request.user
					article.save()
				except Exception as e:
					print e
				success=True
				return admin(request,article.id,True,'News created')
		else:
			form = ArticleForm()
	
		return render_to_response("news_createform.html",{'form' : form,'success' : success},context_instance=RequestContext(request))
	except Exception as e:
		print e