Skip to content

Instantly share code, notes, and snippets.

@gocreating
Created July 28, 2015 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gocreating/9d77c9cb3ce61a0a93ee to your computer and use it in GitHub Desktop.
Save gocreating/9d77c9cb3ce61a0a93ee to your computer and use it in GitHub Desktop.
class SubnetForm(forms.Form):
# ...略
@staticmethod
def int_to_human(address):
# ...略
return ".".join(str(int(part.ljust(8, "0"), 2)) for part in parts)
def get_network_information(self):
return ({
"address": self.int_to_human(address),
"broadcast": self.int_to_human(broadcast),
"cidr": cidr,
"first_host": self.int_to_human(first_host),
"last_host": self.int_to_human(last_host),
"network": self.int_to_human(network),
"num_hosts": num_hosts,
})
from .forms import SubnetForm
@login_required
def ip_use_count(request):
form = SubnetForm(request.POST)
first_host = form.get_network_information().values()[6]
last_host = form.get_network_information().values()[2]
subnet_id = form.get_network_information().values()[0]
broadcast = form.get_network_information().values()[1]
cidr = form.get_network_information().values()[4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment