def admin_record_account_share_add(request, record_id, account_id): record = IndivoRecord(record_id=record_id) account = IndivoAccount(account_id=account_id, new=False) try: share = record.create_fullshare_with(account) except Exception as e: # TODO raise return redirect('/admin/record/' + record_id +'/')
def admin_record_share_add(request, record_id): record = IndivoRecord(record_id=record_id) if request.POST['existing'] == 'False': # Create new Account and add Share 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, }) record.create_fullshare_with(account) return redirect('/admin/record/' + record_id +'/') else: return render_admin_response(request, 'share_add.html', { 'account_form': form, 'account_search_form': AccountForm(), 'record': record, }) else: # Add share to existing 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, 'share_add.html', { 'record': record, 'accounts': accounts, 'account_search_form': AccountForm(initial={'full_name':request.POST['full_name'], 'email':request.POST['email']}) })