Created
September 10, 2008 09:15
-
-
Save gijs/9853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getxml(request): | |
"""docstring for getxml""" | |
""" | |
<vars> | |
<prices type="array"> | |
<price count="0" type="int">0</price> | |
<price count="1" type="int">1</price> | |
<price count="2" type="int">2</price> | |
<price count="3" type="int">3</price> | |
<price count="4" type="int">4</price> | |
<price count="5" type="int">5</price> | |
<price count="6" type="int">6</price> | |
</prices> | |
</vars> | |
""" | |
# import pdb | |
# pdb.set_trace() | |
from stupidxml import Node | |
root = Node("vars") | |
prices = root.append(Node("prices", type="array")) | |
distance = request.GET['distance'] | |
volwassenen = request.GET['volwassenen'] | |
kinderen = request.GET['kinderen'] | |
woningtype = request.GET['woningtype'] | |
kamers = request.GET['kamers'] | |
current = request.GET['huidigevraag'] | |
if current == "0": | |
# partnerkeuze | |
try: | |
d = Distance.objects.filter(distance_min__lte=distance).filter(distance_max__gte=distance) | |
v = Volume.objects.filter(volwassenen='1').filter(kinderen=kinderen).filter(woningtype=woningtype).filter(kamers=kamers) | |
print "v: ", v | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="0")) | |
v = Volume.objects.filter(volwassenen='2').filter(kinderen=kinderen).filter(woningtype=woningtype).filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="1")) | |
except: | |
# prices.append(Node("price", "0", type="int", count="0")) | |
pass | |
return HttpResponse(root.dom.toxml("UTF-8")) | |
elif current == "1": | |
# kinderen | |
try: | |
d = Distance.objects.filter(distance_min__lte=distance).filter(distance_max__gte=distance) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen='0').filter(woningtype=woningtype).filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="0")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen='1').filter(woningtype=woningtype).filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="1")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen='2').filter(woningtype=woningtype).filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="2")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen='3').filter(woningtype=woningtype).filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="3")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen='4').filter(woningtype=woningtype).filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="4")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen='5').filter(woningtype=woningtype).filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="5")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen='6').filter(woningtype=woningtype).filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="6")) | |
except: | |
# prices.append(Node("price", "0", type="int", count="0")) | |
pass | |
return HttpResponse(root.dom.toxml("UTF-8")) | |
elif current == "2": | |
# kamers | |
try: | |
d = Distance.objects.filter(distance_min__lte=distance).filter(distance_max__gte=distance) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen=kinderen).filter(woningtype=woningtype).filter(kamers='1') | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="0")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen=kinderen).filter(woningtype=woningtype).filter(kamers='2') | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="1")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen=kinderen).filter(woningtype=woningtype).filter(kamers='3') | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="2")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen=kinderen).filter(woningtype=woningtype).filter(kamers='4') | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="3")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen=kinderen).filter(woningtype=woningtype).filter(kamers='5') | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="4")) | |
except: | |
# prices.append(Node("price", "0", type="int", count="0")) | |
pass | |
return HttpResponse(root.dom.toxml("UTF-8")) | |
elif current == "3": | |
# woningtype | |
try: | |
d = Distance.objects.filter(distance_min__lte=distance).filter(distance_max__gte=distance) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen=kinderen).filter(woningtype='1').filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="0")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen=kinderen).filter(woningtype='2').filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="1")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen=kinderen).filter(woningtype='3').filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="2")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen=kinderen).filter(woningtype='4').filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="3")) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen=kinderen).filter(woningtype='5').filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
prices.append(Node("price", str(p[0]), type="int", count="4")) | |
except Exception, e: | |
# prices.append(Node("price", "0", type="int", count="0")) | |
pass | |
return HttpResponse(root.dom.toxml("UTF-8")) | |
elif current == "4": | |
# distance | |
try: | |
d = Distance.objects.filter(distance_min__lte=distance).filter(distance_max__gte=distance) | |
v = Volume.objects.filter(volwassenen=volwassenen).filter(kinderen=kinderen).filter(woningtype=woningtype).filter(kamers=kamers) | |
p = Price.objects.filter(volume_min__lte=v[0].volume, volume_max__gte=v[0].volume, distance=d[0]) | |
print "d: ", d | |
print "v: ", v | |
print "p: ", p | |
prices.append(Node("price", str(p[0]), type="int", count="0")) | |
except: | |
# prices.append(Node("price", "0", type="int", count="0")) | |
pass | |
return HttpResponse(root.dom.toxml("UTF-8")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment