示例#1
0
文件: views.py 项目: techhat/ConMan
def index(request):
    # First we need to check if the user has already submitted a request and 
    # if so we check to see if a role has been assigned.  If one has not we
    # notify them that their request has already been processed but not 
    # decision has been made.  If a role has been assigned we display it.
    volunteer_existed = False
    profile = request.user.get_profile()

    try:
        instance = Volunteer.objects.get(volunteer=profile)
        volunteer_existed = True
    except Volunteer.DoesNotExist:
        instance = profile

    if request.method == 'POST':
        vf = VolunteerForm(request.POST, instance=instance)
        if vf.is_valid():
            # not as elegant as I'd prefer...  there's gotta be a better way
            page = "volunteer_submitted.html"
            v = Volunteer()
            if volunteer_existed:
                v = instance
                page = "volunteer_updated.html"
            v.requested = vf.cleaned_data['requested']
            v.comments = vf.cleaned_data['comments']
            v.volunteer = profile
            v.save()
            # should send an email at this point
            return render_to_response(page,
                                      context_instance=RequestContext(request))

    else:
        vf = VolunteerForm(instance=instance)

    return render_to_response("call_for_volunteers.html",
                              { "volunteers_form" : vf },
                              context_instance=RequestContext(request))