Skip to content

Commit

Permalink
corrige les urls des tutos et quelques tests
Browse files Browse the repository at this point in the history
  • Loading branch information
firm1 authored and Alex-D committed Jun 20, 2014
1 parent 27f4c0e commit 21774f0
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 179 deletions.
2 changes: 1 addition & 1 deletion templates/tutorial/chapter/view_online.html
Expand Up @@ -11,7 +11,7 @@

{% block breadcrumb %}
<li><a href="{{ chapter.part.tutorial.get_absolute_url_online }}">{{ chapter.part.tutorial.title }}</a></li>
<li><a href="{% url "view-part-url-online" chapter.part.tutorial.pk chapter.part.tutorial.slug chapter.part.slug %}">
<li><a href="{% url "view-part-url-online" chapter.part.tutorial.pk chapter.part.tutorial.slug chapter.part.pk chapter.part.slug %}">
{{ chapter.part.title }}
</a></li>
<li>{{ chapter.title }}</li>
Expand Down
8 changes: 4 additions & 4 deletions templates/tutorial/includes/part.part.html
Expand Up @@ -15,9 +15,9 @@
<h3>
<a href="
{% if online %}
{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.slug chapter.slug %}
{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.pk part.slug chapter.pk chapter.slug %}
{% else %}
{% url "view-chapter-url" tutorial.pk tutorial.slug part.slug chapter.slug %}{% if version %}?version={{version}}{% endif %}
{% url "view-chapter-url" tutorial.pk tutorial.slug part.pk part.slug chapter.pk chapter.slug %}{% if version %}?version={{ version }}{% endif %}
{% endif %}
">
Chapitre {{ chapter.part.position_in_tutorial }}.{{ chapter.position_in_part }} | {{ chapter.title }}
Expand All @@ -29,9 +29,9 @@ <h3>
<h4>
<a href="{% spaceless %}
{% if online %}
{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.slug chapter.slug %}
{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.pk part.slug chapter.pk chapter.slug %}
{% else %}
{% url "view-chapter-url" tutorial.pk tutorial.slug part.slug chapter.slug %}{% if version %}?version={{version}}{% endif %}
{% url "view-chapter-url" tutorial.pk tutorial.slug part.pk part.slug chapter.pk chapter.slug %}{% if version %}?version={{ version }}{% endif %}
{% endif %}
{% endspaceless %}#{{ extract.position_in_chapter }}-{{ extract.title|slugify }}">
{{ extract.title }}
Expand Down
4 changes: 2 additions & 2 deletions templates/tutorial/includes/part_export.part.html
Expand Up @@ -20,11 +20,11 @@
<ul>
{% for chapter in chapters %}
<li>
<a href="{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.slug chapter.slug %}"><h2>Chapitre {{ chapter.part.position_in_tutorial }}.{{ chapter.position_in_part }} | {{ chapter.title }}</h2></a>
<a href="{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.pk part.slug chapter.pk chapter.slug %}"><h2>Chapitre {{ chapter.part.position_in_tutorial }}.{{ chapter.position_in_part }} | {{ chapter.title }}</h2></a>
<ul>
{% for extract in chapter.extracts %}
<li>
<a href="{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.slug chapter.slug %}#{{ extract.position_in_chapter }}-{{ extract.title|slugify }}">
<a href="{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.pk part.slug chapter.pk chapter.slug %}#{{ extract.position_in_chapter }}-{{ extract.title|slugify }}">
<h3>{{ extract.title }}</h3>
</a>
{{ extract.txt|safe }}
Expand Down
12 changes: 6 additions & 6 deletions templates/tutorial/includes/summary.part.html
Expand Up @@ -30,9 +30,9 @@ <h3>Sommaire</h3>
<h4 data-num="{{ part.position_in_tutorial|roman }}">
<a class="mobile-menu-link"
{% if online %}
href="{% url "view-part-url-online" tutorial.pk tutorial.slug part.slug %}"
href="{% url "view-part-url-online" tutorial.pk tutorial.slug part.pk part.slug %}"
{% else %}
href="{% url "view-part-url" tutorial.pk tutorial.slug part.slug %}{% if version %}?version={{version}}{% endif %}"
href="{% url "view-part-url" tutorial.pk tutorial.slug part.pk part.slug %}"{% if version %}?version={{ version }}{% endif %}
{% endif %}
>
{{ part.title }}
Expand All @@ -44,9 +44,9 @@ <h4 data-num="{{ part.position_in_tutorial|roman }}">
<li {% if chapter_current.pk == chapter.pk %}class="current"{% endif %}>
<a data-num="{{ chapter.position_in_part }}"
{% if online %}
href="{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.slug chapter.slug %}"
href="{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.pk part.slug chapter.pk chapter.slug %}"
{% else %}
href="{% url "view-chapter-url" tutorial.pk tutorial.slug part.slug chapter.slug %}{% if version %}?version={{ version }}{% endif %}"
href="{% url "view-chapter-url" tutorial.pk tutorial.slug part.pk part.slug chapter.pk chapter.slug %}"{% if version %}?version={{ version }}{% endif %}
{% endif %}
class="mobile-menu-link mobile-menu-sublink {% if chapter_current.pk = chapter.pk %}unread{% endif %}"
>
Expand All @@ -59,9 +59,9 @@ <h4 data-num="{{ part.position_in_tutorial|roman }}">
<li>
<a
{% if online %}
href="{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.slug chapter.slug %}#{{ extract.position_in_chapter }}-{{ extract.title|slugify }}"
href="{% url "view-chapter-url-online" tutorial.pk tutorial.slug part.pk part.slug chapter.pk chapter.slug %}#{{ extract.position_in_chapter }}-{{ extract.title|slugify }}"
{% else %}
href="{% url "view-chapter-url" tutorial.pk tutorial.slug part.slug chapter.slug %}{% if version %}?version={{ version }}{% endif %}#{{ extract.position_in_chapter }}-{{ extract.title|slugify }}"
href="{% url "view-chapter-url" tutorial.pk tutorial.slug part.pk part.slug chapter.pk chapter.slug %}#{{ extract.position_in_chapter }}-{{ extract.title|slugify }}"{% if version %}?version={{ version }}{% endif %}
{% endif %}
>
{{ extract.title }}
Expand Down
2 changes: 1 addition & 1 deletion templates/tutorial/part/view.html
Expand Up @@ -50,7 +50,7 @@ <h2>
{% for chapter in part.chapters %}
<li>
<h3>
<a href="{% url "view-chapter-url" part.tutorial.pk part.tutorial.slug part.slug chapter.slug %}?version={{ version }}">
<a href="{% url "view-chapter-url" part.tutorial.pk part.tutorial.slug part.pk part.slug chapter.pk chapter.slug %}?version={{version}}">
{{ chapter.title }}
</a>
</h3>
Expand Down
2 changes: 1 addition & 1 deletion templates/tutorial/tutorial/view.html
Expand Up @@ -69,7 +69,7 @@ <h3 class="subtitle">

{% for part in parts %}
<h2>
<a href="{% url "view-part-url" tutorial.pk tutorial.slug part.slug %}{% if version %}?version={{version}}{% endif %}">
<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>
Expand Down
2 changes: 1 addition & 1 deletion templates/tutorial/tutorial/view_online.html
Expand Up @@ -52,7 +52,7 @@ <h3 class="subtitle">
{% if parts %}
{% for part in parts %}
<h2>
<a href="{% url "view-part-url-online" tutorial.pk tutorial.slug part.slug %}">
<a href="{% url "view-part-url-online" tutorial.pk tutorial.slug part.pk part.slug %}">
Partie {{ part.position_in_tutorial }} : {{ part.title }}
</a>
</h2>
Expand Down
4 changes: 2 additions & 2 deletions zds/article/models.py
Expand Up @@ -97,7 +97,7 @@ def get_absolute_url(self):
kwargs={'article_pk': self.pk,
'article_slug': slugify(self.title)})

def get_slug(self):
def get_phy_slug(self):
return str(self.pk) + "_" + self.slug

def get_absolute_url_online(self):
Expand All @@ -122,7 +122,7 @@ def get_path(self, relative=False):
if relative:
return None
else:
return os.path.join(settings.REPO_ARTICLE_PATH, self.get_slug())
return os.path.join(settings.REPO_ARTICLE_PATH, self.get_phy_slug())

def load_json(self, path=None, online=False):
if path is None:
Expand Down
4 changes: 2 additions & 2 deletions zds/article/views.py
Expand Up @@ -322,7 +322,7 @@ def edit(request):

new_slug = os.path.join(
settings.REPO_ARTICLE_PATH,
article.get_slug())
article.get_phy_slug())

maj_repo_article(request,
old_slug_path=old_slug,
Expand Down Expand Up @@ -409,7 +409,7 @@ def download(request):

article = get_object_or_404(Article, pk=request.GET['article'])

ph = os.path.join(settings.REPO_ARTICLE_PATH, article.get_slug())
ph = os.path.join(settings.REPO_ARTICLE_PATH, article.get_phy_slug())
repo = Repo(ph)
repo.archive(open(ph + ".tar", 'w'))

Expand Down
12 changes: 6 additions & 6 deletions zds/tutorial/factories.py
Expand Up @@ -119,8 +119,8 @@ def _prepare(cls, create, **kwargs):
if not os.path.isdir(path):
os.makedirs(path, mode=0o777)

part.introduction = os.path.join(part.get_slug(), 'introduction.md')
part.conclusion = os.path.join(part.get_slug(), 'conclusion.md')
part.introduction = os.path.join(part.get_phy_slug(), 'introduction.md')
part.conclusion = os.path.join(part.get_phy_slug(), 'conclusion.md')
part.save()

f = open(os.path.join(tutorial.get_path(), part.introduction), "w")
Expand Down Expand Up @@ -189,12 +189,12 @@ def _prepare(cls, create, **kwargs):

elif part:
chapter.introduction = os.path.join(
part.get_slug(),
chapter.get_slug(),
part.get_phy_slug(),
chapter.get_phy_slug(),
'introduction.md')
chapter.conclusion = os.path.join(
part.get_slug(),
chapter.get_slug(),
part.get_phy_slug(),
chapter.get_phy_slug(),
'conclusion.md')
chapter.save()
f = open(
Expand Down
42 changes: 22 additions & 20 deletions zds/tutorial/models.py
Expand Up @@ -111,7 +111,7 @@ class Meta:
def __unicode__(self):
return self.title

def get_slug(self):
def get_phy_slug(self):
return str(self.pk) + "_" + self.slug

def get_absolute_url(self):
Expand Down Expand Up @@ -170,7 +170,7 @@ def get_path(self, relative=False):
if relative:
return ''
else:
return os.path.join(settings.REPO_PATH, self.get_slug())
return os.path.join(settings.REPO_PATH, self.get_phy_slug())

def get_prod_path(self):
data = self.load_json_for_public()
Expand Down Expand Up @@ -460,20 +460,22 @@ def __unicode__(self):
return u'<Partie pour {0}, {1}>' \
.format(self.tutorial.title, self.position_in_tutorial)

def get_slug(self):
def get_phy_slug(self):
return str(self.pk) + "_" + self.slug

def get_absolute_url(self):
return reverse('zds.tutorial.views.view_part', args=[
self.tutorial.pk,
self.tutorial.slug,
self.pk,
self.slug,
])

def get_absolute_url_online(self):
return reverse('zds.tutorial.views.view_part_online', args=[
self.tutorial.pk,
self.tutorial.slug,
self.pk,
self.slug,
])

Expand All @@ -483,9 +485,9 @@ def get_chapters(self):

def get_path(self, relative=False):
if relative:
return self.get_slug()
return self.get_phy_slug()
else:
return os.path.join(settings.REPO_PATH, self.tutorial.get_slug(), self.get_slug())
return os.path.join(settings.REPO_PATH, self.tutorial.get_phy_slug(), self.get_phy_slug())

def get_introduction(self):
intro = open(
Expand Down Expand Up @@ -591,15 +593,15 @@ def __unicode__(self):
else:
return u'<orphelin>'

def get_slug(self):
def get_phy_slug(self):
return str(self.pk) + "_" + self.slug

def get_absolute_url(self):
if self.tutorial:
return self.tutorial.get_absolute_url()

elif self.part:
return self.part.get_absolute_url() + '{0}/'.format(self.slug)
return self.part.get_absolute_url() + '{0}/{1}/'.format(self.pk, self.slug)

else:
return reverse('zds.tutorial.views.index')
Expand All @@ -610,7 +612,7 @@ def get_absolute_url_online(self):

elif self.part:
return self.part.get_absolute_url_online(
) + '{0}/'.format(self.slug)
) + '{0}/{1}/'.format(self.pk, self.slug)

else:
return reverse('zds.tutorial.views.index')
Expand Down Expand Up @@ -646,17 +648,17 @@ def update_position_in_tutorial(self):
def get_path(self, relative=False):
if relative:
if self.tutorial:
chapter_path = self.get_slug()
chapter_path = self.get_phy_slug()
else:
chapter_path = os.path.join(self.part.get_slug(), self.get_slug())
chapter_path = os.path.join(self.part.get_phy_slug(), self.get_phy_slug())
else:
if self.tutorial:
chapter_path = os.path.join(settings.REPO_PATH, self.tutorial.get_slug(), self.get_slug())
chapter_path = os.path.join(settings.REPO_PATH, self.tutorial.get_phy_slug(), self.get_phy_slug())
else:
chapter_path = os.path.join(settings.REPO_PATH,
self.part.tutorial.get_slug(),
self.part.get_slug(),
self.get_slug())
self.part.tutorial.get_phy_slug(),
self.part.get_phy_slug(),
self.get_phy_slug())

return chapter_path

Expand Down Expand Up @@ -793,16 +795,16 @@ def get_path(self, relative=False):
chapter_path = ''
else:
chapter_path = os.path.join(
self.chapter.part.get_slug(),
self.chapter.get_slug())
self.chapter.part.get_phy_slug(),
self.chapter.get_phy_slug())
else:
if self.chapter.tutorial:
chapter_path = os.path.join(settings.REPO_PATH, self.chapter.tutorial.get_slug())
chapter_path = os.path.join(settings.REPO_PATH, self.chapter.tutorial.get_phy_slug())
else:
chapter_path = os.path.join(settings.REPO_PATH,
self.chapter.part.tutorial.get_slug(),
self.chapter.part.get_slug(),
self.chapter.get_slug())
self.chapter.part.tutorial.get_phy_slug(),
self.chapter.part.get_phy_slug(),
self.chapter.get_phy_slug())

return os.path.join(chapter_path, str(self.pk) + "_" + slugify(self.title)) + '.md'

Expand Down

0 comments on commit 21774f0

Please sign in to comment.