Esempio n. 1
0
 def get_context_data(self, **kwargs):
     context = super(ProjectView, self).get_context_data(**kwargs)
     project = self.get_project()
     context.update({
         "project": project,
         "tickets": improve_queryset_consistency(project.tickets.all())
     })
     return context
Esempio n. 2
0
 def get_context_data(self, **kwargs):
     context = super(ProjectView, self).get_context_data(**kwargs)
     project = self.get_project()
     context.update({
         "project":
         project,
         "tickets":
         improve_queryset_consistency(project.tickets.all())
     })
     return context
 def test_newly_created_objects_returned(self):
     existing = TestModel.objects.create(name='existing')
     queryset = TestModel.objects.all()
     self.assertItemsEqual(queryset.all(), [existing])
     # Add a new object with eventual consistency being slow
     with inconsistent_db():
         new = TestModel.objects.create(name='new')
         # The new object should not yet be returned
         self.assertItemsEqual(queryset.all(), [existing])
         # But using our handy function it should be returned
         consistent = improve_queryset_consistency(queryset)
         self.assertItemsEqual(consistent.all(), [existing, new])
 def test_ordering_retained(self):
     """ Test that using improve_queryset_consistency still retains the ordering. """
     b = TestModel.objects.create(name='B')
     a = TestModel.objects.create(name='A')
     c = TestModel.objects.create(name='C')
     queryset = TestModel.objects.all().order_by('name')
     # To be sure that we test a query which combines the Datastore result with our cache we
     # include some inconsistent_db stuff here...
     with inconsistent_db():
         d = TestModel.objects.create(name='D')
         queryset = improve_queryset_consistency(queryset)
         self.assertEqual(list(queryset), [a, b, c, d])
Esempio n. 5
0
 def test_newly_created_objects_returned(self):
     existing = TestModel.objects.create(name='existing')
     queryset = TestModel.objects.all()
     self.assertItemsEqual(queryset.all(), [existing])
     # Add a new object with eventual consistency being slow
     with inconsistent_db():
         new = TestModel.objects.create(name='new')
         # The new object should not yet be returned
         self.assertItemsEqual(queryset.all(), [existing])
         # But using our handy function it should be returned
         consistent = improve_queryset_consistency(queryset)
         self.assertItemsEqual(consistent.all(), [existing, new])
Esempio n. 6
0
 def test_ordering_retained(self):
     """ Test that using improve_queryset_consistency still retains the ordering. """
     b = TestModel.objects.create(name='B')
     a = TestModel.objects.create(name='A')
     c = TestModel.objects.create(name='C')
     queryset = TestModel.objects.all().order_by('name')
     # To be sure that we test a query which combines the Datastore result with our cache we
     # include some inconsistent_db stuff here...
     with inconsistent_db():
         d = TestModel.objects.create(name='D')
         queryset = improve_queryset_consistency(queryset)
         self.assertEqual(list(queryset), [a, b, c, d])
 def test_deleted_objects_not_returned(self):
     """ When an object is deleted, improve_queryset_consistency should ensure that it is not
         returned.
     """
     obj = TestModel.objects.create(name='A')
     queryset = TestModel.objects.filter(name='A')
     self.assertItemsEqual(queryset.all(), [obj])
     with inconsistent_db():
         obj.delete()
         # The object no longer exists, but the inconsistent db will still return it
         self.assertItemsEqual(queryset.all(), [obj])
         # improve_queryset_consistency to the rescue!
         consistent = improve_queryset_consistency(queryset)
         self.assertEqual(consistent.count(), 0)
Esempio n. 8
0
 def test_deleted_objects_not_returned(self):
     """ When an object is deleted, improve_queryset_consistency should ensure that it is not
         returned.
     """
     obj = TestModel.objects.create(name='A')
     queryset = TestModel.objects.filter(name='A')
     self.assertItemsEqual(queryset.all(), [obj])
     with inconsistent_db():
         obj.delete()
         # The object no longer exists, but the inconsistent db will still return it
         self.assertItemsEqual(queryset.all(), [obj])
         # improve_queryset_consistency to the rescue!
         consistent = improve_queryset_consistency(queryset)
         self.assertEqual(consistent.count(), 0)
Esempio n. 9
0
    def get_context_data(self, **kwargs):
        context = super(ProjectView, self).get_context_data(**kwargs)
        user_id = str(self.request.user.pk)
        project = self.get_project()
        tickets = project.tickets.all()
        tickets = improve_queryset_consistency(tickets)
        tickets = sorted(tickets,
                         key=lambda i: user_id in i.assignees_ids,
                         reverse=True)

        context.update({
            'project': project,
            'tickets': tickets
        })
        return context
Esempio n. 10
0
 def test_newly_modified_objects_returned(self):
     """ If an object which previously did not match the query is modified to now match it, then
         improve_queryset_consistency should include it even when the DB hasn't caught up yet.
     """
     obj = TestModel.objects.create(name='A')
     queryset = TestModel.objects.filter(name='B')
     self.assertEqual(queryset.all().count(), 0)
     with inconsistent_db():
         obj.name = 'B'
         obj.save()
         # The DB is inconsistent, so the queryset should still return nothing
         self.assertEqual(queryset.all().count(), 0)
         # But improve_queryset_consistency should include the object
         consistent = improve_queryset_consistency(queryset)
         self.assertEqual(consistent.all().count(), 1)
 def test_newly_modified_objects_returned(self):
     """ If an object which previously did not match the query is modified to now match it, then
         improve_queryset_consistency should include it even when the DB hasn't caught up yet.
     """
     obj = TestModel.objects.create(name='A')
     queryset = TestModel.objects.filter(name='B')
     self.assertEqual(queryset.all().count(), 0)
     with inconsistent_db():
         obj.name = 'B'
         obj.save()
         # The DB is inconsistent, so the queryset should still return nothing
         self.assertEqual(queryset.all().count(), 0)
         # But improve_queryset_consistency should include the object
         consistent = improve_queryset_consistency(queryset)
         self.assertEqual(consistent.all().count(), 1)
Esempio n. 12
0
    def get_queryset(self):
        qs = super(ProjectListView,
                   self).get_queryset().prefetch_related('tickets')

        qs = improve_queryset_consistency(qs)

        projects = []
        for project in qs:
            inserted = False
            for ticket in project.tickets.all():
                if self.request.user in ticket.assignees.all():
                    projects.insert(0, project)
                    inserted = True
                    break
            if not inserted:
                projects.append(project)

        return projects
Esempio n. 13
0
    def get_queryset(self):
        qs = super(ProjectListView, self).get_queryset().prefetch_related(
            'tickets'
        )

        qs = improve_queryset_consistency(qs)

        projects = []
        for project in qs:
            inserted = False
            for ticket in project.tickets.all():
                if self.request.user in ticket.assignees.all():
                    projects.insert(0, project)
                    inserted = True
                    break
            if not inserted:
                projects.append(project)

        return projects
Esempio n. 14
0
 def get_context_data(self, **kwargs):
     context = super(ProjectDetailView, self).get_context_data(**kwargs)
     context['video_search_form'] = YouTubeVideoSearchForm()
     context['videos'] = improve_queryset_consistency(
         self.object.video_set.all())
     return context
Esempio n. 15
0
 def get_queryset(self):
     return improve_queryset_consistency(
         self.model.objects.filter(project=self.kwargs['project_pk'],
                                   owner=self.request.user))
Esempio n. 16
0
 def get_queryset(self):
     return improve_queryset_consistency(
         self.model.objects.filter(owner=self.request.user))
Esempio n. 17
0
 def get_queryset(self):
     return improve_queryset_consistency(Project.objects.all())
Esempio n. 18
0
 def get_queryset(self):
     return improve_queryset_consistency(
         self.model.objects.filter(video=self.video))