def upload_keepass(request): # If data was submitted if request.method == 'POST': form = KeepassImportForm(request.user, request.POST, request.FILES) # And it is valid if form.is_valid(): # Store the data in the session data = { 'group': form.cleaned_data['group'].id, 'entries': form.cleaned_data['db']['entries'], } request.session['imported_data'] = data # Start the user processing entries return HttpResponseRedirect(reverse('staff.views.import_overview')) else: form = KeepassImportForm(request.user) return render(request, 'staff_keepassimport.html', {'form': form})
def import_from_keepass(request): if request.method == 'POST': form = KeepassImportForm(request.user, request.POST, request.FILES) if form.is_valid(): group = form.cleaned_data['group'] for e in form.cleaned_data['db']['entries']: cred = Cred( title=e['title'], username=e['username'], password=e['password'], description=e['description'], group=group, ) cred.save() CredAudit(audittype=CredAudit.CREDADD, cred=cred, user=request.user).save() for t in e['tags']: (tag, create) = Tag.objects.get_or_create(name=t) cred.tags.add(tag) return HttpResponseRedirect(reverse('staff.views.home')) else: form = KeepassImportForm(request.user) return render(request, 'staff_keepassimport.html', {'form': form})