Example #1
0
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']})
            })
Example #2
0
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 +'/')
Example #3
0
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 +'/')
Example #4
0
def admin_record_account_share_delete(request, record_id, account_id):
    record = IndivoRecord(record_id=record_id)
    account = IndivoAccount(account_id=account_id, new=False)
    success = record.remove_fullshare_with(account)
    if not success:
        # TODO
        raise Exception("couldn't delete share!")
    
    return redirect('/admin/record/' + record_id + '/')
Example #5
0
def admin_record_create(request):
    form = RecordForm(request.POST) 
    if form.is_valid(): 
        # Process the data in form.cleaned_data
        contact_data = copy.copy(form.cleaned_data)
        contact_data['phone_numbers'] = [contact_data['phone_number']]
        del contact_data['phone_number']
        contact_obj = IndivoContact(contact_data)

        try:
            default_account = IndivoAccount.DEFAULT()
            record = IndivoRecord.from_contact(contact_obj)
            record.push()
            record.set_owner(default_account)
        except Exception as e:
            # TODO
            raise
        return redirect('/admin/record/' + record.record_id + '/')
    else:
        return render_admin_response(request, 'record_show.html', {
            'record_form': form,
        })  
Example #6
0
def admin_account_retire(request, account_id):
    account = IndivoAccount(account_id=account_id, new=False)
    account.retire()
    return redirect('/admin/account/' + account_id + '/')
Example #7
0
def admin_account_show(request, account_id):
    account = IndivoAccount(account_id=account_id, new=False)
    return render_admin_response(request, 'account.html', {
        'account': account
    })