Ejemplo n.º 1
0
def create_vendor_account(request):
    scenario = 'Create'
    party = Party()
    party.type = 'Supplier'
    for query in request.GET:
        setattr(party, query, request.GET[query])
    if request.POST:
        form = PartyForm(data=request.POST, instance=party)
        if form.is_valid():
            party = form.save(commit=False)
            party.company = request.company
            party.save()
            if request.is_ajax():
                return render(request, 'callback.html', {'obj': CashVendorSerializer(party.supplier_account).data})
            redirect('/ledger/parties')
    else:
        form = PartyForm(instance=party)
        form.fields['type'].widget = form.fields['type'].hidden_widget()
        form.fields['type'].label = ''
        form.hide_field(request)
    if request.is_ajax():
        base_template = 'modal.html'
    else:
        base_template = 'dashboard.html'
    return render(request, 'party_form.html', {
        'form': form,
        'scenario': scenario,
        'base_template': base_template,
    })
Ejemplo n.º 2
0
def edit_party(request, party_id):
    party = get_object_or_404(Party, id = party_id, creator = request.user)
    
    if request.method == 'POST':
        form = PartyForm(request.POST, instance = party)
        if form.is_valid():
            party = form.save()
            if 'save_send' in request.POST:
                if party.invite_type == 'email':
                    return redirect('email_invite', party_id = party.id)
                else:
                    return redirect('sms_invite', party_id = party.id)  
            else:
                if 'sms_invite' in request.POST:
                    return redirect('sms_invite', party_id = party.id)
                elif 'email_invite' in request.POST:
                    return redirect('email_invite', party_id = party.id)
                else:
                    return redirect('list_party')
        else:
            
            return TemplateResponse(request, 'parties/edit_party.html', {'form': form, 'party': party})       
    else:
        if party.start_date:
            party.start_date = datetime.date.strftime(party.start_date, '%Y-%m-%d')
        if party.start_time:
            party.start_time = datetime.time.strftime(party.start_time, '%H:%M')
        form = PartyForm(instance = party)
        
    return TemplateResponse(request, 'parties/edit_party.html', {'form': form, 'party': party})
Ejemplo n.º 3
0
def party_form(request, id=None):
    if id:
        scenario = 'Update'
        party = get_object_or_404(Party, id=id, company=request.company)
    else:
        scenario = 'Create'
        party = Party()
    for query in request.GET:
        setattr(party, query, request.GET[query])
    if request.POST:
        form = PartyForm(data=request.POST, instance=party)
        if form.is_valid():
            party = form.save(commit=False)
            party.company = request.company
            party.save()
            if request.is_ajax():
                return render(request, 'callback.html', {'obj': PartySerializer(party).data})
            redirect('/ledger/parties')
    else:
        form = PartyForm(instance=party)
        form.hide_field(request)
    if request.is_ajax():
        base_template = 'modal.html'
    else:
        base_template = 'dashboard.html'
    return render(request, 'party_form.html', {
        'form': form,
        'scenario': scenario,
        'base_template': base_template,
    })
Ejemplo n.º 4
0
def create_party(request):
    if request.method == 'POST':
        form = PartyForm(request.POST)
        if form.is_valid():
            party = form.save(commit = False)
            party.creator = request.user
            party.save()
            
            if 'sms_invite' in request.POST:
                return redirect('sms_invite', party_id = party.id)
            elif 'email_invite' in request.POST:
                return redirect('email_invite', party_id = party.id)
            else:
                return redirect('list_party')
        else:
            
            return TemplateResponse(request, 'parties/create_party.html', {'form': form})   
                
    else:
        form = PartyForm()
    
    return TemplateResponse(request, 'parties/create_party.html', {'form': form})