Exemple #1
0
def create_affiliate(request):
    """
    Allows admin to create a new affiliate, verifies form
    :param request: any request
    :return: a bootstrap form for creating an affiliate
    """
    form = AffiliateForm()
    if request.method == 'POST':
        form = AffiliateForm(request.POST)
        if form.is_valid():
            affiliate = form.save()
            affiliate_message = "<i class='fa fa-check'></i> %s was successfully created." % affiliate.name
            messages.success(request, affiliate_message)
            return redirect('/spudderadmin/affiliates')
    return render(request, 'spudderadmin/pages/affiliates/create.html', {'create_affiliate_form': form})
Exemple #2
0
def edit_affiliate(request, affiliate_id):
    """
    Allows user to edit affiliate information
    :param request: any request
    :param affiliate_id: a valid ID of an Affiliate object
    :return: a bootstrap form filled out for given affiliate
    """
    aff = Affiliate.objects.get(id=affiliate_id)
    form = AffiliateForm(instance=aff)
    if request.method == 'POST':
        form = AffiliateForm(request.POST, instance=aff)
        if form.is_valid():
            affiliate = form.save()
            affiliate_message = "<i class='fa fa-check'></i> %s updated." % affiliate.name
            messages.success(request, affiliate_message)
            return redirect('/spudderadmin/affiliates')
    return render_to_response('spudderadmin/pages/affiliates/edit.html', {'form': form, 'name': aff.name})
Exemple #3
0
def create_affiliate(request):
    """
    Allows admin to create a new affiliate, verifies form
    :param request: any request
    :return: a bootstrap form for creating an affiliate
    """
    form = AffiliateForm()
    if request.method == 'POST':
        form = AffiliateForm(request.POST)
        if form.is_valid():
            affiliate = form.save()
            affiliate_message = "<i class='fa fa-check'></i> %s was successfully created." % affiliate.name
            messages.success(request, affiliate_message)
            return redirect('/spudderadmin/affiliates')
    return render(request, 'spudderadmin/pages/affiliates/create.html',
                  {'create_affiliate_form': form})
Exemple #4
0
def edit_affiliate(request, affiliate_id):
    """
    Allows user to edit affiliate information
    :param request: any request
    :param affiliate_id: a valid ID of an Affiliate object
    :return: a bootstrap form filled out for given affiliate
    """
    aff = Affiliate.objects.get(id=affiliate_id)
    form = AffiliateForm(instance=aff)
    if request.method == 'POST':
        form = AffiliateForm(request.POST, instance=aff)
        if form.is_valid():
            affiliate = form.save()
            affiliate_message = "<i class='fa fa-check'></i> %s updated." % affiliate.name
            messages.success(request, affiliate_message)
            return redirect('/spudderadmin/affiliates')
    return render_to_response('spudderadmin/pages/affiliates/edit.html', {
        'form': form,
        'name': aff.name
    })