def biz_edit(request, biz_id, template_name="biz/biz_edit.html"):
    """ Page that renders the current businesses Information form. 
    Clients can set their relevant info via the forms provided.
    """
    biz = get_object_or_404(Business, pk=biz_id)
    form = BusinessForm(request.POST or None, instance=biz)

    if form.is_valid():
        biz = form.save(commit=False)
        biz.members.add(request.user.id)
        biz.save()
        messages.success(request, _("Your business was edited successfully."), fail_silently=True)
        return redirect("biz_details", biz_id=biz_id)

    context = {"page_name": "biz_edit", "user_id": request.user.id, "biz_id": biz_id, "form": form, "biz": biz}
    return render(request, template_name, context)
def biz_new(request, template_name="biz/biz_create.html"):
    """ Page for clients to create a new business.
    """
    # check to see if a business is already associated with this user
    # and if it is then redirect to that businesses page
    biz_list = Business.objects.filter(members__exact=request.user.id)
    if biz_list:
        return redirect("biz_details", biz_id=biz_list[0].id)

    if request.method == "POST":
        form = BusinessForm(request.POST)

        if form.is_valid():
            biz = form.save()
            biz.members.add(request.user.id)
            biz.save()
            messages.success(request, _("Your business has been created."), fail_silently=True)
            return redirect("biz_details", biz_id=biz.id)
    else:
        # render the business form
        form = BusinessForm()

    context = {"user_id": request.user.id, "form": form}
    return render(request, template_name, context)