Exemplo n.º 1
0
Arquivo: views.py Projeto: virajh/295b
def handlePharmacy(request, pharmacy_id):

    if request.method == 'GET':
        pharmacy = get_object_or_404(Pharmacy, pharmacy_id=pharmacy_id)
        form = PharmacyForm(instance=pharmacy)
        return render_to_response('erx/new_pharmacy.html', {'pharmacy': pharmacy, 'form': form},
            context_instance=RequestContext(request))

    if request.method == 'POST':
        pharmacy = get_object_or_404(Pharmacy, pharmacy_id=pharmacy_id)
        form = PharmacyForm(request.POST, instance=pharmacy)
        if form.is_valid():
            form.save()
            return pharmacyHome(request, pharmacy=pharmacy_id,
                message="[%s] %s profile successfully updated." % (strftime("%Y-%m-%d %H:%M:%S"), pharmacy))
        else:
            return render_to_response('erx/new_pharmacy.html',
                {'pharmacy': pharmacy, 'form': form,
                 'message': 'Errors: %s' % (form.errors)},
                context_instance=RequestContext(request))
Exemplo n.º 2
0
Arquivo: views.py Projeto: virajh/295b
def createPharmacy(request, user_id):

    if request.method == 'POST':
        form = PharmacyForm(request.POST)

        if form.is_valid():
            instance = form.save()
            myuser = MyUser.objects.get(my_id=user_id)
            myuser.setUser(instance.pharmacy_id)
            myuser.save()
            message = 'Profile for pharmacy %s created.' % (instance)
            return pharmacyHome(request, message=message, pharmacy_id=instance.pharmacy_id)

        else:
            return render_to_response('erx/new_pharmacy.html',
                {'form': PharmacyForm(request.POST),'message': form.errors},
                context_instance=RequestContext(request))

    else:
       if request.method == "GET":
           return render_to_response('erx/new_pharmacy.html', {'form': PharmacyForm}, context_instance=RequestContext(request))