예제 #1
0
파일: views_topology.py 프로젝트: smbz/vns
def make_ctform(user):
    user_org = user.get_profile().org
    parent_org = user_org.parentOrg
    template_choices = [(t.id, t.name) for t in permissions.get_allowed_templates(user)]
    ipblock_choices = [(t.id, str(t)) for t in permissions.get_allowed_ipblocks(user)]
    class CTForm(forms.Form):
        template = forms.ChoiceField(label='Template', choices=template_choices)
        ipblock = forms.ChoiceField(label='IP Block to Allocate From', choices=ipblock_choices)
        num_to_create = forms.IntegerField(label='# to Create', initial='1')
    return CTForm
예제 #2
0
def topologytemplate_list(request):
    """Shows a list of topology templates, taking into account the user's permissions and
    the template's visibility level."""
    tn = 'vns/topologytemplate_list.html'

    # Get the templates we're allowed to see
    templates = permissions.get_allowed_templates(request.user)

    # Sort by template name
    templates.order_by("name");

    # Convert to a list
    templates = [t for t in templates]

    return direct_to_template(request, tn, {"templates":templates});
예제 #3
0
파일: views_group.py 프로젝트: smbz/vns
def make_ctform(user):
    user_org = user.get_profile().org
    parent_org = user_org.parentOrg
    template_choices = [(t.id, t.name) for t in permissions.get_allowed_templates(user)]
    ipblock_choices = [(t.id, str(t)) for t in permissions.get_allowed_ipblocks(user)]
    class CTForm(forms.Form):
        template = forms.ChoiceField(label='Template', choices=template_choices)
        ipblock = forms.ChoiceField(label='IP Block to Allocate From', choices=ipblock_choices)
        num_to_create = forms.IntegerField(label='# to Create per User', initial='1')
        ip_subnet = forms.IPAddressField(label='IP address subnet to allow', required=False)
        ip_subnet_mask = forms.IntegerField(label='Significant bits in subnet', required=False,
                                      min_value=0, max_value=32)

        def clean_ip_subnet_mask(self):

            # Test if the user provided a subnet mask
            has_subnet_mask = True
            try:
                ip_subnet_mask = self.cleaned_data['ip_subnet_mask']
            except KeyError:
                has_subnet_mask = False
            if ip_subnet_mask == None:
                has_subnet_mask = False

            # Test if they provided a subnet
            has_subnet = True
            try:
                ip_subnet = self.cleaned_data['ip_subnet']
            except KeyError:
                has_subnet = False
            if ip_subnet == '':
                has_subnet = False
            
            # Check that either subnet and mask or provded, or neither
            if has_subnet != has_subnet_mask:
                raise forms.ValidationError("You must provide both a subnet "
                                            "and a mask, or neither.")

            # If we have a mask, make sure it has a correct value
            if has_subnet_mask:
                if ip_subnet_mask < 0 or ip_subnet_mask > 32:
                    raise forms.ValidationError("The subnet mask must be between 0 and "
                                                "32 inclusive")

            return ip_subnet_mask if has_subnet_mask else None

    return CTForm