[geany/www.geany.org] 03ff9c: Use django.utils.timezone.now() instead of datetime.now()

Enrico Tröger git-noreply at xxxxx
Sun Jan 5 18:39:40 UTC 2014

Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Sun, 05 Jan 2014 18:39:40 UTC
Commit:      03ff9c72c55967385b2bd79056c33f56519f53de

Log Message:
Use django.utils.timezone.now() instead of datetime.now()

This prevents timezone errors in Django. django.utils.timezone.now() is
Timezone aware.

Modified Paths:

Modified: pastebin/models.py
11 files changed, 6 insertions(+), 5 deletions(-)
@@ -3,20 +3,21 @@
 # it under the terms of the GNU Affero General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # GNU Affero General Public License for more details.
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
+from datetime import timedelta
 from django.core.urlresolvers import reverse
 from django.db import models
+from django.utils import timezone
 from django.utils.translation import ugettext_lazy as _
 from pastebin.highlight import LEXER_DEFAULT
-import datetime
 import random
 import re
 import time
@@ -66,7 +67,7 @@ def _readable_delta(self, from_seconds, until_seconds=None):
             until_seconds = time.time()
         seconds = until_seconds - from_seconds
-        delta = datetime.timedelta(seconds=seconds)
+        delta = timedelta(seconds=seconds)
         # deltas store time as seconds and days, we have to get hours and minutes ourselves
         delta_minutes = delta.seconds // 60
@@ -93,7 +94,7 @@ def content_splitted(self):
     def save(self, *args, **kwargs):
         if not self.pk:
-            self.published = datetime.datetime.now()
+            self.published = timezone.now()
             self.secret_id = generate_secret_id()
         self.content_highlighted = self.content
         models.Model.save(self, *args, **kwargs)

This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).

More information about the Commits mailing list