diff --git a/zds/tutorialv2/models/models_database.py b/zds/tutorialv2/models/models_database.py index 51881eea68..5001fa173f 100644 --- a/zds/tutorialv2/models/models_database.py +++ b/zds/tutorialv2/models/models_database.py @@ -353,7 +353,7 @@ def insert_data_in_versioned(self, versioned): """ attrs = [ - 'pk', 'authors', 'authors', 'subcategory', 'image', 'creation_date', 'pubdate', 'update_date', 'source', + 'pk', 'authors', 'subcategory', 'image', 'creation_date', 'pubdate', 'update_date', 'source', 'sha_draft', 'sha_beta', 'sha_validation', 'sha_public' ] @@ -491,17 +491,6 @@ def antispam(self, user=None): if t.total_seconds() < settings.ZDS_APP['forum']['spam_limit_seconds']: return True - return False - - def change_type(self, new_type): - """Allow someone to change the content type, basically from tutorial to article - - :param new_type: the new type, either `"ARTICLE"` or `"TUTORIAL"` - """ - if new_type not in TYPE_CHOICES: - raise ValueError("This type of content does not exist") - self.type = new_type - def repo_delete(self): """ Delete the entities and their filesystem counterparts @@ -536,8 +525,6 @@ class PublishedContent(models.Model): Linked to a ``PublishableContent`` for the rest. Don't forget to add a ``.prefetch_related("content")`` !! """ - # TODO: by playing with this class, it may solve most of the SEO problems !! - class Meta: verbose_name = 'Contenu publié' verbose_name_plural = 'Contenus publiés' @@ -571,12 +558,7 @@ def get_absolute_url_online(self): :return: the URL of the published content :rtype: str """ - reversed_ = '' - - if self.is_article(): - reversed_ = 'article' - elif self.is_tutorial(): - reversed_ = 'tutorial' + reversed_ = self.content_type.lower() return reverse(reversed_ + ':view', kwargs={'pk': self.content_pk, 'slug': self.content_public_slug}) @@ -685,12 +667,7 @@ def get_absolute_url_to_extra_content(self, type_): allowed_types = ['pdf', 'md', 'html', 'epub', 'zip'] if type_ in allowed_types: - reversed_ = '' - - if self.is_article(): - reversed_ = 'article' - elif self.is_tutorial(): - reversed_ = 'tutorial' + reversed_ = self.content_type.lower() return reverse( reversed_ + ':download-' + type_, kwargs={'pk': self.content_pk, 'slug': self.content_public_slug}) diff --git a/zds/tutorialv2/models/models_versioned.py b/zds/tutorialv2/models/models_versioned.py index 433e57419b..24f4289719 100644 --- a/zds/tutorialv2/models/models_versioned.py +++ b/zds/tutorialv2/models/models_versioned.py @@ -39,8 +39,6 @@ class Container: children_dict = {} slug_pool = {} - # TODO: thumbnails ? - def __init__(self, title, slug='', parent=None, position_in_parent=1): """Initialize the data model that will handle the dialog with raw versionned data at level container @@ -278,7 +276,6 @@ def update_children(self): child.update_children() elif isinstance(child, Extract): child.text = child.get_path(relative=True) - # TODO : does this function should also rewrite `slug_pool` ? def get_path(self, relative=False): """Get the physical path to the draft version of the container. diff --git a/zds/tutorialv2/tests/tests_views.py b/zds/tutorialv2/tests/tests_views.py index 3d3e9ac50d..3912143473 100644 --- a/zds/tutorialv2/tests/tests_views.py +++ b/zds/tutorialv2/tests/tests_views.py @@ -3268,6 +3268,8 @@ def test_publication_make_extra_contents(self): self.assertTrue(published.have_type(extra)) result = self.client.get(published.get_absolute_url_to_extra_content(extra)) self.assertEqual(result.status_code, 200) + + # test that deletion give a 404 markdown_url = published.get_absolute_url_md() md_path = os.path.join(published.get_extra_contents_directory(), published.content_public_slug + '.md') os.remove(md_path) @@ -3275,8 +3277,9 @@ def test_publication_make_extra_contents(self): self.assertEqual('', published.get_absolute_url_to_extra_content('kboom')) self.client.logout() - with open(md_path, "w") as f: + with open(md_path, "w") as f: # remake a .md file, whatever the content f.write("I rebuilt it to finish the test. Perhaps a funny quote would be a good thing?") + # same test with author: self.assertEqual( self.client.login( diff --git a/zds/tutorialv2/utils.py b/zds/tutorialv2/utils.py index abff86bc5b..cce70cf1c8 100644 --- a/zds/tutorialv2/utils.py +++ b/zds/tutorialv2/utils.py @@ -474,8 +474,6 @@ def publish_container(db_object, base_dir, container): if not isinstance(container, Container): raise FailureDuringPublication(_(u'Le conteneur n\'en est pas un !')) - # TODO: images stuff !! - template = 'tutorialv2/export/chapter.html' # jsFiddle support diff --git a/zds/tutorialv2/views/views_contents.py b/zds/tutorialv2/views/views_contents.py index f7bd3196bf..3eead43a73 100644 --- a/zds/tutorialv2/views/views_contents.py +++ b/zds/tutorialv2/views/views_contents.py @@ -345,14 +345,14 @@ def delete(self, request, *args, **kwargs): if self.object.authors.count() > 1: # if more than one author, just remove author from list RemoveAuthorFromContent.remove_author(self.object, self.request.user) - messages.success(self.request, _(u'Vous avez quitté la rédaction de {}').format(_type)) + messages.success(self.request, _(u'Vous avez quitté la rédaction de {}.').format(_type)) else: validation = Validation.objects.filter(content=self.object).order_by("-date_proposition").first() if validation and validation.status == 'PENDING_V': # if the validation have a validator, warn him by PM if 'text' not in self.request.POST or len(self.request.POST['text'].strip()) < 3: - messages.error(self.request, 'Merci de fournir une raison à la suppression.') + messages.error(self.request, _(u'Merci de fournir une raison à la suppression.')) return redirect(self.object.get_absolute_url()) else: bot = get_object_or_404(User, username=settings.ZDS_APP['member']['bot_account']) @@ -388,7 +388,7 @@ def delete(self, request, *args, **kwargs): self.object.delete() - messages.success(self.request, _(u'Vous avez bien supprimé {}').format(_type)) + messages.success(self.request, _(u'Vous avez bien supprimé {}.').format(_type)) return redirect(reverse('content:find-' + object_type, args=[request.user.pk])) @@ -679,7 +679,7 @@ def form_valid(self, form): try: zfile = zipfile.ZipFile(self.request.FILES['archive'], "r") except zipfile.BadZipfile: - messages.error(self.request, _(u'Cette archive n\'est pas au format ZIP')) + messages.error(self.request, _(u'Cette archive n\'est pas au format ZIP.')) return super(UpdateContentWithArchive, self).form_invalid(form) try: @@ -693,7 +693,7 @@ def form_valid(self, form): manifest = json_reader.loads(unicode(zfile.read('manifest.json'), 'utf-8')) if 'licence' not in manifest or manifest['licence'] != new_version.licence.code: messages.info( - self.request, _(u'la licence « {} » a été appliquée'.format(new_version.licence.code))) + self.request, _(u'la licence « {} » a été appliquée.').format(new_version.licence.code)) # first, update DB object (in order to get a new slug if needed) self.object.title = new_version.title @@ -752,7 +752,7 @@ def form_valid(self, form): try: zfile = zipfile.ZipFile(self.request.FILES["image_archive"], "r") except zipfile.BadZipfile: - messages.error(self.request, _(u'L\'archive contenant les images n\'est pas au format ZIP')) + messages.error(self.request, _(u'L\'archive contenant les images n\'est pas au format ZIP.')) return self.form_invalid(form) UpdateContentWithArchive.use_images_from_archive( @@ -787,7 +787,7 @@ def form_valid(self, form): try: zfile = zipfile.ZipFile(self.request.FILES['archive'], "r") except zipfile.BadZipfile: - messages.error(self.request, _(u'Cette archive n\'est pas au format ZIP')) + messages.error(self.request, _(u'Cette archive n\'est pas au format ZIP.')) return self.form_invalid(form) try: @@ -804,7 +804,7 @@ def form_valid(self, form): manifest = json_reader.loads(unicode(zfile.read('manifest.json'), 'utf-8')) if 'licence' not in manifest or manifest['licence'] != new_content.licence.code: messages.info( - self.request, _(u'la licence « {} » a été appliquée'.format(new_content.licence.code))) + self.request, _(u'la licence « {} » a été appliquée.'.format(new_content.licence.code))) # first, create DB object (in order to get a slug) self.object = PublishableContent() @@ -875,7 +875,7 @@ def form_valid(self, form): try: zfile = zipfile.ZipFile(self.request.FILES["image_archive"], "r") except zipfile.BadZipfile: - messages.error(self.request, _(u'L\'archive contenant les images n\'est pas au format ZIP')) + messages.error(self.request, _(u'L\'archive contenant les images n\'est pas au format ZIP.')) return self.form_invalid(form) UpdateContentWithArchive.use_images_from_archive( @@ -913,7 +913,7 @@ def get_context_data(self, **kwargs): def render_to_response(self, context, **response_kwargs): parent = context['container'] if not parent.can_add_container(): - messages.error(self.request, _(u'Vous ne pouvez plus ajouter de conteneur à « {} »').format(parent.title)) + messages.error(self.request, _(u'Vous ne pouvez plus ajouter de conteneur à « {} ».').format(parent.title)) return redirect(parent.get_absolute_url()) return super(CreateContainer, self).render_to_response(context, **response_kwargs) @@ -1092,7 +1092,7 @@ def get_context_data(self, **kwargs): def render_to_response(self, context, **response_kwargs): parent = context['container'] if not parent.can_add_extract(): - messages.error(self.request, _(u'Vous ne pouvez plus ajouter de section à « {} »').format(parent.title)) + messages.error(self.request, _(u'Vous ne pouvez plus ajouter de section à « {} ».').format(parent.title)) return redirect(parent.get_absolute_url()) return super(CreateExtract, self).render_to_response(context, **response_kwargs) @@ -1787,10 +1787,10 @@ def form_valid(self, form): if not current_user: # if the removed author is not current user messages.success( - self.request, _(u'Vous avez enlevé {} de la liste des auteurs de {}').format(authors_list, _type)) + self.request, _(u'Vous avez enlevé {} de la liste des auteurs de « {} ».').format(authors_list, _type)) self.success_url = self.object.get_absolute_url() else: # if current user is leaving the content's redaction, redirect him to a more suitable page - messages.success(self.request, _(u'Vous avez bien quitté la rédaction de {}').format(_type)) + messages.success(self.request, _(u'Vous avez bien quitté la rédaction de « {} ».').format(_type)) self.success_url = reverse('content:find-' + self.object.type.lower(), args=[self.request.user.pk]) self.already_finished = True # this one is kind of tricky : because of inheritance we used to force redirection # to the content itself. This does not please me but I think it is better to do that like that instead of diff --git a/zds/tutorialv2/views/views_published.py b/zds/tutorialv2/views/views_published.py index 9fbfdc3ee4..11f89611c9 100644 --- a/zds/tutorialv2/views/views_published.py +++ b/zds/tutorialv2/views/views_published.py @@ -57,8 +57,6 @@ def get_context_data(self, **kwargs): """Show the given tutorial if exists.""" context = super(DisplayOnlineContent, self).get_context_data(**kwargs) - # TODO: deal with messaging and stuff like this !! - if context['is_staff']: context['formRevokeValidation'] = RevokeValidationForm( self.versioned_object, initial={'version': self.versioned_object.sha_public}) @@ -630,7 +628,7 @@ def post(self, request, *args, **kwargs): alert.pubdate = datetime.now() alert.save() - messages.success(self.request, _(u"Ce commentaire a bien été signalé aux modérateurs")) + messages.success(self.request, _(u"Ce commentaire a bien été signalé aux modérateurs.")) return redirect(note.get_absolute_url()) diff --git a/zds/tutorialv2/views/views_validations.py b/zds/tutorialv2/views/views_validations.py index 1f810f110f..ba0908f1be 100644 --- a/zds/tutorialv2/views/views_validations.py +++ b/zds/tutorialv2/views/views_validations.py @@ -119,7 +119,6 @@ def form_valid(self, form): # warn the former validator that an update has been made, if any if old_validator: validation.validator = old_validator - # TODO: why not let the validator be the same using PENDING_V ? bot = get_object_or_404(User, username=settings.ZDS_APP['member']['bot_account']) msg = render_to_string(