returns tuple(choices, grouped, ungrouped)

    requires feincms_object for getting content types

    request optionaly for checking permissions, but not required

    grouped = {'web': (id, label, icon)}
339757
def get_grouped_widgets(feincms_object, request=None):
    '''
    '''

    grouped = {}
    ungrouped = []
    choices = []

    for ct in feincms_object._feincms_content_types:
        # Skip cts that we shouldn't be adding anyway
        opts = ct._meta
        # check permissions
        if request and request.user:
            from django.contrib.auth import get_permission_codename
            perm = opts.app_label + "." + \
                get_permission_codename('add', opts)
            if not request.user.has_perm(perm):
                continue

        ct_info = ('.'.join([ct._meta.app_label,
                             ct.__name__.lower()]),
                   ct._meta.verbose_name,
                   ct.get_widget_icon)
        if hasattr(ct, 'optgroup'):
            if ct.optgroup in grouped:
                grouped[ct.optgroup].append(ct_info)
            else:
                grouped[ct.optgroup] = [ct_info]
        else:
            ungrouped.append(ct_info)
        choices.append(ct_info)

    return choices, grouped, ungrouped
923317
def get_permissions_for_registration(self):
        
        from wagtail.wagtailsnippets.models import SNIPPET_MODELS
        if not self.is_pagemodel and self.model not in SNIPPET_MODELS:
            return self.permission_helper.get_all_model_permissions()
        return Permission.objects.none()
631612
def get_required_permissions(self, request):
        
        perms = []

        if not self.permission_required:
            return perms

        if isinstance(self.permission_required, string_types):
            perms = [self.permission_required, ]
        elif isinstance(self.permission_required, Iterable):
            perms = [perm for perm in self.permission_required]
        else:
            raise ImproperlyConfigured(
                '\'PermissionRequiredMixin\' requires \'permission_required\' '
                'attribute to be set to \'<app_label>.<permission codename>\' but is set to {} '
                'instead'.format(self.permission_required)
            )
        return perms
376129
def get_choices(field):
		
	empty_label = getattr(field.field, "empty_label", False)
	needs_empty_value = False
	choices = []

	# Data is the choices
	if hasattr(field.field, "_choices"):
		choices = field.field._choices

	# Data is a queryset
	elif hasattr(field.field, "_queryset"):
		queryset = field.field._queryset
		field_name = getattr(field.field, "to_field_name") or "pk"
		choices += ((getattr(obj, field_name), str(obj)) for obj in queryset)

	# Determine if an empty value is needed
	if choices and (choices[0][1] == BLANK_CHOICE_DASH[0][1] or choices[0][0]):
		needs_empty_value = True

		# Delete empty option
		if not choices[0][0]:
			del choices[0]

	# Remove dashed empty choice
	if empty_label == BLANK_CHOICE_DASH[0][1]:
		empty_label = None

	# Add custom empty value
	if empty_label or not field.field.required:
		if needs_empty_value:
			choices.insert(0, ("", empty_label or BLANK_CHOICE_DASH[0][1]))

	return choices
768709
def group_list(self, params=None):
        ''' 
        '''
        params = params if params else dict()
        return self.request('/v1/firewall/group_list', params, 'GET')
1120578
def _get_sg_name_dict(self, data, page_size, no_nameconv):
        
        if no_nameconv:
            return {}
        neutron_client = self.get_client()
        search_opts = {'fields': ['id', 'name']}
        if self.pagination_support:
            if page_size:
                search_opts.update({'limit': page_size})
        sec_group_ids = set()
        for rule in data:
            for key in self.replace_rules:
                if rule.get(key):
                    sec_group_ids.add(rule[key])
        sec_group_ids = list(sec_group_ids)

        def _get_sec_group_list(sec_group_ids):
            search_opts['id'] = sec_group_ids
            return neutron_client.list_security_groups(
                **search_opts).get('security_groups', [])

        try:
            secgroups = _get_sec_group_list(sec_group_ids)
        except exceptions.RequestURITooLong as uri_len_exc:
            # Length of a query filter on security group rule id
            # id=<uuid>& (with len(uuid)=36)
            sec_group_id_filter_len = 40
            # The URI is too long because of too many sec_group_id filters
            # Use the excess attribute of the exception to know how many
            # sec_group_id filters can be inserted into a single request
            sec_group_count = len(sec_group_ids)
            max_size = ((sec_group_id_filter_len * sec_group_count) -
                        uri_len_exc.excess)
            chunk_size = max_size // sec_group_id_filter_len
            secgroups = []
            for i in range(0, sec_group_count, chunk_size):
                secgroups.extend(
                    _get_sec_group_list(sec_group_ids[i: i + chunk_size]))

        return dict([(sg['id'], sg['name'])
                     for sg in secgroups if sg['name']])
984790
def get_form_kwargs(self):
        
        update_data ={}
        sfdict = self.filter_class.get_search_fields()
        for fieldname in sfdict:
            try:
                has_multiple = sfdict[fieldname].get('multiple', False)
            except:
                has_multiple = False

            if has_multiple:
                value = self.request.GET.getlist(fieldname, [])
            else:
                value = self.request.GET.get(fieldname, None)

            update_data[fieldname] =  value

        if self.order_field:
            update_data[self.order_field] = self.request.GET.get(self.order_field, None)

        initial = self.get_initial()
        initial.update(update_data)
        kwargs = {'initial': initial }

        if self.groups_for_userlist != None:
            pot_users = User.objects.exclude(id=self.request.user.id)
            if len(self.groups_for_userlist):
                pot_users = pot_users.filter(groups__name__in = self.groups_for_userlist)
            pot_users = pot_users.distinct().order_by('username')
            user_choices = tuple([(user.id, str(user)) for user in pot_users])
            kwargs['user_choices'] = user_choices

        return kwargs
123118
def choices_label(choices: tuple, value) -> str:
    
    for key, label in choices:
        if key == value:
            return label
    return ''
1264690
def get_choices(self):
        
        choices = []
        for label_prefix, templates_dir, template_name_prefix in \
                appsettings.LAYOUT_TEMPLATES:
            source_dir = os.path.join(templates_dir, template_name_prefix)
            # Walk directories, appending a choice for each source file.
            for local, dirs, files in os.walk(source_dir, followlinks=True):
                for source_file in files:
                    template_name = os.path.join(
                        template_name_prefix, source_file)
                    label = '%s: %s' % (label_prefix, source_file)
                    choices.append((template_name, label))
        return choices
372233
def get_choices(self):
        
        choices = []
        for related_object in self.field.model._meta.get_all_related_objects():
            # Django 1.8 deprecated `get_all_related_objects()`. We're still
            # using it for now with the documented work-around for
            # compatibility with Django <=1.7.
            meta = getattr(
                related_object, 'related_model', related_object.model)._meta
            # App default.
            template_name = '%s/layouts/default.html' % meta.app_label
            label = '%s: Default' % meta.app_config.verbose_name
            choices.append((template_name, label))
            # Model default.
            template_name = '%s/%s/layouts/default.html' % (
                meta.app_label,
                meta.model_name,
            )
            label = '%s: %s' % (
                meta.app_config.verbose_name,
                meta.verbose_name.capitalize(),
            )
            choices.append((template_name, label))
            # Polymorphic child model defaults.
            for relation in meta.get_all_related_objects():
                model = getattr(relation, 'related_model', relation.model)
                if issubclass(model, meta.model):
                    template_name = '%s/%s/layouts/%s.html' % (
                        meta.app_label,
                        meta.model_name,
                        model._meta.model_name,
                    )
                    label = '%s: %s' % (
                        meta.app_config.verbose_name,
                        model._meta.verbose_name.capitalize(),
                    )
                    choices.append((template_name, label))
        return choices
1264304
def _get_choices(self, gandi):
        
        iso_codes = []
        dc_codes = []
        for item in gandi.datacenter.list():
            iso_codes.append(item['iso'])
            if item.get('dc_code'):
                dc_codes.append(item['dc_code'])
        return dc_codes + iso_codes
352112
def geturi(self, key, **kwargs):
        

        return self.get(key, cast_func=urlparse, **kwargs)
1307478
def to_choices_dict(choices):
    
    # Allow single, paired or grouped choices style:
    # choices = [1, 2, 3]
    # choices = [(1, 'First'), (2, 'Second'), (3, 'Third')]
    # choices = [('Category', ((1, 'First'), (2, 'Second'))), (3, 'Third')]
    ret = OrderedDict()
    for choice in choices:
        if (not isinstance(choice, (list, tuple))):
            # single choice
            ret[choice] = choice
        else:
            key, value = choice
            if isinstance(value, (list, tuple)):
                # grouped choices (category, sub choices)
                ret[key] = to_choices_dict(value)
            else:
                # paired choice (key, display value)
                ret[key] = value
    return ret
444905
def get_parameters(self):
        
        d = {}
        for k in ['label', 'verbose_name', 'required', 'hint', 'placeholder', 'choices',
            'default', 'validators', 'max_length']:
            d[k] = getattr(self, k)
        return d
1256735
def signature(name: str) -> Optional[Tuple]:
    
    return url_signature(name) if is_url(name) else file_signature(name) if is_file(name) else None
519921
def __getOrganizations(self, web):
        
        orgsElements = web.find_all("a", {"class": "avatar-group-item"})
        self.organizations = len(orgsElements)
1093956
def get_markup_choices():
    
    available_reader_list = []
    module_dir = os.path.realpath(os.path.dirname(__file__))
    module_names = filter(
        lambda x: x.endswith('_reader.py'), os.listdir(module_dir))

    for module_name in module_names:
        markup = module_name.split('_')[0]
        reader = get_reader(markup=markup)

        if reader.enabled is True:
            available_reader_list.append((markup, reader.name))

    return available_reader_list