def admin_record_account_owner_set(request, record_id, account_id): record = IndivoRecord(record_id=record_id) account = IndivoAccount(account_id=account_id, new=False) try: record.set_owner(account) except Exception as e: # TODO raise return redirect('/admin/record/' + record_id +'/')
def admin_record_owner(request, record_id): record = IndivoRecord(record_id = record_id) if request.POST['existing'] == 'False': # Create new Account and set as Owner form = AccountForm(request.POST) if form.is_valid(): # TODO: generate account id account = IndivoAccount(account_id=form.cleaned_data['email'], full_name=form.cleaned_data['full_name'], contact_email=form.cleaned_data['email']) try: account.push() except ValueError as e: append_error_to_form(form, 'email', str(e)) return render_admin_response(request, 'share_add.html', { 'account_form': form, 'account_search_form': AccountForm(), 'record': record, }) account = record.set_owner(account) return redirect('/admin/record/' + record_id +'/') else: return render_admin_response(request, 'owner_set.html', { 'account_form': form, 'account_search_form': AccountForm(), 'record': record }) else: # set existing Account as owner account = [] try: accounts = IndivoAccount.search(full_name=request.POST['full_name'], contact_email=request.POST['email']) except Exception as e: #TODO raise e return render_admin_response(request, 'owner_set.html', { 'record': record, 'accounts': accounts, 'account_search_form': AccountForm(initial={'full_name':request.POST['full_name'], 'email':request.POST['email']}) })