def editcontact(request, id): contact = Contact.objects.get(id=id) # re-get the contact from the db to make sure it's the current data. if request.method == "POST": form = AddContact(request.POST, instance=contact) if form.is_valid(): # TODO: If state is set and nothing else in the address is set, set the state blank. # Update the contact contact = form.save() # log it in the history contacteditlog(request, contact, "Contact updated.") # return to this form, or to the search results. if request.POST['submit'] == "Save and close": return HttpResponseRedirect("/contacts/search/results") # else, return to this form (meaning, render it as if it hadn't been a post, but with error messages) else: # request.method == GET form = AddContact(instance=contact) cform = form return render_to_response('contacts/edit.html', locals())
def add(request): # initialize session data request.session['newcontacts'] = [] request.session['newcontactscsv'] = [] request.session['existingcontacts'] = [] request.session['existingcontactscsv'] = [] request.session['badcontacts'] = [] request.session['badcontactscsv'] = [] if (request.method == "POST"): form = AddContact(request.POST) if form.is_valid(): # add the contact and redirect to /contacts/new line = copy.deepcopy(form.cleaned_data) savecontact(request, form, line) return HttpResponseRedirect('/contacts/new/') else: form = AddContact() return render_to_response('contacts/add.html', locals())