Skip to content
Snippets Groups Projects
Commit 4841929b authored by florimondmanca's avatar florimondmanca
Browse files

fix editable article published date, quick improvements

parent a4ea5b51
Branches
No related tags found
No related merge requests found
......@@ -20,7 +20,6 @@ class ArticleFactory(factory.DjangoModelFactory):
title = factory.Faker('sentence', locale='fr')
content = factory.Faker('text', max_nb_chars=2000, locale='fr')
introduction = factory.Faker('text', max_nb_chars=200, locale='fr')
published = factory.Faker('date')
pinned = factory.Iterator((True, False, False, False))
......
# Generated by Django 2.0.5 on 2018-05-12 14:43
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('showcase_site', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='article',
name='published',
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='publié le'),
),
migrations.AlterField(
model_name='partner',
name='start_date',
field=models.DateField(blank=True, help_text='Laisser vide si inconnu. (Cette information est stockée pour historique uniquement.)', null=True, verbose_name='début du partenariat'),
),
]
"""Showcase site models."""
from datetime import timedelta
from django.db import models
from django.shortcuts import reverse
from django.utils.text import slugify
from django.utils.timezone import now
from dry_rest_permissions.generics import authenticated_users
from markdownx.models import MarkdownxField
......@@ -32,24 +30,7 @@ class Category(models.Model):
class Article(models.Model):
"""Represents a piece of news.
Fields
------
title : str
Title of the news.
slug : str
A brief label identifying the article.
It is generated from the title on creation.
However, it is not used for the article's API URL.
content : str
Full content of the news.
published : date
Date the article was published. Today's date by default.
image : Image
An image to illustrate the article.
pinned : bool
"""
"""Represents a piece of news."""
title = models.CharField('titre', max_length=300,
help_text="Titre de l'article")
......@@ -68,7 +49,7 @@ class Article(models.Model):
content = MarkdownxField(
'contenu',
help_text="Contenu complet de l'article (Markdown est supporté).")
published = models.DateTimeField('publié le', auto_now_add=True)
published = models.DateTimeField('publié le', default=now)
modified = models.DateTimeField(
'modifié le', auto_now=True)
image = models.ImageField('illustration', blank=True, null=True,
......@@ -112,12 +93,6 @@ class Article(models.Model):
"""Return the article's absolute url."""
return reverse('api:article-detail', args=[str(self.slug)])
@property
def was_modified(self):
"""Return whether the article has been modified at least once."""
return self.modified - self.published > timedelta(seconds=1)
was_modified.fget.short_description = 'Modifié'
# Permissions
@staticmethod
......@@ -265,7 +240,7 @@ class Partner(models.Model):
)
)
start_date = models.DateField(
'début du partenariat', default=now, blank=True, null=True,
'début du partenariat', blank=True, null=True,
help_text=(
"Laisser vide si inconnu. "
"(Cette information est stockée pour historique uniquement.)"
......
......@@ -48,11 +48,6 @@ class ArticleSerializer(serializers.HyperlinkedModelSerializer):
content = MarkdownField()
categories = CategoryField(many=True, required=False)
modified = serializers.SerializerMethodField()
def get_modified(self, obj: Article):
"""Only expose modified if article has already been modified."""
return obj.was_modified and obj.modified or None
class Meta: # noqa
model = Article
......
......@@ -84,12 +84,6 @@ class ArticleTest(ModelTestCase):
ArticleFactory.create(title='first article')
ArticleFactory.create(title='second article')
def test_was_modified(self):
self.assertFalse(self.obj.was_modified)
sleep(1)
self.obj.save()
self.assertTrue(self.obj.was_modified)
class CleanCategoriesTest(TestCase):
"""Test the clean_categories pre_delete signal on Article."""
......
......@@ -66,11 +66,3 @@ class TestArticleSerializer(SerializerTestCaseMixin, TestCase):
expected = set(self.serializer.data['categories'])
actual = set(c.title for c in self.obj.categories.all())
self.assertEqual(actual, expected)
def test_modified_only_contained_if_was_modified(self):
obj = self.get_object()
self.assertIsNone(self.serializer.data['modified'])
sleep(1)
obj.save()
serializer = self.get_serializer(obj)
self.assertIsNotNone(serializer.data['modified'])
"""Partner model tests."""
from django.utils.timezone import now
from showcase_site.factory import PartnerFactory
from showcase_site.models import Partner
from tests.utils import ModelTestCase
......@@ -33,7 +31,6 @@ class PartnerTest(ModelTestCase):
},
'start_date': {
'verbose_name': 'début du partenariat',
'default': now,
}
}
model_tests = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment