def newapikey(request): if request.method == 'POST': newkey = ApiKey(user=request.user, active=True) form = ApiKeyForm(request.POST, instance=newkey) if form.is_valid(): form.save() return render(request, 'account_viewapikey.html', {'key': newkey}) else: form = ApiKeyForm() return render(request, 'account_newapikey.html', {'form': form})
def done(self, form_list, **kwargs): login(self.request, self.get_user()) ApiKey.delete_expired(user=self.request.user) newkey = ApiKey(user=self.request.user, active=True, expires=timezone.now() + timedelta(minutes=5)) form = ApiKeyForm({"name": uuid.uuid1()}, instance=newkey) if form.is_valid(): form.save() res = HttpResponse(newkey.key) res.status_code = 200 return res