-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1559 from DemocracyClub/feature/timestamps
Feature/timestamps
- Loading branch information
Showing
33 changed files
with
374 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django_filters import filterset, filters | ||
|
||
|
||
class LastUpdatedMixin(filterset.FilterSet): | ||
last_updated = filters.IsoDateTimeFilter( | ||
field_name="modified", | ||
lookup_expr="gt", | ||
label="Last updated", | ||
help_text="An ISO datetime", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Generated by Django 2.2.20 on 2021-06-17 14:06 | ||
|
||
from django.db import migrations | ||
import django.utils.timezone | ||
import django_extensions.db.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("candidates", "0069_ballot_voting_system")] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="ballot", | ||
options={ | ||
"get_latest_by": "modified", | ||
"ordering": ("-modified", "-created"), | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name="ballot", | ||
name="created", | ||
field=django_extensions.db.fields.CreationDateTimeField( | ||
auto_now_add=True, | ||
default=django.utils.timezone.now, | ||
verbose_name="created", | ||
), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name="ballot", | ||
name="modified", | ||
field=django_extensions.db.fields.ModificationDateTimeField( | ||
auto_now=True, verbose_name="modified" | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 2.2.20 on 2021-06-17 14:08 | ||
|
||
from django.db import migrations | ||
|
||
from elections.helpers import four_weeks_before_election_date | ||
|
||
|
||
def add_created_date(apps, schema_editor): | ||
Ballot = apps.get_model("candidates", "Ballot") | ||
for ballot in Ballot.objects.select_related("election").iterator(): | ||
ballot.created = four_weeks_before_election_date( | ||
election=ballot.election | ||
) | ||
ballot.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("candidates", "0070_auto_20210617_1506")] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=add_created_date, reverse_code=migrations.RunPython.noop | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.utils import timezone | ||
|
||
from elections.models import Election | ||
from elections import helpers | ||
|
||
|
||
class TestHelpers: | ||
def test_four_weeks_before_election_date(self): | ||
election = Election(election_date=timezone.datetime(2021, 5, 6).date()) | ||
expected = timezone.datetime(2021, 4, 8, 0, 0, 0, tzinfo=timezone.utc) | ||
result = helpers.four_weeks_before_election_date(election=election) | ||
assert result == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from parties.models import Party | ||
from api.next.filters import LastUpdatedMixin | ||
|
||
|
||
class PartyFilter(LastUpdatedMixin): | ||
class Meta: | ||
model = Party | ||
fields = ["last_updated"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from people.models import Person | ||
from api.next.filters import LastUpdatedMixin | ||
|
||
|
||
class PersonFilter(LastUpdatedMixin): | ||
class Meta: | ||
model = Person | ||
fields = ["last_updated"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 2.2.20 on 2021-06-16 15:42 | ||
|
||
from django.db import migrations | ||
import django.utils.timezone | ||
import django_extensions.db.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("people", "0029_default_versions_to_list")] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="person", | ||
name="created", | ||
field=django_extensions.db.fields.CreationDateTimeField( | ||
auto_now_add=True, | ||
default=django.utils.timezone.now, | ||
verbose_name="created", | ||
), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name="person", | ||
name="modified", | ||
field=django_extensions.db.fields.ModificationDateTimeField( | ||
auto_now=True, verbose_name="modified" | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 2.2.20 on 2021-06-16 15:59 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def copy_created_at(apps, schema_editor): | ||
Person = apps.get_model("people", "Person") | ||
for person in Person.objects.iterator(): | ||
person.created = person.created_at | ||
person.save() | ||
|
||
|
||
def copy_created(apps, schema_editor): | ||
Person = apps.get_model("people", "Person") | ||
for person in Person.objects.iterator(): | ||
person.created_at = person.created | ||
person.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("people", "0030_auto_20210616_1642")] | ||
|
||
operations = [ | ||
migrations.RunPython(code=copy_created_at, reverse_code=copy_created) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Generated by Django 2.2.20 on 2021-06-16 16:00 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("people", "0031_copy_created")] | ||
|
||
operations = [ | ||
migrations.RemoveField(model_name="person", name="created_at"), | ||
migrations.RemoveField(model_name="person", name="updated_at"), | ||
] |
Oops, something went wrong.