コード例 #1
0
ファイル: forum.py プロジェクト: clockworkrage/subd
def forum_details(request):
	main_response = {}
	json_response = {}
	if request.method == 'GET':
		required = ['forum']

		try:
			check_dict(request.GET, required)
		except Exception as e:
			if e.message == 'required':
				return JsonResponse({'code':1, 'response': e.message})

		short_name = request.GET['forum']
		related = request.GET['related']

		forum = Forum.objects.get(short_name = short_name)

		main_response = {'code':0}
		json_response['id'] = forum.id
		json_response['name'] = forum.name
		json_response['short_name'] = forum.short_name

		if related.count('user') == 1:
			json_response['user'] = get_user_info(forum.user)


	main_response['response'] = json_response
	response = JsonResponse(main_response)

	return response
コード例 #2
0
ファイル: user.py プロジェクト: clockworkrage/subd
def user_create(request):

	main_response = {}
	
	if request.method == 'POST':

		input_params = json.loads(request.body)

		required = ['username', 'about', 'name', 'email']

		try:
			check_dict(input_params, required)
		except Exception as e:
			if e.message == 'required':
				return JsonResponse({'code':1, 'response': e.message})

		isUserExistsError = False
		json_response = {}

		isAnon = input_params['isAnonymous']
		email = input_params['email']

		if isAnon:
			about = ''
			name = ''
			username = ''
		else:
			about = input_params['about']
			name = input_params['name']
			username = input_params['username']

		user_id = 0
		num_results = User.objects.filter(email = email).count()

		if num_results != 0:
			isUserExistsError = True

		if isUserExistsError == False:
			user = User(name=name, username=username, isAnonymous=isAnon, email=email, about=about)
			user.save()
			user_id = user.id

			main_response = {'code':0}
			json_response['about'] = about
			json_response['email'] = email
			json_response['id'] = user_id
			json_response['isAnonymous'] = isAnon
			json_response['name'] = name
			json_response['username'] = username

		if isUserExistsError == True:
			main_response = {'code':5}
			json_response = "error message"


	

	main_response['response'] = json_response;
	response = JsonResponse(main_response)

	return response