Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Répare le compte de caractères des contenus #4171

Merged
merged 1 commit into from Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion update.md
Expand Up @@ -848,7 +848,7 @@ Actions à faire pour l'upgrade v22
Issue #2743
-----------

Lancer la commande de calcul des temps de lecture : `python manage.py adjust_nb_letters`.
Lancer la commande de calcul du nombre de caractères des contenus publiés : `python manage.py adjust_char_count`.

Maj de Raven + releases
-----------------------
Expand Down
Expand Up @@ -6,11 +6,11 @@

class Command(BaseCommand):
"""
`python manage.py adjust_nb_letters`; set the number of letter for every published content.
`python manage.py adjust_char_count`; set the number of characters for every published content.
"""

def handle(self, *args, **options):
for content in PublishedContent.objects.filter(nb_letter=None):
content.nb_letter = content.get_nb_letters()
for content in PublishedContent.objects.filter(char_count=None, must_redirect=False):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le problème était là : les contenus redirigés plantaient la commande.

content.char_count = content.get_char_count()
content.save()
logging.info('content %s got %d letters', content.title(), content.nb_letter)
logging.info('content %s got %d letters', content.title(), content.char_count)
23 changes: 23 additions & 0 deletions zds/tutorialv2/migrations/0016_auto_20170201_1940.py
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tutorialv2', '0015_publishedcontent_nb_letter'),
]

operations = [
migrations.RemoveField(
model_name='publishedcontent',
name='nb_letter',
),
migrations.AddField(
model_name='publishedcontent',
name='char_count',
field=models.IntegerField(default=None, null=True, verbose_name=b'Nombre de lettres du contenu', blank=True),
),
]
4 changes: 2 additions & 2 deletions zds/tutorialv2/models/models_database.py
Expand Up @@ -570,7 +570,7 @@ class Meta:
publication_date = models.DateTimeField('Date de publication', db_index=True, blank=True, null=True)
update_date = models.DateTimeField('Date de mise à jour', db_index=True, blank=True, null=True, default=None)
sha_public = models.CharField('Sha1 de la version publiée', blank=True, null=True, max_length=80, db_index=True)
nb_letter = models.IntegerField(default=None, null=True, verbose_name=b'Nombre de lettres du contenu', blank=True)
char_count = models.IntegerField(default=None, null=True, verbose_name=b'Nombre de lettres du contenu', blank=True)

must_redirect = models.BooleanField(
'Redirection vers une version plus récente', blank=True, db_index=True, default=False)
Expand Down Expand Up @@ -834,7 +834,7 @@ def get_absolute_url_zip(self):
def get_last_action_date(self):
return self.update_date or self.publication_date

def get_nb_letters(self, md_file_path=None):
def get_char_count(self, md_file_path=None):
""" Compute the number of letters for a given content

:param md_file_path: use another file to compute the number of letter rather than the default one.
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/publication_utils.py
Expand Up @@ -126,7 +126,7 @@ def publish_content(db_object, versioned, is_major_update=True):
public_version.content = db_object
public_version.must_reindex = True
public_version.save()
public_version.nb_letter = public_version.get_nb_letters(md_file_path)
public_version.char_count = public_version.get_char_count(md_file_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il ne manquerais pas une migration ? J'ai checkout ta branche, il me met « no such colomn tutorialv2_publishedcontent.char_count »

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ça doit être mon installation qui à foirer.


for author in db_object.authors.all():
public_version.authors.add(author)
Expand Down
8 changes: 4 additions & 4 deletions zds/tutorialv2/tests/tests_models.py
Expand Up @@ -516,8 +516,8 @@ def test_add_tags(self):
self.assertNotIn(' another tag', tuto_tags_list)
self.assertIn('another tag', tuto_tags_list)

def test_nb_letter_after_publication(self):
"""Test the ``get_nb_letters()`` function.
def test_char_count_after_publication(self):
"""Test the ``get_char_count()`` function.

Special care should be taken with this function, since:

Expand All @@ -534,7 +534,7 @@ def test_nb_letter_after_publication(self):

article = PublishedContentFactory(type='ARTICLE', author_list=[author], title=u'Un titre')
published = PublishedContent.objects.filter(content=article).first()
self.assertEqual(published.get_nb_letters(), 160 + len_date_now)
self.assertEqual(published.get_char_count(), 160 + len_date_now)

tuto = PublishableContentFactory(type='TUTORIAL', author_list=[author], title=u'Un titre')

Expand All @@ -550,7 +550,7 @@ def test_nb_letter_after_publication(self):
tuto.save()

published = PublishedContent.objects.filter(content=tuto).first()
self.assertEqual(published.get_nb_letters(), 335 + len_date_now)
self.assertEqual(published.get_char_count(), 335 + len_date_now)

def tearDown(self):
if os.path.isdir(settings.ZDS_APP['content']['repo_private_path']):
Expand Down
10 changes: 5 additions & 5 deletions zds/tutorialv2/tests/tests_utils.py
Expand Up @@ -570,18 +570,18 @@ def __init__(self, *__):
handler.prepare_generation.assert_called_with('/path/to')
os.remove('path')

def test_adjust_nb_letters(self):
"""Test the `adjust_nb_letters` command"""
def test_adjust_char_count(self):
"""Test the `adjust_char_count` command"""

article = PublishedContentFactory(type='ARTICLE', author_list=[self.user_author])
published = PublishedContent.objects.filter(content=article).first()
published.nb_letter = None
published.char_count = None
published.save()

call_command('adjust_nb_letters')
call_command('adjust_char_count')

published = PublishedContent.objects.get(pk=published.pk)
self.assertEqual(published.nb_letter, published.get_nb_letters())
self.assertEqual(published.char_count, published.get_char_count())

def tearDown(self):
if os.path.isdir(settings.ZDS_APP['content']['repo_private_path']):
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/views/views_published.py
Expand Up @@ -133,7 +133,7 @@ def get_context_data(self, **kwargs):
context['subscriber_count'] = ContentReactionAnswerSubscription.objects.get_subscriptions(self.object).count()
# We need reading time expressed in minutes
try:
context['reading_time'] = (self.object.public_version.nb_letter /
context['reading_time'] = (self.object.public_version.char_count /
settings.ZDS_APP['content']['sec_per_minute'])
except ZeroDivisionError as e:
logger.warning('could not compute reading time : setting sec_per_minute is set to zero (error=%s)', e)
Expand Down