def reg_client2(request): if request.method == 'GET': form = ClientForm() return render_to_response('regclient2.html', {"form": form}, context_instance=RequestContext(request)) elif request.method == 'POST': form = ClientForm(request.POST) if form.is_valid(): client = form.save(commit=False) client.user = request.user client.save() d = {"name":client.name,"app_id":client.client_id, "secret":client.client_secret, "info_message": "Your Client Credentials"} return render_to_response('reg_success.html', d, context_instance=RequestContext(request)) else: return render_to_response('regclient2.html', {"form": form}, context_instance=RequestContext(request))
def test_client_form(self): form = ClientForm({ 'name': 'TestName', 'url': 'http://127.0.0.1:8000', 'redirect_uri': 'http://localhost:8000/' }) self.assertFalse(form.is_valid()) form = ClientForm({ 'name': 'TestName', 'url': 'http://127.0.0.1:8000', 'redirect_uri': 'http://localhost:8000/', 'client_type': constants.CLIENT_TYPES[0][0] }) self.assertTrue(form.is_valid()) form.save()
def test_client_form(self): form = ClientForm({'name': 'TestName', 'url': 'http://127.0.0.1:8000', 'redirect_uri': 'http://localhost:8000/'}) self.assertFalse(form.is_valid()) form = ClientForm({ 'name': 'TestName', 'url': 'http://127.0.0.1:8000', 'redirect_uri': 'http://localhost:8000/', 'client_type': constants.CLIENT_TYPES[0][0]}) self.assertTrue(form.is_valid()) form.save()
def reg_client2(request): if request.method == 'GET': form = ClientForm() return render_to_response('regclient2.html', {"form": form}, context_instance=RequestContext(request)) elif request.method == 'POST': form = ClientForm(request.POST) if form.is_valid(): client = form.save(commit=False) client.user = request.user client.save() d = { "name": client.name, "app_id": client.client_id, "secret": client.client_secret, "info_message": "Your Client Credentials" } return render_to_response('reg_success.html', d, context_instance=RequestContext(request)) else: return render_to_response('regclient2.html', {"form": form}, context_instance=RequestContext(request))