Ejemplo n.º 1
0
def addvolunteer(request):
    if request.POST:
            form = VolunteerForm(request.POST)
            if form.is_valid():
                form.save()
                messages.success(request, 'Volunteer added!')
                return HttpResponseRedirect('/volunteers/')
    else:
        form = VolunteerForm()

    return render(request, 'addvolunteer.html', locals())
Ejemplo n.º 2
0
def addvolunteer(request):
    if request.POST:
        form = VolunteerForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, 'Volunteer added!')
            return HttpResponseRedirect('/volunteers/')
    else:
        form = VolunteerForm()

    return render(request, 'addvolunteer.html', locals())
Ejemplo n.º 3
0
def volunteer_apply(request, user_id):
    # before register volunteer, the user must be the system's user
    template_name = "volunteer/apply_volunteer.html"
    data = {}
    if request.method == "GET":
        volunteer_model = Volunteer.objects.filter(user_id=user_id)
        if volunteer_model:
            data["volunteer_form"] = VolunteerForm(instance=volunteer_model[0])
        else:
            data["volunteer_form"] = VolunteerForm()
        return render_to_response(template_name,
                                  data,
                                  context_instance=RequestContext(request))
    else:  # POST
        volunteer_form = VolunteerForm(request.POST, request.FILES)
        if volunteer_form.is_valid():
            volunteer_model = Volunteer.objects.filter(user_id=user_id)
            if len(volunteer_model) > 0:
                data["message"] = "您的申请已修改。请等待管理员联系。 谢谢您的参与!"
                volunteer_model = VolunteerForm(
                    instance=volunteer_model[0]).save(commit=False)
            else:
                data["message"] = "您的申请已递交,请等待管理员联系。 谢谢您的参与!"
                volunteer_model = volunteer_form.save(commit=False)

            if volunteer_form.cleaned_data.get("headshot"):
                utils.handle_upload_file(request.FILES["headshot"],
                                         "hs_" + user_id + ".jpeg",
                                         MEDIA_ROOT + '/headshot/')
                volunteer_model.headshot = "/media/headshot/" + "hs_" + user_id + ".jpeg"
            volunteer_model.free_time = request.POST.get("free_time")
            volunteer_model.user_id = user_id
            volunteer_model.status = '10'
            volunteer_model.volunteer_type = '01'

            volunteer_model.save()
            data["volunteer_form"] = volunteer_form

        else:
            data["volunteer_form"] = volunteer_form

        return render_to_response(template_name,
                                  data,
                                  context_instance=RequestContext(request))
Ejemplo n.º 4
0
def editvolunteer(request, volunteer_id):
    vol = get_object_or_404(Volunteer, pk=volunteer_id)
    t = "Edit"
    tasks = Task.objects.filter(volunteers__id=volunteer_id)

    if request.POST:
        form = VolunteerForm(request.POST, instance=vol)
        if form.is_valid():
            form.save()
            messages.success(request, 'Updated!')
            return HttpResponseRedirect('/volunteers/')

    else:
        form = VolunteerForm(instance=vol)

    return render_to_response("editvolunteer.html", {
        'form': form,
        't': t,
        'vol': vol,
        'tasks': tasks,
    }, context_instance=RequestContext(request))
Ejemplo n.º 5
0
def editvolunteer(request, volunteer_id):
    vol = get_object_or_404(Volunteer, pk=volunteer_id)
    t = "Edit"
    tasks = Task.objects.filter(volunteers__id=volunteer_id)

    if request.POST:
        form = VolunteerForm(request.POST, instance=vol)
        if form.is_valid():
            form.save()
            messages.success(request, 'Updated!')
            return HttpResponseRedirect('/volunteers/')

    else:
        form = VolunteerForm(instance=vol)

    return render_to_response("editvolunteer.html", {
        'form': form,
        't': t,
        'vol': vol,
        'tasks': tasks,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 6
0
def volunteer_apply(request, user_id):
    # before register volunteer, the user must be the system's user
    template_name = "volunteer/apply_volunteer.html"
    data = {}
    if request.method == "GET":
        volunteer_model = Volunteer.objects.filter(user_id=user_id)
        if volunteer_model:
            data["volunteer_form"] = VolunteerForm(instance=volunteer_model[0])
        else:
            data["volunteer_form"] = VolunteerForm()
        return render_to_response(template_name, data,
                                  context_instance=RequestContext(request))
    else:  # POST
        volunteer_form = VolunteerForm(request.POST, request.FILES)
        if volunteer_form.is_valid():
            volunteer_model = Volunteer.objects.filter(user_id=user_id)
            if len(volunteer_model) > 0:
                data["message"] = "您的申请已修改。请等待管理员联系。 谢谢您的参与!"
                volunteer_model = VolunteerForm(instance=volunteer_model[0]).save(commit=False)
            else:
                data["message"] = "您的申请已递交,请等待管理员联系。 谢谢您的参与!"
                volunteer_model = volunteer_form.save(commit=False)

            if volunteer_form.cleaned_data.get("headshot"):
                utils.handle_upload_file(request.FILES["headshot"], "hs_" + user_id + ".jpeg", MEDIA_ROOT + '/headshot/')
                volunteer_model.headshot = "/media/headshot/" + "hs_" + user_id + ".jpeg"
            volunteer_model.free_time = request.POST.get("free_time")
            volunteer_model.user_id = user_id
            volunteer_model.status = '10'
            volunteer_model.volunteer_type = '01'

            volunteer_model.save()
            data["volunteer_form"] = volunteer_form

        else:
            data["volunteer_form"] = volunteer_form

        return render_to_response(template_name, data, context_instance=RequestContext(request))
Ejemplo n.º 7
0
def add_volunteer(request):
	#Get the context from the request
	context = RequestContext(request)

	# A HTTP
	if request.method == "POST":
		form = VolunteerForm(request.POST)
	# Have we been provided with a valid form?
		if form.is_valid():
		#Save the new volunteer to the database
			form.save()
		#now call the volunteer() view
		#the user will be shown the volunteer page
			return volunteer(request)
		else:
			print form.errors

	else:
		# The supplied form contained errors - just print them to the terminal
		form = VolunteerForm()

	# Bad form (or form details), no form supplied...
	# Render the form with error messages (if any)
	return render_to_response('add_volunteer.html', {'form': form}, context)