From 3b67802b61b6c25d64436f9a9706bb6ccf20c6f5 Mon Sep 17 00:00:00 2001 From: farhan Date: Wed, 12 Feb 2025 21:05:40 +0500 Subject: [PATCH 1/4] changed new business ordering to id --- foundation/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/foundation/views.py b/foundation/views.py index 0cef304de2..a1450f39f5 100644 --- a/foundation/views.py +++ b/foundation/views.py @@ -51,7 +51,7 @@ def get_context_data(self, **kwargs): ) context_data["new_business"] = meeting.business.filter( business_type=models.Business.NEW - ) + ).order_by("id") return context_data From d41fe125a5c5758b27afa3b6edb9d86b52105ea5 Mon Sep 17 00:00:00 2001 From: farhan Date: Wed, 5 Mar 2025 21:24:12 +0500 Subject: [PATCH 2/4] updated tests and created_on based order --- .../migrations/0007_business_created_on.py | 20 ++++++ foundation/models.py | 1 + foundation/tests.py | 70 ++++++++++++++++++- foundation/views.py | 2 +- 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 foundation/migrations/0007_business_created_on.py diff --git a/foundation/migrations/0007_business_created_on.py b/foundation/migrations/0007_business_created_on.py new file mode 100644 index 0000000000..270d96494f --- /dev/null +++ b/foundation/migrations/0007_business_created_on.py @@ -0,0 +1,20 @@ +# Generated by Django 5.1.5 on 2025-03-05 09:18 + +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('foundation', '0006_hardcode_currency_choices'), + ] + + operations = [ + migrations.AddField( + model_name='business', + name='created_on', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + ] diff --git a/foundation/models.py b/foundation/models.py index 598ee21162..2bdc87fb19 100644 --- a/foundation/models.py +++ b/foundation/models.py @@ -207,6 +207,7 @@ class Business(models.Model): meeting = models.ForeignKey( Meeting, related_name="business", on_delete=models.CASCADE ) + created_on = models.DateTimeField(auto_now_add=True) class Meta: ordering = ("title",) diff --git a/foundation/tests.py b/foundation/tests.py index 38569f3756..e706636d22 100644 --- a/foundation/tests.py +++ b/foundation/tests.py @@ -1,4 +1,4 @@ -from datetime import date +from datetime import date, datetime, timedelta from django.contrib.auth.models import User from django.test import TestCase @@ -113,3 +113,71 @@ def test_latest_meeting_minutes(self): self.assertContains(response, "Business item 1") self.assertContains(response, "Business item 2") self.assertContains(response, "Business item 3") + + def test_new_business_ordering(self): + """Test that new business items are ordered by created_on timestamp.""" + meeting = Meeting.objects.create( + date=date(2023, 6, 15), + title="DSF Board monthly meeting", + slug="dsf-board-monthly-meeting", + leader=self.member, + treasurer_report="Treasurer Report", + ) + + # Create business items with explicitly set created_on timestamps + # Item 3 is created first but should appear last due to ordering + common_business_data = { + "body": "Example", + "body_html": "Example", + "business_type": "New", + "meeting": meeting, + } + + # Create items with different timestamps, intentionally out of order + now = datetime.now() + Business.objects.create( + title="Business item 3", + created_on=now - timedelta(hours=2), + **common_business_data + ) + Business.objects.create( + title="Business item 1", + created_on=now - timedelta(hours=4), + **common_business_data + ) + Business.objects.create( + title="Business item 2", + created_on=now - timedelta(hours=3), + **common_business_data + ) + response = self.client.get( + reverse( + "foundation_meeting_detail", + kwargs={ + "year": 2023, + "month": "jun", + "day": 15, + "slug": "dsf-board-monthly-meeting", + }, + ) + ) + + self.assertContains(response, "DSF Board monthly meeting") + + # Check that items appear in the correct order based on created_on + content = response.content.decode() + # Find positions of each business item in the response content + pos1 = content.find("Business item 1") + pos2 = content.find("Business item 2") + pos3 = content.find("Business item 3") + + # Verify that items appear in ascending order by created_on timestamp + self.assertGreater(pos1, 0, "Business item 1 not found in response") + self.assertGreater(pos2, 0, "Business item 2 not found in response") + self.assertGreater(pos3, 0, "Business item 3 not found in response") + self.assertLess( + pos1, pos2, "Business item 1 should appear before Business item 2" + ) + self.assertLess( + pos2, pos3, "Business item 2 should appear before Business item 3" + ) diff --git a/foundation/views.py b/foundation/views.py index a1450f39f5..822fb62f70 100644 --- a/foundation/views.py +++ b/foundation/views.py @@ -51,7 +51,7 @@ def get_context_data(self, **kwargs): ) context_data["new_business"] = meeting.business.filter( business_type=models.Business.NEW - ).order_by("id") + ).order_by("created_on") return context_data From 2fe43a90544c34202bf90008fb1b58f47066997a Mon Sep 17 00:00:00 2001 From: farhan Date: Mon, 19 May 2025 17:56:38 +0500 Subject: [PATCH 3/4] Renamed field 'created_on' to 'created_at' in Business model and removed corresponding migration file. --- ...007_business_created_on.py => 0007_business_created_at.py} | 4 ++-- foundation/models.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename foundation/migrations/{0007_business_created_on.py => 0007_business_created_at.py} (84%) diff --git a/foundation/migrations/0007_business_created_on.py b/foundation/migrations/0007_business_created_at.py similarity index 84% rename from foundation/migrations/0007_business_created_on.py rename to foundation/migrations/0007_business_created_at.py index 270d96494f..17604fd8fd 100644 --- a/foundation/migrations/0007_business_created_on.py +++ b/foundation/migrations/0007_business_created_at.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.5 on 2025-03-05 09:18 +# Generated by Django 5.1.5 on 2025-05-19 07:52 import django.utils.timezone from django.db import migrations, models @@ -13,7 +13,7 @@ class Migration(migrations.Migration): operations = [ migrations.AddField( model_name='business', - name='created_on', + name='created_at', field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), preserve_default=False, ), diff --git a/foundation/models.py b/foundation/models.py index 2bdc87fb19..aff9104f70 100644 --- a/foundation/models.py +++ b/foundation/models.py @@ -207,7 +207,7 @@ class Business(models.Model): meeting = models.ForeignKey( Meeting, related_name="business", on_delete=models.CASCADE ) - created_on = models.DateTimeField(auto_now_add=True) + created_at = models.DateTimeField(auto_now_add=True) class Meta: ordering = ("title",) From 23eb48002aeefe2307fbc5dd49733a0bc4500a6e Mon Sep 17 00:00:00 2001 From: farhan Date: Mon, 19 May 2025 20:15:05 +0500 Subject: [PATCH 4/4] Updated tests and views to reflect the renaming of the 'created_on' field to 'created_at' in the Business model, ensuring consistent ordering of business items. --- foundation/tests.py | 14 +++++++------- foundation/views.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/foundation/tests.py b/foundation/tests.py index e706636d22..7133af5dae 100644 --- a/foundation/tests.py +++ b/foundation/tests.py @@ -115,7 +115,7 @@ def test_latest_meeting_minutes(self): self.assertContains(response, "Business item 3") def test_new_business_ordering(self): - """Test that new business items are ordered by created_on timestamp.""" + """Test that new business items are ordered by created_at timestamp.""" meeting = Meeting.objects.create( date=date(2023, 6, 15), title="DSF Board monthly meeting", @@ -124,7 +124,7 @@ def test_new_business_ordering(self): treasurer_report="Treasurer Report", ) - # Create business items with explicitly set created_on timestamps + # Create business items with explicitly set created_at timestamps # Item 3 is created first but should appear last due to ordering common_business_data = { "body": "Example", @@ -137,17 +137,17 @@ def test_new_business_ordering(self): now = datetime.now() Business.objects.create( title="Business item 3", - created_on=now - timedelta(hours=2), + created_at=now - timedelta(hours=2), **common_business_data ) Business.objects.create( title="Business item 1", - created_on=now - timedelta(hours=4), + created_at=now - timedelta(hours=4), **common_business_data ) Business.objects.create( title="Business item 2", - created_on=now - timedelta(hours=3), + created_at=now - timedelta(hours=3), **common_business_data ) response = self.client.get( @@ -164,14 +164,14 @@ def test_new_business_ordering(self): self.assertContains(response, "DSF Board monthly meeting") - # Check that items appear in the correct order based on created_on + # Check that items appear in the correct order based on created_at content = response.content.decode() # Find positions of each business item in the response content pos1 = content.find("Business item 1") pos2 = content.find("Business item 2") pos3 = content.find("Business item 3") - # Verify that items appear in ascending order by created_on timestamp + # Verify that items appear in ascending order by created_at timestamp self.assertGreater(pos1, 0, "Business item 1 not found in response") self.assertGreater(pos2, 0, "Business item 2 not found in response") self.assertGreater(pos3, 0, "Business item 3 not found in response") diff --git a/foundation/views.py b/foundation/views.py index 822fb62f70..202c35169b 100644 --- a/foundation/views.py +++ b/foundation/views.py @@ -51,7 +51,7 @@ def get_context_data(self, **kwargs): ) context_data["new_business"] = meeting.business.filter( business_type=models.Business.NEW - ).order_by("created_on") + ).order_by("created_at") return context_data