def edit(request): forms = [] if request.user.role.name == "client": client = Client.objects.get(user=request.user) forms.append(ClientForm(request.POST or None, instance=client)) elif request.user.role.name == "partner": partner = Partner.objects.get(user=request.user) forms.append(PartnerForm(request.POST or None, instance=partner)) user_form = UserForm(request.POST or None, instance=request.user) forms += [user_form, PasswordForm] if request.method == "GET": return render(request, "shared/editor.html", { "forms": forms, "index_link": reverse("index") }) elif request.method == "POST": password_form = PasswordForm(request.POST) additional = True if request.user.role.name == "client": client = Client.objects.get(user=request.user) form = ClientForm(request.POST or None, instance=client) forms.append(form) additional = form.is_valid() elif request.user.role.name == "partner": partner = Partner.objects.get(user=request.user) form = PartnerForm(request.POST or None, instance=partner) forms.append(form) additional = form.is_valid() if user_form.is_valid() and password_form.is_valid() and additional: if request.user.role.name in ("client", "partner"): form.save() user = user_form.save(commit=False) password = password_form.cleaned_data.get("password") if password and not user.check_password(password): user.set_password(password) user.save() return redirect("auth:logout") user.save() return redirect("index") else: return render(request, "shared/editor.html", { "forms": forms, "index_link": reverse("index") })
def storeClient(request): if request.method == 'POST': form = ClientForm(request.POST) if form.is_valid(): form.save() return redirect('clients.index') else: return redirect('clients.create')
def add_client(request): if request.method == 'GET': return render(request, 'app/clients/add.html') elif request.method == 'POST': client_form = ClientForm(request.POST) if client_form.is_valid(): client = client_form.save(commit=False) client.from_home = request.POST.get('client_type') == 'home' client.save() return redirect('client', client_id=client.id) else: return render(request, 'app/clients/add.html', {'form': client_form})
def home(request): if request.method == "POST": form = ClientForm(request.POST) if form.is_valid(): global client_id global client_secret global redirect_uri redirect_uri = "http://127.0.0.1:8000/callback" client_id = request.POST["client_id"] client_secret = request.POST["client_secret"] return redirect( "http://join.agiliq.com/oauth/authorize?client_id=" + client_id + "&redirect_uri=" + redirect_uri, request_context=RequestContext(request), ) else: form = ClientForm() return render_to_response("home.html", {"form": form}, context_instance=RequestContext(request))
def edit_client(request, client_id): client = get_object_or_404(Client, pk=client_id) if request.method == 'GET': return render(request, 'app/clients/edit.html', {'client': client}) elif request.method == 'POST': edit_form = ClientForm(request.POST, instance=client) if edit_form.is_valid(): client = edit_form.save(commit=False) client.from_home = request.POST.get('client_type') == 'home' client.save() return redirect('client', client_id=client_id) else: return render(request, 'app/clients/edit.html', { 'client': client, 'form': edit_form })