Skip to content

Commit

Permalink
Make model DateTime fields timezone aware.
Browse files Browse the repository at this point in the history
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.ReviewAssignemnt.assigned_at
  - schedule.models.SessionRole.submitted
  - speakers.models.Speaker.created
  - sponsorship.models.Sponsor.added
  - teams.models.Team.created
  • Loading branch information
martey committed Dec 25, 2016
1 parent 6735bce commit 991a3d8
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 17 deletions.
46 changes: 46 additions & 0 deletions symposion/reviews/migrations/0002_make_fields_timezone_aware.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
14 changes: 7 additions & 7 deletions symposion/reviews/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from datetime import datetime
from decimal import Decimal

from django.db import models
from django.db.models import Q, F
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
3 changes: 2 additions & 1 deletion symposion/schedule/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _

Expand Down Expand Up @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
@@ -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'),
),
]
5 changes: 2 additions & 3 deletions symposion/speakers/models.py
Original file line number Diff line number Diff line change
@@ -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 _

Expand Down Expand Up @@ -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")
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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'),
),
]
5 changes: 2 additions & 3 deletions symposion/sponsorship/models.py
Original file line number Diff line number Diff line change
@@ -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 _

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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'),
),
]
5 changes: 2 additions & 3 deletions symposion/teams/models.py
Original file line number Diff line number Diff line change
@@ -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 _

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 991a3d8

Please sign in to comment.