Esempio n. 1
0
    def test_User(self):
        qs = User.objects.all()
        assert not hasattr(qs, 'approx_count')
        qs2 = add_QuerySetMixin(qs)

        assert hasattr(qs2, 'approx_count')
        assert qs.__class__ != qs2.__class__
        assert qs.__class__ in qs2.__class__.__mro__
Esempio n. 2
0
    def test_ContentType(self):
        qs = ContentType.objects.all()
        assert not hasattr(qs, "approx_count")
        qs2 = add_QuerySetMixin(qs)

        assert hasattr(qs2, "approx_count")
        assert qs.__class__ != qs2.__class__
        assert qs.__class__ in qs2.__class__.__mro__
Esempio n. 3
0
    def test_User(self):
        qs = User.objects.all()
        assert not hasattr(qs, 'approx_count')
        qs2 = add_QuerySetMixin(qs)

        assert hasattr(qs2, 'approx_count')
        assert qs.__class__ != qs2.__class__
        assert qs.__class__ in qs2.__class__.__mro__
Esempio n. 4
0
class DocumentViewSet(viewsets.ReadOnlyModelViewSet):
    """
    list: Service providing a list of all documents in ChemExpoDB, along with
    metadata describing the document. Service also provides the actual data
    points found in, and extracted from, the document. e.g., chemicals and their
    weight fractions may be included for composition documents.
    """

    serializer_class = serializers.DocumentSerializer
    # By using the STRAIGHT_JOIN directive, the query time is reduced
    # from >2 seconds to ~0.0005 seconds. Pretty big! This is due to
    # poor MySQL optimization with INNER JOIN and ORDER BY.
    queryset = (add_QuerySetMixin(
        models.DataDocument.objects.all()).prefetch_related(
            Prefetch(
                "extractedtext__rawchem",
                queryset=models.RawChem.objects.filter(dsstox__isnull=False).
                select_related("dsstox").select_subclasses(),
            ),
            Prefetch("products"),
        ).straight_join().select_related("data_group__group_type",
                                         "document_type").order_by("-id"))