def get_view_module_or_404(view_type): """Try to import a view module or raise 404.""" if not view_type: raise AdminHttp404("No category provided.") mod = get_view_module(view_type) if not mod: raise AdminHttp404("No category found with this name: %s" % view_type) return mod
def get_volume_or_404(query, for_update=False): volume_obj = Volume.objects.select_for_update if for_update\ else Volume.objects try: return volume_obj.get(pk=int(query)) except (ObjectDoesNotExist, ValueError): raise AdminHttp404( "No Volume was found that matches this query: %s\n" % query)
def get_network_or_404(query, for_update=False): network_obj = Network.objects.select_for_update() if for_update\ else Network.objects try: return network_obj.get(pk=int(query)) except (ObjectDoesNotExist, ValueError): raise AdminHttp404( "No Network was found that matches this query: %s\n" % query)
def get_vm_or_404(query, for_update=False): vm_obj = VirtualMachine.objects.select_for_update() if for_update\ else VirtualMachine.objects try: return vm_obj.get(pk=int(query)) except (ObjectDoesNotExist, ValueError): raise AdminHttp404( "No VM was found that matches this query: %s\n" % query)
def get_project_or_404(query): # Get by UUID try: return Project.objects.get(uuid=query) except ObjectDoesNotExist: pass # Get by ID try: return Project.objects.get(id=query) except (ObjectDoesNotExist, ValueError): raise AdminHttp404( "No Project was found that matches this query: %s\n" % query)
def get_ip_or_404(query): try: return IPAddress.objects.get(address=query) except ObjectDoesNotExist: pass except MultipleObjectsReturned: raise AdminHttp404("""Hm, that's interesting. There are more than one entries for this address: %s""" % query) try: return IPAddress.objects.get(pk=int(query)) except (ObjectDoesNotExist, ValueError): # Check the IPAddressHistory and inform the user that the IP existed at # sometime. msg = "No IP was found that matches this query: %s" % query try: if IPAddressHistory.objects.filter(address=query).exists(): msg = """This IP was deleted. Check the "IP History" tab for more details.""" except ObjectDoesNotExist: pass raise AdminHttp404(msg)
def get_project_or_404(query, for_update=False): project_obj = Project.objects.select_for_update() if for_update\ else Project.objects if isinstance(query, basestring): q = Q(id=int(query)) if query.isdigit() else Q(uuid=query) elif isinstance(query, int) or isinstance(query, long): q = Q(id=int(query)) else: raise TypeError("Unexpected type of query") try: return project_obj.get(q) except ObjectDoesNotExist: raise AdminHttp404( "No Project was found that matches this query: %s\n" % query)
def get_user_or_404(query, for_update=False): """Get AstakosUser from query. The query can either be a user email, UUID or ID. """ usr_obj = AstakosUser.objects.select_for_update() if for_update\ else AstakosUser.objects if isinstance(query, basestring): q = Q(id=int(query)) if query.isdigit() else Q(uuid=query) | Q( email=query) elif isinstance(query, int) or isinstance(query, long): q = Q(id=int(query)) else: raise TypeError("Unexpected type of query") try: return usr_obj.get(q) except ObjectDoesNotExist: raise AdminHttp404("No User was found that matches this query: %s\n" % query)
def get_user_or_404(query): """Get AstakosUser from query. The query can either be a user email, UUID or ID. """ # Get by UUID try: return AstakosUser.objects.get(uuid=query) except ObjectDoesNotExist: pass # Get by Email try: return AstakosUser.objects.get(email=query) except ObjectDoesNotExist: pass # Get by ID try: return AstakosUser.objects.get(id=int(query)) except (ObjectDoesNotExist, ValueError): raise AdminHttp404( "No User was found that matches this query: %s\n" % query)
def get_volume_or_404(query): try: return Volume.objects.get(pk=int(query)) except (ObjectDoesNotExist, ValueError): raise AdminHttp404( "No Volume was found that matches this query: %s\n" % query)
def details(request, query): """Details view for Cyclades ip history.""" raise AdminHttp404("There are no details for any entry of the IP History")
def get_network_or_404(query): try: return Network.objects.get(pk=int(query)) except (ObjectDoesNotExist, ValueError): raise AdminHttp404( "No Network was found that matches this query: %s\n" % query)
def details(request, query): """Details view for Cyclades groups.""" raise AdminHttp404("There are no details for Groups")
def do_action(request, op, id, data): raise AdminHttp404("There are no actions for Groups")