def seed_create(request):
	seed_form = SeedForm()  
	if request.method == 'POST':
		seed_form = SeedForm(request.POST)
		if seed_form.is_valid():

			seed = Seed.objects.create(
				user = request.user,
				seed_type = seed_form.cleaned_data['seed_type'],
				crop_type = seed_form.cleaned_data['crop_type'],
				seed_variety = seed_form.cleaned_data['seed_variety'],
				seed_description = seed_form.cleaned_data['seed_description'],
				enough_to_share = seed_form.cleaned_data['enough_to_share'],
				year = seed_form.cleaned_data['year'],
				origin = seed_form.cleaned_data['origin']
			)
			seed.save()

			update_seed_events(seed, seed_form.cleaned_data['events'])

			return redirect('seedlibrary.views.seed_create_confirm')
		

	return render_to_response('seed-create.html',
		{"seed_form":seed_form},
		context_instance=RequestContext(request))
def seed_edit(request, id):
	seed = get_object_or_404(Seed, pk=id)
	error = None

	if request.method == 'POST':
		form = SeedForm(request.POST)
		if form.is_valid():
			fill_seed_from_form(seed, form)
			seed.save()

			update_seed_events(seed, form.cleaned_data['events'])

			return redirect('seedlibrary.views.seeds')
	else:
		data = {}
		data['seed_type'] = seed.seed_type
		data['crop_type'] = seed.crop_type
		data['seed_variety'] = seed.seed_variety
		data['seed_description'] = seed.seed_description
		data['enough_to_share'] = seed.enough_to_share
		data['year'] = seed.year
		data['origin'] = seed.origin
		e_ids = []
		for e in seed.event_set.all():
			e_ids.append(e.id)
		data['events'] = e_ids

		form = SeedForm(data)

	return render_to_response('seed-edit.html',
		{ "seed":seed, "form": form, "error": error },
        context_instance=RequestContext(request))
Exemple #3
0
def seed_edit(request, id):
    seed = get_object_or_404(Seed, pk=id)
    error = None

    if request.method == 'POST':
        form = SeedForm(request.POST)
        if form.is_valid():
            fill_seed_from_form(seed, form)
            seed.save()

            update_seed_events(seed, form.cleaned_data['events'])

            return redirect('seedlibrary.views.seeds')
    else:
        data = {}
        data['seed_type'] = seed.seed_type
        data['crop_type'] = seed.crop_type
        data['seed_variety'] = seed.seed_variety
        data['seed_description'] = seed.seed_description
        data['enough_to_share'] = seed.enough_to_share
        data['year'] = seed.year
        data['origin'] = seed.origin
        e_ids = []
        for e in seed.event_set.all():
            e_ids.append(e.id)
        data['events'] = e_ids

        form = SeedForm(data)

    return render_to_response('seed-edit.html', {
        "seed": seed,
        "form": form,
        "error": error
    },
                              context_instance=RequestContext(request))
Exemple #4
0
def seed_create(request):
    seed_form = SeedForm()
    if request.method == 'POST':
        seed_form = SeedForm(request.POST)
        if seed_form.is_valid():

            seed = Seed.objects.create(
                user=request.user,
                seed_type=seed_form.cleaned_data['seed_type'],
                crop_type=seed_form.cleaned_data['crop_type'],
                seed_variety=seed_form.cleaned_data['seed_variety'],
                seed_description=seed_form.cleaned_data['seed_description'],
                enough_to_share=seed_form.cleaned_data['enough_to_share'],
                year=seed_form.cleaned_data['year'],
                origin=seed_form.cleaned_data['origin'])
            seed.save()

            update_seed_events(seed, seed_form.cleaned_data['events'])

            return redirect('seedlibrary.views.seed_create_confirm')

    return render_to_response('seed-create.html', {"seed_form": seed_form},
                              context_instance=RequestContext(request))