Skip to content

Instantly share code, notes, and snippets.

@gocreating gocreating/forms.py
Created Jul 28, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.