Created
January 15, 2014 19:07
-
-
Save kennethlove/8442307 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 index(request): | |
if request.method == "GET": | |
return render_to_response('locations/index.html', {'nosearch': True}) | |
elif request.method == "POST": | |
context = {} | |
result = Location.objects.filter(address=request.POST['address']) | |
loc = result.first() | |
context['loc'] = loc | |
context['services'] = _get_services(loc) | |
return render_to_response('locations/services.html', context) | |
def toggle(request, loc_id, service_id): | |
context = {} | |
service = Service.objects.filter(pk=service_id).first() | |
loc = Location.objects.filter(pk=loc_id).first() | |
context['loc'] = loc | |
context['services'] = _get_services(loc) | |
_toggle_service(service) | |
if not service or not loc: | |
raise Http404 | |
return render_to_response('locations/services.html', context) | |
def _toggle_service(service): | |
service.active = (not service.active) | |
service.save() | |
def _get_services(loc): | |
services = [] | |
if loc: | |
for p in loc.port_set.all(): | |
services.extend(p.service_endpoint_a.all()) | |
services.extend(p.service_endpoint_z.all()) | |
return services |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment