From 83b8e2a861bcf2c366fe91a1fcb2b3f209413ff7 Mon Sep 17 00:00:00 2001 From: Martey Dodoo Date: Sat, 24 Dec 2016 18:18:40 -0500 Subject: [PATCH] Make model DateTime fields timezone aware. Make all Datetime fields in models using `datetime.datetime.now` switch to the timezone-aware `django.utils.timezone.now`. Fields changed include: - reviews.models.Comments.commented_at - reviews.models.LatestVote.submitted_at - reviews.models.ProposalMessage.submitted_at - reviews.models.ResultNotification.timestamp - reviews.models.Review.submitted_at - reviews.models.ReviewAssignment.assigned_at - schedule.models.SessionRole.submitted - speakers.models.Speaker.created - sponsorship.models.Sponsor.added - teams.models.Team.created --- .../0002_make_fields_timezone_aware.py | 46 +++++++++++++++++++ symposion/reviews/models.py | 14 +++--- ...ke_sessionrole_submitted_timezone_aware.py | 21 +++++++++ symposion/schedule/models.py | 3 +- ...003_make_speaker_created_timezone_aware.py | 21 +++++++++ symposion/speakers/models.py | 5 +- .../0003_make_sponsor_added_timezone_aware.py | 21 +++++++++ symposion/sponsorship/models.py | 5 +- .../0002_make_team_created_timezone_aware.py | 21 +++++++++ symposion/teams/models.py | 5 +- 10 files changed, 145 insertions(+), 17 deletions(-) create mode 100644 symposion/reviews/migrations/0002_make_fields_timezone_aware.py create mode 100644 symposion/schedule/migrations/0003_make_sessionrole_submitted_timezone_aware.py create mode 100644 symposion/speakers/migrations/0003_make_speaker_created_timezone_aware.py create mode 100644 symposion/sponsorship/migrations/0003_make_sponsor_added_timezone_aware.py create mode 100644 symposion/teams/migrations/0002_make_team_created_timezone_aware.py diff --git a/symposion/reviews/migrations/0002_make_fields_timezone_aware.py b/symposion/reviews/migrations/0002_make_fields_timezone_aware.py new file mode 100644 index 00000000..6134006f --- /dev/null +++ b/symposion/reviews/migrations/0002_make_fields_timezone_aware.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.12 on 2016-12-25 01:46 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('symposion_reviews', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='comment', + name='commented_at', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Commented at'), + ), + migrations.AlterField( + model_name='latestvote', + name='submitted_at', + field=models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Submitted at'), + ), + migrations.AlterField( + model_name='proposalmessage', + name='submitted_at', + field=models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Submitted at'), + ), + migrations.AlterField( + model_name='resultnotification', + name='timestamp', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Timestamp'), + ), + migrations.AlterField( + model_name='review', + name='submitted_at', + field=models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Submitted at'), + ), + migrations.AlterField( + model_name='reviewassignment', + name='assigned_at', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Assigned at'), + ), + ] diff --git a/symposion/reviews/models.py b/symposion/reviews/models.py index 1419e134..1bb21c04 100644 --- a/symposion/reviews/models.py +++ b/symposion/reviews/models.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from datetime import datetime from decimal import Decimal from django.db import models @@ -8,6 +7,7 @@ from django.db.models.signals import post_save from django.contrib.auth.models import User +from django.utils import timezone from django.utils.translation import ugettext_lazy as _ from symposion.markdown_parser import parse @@ -55,7 +55,7 @@ class ReviewAssignment(models.Model): origin = models.IntegerField(choices=ORIGIN_CHOICES, verbose_name=_("Origin")) - assigned_at = models.DateTimeField(default=datetime.now, verbose_name=_("Assigned at")) + assigned_at = models.DateTimeField(default=timezone.now, verbose_name=_("Assigned at")) opted_out = models.BooleanField(default=False, verbose_name=_("Opted out")) @classmethod @@ -95,7 +95,7 @@ class ProposalMessage(models.Model): message = models.TextField(verbose_name=_("Message")) message_html = models.TextField(blank=True) - submitted_at = models.DateTimeField(default=datetime.now, editable=False, verbose_name=_("Submitted at")) + submitted_at = models.DateTimeField(default=timezone.now, editable=False, verbose_name=_("Submitted at")) def save(self, *args, **kwargs): self.message_html = parse(self.message) @@ -118,7 +118,7 @@ class Review(models.Model): vote = models.CharField(max_length=2, blank=True, choices=VOTES.CHOICES, verbose_name=_("Vote")) comment = models.TextField(verbose_name=_("Comment")) comment_html = models.TextField(blank=True) - submitted_at = models.DateTimeField(default=datetime.now, editable=False, verbose_name=_("Submitted at")) + submitted_at = models.DateTimeField(default=timezone.now, editable=False, verbose_name=_("Submitted at")) def save(self, **kwargs): self.comment_html = parse(self.comment) @@ -201,7 +201,7 @@ class LatestVote(models.Model): # No way to encode "-0" vs. "+0" into an IntegerField, and I don't feel # like some complicated encoding system. vote = models.CharField(max_length=2, choices=VOTES.CHOICES, verbose_name=_("Vote")) - submitted_at = models.DateTimeField(default=datetime.now, editable=False, verbose_name=_("Submitted at")) + submitted_at = models.DateTimeField(default=timezone.now, editable=False, verbose_name=_("Submitted at")) class Meta: unique_together = [("proposal", "user")] @@ -305,7 +305,7 @@ class Comment(models.Model): # Or perhaps more accurately, can the user see this comment. public = models.BooleanField(choices=[(True, _("public")), (False, _("private"))], default=False, verbose_name=_("Public")) - commented_at = models.DateTimeField(default=datetime.now, verbose_name=_("Commented at")) + commented_at = models.DateTimeField(default=timezone.now, verbose_name=_("Commented at")) class Meta: verbose_name = _("comment") @@ -333,7 +333,7 @@ class ResultNotification(models.Model): proposal = models.ForeignKey(ProposalBase, related_name="notifications", verbose_name=_("Proposal")) template = models.ForeignKey(NotificationTemplate, null=True, blank=True, on_delete=models.SET_NULL, verbose_name=_("Template")) - timestamp = models.DateTimeField(default=datetime.now, verbose_name=_("Timestamp")) + timestamp = models.DateTimeField(default=timezone.now, verbose_name=_("Timestamp")) to_address = models.EmailField(verbose_name=_("To address")) from_address = models.EmailField(verbose_name=_("From address")) subject = models.CharField(max_length=100, verbose_name=_("Subject")) diff --git a/symposion/schedule/migrations/0003_make_sessionrole_submitted_timezone_aware.py b/symposion/schedule/migrations/0003_make_sessionrole_submitted_timezone_aware.py new file mode 100644 index 00000000..9694582d --- /dev/null +++ b/symposion/schedule/migrations/0003_make_sessionrole_submitted_timezone_aware.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.12 on 2016-12-25 02:02 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('symposion_schedule', '0002_slot_name'), + ] + + operations = [ + migrations.AlterField( + model_name='sessionrole', + name='submitted', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ] diff --git a/symposion/schedule/models.py b/symposion/schedule/models.py index 859faea1..62bc9560 100644 --- a/symposion/schedule/models.py +++ b/symposion/schedule/models.py @@ -5,6 +5,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.contrib.auth.models import User from django.db import models +from django.utils import timezone from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ @@ -281,7 +282,7 @@ class SessionRole(models.Model): role = models.IntegerField(choices=SESSION_ROLE_TYPES, verbose_name=_("Role")) status = models.NullBooleanField(verbose_name=_("Status")) - submitted = models.DateTimeField(default=datetime.datetime.now) + submitted = models.DateTimeField(default=timezone.now) class Meta: unique_together = [("session", "user", "role")] diff --git a/symposion/speakers/migrations/0003_make_speaker_created_timezone_aware.py b/symposion/speakers/migrations/0003_make_speaker_created_timezone_aware.py new file mode 100644 index 00000000..cf6dfcdb --- /dev/null +++ b/symposion/speakers/migrations/0003_make_speaker_created_timezone_aware.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.12 on 2016-12-24 23:19 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('symposion_speakers', '0002_speaker_twitter_username'), + ] + + operations = [ + migrations.AlterField( + model_name='speaker', + name='created', + field=models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Created'), + ), + ] diff --git a/symposion/speakers/models.py b/symposion/speakers/models.py index 6e6de9d4..6b513579 100644 --- a/symposion/speakers/models.py +++ b/symposion/speakers/models.py @@ -1,9 +1,8 @@ from __future__ import unicode_literals -import datetime - from django.core.urlresolvers import reverse from django.db import models +from django.utils import timezone from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ @@ -39,7 +38,7 @@ class Speaker(models.Model): invite_email = models.CharField(max_length=200, unique=True, null=True, db_index=True, verbose_name=_("Invite_email")) invite_token = models.CharField(max_length=40, db_index=True, verbose_name=_("Invite token")) created = models.DateTimeField( - default=datetime.datetime.now, + default=timezone.now, editable=False, verbose_name=_("Created") ) diff --git a/symposion/sponsorship/migrations/0003_make_sponsor_added_timezone_aware.py b/symposion/sponsorship/migrations/0003_make_sponsor_added_timezone_aware.py new file mode 100644 index 00000000..aa42a0b1 --- /dev/null +++ b/symposion/sponsorship/migrations/0003_make_sponsor_added_timezone_aware.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.12 on 2016-12-25 00:53 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('symposion_sponsorship', '0002_auto_20160517_1726'), + ] + + operations = [ + migrations.AlterField( + model_name='sponsor', + name='added', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='added'), + ), + ] diff --git a/symposion/sponsorship/models.py b/symposion/sponsorship/models.py index f28bc57e..15765132 100644 --- a/symposion/sponsorship/models.py +++ b/symposion/sponsorship/models.py @@ -1,12 +1,11 @@ from __future__ import unicode_literals -import datetime - from django.conf import settings from django.core.exceptions import ValidationError from django.core.urlresolvers import reverse from django.db import models from django.db.models.signals import post_init, post_save +from django.utils import timezone from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ @@ -79,7 +78,7 @@ class Sponsor(models.Model): contact_name = models.CharField(_("Contact Name"), max_length=100) contact_email = models.EmailField(_("Contact Email")) level = models.ForeignKey(SponsorLevel, verbose_name=_("level")) - added = models.DateTimeField(_("added"), default=datetime.datetime.now) + added = models.DateTimeField(_("added"), default=timezone.now) active = models.BooleanField(_("active"), default=False) # Denormalization (this assumes only one logo) diff --git a/symposion/teams/migrations/0002_make_team_created_timezone_aware.py b/symposion/teams/migrations/0002_make_team_created_timezone_aware.py new file mode 100644 index 00000000..ae6f7548 --- /dev/null +++ b/symposion/teams/migrations/0002_make_team_created_timezone_aware.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.12 on 2016-12-25 01:54 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='team', + name='created', + field=models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Created'), + ), + ] diff --git a/symposion/teams/models.py b/symposion/teams/models.py index 774dfbd8..a5b6d815 100644 --- a/symposion/teams/models.py +++ b/symposion/teams/models.py @@ -1,8 +1,7 @@ from __future__ import unicode_literals -import datetime - from django.db import models +from django.utils import timezone from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ @@ -37,7 +36,7 @@ class Team(models.Model): related_name="manager_teams", verbose_name=_("Manager permissions")) - created = models.DateTimeField(default=datetime.datetime.now, + created = models.DateTimeField(default=timezone.now, editable=False, verbose_name=_("Created")) @models.permalink