diff --git a/templates/tutorialv2/includes/warn_typo.part.html b/templates/tutorialv2/includes/warn_typo.part.html index f5051b56e5..16213a76bd 100644 --- a/templates/tutorialv2/includes/warn_typo.part.html +++ b/templates/tutorialv2/includes/warn_typo.part.html @@ -10,6 +10,8 @@ {% trans "cet article" %} {% elif content.type == 'TUTORIAL' %} {% trans "ce tutoriel" %} + {% elif content.type == 'OPINION' %} + {% trans "ce billet" %} {% endif %} {% else %} {% trans "ce chapitre" %} diff --git a/templates/tutorialv2/index_online.html b/templates/tutorialv2/index_online.html index 6ae684020d..7969023b6f 100644 --- a/templates/tutorialv2/index_online.html +++ b/templates/tutorialv2/index_online.html @@ -113,6 +113,7 @@

{% trans "Nouveau billet" %} + {% elif current_content_type == None %} {% trans "Nouvel article" %} @@ -122,6 +123,10 @@

+ + {% trans "Nouveau billet" %} + + {% trans "Aider les auteurs" %} diff --git a/templates/tutorialv2/messages/validation_opinion.md b/templates/tutorialv2/messages/validation_opinion.md index 58f716465e..82c517e475 100644 --- a/templates/tutorialv2/messages/validation_opinion.md +++ b/templates/tutorialv2/messages/validation_opinion.md @@ -1,7 +1,7 @@ {% load i18n %} -{% blocktrans with title=content.title|safe validator_name=validator.username|safe validator_url=validator.get_absolute_url message=message_validation|safe %} +{% blocktrans with title=title|safe validator_name=validator.username|safe validator_url=validator.get_absolute_url message=message_validation|safe %} Félicitations ! Le billet « [{{ title }}]({{ url }}) » a bien été approuvé par l'équipe du site ! @@ -10,4 +10,4 @@ Le billet « [{{ title }}]({{ url }}) » a bien été approuvé par l'équipe du {% blocktrans %} Fêtons-donc ça avec un smoothie ! :D -{% endblocktrans %} \ No newline at end of file +{% endblocktrans %} diff --git a/templates/tutorialv2/view/content.html b/templates/tutorialv2/view/content.html index e78938c727..f0c705e940 100644 --- a/templates/tutorialv2/view/content.html +++ b/templates/tutorialv2/view/content.html @@ -385,8 +385,8 @@

  • {% trans "Publier" %} - {% crispy formPublication %} + {% crispy formPublication %}
  • {% endif %} {% endif %} diff --git a/templates/tutorialv2/view/content_online.html b/templates/tutorialv2/view/content_online.html index fabc4cad51..15d553cb91 100644 --- a/templates/tutorialv2/view/content_online.html +++ b/templates/tutorialv2/view/content_online.html @@ -78,14 +78,9 @@

    {% block content %} {% if content.is_opinion %} - {% if content.sha_public != content.sha_approved %} -
    - {% trans "Ce billet n'a pas encore été validé par l'équipe du site." %} -
    - {% endif %} {% if content.promotion_content %}
    - {% if content.promotion_content.get_absolute_url_online %} + {% if content.promotion_content.get_absolute_url_online %} {% blocktrans with url_article=content.promotion_content.get_absolute_url_online %} Ce billet a été promu en article. {% endblocktrans %} @@ -186,12 +181,12 @@

    {% blocktrans %}Administration{% endblocktrans %}< {% if is_staff %} -
  • - - {% trans "Historique validation" %} - -
  • {% if content.required_validation_before %} +
  • + + {% trans "Historique validation" %} + +
  • {% trans "Dépublier" %} diff --git a/zds/tutorialv2/forms.py b/zds/tutorialv2/forms.py index 2e7e1a83c3..c4f1c23729 100644 --- a/zds/tutorialv2/forms.py +++ b/zds/tutorialv2/forms.py @@ -1066,6 +1066,7 @@ def __init__(self, content, *args, **kwargs): self.helper.layout = Layout( CommonLayoutModalText(), Field('source'), + HTML("

    Ce billet sera publié directement et n'engage que vous.

    "), StrictButton(_(u'Publier'), type='submit') ) @@ -1123,7 +1124,8 @@ def __init__(self, content, *args, **kwargs): self.helper.form_id = 'valid-opinion' self.helper.layout = Layout( - HTML("

    Êtes-vous certain(e) de vouloir valider ce billet ?

    "), + HTML("

    Êtes-vous certain(e) de vouloir valider ce billet ? Il pourra maintenant être présent sur la page " + "d'accueil.

    "), CommonLayoutModalText(), Field('version'), StrictButton( diff --git a/zds/tutorialv2/mixins.py b/zds/tutorialv2/mixins.py index 0b8492583d..ca40815839 100644 --- a/zds/tutorialv2/mixins.py +++ b/zds/tutorialv2/mixins.py @@ -529,6 +529,17 @@ def get(self, context, **response_kwargs): return super(SingleContentDownloadViewMixin, self).get(context, **response_kwargs) +class ValidationBeforeViewMixin(SingleContentDetailViewMixin): + """ + Ensure the content require validation before publication. + """ + + def get(self, request, *args, **kwargs): + if not self.get_object().required_validation_before(): + raise PermissionDenied + return super(ValidationBeforeViewMixin, self).get(request, *args, **kwargs) + + class NoValidationBeforeFormViewMixin(SingleContentFormViewMixin): """ Ensure the content do not require validation before publication. diff --git a/zds/tutorialv2/utils.py b/zds/tutorialv2/utils.py index d668d18f5c..5b116734ba 100644 --- a/zds/tutorialv2/utils.py +++ b/zds/tutorialv2/utils.py @@ -765,6 +765,14 @@ def init_new_repo(db_object, introduction_text, conclusion_text, commit_message= return versioned_content +def clone_repo(old_path, new_path): + if not os.path.isdir(new_path): + os.makedirs(new_path, mode=0o777) + old_repo = Repo(old_path) + new_repo = old_repo.clone(new_path) + return new_repo + + def get_commit_author(): """get a dictionary that represent the commit author with ``author`` and ``comitter`` key. If there is no users, bot account pk is used. diff --git a/zds/tutorialv2/views/views_validations.py b/zds/tutorialv2/views/views_validations.py index 80bf26cf10..83ff97b22e 100644 --- a/zds/tutorialv2/views/views_validations.py +++ b/zds/tutorialv2/views/views_validations.py @@ -1,4 +1,5 @@ # coding: utf-8 + import logging from datetime import datetime @@ -19,11 +20,11 @@ from zds.notification import signals from zds.tutorialv2.forms import AskValidationForm, RejectValidationForm, AcceptValidationForm, RevokeValidationForm, \ CancelValidationForm, PublicationForm, OpinionValidationForm, PromoteOpinionToArticleForm -from zds.tutorialv2.mixins import SingleContentFormViewMixin, SingleContentDetailViewMixin, ModalFormView, \ - SingleOnlineContentFormViewMixin, NoValidationBeforeFormViewMixin +from zds.tutorialv2.mixins import SingleContentFormViewMixin, ModalFormView, \ + SingleOnlineContentFormViewMixin, ValidationBeforeViewMixin, NoValidationBeforeFormViewMixin from zds.tutorialv2.models.models_database import Validation, PublishableContent from zds.tutorialv2.publication_utils import publish_content, FailureDuringPublication, unpublish_content -from zds.tutorialv2.utils import init_new_repo +from zds.tutorialv2.utils import clone_repo from zds.utils.forums import send_post, lock_topic from zds.utils.models import SubCategory from zds.utils.mps import send_mp @@ -310,19 +311,20 @@ def post(self, request, *args, **kwargs): ) -class HistoryOfValidationDisplay(LoginRequiredMixin, PermissionRequiredMixin, SingleContentDetailViewMixin): +class HistoryOfValidationDisplay(LoginRequiredMixin, PermissionRequiredMixin, ValidationBeforeViewMixin): model = PublishableContent - permissions = ["tutorialv2.change_validation"] - template_name = "tutorialv2/validation/history.html" + permissions = ['tutorialv2.change_validation'] + template_name = 'tutorialv2/validation/history.html' def get_context_data(self, **kwargs): context = super(HistoryOfValidationDisplay, self).get_context_data() - context["validations"] = Validation.objects\ - .prefetch_related("validator")\ + context['validations'] = Validation.objects\ + .prefetch_related('validator')\ .filter(content__pk=self.object.pk)\ - .order_by("date_proposition").all() + .order_by('date_proposition')\ + .all() return context @@ -574,6 +576,9 @@ def form_valid(self, form): db_object.public_version = published db_object.save() + # Follow + signals.new_content.send(sender=db_object.__class__, instance=db_object, by_email=False) + messages.success(self.request, _(u'Le contenu a bien été publié.')) self.success_url = published.get_absolute_url_online() @@ -604,6 +609,7 @@ def form_valid(self, form): unpublish_content(self.object) self.object.sha_public = None + self.object.sha_approved = None self.object.pubdate = None self.object.save() @@ -671,7 +677,7 @@ def form_valid(self, form): send_mp( bot, versioned.authors.all(), - _(u"Billet approuvé"), + _(u'Billet approuvé'), versioned.title, msg, True, @@ -690,10 +696,10 @@ class PromoteOpinionToArticle(PermissionRequiredMixin, NoValidationBeforeFormVie modal_form = True prefetch_all = False - permissions = ["tutorialv2.change_validation"] + permissions = ['tutorialv2.change_validation'] def get(self, request, *args, **kwargs): - raise Http404(_(u"Promouvoir un billet n'est pas possible avec la méthode « GET ».")) + raise Http404(_(u"Promouvoir un billet en article n'est pas possible avec la méthode « GET ».")) def get_form_kwargs(self): kwargs = super(PromoteOpinionToArticle, self).get_form_kwargs() @@ -705,6 +711,9 @@ def form_valid(self, form): db_object = self.object versioned = self.versioned_object + # get initial git path + old_git_path = db_object.get_repo_path() + # store data for later authors = db_object.authors.all() subcats = db_object.subcategory.all() @@ -734,11 +743,8 @@ def form_valid(self, form): for tag in tags: db_object.tags.add(tag) - # create the repo - init_new_repo(db_object, - versioned.get_introduction(), - versioned.get_conclusion(), - u'Promotion du billet en article') + # clone the repo + clone_repo(old_git_path, db_object.get_repo_path()) # ask for validation validation = Validation() @@ -764,7 +770,7 @@ def form_valid(self, form): for author in authors: userg = UserGallery() userg.gallery = gal - userg.mode = "W" # write mode + userg.mode = 'W' # write mode userg.user = author userg.save() db_object.gal = gal @@ -772,6 +778,8 @@ def form_valid(self, form): # save updates db_object.save() + # copy git repo + # send message to user msg = render_to_string( 'tutorialv2/messages/opinion_promotion.md', @@ -784,7 +792,7 @@ def form_valid(self, form): send_mp( bot, db_object.authors.all(), - _(u"Billet promu en article"), + _(u'Billet promu en article'), versioned.title, msg, True,