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

Permet de désactiver l'aide Markdown #4335

Merged
merged 2 commits into from
May 9, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions assets/js/markdown-help.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Pour écrire un bout de code au milieu d’une phrase, utilisez la syntaxe <code>`un bout de code`</code>.",
"Le langage d’un bloc de code peut être spécifié après les <code>```</code> ouvrants. La liste des langages supportés <a href=\"" + linkToPygments + "\">est disponible ici</a>.",
"Vous pouvez <a href=\"" + linkToMathsTutorial + "\">écrire des formules mathématiques</a> en encadrant ces dernières du signe dollar <code>$</code>."
];
];

function addDocMD($elem){
$elem.each(function(){
Expand All @@ -38,12 +38,14 @@


$(document).ready(function(){
addDocMD($(".md-editor"));
$("#content").on("DOMNodeInserted", ".md-editor", function(e){
var $editor = $(e.target);
if($editor.next().hasClass("markdown-help") === false) {
addDocMD($editor);
}
});
if ($("body").data("show-markdown-help")) {
addDocMD($(".md-editor"));
$("#content").on("DOMNodeInserted", ".md-editor", function(e){
var $editor = $(e.target);
if($editor.next().hasClass("markdown-help") === false) {
addDocMD($editor);
}
});
}
});
})(document, jQuery);
9 changes: 7 additions & 2 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@
{% endif %}

<body class="{% block body_class %}{% endblock %}{% for vc in visual_changes %} vc-{{ vc }}{% endfor %}"
itemscope
itemtype="http://schema.org/WebPage"
itemscope
itemtype="http://schema.org/WebPage"
{% if not user.is_authenticated or user.profile.show_markdown_help %}
data-show-markdown-help="true"
{% else %}
data-show-markdown-help="false"
{% endif %}
>
<!--[if lt IE 9]>
<p class="chromeframe">Vous utilisez un navigateur <strong>dépassé</strong>. Merci de <a href="http://browsehappy.com/">mettre à jour celui-ci</a> pour améliorer votre expérience.</p>
Expand Down
4 changes: 4 additions & 0 deletions zds/member/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class ProfileForm(MiniProfileForm):
('show_sign', _(u'Afficher les signatures')),
('is_hover_enabled', _(u'Dérouler les menus au survol')),
('allow_temp_visual_changes', _(u'Activer les changements visuels temporaires')),
('show_markdown_help', _(u"Afficher l'aide Markdown dans l'éditeur")),
('email_for_answer', _(u"Recevoir un courriel lors d'une réponse à un message privé")),
),
widget=forms.CheckboxSelectMultiple,
Expand All @@ -246,6 +247,9 @@ def __init__(self, *args, **kwargs):
if 'allow_temp_visual_changes' in initial and initial['allow_temp_visual_changes']:
self.fields['options'].initial += 'allow_temp_visual_changes'

if 'show_markdown_help' in initial and initial['show_markdown_help']:
self.fields['options'].initial += 'show_markdown_help'

if 'email_for_answer' in initial and initial['email_for_answer']:
self.fields['options'].initial += 'email_for_answer'

Expand Down
19 changes: 19 additions & 0 deletions zds/member/migrations/0010_profile_show_markdown_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('member', '0009_profile_show_staff_badge'),
]

operations = [
migrations.AddField(
model_name='profile',
name='show_markdown_help',
field=models.BooleanField(default=True, verbose_name='Afficher l\u2019aide Markdown dans l\u2019\xe9diteur'),
),
]
1 change: 1 addition & 0 deletions zds/member/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Meta:
# do UI components open by hovering them, or is clicking on them required?
is_hover_enabled = models.BooleanField('Déroulement au survol ?', default=True)
allow_temp_visual_changes = models.BooleanField('Activer les changements visuels temporaires', default=True)
show_markdown_help = models.BooleanField("Afficher l'aide Markdown dans l'éditeur", default=True)
email_for_answer = models.BooleanField('Envoyer pour les réponse MP', default=False)
show_staff_badge = models.BooleanField('Afficher le badge staff', default=False)
can_read = models.BooleanField('Possibilité de lire', default=True)
Expand Down
14 changes: 14 additions & 0 deletions zds/member/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,20 @@ def test_github_token(self):
dev = Profile.objects.get(pk=dev.pk)
self.assertEqual(dev.github_token, '')

def test_markdown_help_settings(self):
user = ProfileFactory().user

# login and check that the Markdown help is displayed
self.client.login(username=user.username, password='hostel77')
result = self.client.get(reverse('pages-index'), follow=False)
self.assertContains(result, 'data-show-markdown-help="true"')

# disable Markdown help
user.profile.show_markdown_help = False
user.profile.save()
result = self.client.get(reverse('pages-index'), follow=False)
self.assertContains(result, 'data-show-markdown-help="false"')

def tearDown(self):
if os.path.isdir(settings.ZDS_APP['content']['repo_private_path']):
shutil.rmtree(settings.ZDS_APP['content']['repo_private_path'])
Expand Down
3 changes: 2 additions & 1 deletion zds/member/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ def get_form(self, form_class=ProfileForm):
'show_sign': profile.show_sign,
'is_hover_enabled': profile.is_hover_enabled,
'allow_temp_visual_changes': profile.allow_temp_visual_changes,
'show_markdown_help': profile.show_markdown_help,
'email_for_answer': profile.email_for_answer,
'sign': profile.sign,
'is_dev': profile.is_dev(),
Copy link
Member

Choose a reason for hiding this comment

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

Cette suppression est voulue ou c'est une erreur ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oui, elle est voulue. J'avoue que j'ai un peu fait ça "au passage" vu que j'étais sur ce formulaire. Cette ligne servait à afficher ou non le champ du token GitHub et n'est plus utilisée maintenant que le formulaire est séparé. Un oubli de #4246.

Copy link
Member

Choose a reason for hiding this comment

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

D'accord !

})

return form
Expand Down Expand Up @@ -152,6 +152,7 @@ def update_profile(self, profile, form):
profile.show_sign = 'show_sign' in cleaned_data_options
profile.is_hover_enabled = 'is_hover_enabled' in cleaned_data_options
profile.allow_temp_visual_changes = 'allow_temp_visual_changes' in cleaned_data_options
profile.show_markdown_help = 'show_markdown_help' in cleaned_data_options
profile.email_for_answer = 'email_for_answer' in cleaned_data_options
profile.avatar_url = form.data['avatar_url']
profile.sign = form.data['sign']
Expand Down