コード例 #1
0
def handler404(request, *args, **kwargs):
    if 'poorly-handled-404' in request.path:
        raise Exception('nah')

    response = HttpResponseNotFound('Terrible happenings!',
                                    content_type='text/plain')
    response.status_code = 404
    return response
コード例 #2
0
ファイル: views.py プロジェクト: shwe87/sync_and_share
def deleteShareFromContent(request):
	#print request.user
	#print request.body
	#print request.POST
	if (request.user.is_authenticated()):
		if request.method == 'POST':
			#typeOf = request.POST['typeOf']
			shareId = request.POST['shareId']
			toDeleteId = request.POST['toDeleteId']
			#uniqueId = request.POST['unique']
			#print uniqueId
		
			#Delete an item that the user was sharing with other users.
			try:
				shared_content = Share.objects.get(unique=shareId)
				shared_from = shared_content.shared_from
				if (shared_from.email == request.user.email):	#If the user is the owner
					try:
						sync = Sync.objects.get(unique=toDeleteId)
						#print "sync deleted"
						shared_content.shared.remove(sync)
					except Sync.DoesNotExist:
						response = HttpResponseNotFound()
						response.write("Not Found")
					checkIfEmpty(shared_content)
					#t = shared_content.shared.all()
					#print "Length of shared.all()"
					#print len(t)
					#if (len(t) is 0):
					#	print "deleted"
						#If it is 0, it means, there is nothing to share:
					#	shared_content.delete()
					#for h in t:
					#	print h.title
					#print "sync deleted 2"
					response = HttpResponse()
					response.write("OK")
				else:
					response = HttpResponseNotAllowed('You are not the owner')						
			except Share.DoesNotExist:
				response = HttpResponseNotFound()
				response.write("Not Found")			
		else:
			response = HttpResponseNotAllowed("Only POST allowed")
	else:
		response.status_code= 401
		response['error'] = 'Unauthorized'
		response.content = 'Unauthorized'
	#response= HttpResponse()
	return response