def handlePrescriber(request, prescriber_id): if request.method == 'GET': prescriber = get_object_or_404(Prescriber, prescriber_id=prescriber_id) form = PrescriberForm(instance=prescriber) fields = list(form) p_basic, p_contact = fields[:5], fields[5:] return render_to_response('erx/new_prescriber.html', {'prescriber': prescriber, 'p_basic': p_basic, 'p_contact': p_contact}, context_instance=RequestContext(request)) if request.method == 'POST': prescriber = get_object_or_404(Prescriber, prescriber_id=prescriber_id) form = PrescriberForm(request.POST, instance=prescriber) if form.is_valid(): form.save() return prescriberHome(request, prescriber_id=prescriber_id, message="[%s] Prescriber %s profile modified successfully." % (strftime("%Y-%m-%d %H:%M:%S"), prescriber)) else: fields = list(form) p_basic, p_contact = fields[:5], fields[5:] return render_to_response('erx/new_prescriber.html', {'prescriber': prescriber, 'p_basic': p_basic, 'p_contact': p_contact, 'message': 'Errors: %s ' % (form.errors) }, context_instance=RequestContext(request))
def createPrescriber(request, user_id): if request.method == 'POST': form = PrescriberForm(request.POST) if form.is_valid(): instance = form.save() myuser = MyUser.objects.get(my_id=user_id) myuser.setUser(instance.prescriber_id) myuser.save() message = 'Profile successfully created for Prescriber %s.' % (instance) return prescriberHome(request, prescriber_id=instance.prescriber_id, message=message) else: prescriber = Prescriber() form = PrescriberForm(instance=prescriber) fields = list(form) p_basic, p_contact = fields[:5], fields[5:] return render_to_response('erx/new_prescriber.html', {'message': form.errors, 'prescriber': 'New Prescriber', 'p_basic': p_basic, 'p_contact': p_contact}, context_instance=RequestContext(request)) else: if request.method == "GET": prescriber = Prescriber() form = PrescriberForm(instance=prescriber) fields = list(form) p_basic, p_contact = fields[:5], fields[5:] return render_to_response('erx/new_prescriber.html', {'prescriber': 'New Prescriber', 'p_basic': p_basic, 'p_contact': p_contact}, context_instance=RequestContext(request))