Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Merge pull request #55 from mdn/update_django_extensions_1153288
Browse files Browse the repository at this point in the history
Update django_extensions to 1.5.7
  • Loading branch information
jwhitlock committed Sep 28, 2015
2 parents 1cb25bf + ea64ddf commit 23b9561
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 17 deletions.
33 changes: 33 additions & 0 deletions mdn/migrations/0008_switch_modified_to_datetimefield.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# flake8: noqa
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('mdn', '0007_expand_status_choices'),
]

operations = [
migrations.AlterField(
model_name='featurepage',
name='modified',
field=models.DateTimeField(help_text='Last modification time', auto_now=True, db_index=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pagemeta',
name='crawled',
field=models.DateTimeField(help_text='Time when the content was retrieved', auto_now=True),
preserve_default=True,
),
migrations.AlterField(
model_name='translatedcontent',
name='crawled',
field=models.DateTimeField(help_text='Time when the content was retrieved', auto_now=True),
preserve_default=True,
),
]
15 changes: 8 additions & 7 deletions mdn/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
from django.utils.functional import cached_property
from django.utils.six import text_type
from django.utils.six.moves import zip
from django.utils.six.moves.urllib_parse import urlparse
from django.utils.timesince import timesince
from django_extensions.db.fields import ModificationDateTimeField
from django_extensions.db.fields.json import JSONField

from webplatformcompat.models import Feature
Expand Down Expand Up @@ -69,8 +69,8 @@ class FeaturePage(models.Model):
status = models.IntegerField(
help_text="Status of MDN Parsing process",
default=STATUS_STARTING, choices=STATUS_CHOICES)
modified = ModificationDateTimeField(
help_text="Last modification time", db_index=True)
modified = models.DateTimeField(
help_text="Last modification time", db_index=True, auto_now=True)
raw_data = models.TextField(help_text="JSON-encoded parsed content")

def __str__(self):
Expand All @@ -93,7 +93,7 @@ def slug(self):

def same_since(self):
"""Return a string indicating when the object was changes"""
return timesince(self.modified) + " ago"
return timesince(self.modified or timezone.now()) + " ago"

def meta(self):
"""Get the page Meta section."""
Expand Down Expand Up @@ -378,8 +378,8 @@ class Content(models.Model):
"""The content of an MDN page."""
page = models.ForeignKey(FeaturePage)
path = models.CharField(help_text="Path of MDN page", max_length=1024)
crawled = ModificationDateTimeField(
help_text="Time when the content was retrieved")
crawled = models.DateTimeField(
help_text="Time when the content was retrieved", auto_now=True)
raw = models.TextField(help_text="Raw content of the page")
STATUS_STARTING = 0
STATUS_FETCHING = 1
Expand All @@ -402,7 +402,8 @@ def url(self):
return self.page.domain() + self.path

def __str__(self):
return "%s retrieved %s ago" % (self.path, timesince(self.crawled))
return "%s retrieved %s ago" % (
self.path, timesince(self.crawled or timezone.now()))


class PageMeta(Content):
Expand Down
8 changes: 5 additions & 3 deletions mdn/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,13 @@ def test_context_end_of_page(self):

class TestPageMetaModel(TestCase):
def setUp(self):
fp = FeaturePage(
feature = self.create(Feature)
fp = FeaturePage.objects.create(
feature=feature,
url="https://developer.mozilla.org/en-US/docs/Web/CSS/display",
feature_id=666,
status=FeaturePage.STATUS_PARSED)
self.meta = PageMeta(page=fp, path="/de/docs/Web/CSS/display")
self.meta = PageMeta.objects.create(
page=fp, path="/de/docs/Web/CSS/display")

def test_str(self):
expected = u'/de/docs/Web/CSS/display retrieved 0\xa0minutes ago'
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ django-filter==0.11.0

# Django extensions
six==1.9.0
django-extensions==1.5.5
django-extensions==1.5.7

# JSON API interfaces for Django REST Framework
git+git://github.com/jwhitlock/drf-json-api@v0.1d#egg=drf-json-api
Expand Down
6 changes: 2 additions & 4 deletions webplatformcompat/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from django.db import models
from django.http import HttpResponseBadRequest
from django.utils.timezone import now
from django_extensions.db.fields import (
CreationDateTimeField, ModificationDateTimeField)

from simple_history.middleware import (
HistoryRequestMiddleware as BaseHistoryRequestMiddleware)
Expand Down Expand Up @@ -48,8 +46,8 @@ class Changeset(models.Model):
'supports', 'versions',
]

created = CreationDateTimeField()
modified = ModificationDateTimeField()
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
user = models.ForeignKey(user_model, related_name="changesets")
closed = models.BooleanField(
help_text="Is the changeset closed to new changes?",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('webplatformcompat', '0014_disallow_blank_versions'),
]

operations = [
migrations.AlterField(
model_name='changeset',
name='created',
field=models.DateTimeField(auto_now_add=True),
preserve_default=True,
),
migrations.AlterField(
model_name='changeset',
name='modified',
field=models.DateTimeField(auto_now=True),
preserve_default=True,
),
]
5 changes: 3 additions & 2 deletions webplatformcompat/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def test_browser_v1_invalidator(self):

def test_changeset_v1_serializer(self):
created = datetime(2014, 10, 29, 8, 57, 21, 806744, UTC)
changeset = self.create(Changeset, user=self.user, created=created)
Changeset.objects.filter(pk=changeset.pk).update(modified=created)
changeset = self.create(Changeset, user=self.user)
Changeset.objects.filter(pk=changeset.pk).update(
created=created, modified=created)
changeset = Changeset.objects.get(pk=changeset.pk)
out = self.cache.changeset_v1_serializer(changeset)
expected = {
Expand Down

0 comments on commit 23b9561

Please sign in to comment.