summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--devel/management/commands/reporead.py6
-rw-r--r--feeds.py22
-rw-r--r--main/models.py13
-rw-r--r--news/models.py2
-rw-r--r--packages/views.py2
5 files changed, 20 insertions, 25 deletions
diff --git a/devel/management/commands/reporead.py b/devel/management/commands/reporead.py
index e26bb800..a8875c7e 100644
--- a/devel/management/commands/reporead.py
+++ b/devel/management/commands/reporead.py
@@ -315,7 +315,7 @@ def populate_files(dbpkg, repopkg, force=False):
directory=dirname + '/',
filename=filename)
pkgfile.save(force_insert=True)
- dbpkg.files_last_update = datetime.now()
+ dbpkg.files_last_update = datetime.utcnow()
dbpkg.save()
@transaction.commit_on_success
@@ -374,7 +374,7 @@ def db_update(archname, reponame, pkgs, options):
for p in [x for x in pkgs if x.name in in_sync_not_db]:
logger.info("Adding package %s", p.name)
pkg = Package(pkgname = p.name, arch = architecture, repo = repository)
- populate_pkg(pkg, p, timestamp=datetime.now())
+ populate_pkg(pkg, p, timestamp=datetime.utcnow())
# packages in database and not in syncdb (remove from database)
in_db_not_sync = dbset - syncset
@@ -398,7 +398,7 @@ def db_update(archname, reponame, pkgs, options):
if not force:
continue
else:
- timestamp = datetime.now()
+ timestamp = datetime.utcnow()
if filesonly:
logger.debug("Checking files for package %s in database", p.name)
populate_files(dbp, p, force=force)
diff --git a/feeds.py b/feeds.py
index 7a2f2e40..0be12531 100644
--- a/feeds.py
+++ b/feeds.py
@@ -1,5 +1,4 @@
-import datetime
-from decimal import Decimal, ROUND_HALF_DOWN
+import pytz
from django.contrib.sites.models import Site
from django.contrib.syndication.views import Feed
@@ -10,7 +9,7 @@ from django.utils.hashcompat import md5_constructor
from django.views.decorators.http import condition
from main.models import Arch, Repo, Package
-from main.utils import CACHE_TIMEOUT, INVALIDATE_TIMEOUT
+from main.utils import CACHE_TIMEOUT
from main.utils import CACHE_PACKAGE_KEY, CACHE_NEWS_KEY
from news.models import News
@@ -32,17 +31,6 @@ class GuidNotPermalinkFeed(Rss201rev2Feed):
super(GuidNotPermalinkFeed, self).write_items(handler)
-def utc_offset():
- '''Calculate the UTC offset from local time. Useful for converting values
- stored in local time to things like cache last modifed headers.'''
- timediff = datetime.datetime.utcnow() - datetime.datetime.now()
- secs = timediff.days * 86400 + timediff.seconds
- # round to nearest minute
- mins = Decimal(secs) / Decimal(60)
- mins = mins.quantize(Decimal('0'), rounding=ROUND_HALF_DOWN)
- return datetime.timedelta(minutes=int(mins))
-
-
def retrieve_package_latest():
# we could break this down based on the request url, but it would probably
# cost us more in query time to do so.
@@ -52,7 +40,6 @@ def retrieve_package_latest():
try:
latest = Package.objects.values('last_update').latest(
'last_update')['last_update']
- latest = latest + utc_offset()
# Using add means "don't overwrite anything in there". What could be in
# there is an explicit None value that our refresh signal set, which
# means we want to avoid race condition possibilities for a bit.
@@ -132,7 +119,7 @@ class PackageFeed(Feed):
date.strftime('%Y%m%d%H%M'))
def item_pubdate(self, item):
- return item.last_update
+ return item.last_update.replace(tzinfo=pytz.utc)
def item_categories(self, item):
return (item.repo.name, item.arch.name)
@@ -145,7 +132,6 @@ def retrieve_news_latest():
try:
latest = News.objects.values('last_modified').latest(
'last_modified')['last_modified']
- latest = latest + utc_offset()
# same thoughts apply as in retrieve_package_latest
cache.add(CACHE_NEWS_KEY, latest, CACHE_TIMEOUT)
return latest
@@ -184,7 +170,7 @@ class NewsFeed(Feed):
return item.guid
def item_pubdate(self, item):
- return item.postdate
+ return item.postdate.replace(tzinfo=pytz.utc)
def item_author_name(self, item):
return item.author.get_full_name()
diff --git a/main/models.py b/main/models.py
index 4370fa24..8d34731f 100644
--- a/main/models.py
+++ b/main/models.py
@@ -5,6 +5,7 @@ from django.contrib.sites.models import Site
from main.utils import cache_function, make_choice
from packages.models import PackageRelation
+from datetime import datetime
from itertools import groupby
import pytz
@@ -351,7 +352,7 @@ class Todolist(models.Model):
creator = models.ForeignKey(User)
name = models.CharField(max_length=255)
description = models.TextField()
- date_added = models.DateTimeField(auto_now_add=True, db_index=True)
+ date_added = models.DateTimeField(db_index=True)
objects = TodolistManager()
def __unicode__(self):
@@ -383,10 +384,18 @@ class TodolistPkg(models.Model):
db_table = 'todolist_pkgs'
unique_together = (('list','pkg'),)
+def set_todolist_fields(sender, **kwargs):
+ todolist = kwargs['instance']
+ if not todolist.date_added:
+ todolist.date_added = datetime.utcnow()
+
# connect signals needed to keep cache in line with reality
from main.utils import refresh_package_latest
-from django.db.models.signals import post_save
+from django.db.models.signals import pre_save, post_save
+
post_save.connect(refresh_package_latest, sender=Package,
dispatch_uid="main.models")
+pre_save.connect(set_todolist_fields, sender=Todolist,
+ dispatch_uid="main.models")
# vim: set ts=4 sw=4 et:
diff --git a/news/models.py b/news/models.py
index c4fb136a..17d51de9 100644
--- a/news/models.py
+++ b/news/models.py
@@ -27,7 +27,7 @@ class News(models.Model):
def set_news_fields(sender, **kwargs):
news = kwargs['instance']
- now = datetime.now()
+ now = datetime.utcnow()
news.last_modified = now
if not news.postdate:
news.postdate = now
diff --git a/packages/views.py b/packages/views.py
index 2f614e34..1587563b 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -371,7 +371,7 @@ def flag(request, name, repo, arch):
# find all packages from (hopefully) the same PKGBUILD
pkgs = Package.objects.filter(
pkgbase=pkg.pkgbase, repo__testing=pkg.repo.testing)
- pkgs.update(flag_date=datetime.now())
+ pkgs.update(flag_date=datetime.utcnow())
maints = pkg.maintainers
if not maints: