Custom initial method:
            * ensure node exists and store it in an instance attribute
            * change queryset to return only images of current node
359416
def initial(self, request, *args, **kwargs):
        
        super(NodeImageList, self).initial(request, *args, **kwargs)
        # ensure node exists
        self.node = get_queryset_or_404(
            Node.objects.published().accessible_to(request.user),
            {'slug': self.kwargs['slug']}
        )
        # check permissions on node (for image creation)
        self.check_object_permissions(request, self.node)
365539
def __initial_minus_queryset(self):
        
        queryset = self.get_queryset()

        def initial_not_in_queryset(initial):
            for x in queryset:
                if x.slot == initial['slot']:
                    return False

            return True

        return list(filter(initial_not_in_queryset, self._initial))
839476
def get_queryset(self):
        
        queryset = super(UpdateImageView, self).get_queryset()
        queryset = queryset.filter(user=self.user)
        return queryset
704861
def update_instance(self):
        """"""

        # NOTE: django model form has a save method - not applicable here,
        # since an XmlObject by itself is not expected to have a save method
        # (only likely to be saved in context of a fedora or exist object)

        if hasattr(self, 'cleaned_data'):   # possible to have an empty object/no data

            opts = self._meta

            # NOTE: _fields doesn't seem to order, which is
            # problematic for some xml (e.g., where order matters for validity)

            # use field order as declared in the form for update order
            # when possible.
            # (NOTE: this could be problematic also, since display order may
            # not always be the same as schema order)
            fields_in_order = []
            if hasattr(self.Meta, 'fields'):
                fields_in_order.extend(self.Meta.fields)
                fields_in_order.extend([name for name in six.iterkeys(self.instance._fields)
                                        if name in self.Meta.fields])
            else:
                fields_in_order = self.instance._fields.keys()

            for name in fields_in_order:
            # for name in self.instance._fields.iterkeys():
            # for name in self.declared_fields.iterkeys():
                if opts.fields and name not in opts.parsed_fields.fields:
                    continue
                if opts.exclude and name in opts.parsed_exclude.fields:
                    continue
                if name in self.cleaned_data:
                    # special case: we don't want empty attributes and elements
                    # for fields which returned no data from the form
                    # converting '' to None and letting XmlObject handle
                    if self.cleaned_data[name] == '':
                        self.cleaned_data[name] = None
                    setattr(self.instance, name, self.cleaned_data[name])

            # update sub-model portions via any subforms
            for name, subform in six.iteritems(self.subforms):
                self._update_subinstance(name, subform)
            for formset in six.itervalues(self.formsets):
                formset.update_instance()
        return self.instance
246642
def _get_instance(self, **kwargs):
        '''
        '''
        return session.query(self.response_class).filter_by(**kwargs).first()
984501
def convert_to_node(instance, xml_node: XmlNode, node_globals: InheritedDict = None)\
    -> InstanceNode:
    ''''''
    return InstanceNode(instance, xml_node, node_globals)
777435
def _visit_or_none(node, attr, visitor, parent, visit="visit", **kws):
    
    value = getattr(node, attr, None)
    if value:
        return getattr(visitor, visit)(value, parent, **kws)

    return None
1076804
def avail_images(call=None):
    '''
    
    '''
    all_servers = list_nodes_full()
    templates = {}
    for server in all_servers:
        if server["IsTemplate"]:
            templates.update({"Template Name": server["Name"]})
    return templates
897032
def queryset(self, request, queryset):
        
        if self.value():
            parent = Question.objects.get(slug=self.value())
            return Choice.objects.child_of(parent).order_by('-id')
        return queryset
1319360
def locate(self, image):
        
        from .entity import Image
        if not isinstance(image, Image):
            raise TypeError('image must be a sqlalchemy_imageattach.entity.'
                            'Image instance, not ' + repr(image))
        url = self.get_url(image.object_type, image.object_id,
                           image.width, image.height, image.mimetype)
        if '?' in url:
            fmt = '{0}&_ts={1}'
        else:
            fmt = '{0}?_ts={1}'
        return fmt.format(url, image.created_at.strftime('%Y%m%d%H%M%S%f'))
27904
def main():
    

    parser = argparse.ArgumentParser(description='Run SSOIS and return the available images in a particular filter.')

    parser.add_argument("--filter",
                        action="store",
                        default='r',
                        dest="filter",
                        choices=['r', 'u'],
                        help="Passband: default is r.")
    parser.add_argument("--family", '-f',
                        action="store",
                        default=None,
                        help='List of objects to query.')
    parser.add_argument("--member", '-m',
                        action="store",
                        default=None,
                        help='Member object of family to query.')

    args = parser.parse_args()

    if args.family != None and args.member == None:
        get_family_info(str(args.family), args.filter)
    elif args.family == None and args.member != None:
        get_member_info(str(args.member), args.filter)
    else:
        print "Please input either a family or single member name"
1253683
def initial(self, request, *args, **kwargs):
        
        super(NodeLinkList, self).initial(request, *args, **kwargs)
        # ensure node exists
        try:
            self.node = Node.objects.published()\
                                    .accessible_to(request.user)\
                                    .get(slug=self.kwargs.get('slug', None))
        except Node.DoesNotExist:
            raise Http404(_('Node not found.'))
        # check permissions on node (for link creation)
        self.check_object_permissions(request, self.node)
        # return only links of current node
        self.queryset = Link.objects.select_related('node_a', 'node_b')\
                                    .accessible_to(self.request.user)\
                                    .filter(Q(node_a_id=self.node.id) |
                                            Q(node_b_id=self.node.id))
939565
def for_object(self, instance, flag=''):
        
        check(instance)
        content_type = ContentType.objects.get_for_model(instance).pk
        queryset = self.filter(content_type=content_type, object_id=instance.pk)
        if flag:
            queryset = queryset.filter(flag=flag)
        return queryset
656776
def original(self):
        
        images = self.query._original_images(**self.identity_map)
        if images:
            return images[0]
430391
function ImageNode(src, func, inBrowserCache) {
                this.loaded = undefined;
                this.loading = true;

                if (!inBrowserCache) {
                    this.node = new Image();
                    this.bind(func);
                    this.node.src = src;
                }
                else {
                    this.__onload(func, true);
                }

            }
1292896
def queryset(self, request, queryset):
        
        if self.value():
            try:
                section = SectionPage.objects.get(id=self.value())
                return queryset.child_of(section).all()
            except (ObjectDoesNotExist, MultipleObjectsReturned):
                return None
1361096
def tree_queryset(value):
    
    from django.db.models.query import QuerySet
    from copy import deepcopy
    if not isinstance(value, QuerySet):
        return value

    qs = value
    qs2 = deepcopy(qs)
    # Reaching into the bowels of query sets to find out whether the qs is
    # actually filtered and we need to do the INCLUDE_ANCESTORS dance at all.
    # INCLUDE_ANCESTORS is quite expensive, so don't do it if not needed.
    is_filtered = bool(qs.query.where.children)
    if is_filtered:
        include_pages = set()
        # Order by 'rght' will return the tree deepest nodes first;
        # this cuts down the number of queries considerably since all ancestors
        # will already be in include_pages when they are checked, thus not
        # trigger additional queries.
        for p in qs2.order_by('rght').iterator():
            if p.parent_id and p.parent_id not in include_pages and p.id not in include_pages:
                ancestor_id_list = p.get_ancestors().values_list('id', flat=True)
                include_pages.update(ancestor_id_list)

        if include_pages:
            qs = qs | qs.model._default_manager.filter(id__in=include_pages)

        qs = qs.distinct()
    return qs