コード例 #1
0
ファイル: views.py プロジェクト: bbterry/simpleblog
def add_post(request):
    if request.method == 'GET':
        if 'user' in request.session:
            return render_to_response('add_post.html', RequestContext(request))
        else:
            return redirect(request, 'You need to login to make a post', '')
    elif request.method == 'POST':
        d = request.POST
        title = d['title']
        content = d['content']
        date = datetime.datetime.now()
        viewable = d['viewable']
        author = None
        for user in User.objects(username=request.session['user']):
            author = user
        form = UploadImgForm(request.POST, request.FILES)
        if form.is_valid():
            newImg = Img(img_width=50, img_height=50)
            newImg.img_src.put(request.FILES['img'], content_type='image/jpeg')
            newImg.save()
            newPost = Post(title=title,
                           content=content,
                           date_added=date,
                           image_id=newImg,
                           author=author,
                           viewable=viewable)
            newPost.save()
            return redirect(request, 'Added post successfully', '')
        return redirect(request, 'All inputs need to be filled', 'add_post')
コード例 #2
0
ファイル: views.py プロジェクト: bbterry/simpleblog
def delete(request):
	if request.method == 'GET':
		if 'user' in request.session:
			d = request.GET
			id = d['id']
			username = d['username']
			return render_to_response('delete.html', {'id': id, 'username': username}, RequestContext(request))
		return redirect(request, 'Illegal operation!', '')				
	elif request.method == 'POST':
		if 'user' in request.session:
			d = request.POST
			if request.session['user'] == d['username'] or request.session['security_level'] == 10:
				id = d['id']
				if Post.objects(id=id).first().image_id is not None:
					img_id = Post.objects(id=id).first().image_id.id
					Img.objects(id=img_id).delete()
				Post.objects(id=id).delete()
				return redirect(request, 'deleted post successfully', '')
			
	return redirect(request, 'Illegal operation!', '')
コード例 #3
0
ファイル: views.py プロジェクト: bbterry/simpleblog
def add_post(request):
	if request.method == 'GET':
		if 'user' in request.session:
			return render_to_response('add_post.html', RequestContext(request))
		else:
			return redirect(request, 'You need to login to make a post', '')
	elif request.method == 'POST':
		d = request.POST
		title = d['title']
		content = d['content']
		date = datetime.datetime.now()
		viewable = d['viewable']
		author = None
		for user in User.objects(username=request.session['user']):
			author = user
		form = UploadImgForm(request.POST, request.FILES)
		if form.is_valid():
			newImg = Img(img_width = 50, img_height=50)
			newImg.img_src.put(request.FILES['img'], content_type = 'image/jpeg')
			newImg.save()			
			newPost = Post(title=title, content=content, date_added=date, image_id=newImg, author=author, viewable=viewable)
			newPost.save()
			return redirect(request, 'Added post successfully', '')
		return redirect(request, 'All inputs need to be filled', 'add_post')
コード例 #4
0
ファイル: views.py プロジェクト: bbterry/simpleblog
def delete(request):
    if request.method == 'GET':
        if 'user' in request.session:
            d = request.GET
            id = d['id']
            username = d['username']
            return render_to_response('delete.html', {
                'id': id,
                'username': username
            }, RequestContext(request))
        return redirect(request, 'Illegal operation!', '')
    elif request.method == 'POST':
        if 'user' in request.session:
            d = request.POST
            if request.session['user'] == d['username'] or request.session[
                    'security_level'] == 10:
                id = d['id']
                if Post.objects(id=id).first().image_id is not None:
                    img_id = Post.objects(id=id).first().image_id.id
                    Img.objects(id=img_id).delete()
                Post.objects(id=id).delete()
                return redirect(request, 'deleted post successfully', '')

    return redirect(request, 'Illegal operation!', '')
コード例 #5
0
ファイル: views.py プロジェクト: bbterry/simpleblog
def img_api(request,img_id):
	img = Img.objects(id=img_id).first()
	pic = img.img_src.read()
	content_type = img.img_src.content_type
	return HttpResponse(pic, content_type)
コード例 #6
0
ファイル: views.py プロジェクト: bbterry/simpleblog
def img_api(request, img_id):
    img = Img.objects(id=img_id).first()
    pic = img.img_src.read()
    content_type = img.img_src.content_type
    return HttpResponse(pic, content_type)