Skip to content

Commit

Permalink
Le titre des tutoriels est versionné (fix #1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-24 committed Jul 29, 2014
1 parent 9579e6f commit 2090471
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 73 deletions.
2 changes: 0 additions & 2 deletions templates/tutorial/includes/chapter.part.html
@@ -1,8 +1,6 @@
{% load emarkdown %}
{% load repo_reader %}



{% with extracts=chapter.extracts %}
{% if not chapter.type = 'MINI' %}
{% if chapter.intro and chapter.intro != None %}
Expand Down
71 changes: 34 additions & 37 deletions templates/tutorial/tutorial/view.html
Expand Up @@ -96,51 +96,48 @@ <h2 class="subtitle">
{% endblock %}



{% block content %}
{% with tuto_version=tutorial|repo_tuto:version %}
{% if tuto_version.introduction and tuto_version.introduction != "None" %}
{{ tuto_version.introduction|emarkdown }}
{% elif not tutorial.in_beta %}
<p class="ico-after warning">
Il n'y a pas d'introduction.
</p>
{% endif %}
{% if tutorial.get_introduction and tutorial.get_introduction != "None" %}
{{ tutorial.get_introduction|emarkdown }}
{% elif not tutorial.in_beta %}
<p class="ico-after warning">
Il n'y a pas d'introduction.
</p>
{% endif %}

{% if tutorial.is_mini %}
{# Small tutorial #}
{% if tutorial.is_mini %}
{# Small tutorial #}

{% include "tutorial/includes/chapter.part.html" with authors=tutorial.authors.all %}
{% else %}
{# Large tutorial #}
{% include "tutorial/includes/chapter.part.html" with authors=tutorial.authors.all %}
{% else %}
{# Large tutorial #}

<hr />
<hr />

{% for part in parts %}
<h2>
<a href="{% url "view-part-url" tutorial.pk tutorial.slug part.pk part.slug %}{% if version %}?version={{ version }}{% endif %}">
Partie {{ part.position_in_tutorial }} : {{ part.title }}
</a>
</h2>
{% include "tutorial/includes/part.part.html" %}
{% empty %}
<p class="ico-after warning">
Il n'y a actuellement aucune partie dans ce tutoriel.
</p>
{% endfor %}
{% for part in parts %}
<h2>
<a href="{% url "view-part-url" tutorial.pk tutorial.slug part.pk part.slug %}{% if version %}?version={{ version }}{% endif %}">
Partie {{ part.position_in_tutorial }} : {{ part.title }}
</a>
</h2>
{% include "tutorial/includes/part.part.html" %}
{% empty %}
<p class="ico-after warning">
Il n'y a actuellement aucune partie dans ce tutoriel.
</p>
{% endfor %}

<hr />
<hr />

{% endif %}
{% endif %}

{% if tuto_version.conclusion and tuto_version.conclusion != "None" %}
{{ tuto_version.conclusion|emarkdown }}
{% elif not tutorial.in_beta %}
<p class="ico-after warning">
Il n'y a pas de conclusion.
</p>
{% endif %}
{% endwith %}
{% if tutorial.get_conclusion and tutorial.get_conclusion != "None" %}
{{ tutorial.get_conclusion|emarkdown }}
{% elif not tutorial.in_beta %}
<p class="ico-after warning">
Il n'y a pas de conclusion.
</p>
{% endif %}
{% endblock %}


Expand Down
61 changes: 34 additions & 27 deletions zds/tutorial/models.py
Expand Up @@ -182,35 +182,42 @@ def get_prod_path(self):
settings.REPO_PATH_PROD,
str(self.pk) + '_' + slugify(data['title']))

def load_dic(self, mandata):
mandata['get_absolute_url_online'] = reverse(
'zds.tutorial.views.view_tutorial_online',
args=[self.pk, slugify(mandata["title"])]
)

mandata['get_absolute_url_beta'] = reverse(
'zds.tutorial.views.view_tutorial', args=[
self.pk, slugify(self.title)
]) + '?version=' + self.sha_beta
def load_dic(self, mandata, sha=None,public=False):
fns = ['is_big', 'is_mini', 'have_markdown','have_html','have_pdf','have_epub',
'get_introduction_online', 'get_conclusion_online', 'get_path']
attrs = ['pk','authors','subcategory','image','pubdate', 'update','source',
'sha_draft', 'sha_beta', 'sha_validation', 'sha_public']
#load functions in tree
for fn in fns: mandata[fn]=getattr(self,fn)()
#load attributes in tree
for attr in attrs: mandata[attr]=getattr(self,attr)
# general information
mandata['slug'] = slugify(mandata['title'])

#draft informations
mandata['get_absolute_url'] = reverse('zds.tutorial.views.view_tutorial',
args=[self.pk, slugify(mandata["title"])])

mandata['get_introduction_online'] = self.get_introduction_online()
mandata['get_conclusion_online'] = self.get_conclusion_online()

mandata['slug'] = slugify(mandata['title'])
mandata['pk'] = self.pk
mandata['on_line'] = self.on_line
mandata['authors'] = self.authors
mandata['subcategory'] = self.subcategory
mandata['image'] = self.image
mandata['pubdate'] = self.pubdate
mandata['source'] = self.source
mandata['have_markdown'] = self.have_markdown()
mandata['have_html'] = self.have_html()
mandata['have_pdf'] = self.have_pdf()
mandata['have_epub'] = self.have_epub()
args=[self.pk, mandata['slug']])
if not public:
mandata['get_introduction'] = self.get_introduction(sha)
mandata['get_conclusion'] = self.get_conclusion(sha)

# beta information
if self.in_beta():
mandata['get_absolute_url_beta'] = reverse('zds.tutorial.views.view_tutorial',
args=[self.pk, mandata['slug']])\
+'?version=' +self.sha_beta
else:
mandata['get_absolute_url_beta'] = reverse('zds.tutorial.views.view_tutorial',
args=[self.pk, mandata['slug']])
mandata['in_beta'] = self.in_beta() and self.sha_beta == sha

#validations informations
mandata['in_validation'] = self.in_validation() and self.sha_validation == sha

#online informations
mandata['get_absolute_url_online'] = reverse('zds.tutorial.views.view_tutorial_online',
args=[self.pk, mandata['slug']])
mandata['on_line'] = self.on_line() and self.sha_public == sha

return mandata

Expand Down
17 changes: 10 additions & 7 deletions zds/tutorial/views.py
Expand Up @@ -666,11 +666,14 @@ def view_tutorial(request, tutorial_pk, tutorial_slug):

manifest = get_blob(repo.commit(sha).tree, "manifest.json")
mandata = json_reader.loads(manifest)
mandata = tutorial.load_dic(mandata, sha)

#print mandata

# If it's a small tutorial, fetch its chapter

if tutorial.type == "MINI":
if "chapter" in mandata:
if 'chapter' in mandata:
chapter = mandata["chapter"]
chapter["path"] = tutorial.get_path()
chapter["type"] = "MINI"
Expand Down Expand Up @@ -724,7 +727,7 @@ def view_tutorial(request, tutorial_pk, tutorial_slug):
formValid = ValidForm()
formReject = RejectForm()
return render_template("tutorial/tutorial/view.html", {
"tutorial": tutorial,
"tutorial": mandata,
"chapter": chapter,
"parts": parts,
"version": sha,
Expand Down Expand Up @@ -753,7 +756,7 @@ def view_tutorial_online(request, tutorial_pk, tutorial_slug):
# find the good manifest file

mandata = tutorial.load_json_for_public()
mandata = tutorial.load_dic(mandata)
mandata = tutorial.load_dic(mandata, sha=tutorial.sha_public, public=True)
mandata["update"] = tutorial.update
mandata["get_note_count"] = tutorial.get_note_count()

Expand Down Expand Up @@ -1166,7 +1169,7 @@ def view_part_online(
# find the good manifest file

mandata = tutorial.load_json_for_public()
mandata = tutorial.load_dic(mandata)
mandata = tutorial.load_dic(mandata, sha=tutorial.sha_public, public=True)
mandata["update"] = tutorial.update

mandata["get_parts"] = mandata["parts"]
Expand Down Expand Up @@ -1518,7 +1521,7 @@ def view_chapter_online(
# find the good manifest file

mandata = tutorial.load_json_for_public()
mandata = tutorial.load_dic(mandata)
mandata = tutorial.load_dic(mandata, sha=tutorial.sha_public, public=True)
mandata["update"] = tutorial.update

mandata['get_parts'] = mandata["parts"]
Expand Down Expand Up @@ -2097,7 +2100,7 @@ def find_tuto(request, pk_user):
tuto_versions = []
for tutorial in tutorials:
mandata = tutorial.load_json_for_public(sha=tutorial.sha_beta)
mandata = tutorial.load_dic(mandata)
mandata = tutorial.load_dic(mandata, sha=tutorial.sha_beta)
tuto_versions.append(mandata)

return render_template("tutorial/member/beta.html",
Expand All @@ -2110,7 +2113,7 @@ def find_tuto(request, pk_user):
tuto_versions = []
for tutorial in tutorials:
mandata = tutorial.load_json_for_public()
mandata = tutorial.load_dic(mandata)
mandata = tutorial.load_dic(mandata, sha=tutorial.sha_public, public=True)
tuto_versions.append(mandata)

return render_template("tutorial/member/online.html", {"tutorials": tuto_versions,
Expand Down

0 comments on commit 2090471

Please sign in to comment.