def test_upload_sshkey(self): form = UserKeyForm( data={'public_key': SSH_PUBLIC_KEY}, instance=self.userkey, ) print(form.is_valid()) self.assertFalse(form.is_valid())
def test_upload_rsakey(self): form = UserKeyForm( data={'public_key': PUBLIC_KEY}, instance=self.userkey, ) self.assertTrue(form.is_valid()) self.assertTrue(form.save())
def post(self, request): form = UserKeyForm(data=request.POST, instance=self.userkey) if form.is_valid(): uk = form.save(commit=False) uk.user = request.user uk.save() messages.success(request, "Your user key has been saved.") return redirect('user:userkey') return render(request, self.template_name, { 'userkey': self.userkey, 'form': form, 'active_tab': 'userkey', })
def userkey_edit(request): try: userkey = UserKey.objects.get(user=request.user) except UserKey.DoesNotExist: userkey = UserKey(user=request.user) if request.method == 'POST': form = UserKeyForm(data=request.POST, instance=userkey) if form.is_valid(): uk = form.save(commit=False) uk.user = request.user uk.save() messages.success(request, u"Your user key has been saved.") return redirect('users:userkey') else: form = UserKeyForm(instance=userkey) return render(request, 'users/userkey_edit.html', { 'userkey': userkey, 'form': form, })