def view_delete_address(self, request, vrf_id, afi, address): """ Delete address """ # Validate vrf = self.get_object_or_404(VRF, id=int(vrf_id)) if (afi == "4" and not vrf.afi_ipv4) or (afi == "6" and not vrf.afi_ipv6): return self.response_forbidden("Invalid AFI") address = self.get_object_or_404(Address, vrf=vrf, afi=afi, address=address) if not PrefixAccess.user_can_change(request.user, vrf, afi, address.address): return self.response_forbidden() # Check not in locked range if AddressRange.address_is_locked(vrf, afi, address.address): self.message_user(request, _( "Address %(address)s is in the locked range") % { "address": address.address}) return self.response_redirect( "ip:ipam:vrf_index", vrf.id, afi, address.prefix.prefix) # Delete prefix = address.prefix address.delete() # Redirect self.message_user(request, _("Address %(address)s deleted") % { "address": address.address}) return self.response_redirect("ip:ipam:vrf_index", vrf.id, afi, prefix.prefix)
def queryset(self, request, query=None): qs = super(PrefixApplication, self).queryset(request, query=query) return qs.filter(PrefixAccess.read_Q(request.user))
def can_delete(self, user, obj): return PrefixAccess.user_can_change(user, obj.vrf, obj.afi, obj.prefix)
def queryset(self, request, query=None): qs = super(AddressApplication, self).queryset(request, query=query) return qs.filter( PrefixAccess.read_Q(request.user, field="address", table="ip_address"))