コード例 #1
0
    def add_volunteer_submission():
        # adds a new volunteer with data from volunteer_form and redirects to
        # the dashboard
        form = VolunteerForm()
        if not form.validate_on_submit():
            # if the form has errors, display error messages and resend the
            # current page
            flash('Task could not be created because one or more data fields'
                  ' were invalid:')
            for field, message in form.errors.items():
                flash(message[0])
            return render_template('volunteer_form.html',
                                   form=form,
                                   title="Add a New Volunteer")

        # the form is valid
        name = request.form['name']
        address = request.form['address']
        city = request.form['city']
        state = request.form['state']
        zip_code = request.form['zip_code']
        phone_number = request.form['phone_number']

        new_volunteer = Volunteer(name, address, city, state, zip_code,
                                  phone_number)
        try:
            new_volunteer.insert()
            flash('Volunteer ' + name + ' was successfully added')
        except Exception as e:
            flash('An error occurred.  The Volunteer could not be added')
            abort(422)

        return redirect('/dashboard')
コード例 #2
0
ファイル: postadmin.py プロジェクト: kevnsn/pcmedkit
 def post(self, post_code):
     v = simple_validate({'post_code': post_code})
     if v['valid']:
         f = VolunteerForm(self.request.POST)
         if f.validate():
             new_v = Volunteer(
                 first_name=f.first_name.data,
                 last_name=f.last_name.data,
                 phone=f.phone.data,
                 email=f.email.data,
                 project=f.project.data,
                 sitelocation=f.sitelocation.data,
                 notes=f.notes.data,
                 cos=f.cos.data,
                 trainee_input="",
             )
             new_v.put()
             new_kit = MedKit(
                 date_issued=datetime.now(),
                 in_use=True,
                 delivery_events=[],
                 volunteer=new_v,
                 post_default=v["post_default"],
             )
             new_kit.put()
             v['Volunteer'] = new_v
             v['MedKit'] = new_kit
             html = render.page(self,
                                "templates/postadmin/confirmation.html", v)
             self.response.out.write(html)
         else:
             self.response.out.write(
                 "invalid entry for one of the form items")
     else:
         render.not_found(self)
コード例 #3
0
ファイル: postadmin.py プロジェクト: kevnsn/pcmedkit
 def post(self, post_code):
     v = simple_validate({"post_code": post_code})
     if v["valid"]:
         f = VolunteerForm(self.request.POST)
         if f.validate():
             new_v = Volunteer(
                 first_name=f.first_name.data,
                 last_name=f.last_name.data,
                 phone=f.phone.data,
                 email=f.email.data,
                 project=f.project.data,
                 sitelocation=f.sitelocation.data,
                 notes=f.notes.data,
                 cos=f.cos.data,
                 trainee_input="",
             )
             new_v.put()
             new_kit = MedKit(
                 date_issued=datetime.now(),
                 in_use=True,
                 delivery_events=[],
                 volunteer=new_v,
                 post_default=v["post_default"],
             )
             new_kit.put()
             v["Volunteer"] = new_v
             v["MedKit"] = new_kit
             html = render.page(self, "templates/postadmin/confirmation.html", v)
             self.response.out.write(html)
         else:
             self.response.out.write("invalid entry for one of the form items")
     else:
         render.not_found(self)
コード例 #4
0
ファイル: views.py プロジェクト: tmcintire/backwaterblues
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())
コード例 #5
0
    def update_volunteer_submission(vol_id):
        # updates the volunteer having id = vol_id and returns the updated
        # volunteer to the gui.  Use route /volunteers/vol_id method=PATCH to
        # return the volunteer to the api
        form = VolunteerForm()

        if not form.validate_on_submit():
            # if the form has errors, display error messages and resend the
            # current page
            flash('Volunteer ' + request.form['name'] + ' could not be updated'
                  ' because one or more '
                  'fields were invalid:')
            for field, message in form.errors.items():
                flash(message[0])
            volunteer = form.data
            volunteer['id'] = vol_id
            return render_template('volunteer_form.html',
                                   form=form,
                                   volunteer=volunteer,
                                   title="Update Volunteer")

        # form is valid
        try:
            volunteer = Volunteer.query.get(vol_id)
            form = VolunteerForm(obj=volunteer)
            form.populate_obj(volunteer)
            volunteer.update()
        except Exception as e:
            flash('Volunteer ' + request.form['name'] +
                  ' could not be updated')
            abort(422)

        flash('Volunteer ' + volunteer.name + ' was successfully updated')
        return redirect('/volunteers')
コード例 #6
0
    def update_volunteer_form(vol_id):
        # sends the volunteer_form.html page"
        volunteer = Volunteer.query.get(vol_id)
        form = VolunteerForm(obj=volunteer)

        return render_template('volunteer_form.html',
                               form=form,
                               volunteer=volunteer,
                               title="Update Volunteer")
コード例 #7
0
ファイル: views.py プロジェクト: tmcintire/backwaterblues
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))
コード例 #8
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())
コード例 #9
0
ファイル: views.py プロジェクト: trezp/litcouncil-django
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)
コード例 #10
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))
コード例 #11
0
ファイル: volunteer.py プロジェクト: Allen-yan/Miao
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))
コード例 #12
0
ファイル: postadmin.py プロジェクト: kevnsn/pcmedkit
 def get(self, post_code):
     v = simple_validate({'post_code': post_code})
     if v['valid']:
         v['vf'] = VolunteerForm()
     html = render.page(self, "templates/forms/assign_medkit.html", v)
     self.response.out.write(html)
コード例 #13
0
ファイル: volunteer.py プロジェクト: anjiannian/Miao
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))
コード例 #14
0
 def add_volunteer_form():
     # sends a blank volunteer_form to the gui
     form = VolunteerForm()
     return render_template('volunteer_form.html',
                            form=form,
                            title="Add a New Volunteer")