Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Dashboard SIAE): Réordonner les besoins (derniers publiés en premier) #1098

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ def order_by_deadline_date(self, limit_date=datetime.today()):
"deadline_date_is_outdated_annotated", "deadline_date", "-updated_at"
)

def order_by_last_published(self):
return self.order_by("-published_at", "-updated_at")

def with_question_stats(self):
return self.annotate(question_count_annotated=Count("questions", distinct=True))

Expand Down
14 changes: 11 additions & 3 deletions lemarche/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

date_tomorrow = timezone.now() + timedelta(days=1)
date_next_week = timezone.now() + timedelta(days=7)
date_today = timezone.now() + timedelta(days=7)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

date_today ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrigé ici : 9fb11c5

date_two_days_ago = timezone.now() - timedelta(days=2)
date_last_week = timezone.now() - timedelta(days=7)
date_last_month = timezone.now() - timedelta(days=30)


class TenderModelTest(TestCase):
Expand Down Expand Up @@ -418,9 +420,9 @@ def test_in_perimeters(self):
class TenderModelQuerysetOrderTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.tender_1 = TenderFactory(deadline_date=date_next_week)
cls.tender_2 = TenderFactory(deadline_date=date_tomorrow)
cls.tender_3 = TenderFactory(deadline_date=date_last_week)
cls.tender_1 = TenderFactory(deadline_date=date_next_week, published_at=date_today)
cls.tender_2 = TenderFactory(deadline_date=date_tomorrow, published_at=date_two_days_ago)
cls.tender_3 = TenderFactory(deadline_date=date_last_week, published_at=date_last_month)

def test_default_order(self):
tender_queryset = Tender.objects.all()
Expand All @@ -433,6 +435,12 @@ def test_order_by_deadline_date(self):
self.assertEqual(tender_queryset.first().id, self.tender_2.id)
self.assertEqual(tender_queryset.last().id, self.tender_3.id)

def test_order_by_last_published(self):
tender_queryset = Tender.objects.order_by_last_published()
self.assertEqual(tender_queryset.count(), 3)
self.assertEqual(tender_queryset.first().id, self.tender_1.id)
self.assertEqual(tender_queryset.last().id, self.tender_3.id)


class TenderModelQuerysetStatsTest(TestCase):
@classmethod
Expand Down
2 changes: 1 addition & 1 deletion lemarche/www/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_context_data(self, **kwargs):
if user.kind == User.KIND_SIAE:
siaes = user.siaes.all()
if siaes:
context["last_3_tenders"] = Tender.objects.filter_with_siaes(siaes).order_by_deadline_date()[:3]
context["last_3_tenders"] = Tender.objects.filter_with_siaes(siaes).order_by_last_published()[:3]
else:
context["last_3_tenders"] = Tender.objects.filter(author=user).order_by_deadline_date()[:3]
context["user_buyer_count"] = User.objects.filter(kind=User.KIND_BUYER).count()
Expand Down
Loading