Return the ``model`` object with the passed ``object_id``.  If
    ``object_id`` is None, then return the object whose ``slug_field``
    equals the passed ``slug``.  If ``slug`` and ``slug_field`` are not passed,
    then raise Http404 exception.
423772
def lookup_object(model, object_id, slug, slug_field):
    
    lookup_kwargs = {}
    if object_id:
        lookup_kwargs['%s__exact' % model._meta.pk.name] = object_id
    elif slug and slug_field:
        lookup_kwargs['%s__exact' % slug_field] = slug
    else:
        raise GenericViewError(
            "Generic view must be called with either an object_id or a"
            " slug/slug_field.")
    try:
        return model.objects.get(**lookup_kwargs)
    except ObjectDoesNotExist:
        raise Http404("No %s found for %s"
                      % (model._meta.verbose_name, lookup_kwargs))
933907
def get(self, id):
        
        for obj in self.model.db:
            if obj["id"] == id:
                return self._cast_model(obj)

        return None
1159233
def get_object(self, queryset=None):
        

        schema = manager.get_schema()
        vid = None
        if self.request.GET.get('vid') and self.request.user.is_staff and \
                self.request.user.is_active:
            try:
                schema = 'public'
                vid = int(self.request.GET.get('vid'))
                queryset = self.model.normal.filter(vid=vid)
            except ValueError:
                pass

        with manager.SwitchSchema(schema):
            # Use a custom queryset if provided
            if queryset is None:
                queryset = self.get_queryset()

            # Next, try looking up by primary key.
            pk = self.kwargs.get(self.pk_url_kwarg, None)
            slug = self.kwargs.get(self.slug_url_kwarg, None)
            if pk is not None:
                if vid:
                    queryset = queryset.filter(vid=vid)
                else:
                    queryset = queryset.filter(object_id=pk)

            # Next, try looking up by slug.
            elif slug is not None:
                slug_field = self.get_slug_field()
                queryset = queryset.filter(**{slug_field: slug})

            # If none of those are defined, it's an error.
            else:
                raise AttributeError(u"View %s must be called with "
                                     u"either an object pk or a slug."
                                     % self.__class__.__name__)

            try:
                obj = queryset.get()
            except queryset.model.DoesNotExist:
                raise http.Http404(
                        u"No %(verbose_name)s found matching the query" %
                         {'verbose_name': queryset.model._meta.verbose_name})

        return obj
497487
def object(self, session):
        ''''''
        if not hasattr(self, '_object'):
            pkname = self.model_type._meta.pkname()
            query = session.query(self.model_type).filter(**{pkname:
                                                             self.object_id})
            return query.items(callback=self.__set_object)
        else:
            return self._object
305253
def get_object(self):
        
        obj = super(PublishView, self).get_object()

        if not obj or not hasattr(obj, 'publish'):
            raise http.Http404

        return obj
577157
def get_object(self, request, year, month, day, slug):
        
        return get_object_or_404(Entry, slug=slug,
                                 publication_date__year=year,
                                 publication_date__month=month,
                                 publication_date__day=day)
785017
def instantiate_object_id_field(object_id_class_or_tuple=models.TextField):
    
    if isinstance(object_id_class_or_tuple, (list, tuple)):
        object_id_class, object_id_kwargs = object_id_class_or_tuple
    else:
        object_id_class = object_id_class_or_tuple
        object_id_kwargs = {}

    if not issubclass(object_id_class, models.fields.Field):
        raise TypeError('settings.%s must be a Django model field or (field, kwargs) tuple' % OBJECT_ID_TYPE_SETTING)
    if not isinstance(object_id_kwargs, dict):
        raise TypeError('settings.%s kwargs must be a dict' % OBJECT_ID_TYPE_SETTING)

    return object_id_class(db_index=True, **object_id_kwargs)
297382
def get_object(request, pid):
    """"""
    sciobj = d1_gmn.app.models.ScienceObject.objects.get(pid__did=pid)
    content_type_str = d1_gmn.app.object_format_cache.get_content_type(
        sciobj.format.format
    )
    # Return local or proxied SciObj bytes
    response = django.http.StreamingHttpResponse(
        _get_sciobj_iter(sciobj), content_type_str
    )
    d1_gmn.app.views.headers.add_sciobj_properties_headers_to_response(response, sciobj)
    d1_gmn.app.event_log.log_read_event(pid, request)
    return response
1061505
def generate_slug(self, model_instance):
        """"""
        queryset = model_instance.__class__._default_manager.all()

        # Only count slugs that match current length to prevent issues
        # when pre-existing slugs are a different length.
        lookup = {'%s__regex' % self.attname: r'^.{%s}$' % self.length}
        if queryset.filter(**lookup).count() >= len(self.chars)**self.length:
            raise FieldError("No available slugs remaining.")

        slug = get_random_string(self.length, self.chars)

        # Exclude the current model instance from the queryset used in
        # finding next valid slug.
        if model_instance.pk:
            queryset = queryset.exclude(pk=model_instance.pk)

        # Form a kwarg dict used to impliment any unique_together
        # contraints.
        kwargs = {}
        for params in model_instance._meta.unique_together:
            if self.attname in params:
                for param in params:
                    kwargs[param] = getattr(model_instance, param, None)
        kwargs[self.attname] = slug

        while queryset.filter(**kwargs):
            slug = get_random_string(self.length, self.chars)
            kwargs[self.attname] = slug

        return slug
646904
def get_object(self):
        
        queryset = self.get_queryset()             # Get the base queryset
        queryset = self.filter_queryset(queryset)  # Apply any filter backends
        filter = {}  # pylint: disable=W0622
        for field in self.lookup_fields:
            filter[field] = self.kwargs[field]
        return get_object_or_404(queryset, **filter)
1271837
def get_object_or_none(klass, *args, **kwargs):
    
    queryset = _get_queryset(klass)
    try:
        return queryset.get(*args, **kwargs)
    except:  # noqa: E722
        return None
85171
def get_object(self, **kwargs) ->Model:
        
        queryset = self.filter_queryset(
            queryset=self.get_queryset(**kwargs),
            **kwargs
        )

        # Perform the lookup filtering.
        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field

        assert lookup_url_kwarg in kwargs, (
                'Expected view %s to be called with a URL keyword argument '
                'named "%s". Fix your URL conf, or set the `.lookup_field` '
                'attribute on the view correctly.' %
                (self.__class__.__name__, lookup_url_kwarg)
        )

        filter_kwargs = {self.lookup_field: kwargs[lookup_url_kwarg]}

        obj = get_object_or_404(queryset, **filter_kwargs)
        # TODO check_object_permissions

        return obj
994196
def get_object(self):
        

        if not self.force_add and self.kwargs.get(self.slug_url_kwarg, None):
            return super(FormView, self).get_object()
        else:
            self.queryset = self.get_queryset()

        return None
942311
def fetch_object(self, model_id):
        """"""
        pk_field_instance = getattr(self.object_class, self.pk_field)
        qs = self.object_class.query.filter(pk_field_instance == model_id)
        model = qs.one_or_none()
        if not model:
            raise ReferenceNotFoundError
        return model
1305937
def get(self, id):
        
        try:
            if self.request.headers.get("Id"):
                object_ = yield self.client.find_one({self.request.headers.get("Id"): id})
            else:
                object_ = yield self.client.find_one_by_id(id)

            if object_:
                self.write(object_)
                return

            self.raise_error(404, "%s/%s not found" % (self.object_name, id))

        except InvalidId as ex:
            self.raise_error(400, message="Your ID is malformed: %s" % id)
        except Exception as ex:
            self.logger.error(ex)
            self.raise_error()
454556
def get(self, obj, id, sub_object=None):
        
        self.url = '{}{}/{}'.format(self.base_url, obj, id)
        self.method = 'GET'
        if sub_object:
            self.url += '/' + sub_object
        self.resp = requests.get(url=self.url, auth=self.auth,
                                 headers=self.headers, cert=self.ca_cert)
        if self.__process_resp__(obj):
            return self.res
        return False
433120
def retrieve(self, request, *args, **kwargs):
        

        try:
            instance = self.get_object()
            serializer = self.get_serializer(instance)
            return Response(serializer.data)
        except Http404:
            pass

        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
        slug = self.kwargs[lookup_url_kwarg]

        # fall back to accession_temp_fallback
        try:
            tmp = get_object_or_404(
                self.queryset, accession_temp_fallback=slug)
            return HttpResponseRedirect(
                reverse(self.redirect_view_name, (tmp.slug, ))
            )
        except (Http404, FieldError):
            pass

        # fall back to embark ID
        try:
            embark = get_object_or_404(self.queryset, id=int(slug))
            return HttpResponseRedirect(
                reverse(self.redirect_view_name, (embark.slug, ))
            )
        except (Http404, ValueError):
            pass

        # fall back to alt slug
        try:
            from glamkit_collections.utils import alt_slugify
            alt_slug = alt_slugify(slug)
            alt = get_object_or_404(self.queryset, alt_slug=alt_slug)
            return HttpResponseRedirect(
                reverse(self.redirect_view_name, (alt.slug, ))
            )
        except Http404:
            pass

        # well, we tried
        raise Http404