Skip to content

Commit

Permalink
Merge pull request #18 from RadioRevolt/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Boye Borg committed Aug 15, 2015
2 parents 51af86d + 46c05c9 commit 73df543
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 12 deletions.
6 changes: 1 addition & 5 deletions page/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,13 @@

# Markdown

MARKDOWN_EXTENSIONS = ['extra', 'wikilinks', 'toc']
MARKDOWN_EXTENSIONS = ['extra', 'toc']
MARKDOWN_EXTENSION_CONFIGS = {
'toc': {
'separator': '-',
'title': 'Innhold',
'baselevel': 2,
},
'wikilinks': {
'base_url': '/view/',
'end_url': '.html',
},
}

# Haystack
Expand Down
1 change: 0 additions & 1 deletion wiki/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def get_url(self):
def save(self, *args, **kwargs):
if not self.id:
self.slug = slugify(self.slug)
self.title = slugify(self.slug).replace('_', ' ').title()

super(Page, self).save(*args, **kwargs)

Expand Down
4 changes: 4 additions & 0 deletions wiki/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ body {
float: right;
}

.markdown-body a.DoesNotExist {
color: #C04040;
}

#delete-popup {
display: none;
background-color: #FFF;
Expand Down
6 changes: 5 additions & 1 deletion wiki/templates/create_page.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% extends 'base.html' %}

{% block content %}
Siden <b>{{ page_title|title }}</b> finnes ikke. <a href="{% url 'edit_page' slug %}">Opprett <b>{{ page_title|title }}</b></a>.
Siden <b>{{ page_title|title }}</b> finnes ikke.<br />
<form action="{% url 'edit_page' slug %}">
Tittel: <input type="text" name="title" value="{{ page_title|title }}"/><br />
<button type="submit">Opprett</button>
</form>
{% endblock %}
3 changes: 2 additions & 1 deletion wiki/templates/edit_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
{% endblock %}

{% block content %}
<h1>{{ page_title|title }} - {% if page %}Rediger <a href="#" class="delete-popup_open button">Slett</a>{% else %}Opprett{% endif %}</h1>
<h1>{{ page_title }} - {% if page %}Rediger <a href="#" class="delete-popup_open button">Slett</a>{% else %}Opprett{% endif %}</h1>
<a href="{% url 'view_page' slug %}">&#8592; Tilbake</a>
<br />
<br />
<pre id="content" name="content">{{ page.content }}</pre>
<form method="post" id="edit-form" action="{% url 'save_page' slug %}">
{% csrf_token %}
<input type="hidden" name="title" value="{{ page_title }}" />
<input class="button" type="submit" value="Lagre" />
</form>
<a href="{% url 'view_page' slug %}" class="button">Avbryt</a>
Expand Down
1 change: 1 addition & 0 deletions wiki/templates/shortcodes/link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="/view/{{ link }}.html#{{ segment }}" class="{{ class }}">{{ title }}</a>
3 changes: 2 additions & 1 deletion wiki/templates/view_page.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends 'base.html' %}

{% load django_markdown %}
{% load shortcodes %}

{% block head %}
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/default.min.css">
Expand All @@ -15,5 +16,5 @@ <h1>
[ <a href="{% url 'edit_page' page.get_url %}">Rediger</a> | <a href="{% url 'page_history' page.get_url %}">Historikk</a> ]
</span>
</h1>
{{ page.content|markdown }}
{{ page.content|expand_shortcodes|markdown }}
{% endblock %}
39 changes: 36 additions & 3 deletions wiki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
# -*- coding: utf-8 -*-

from django.shortcuts import render, redirect
from django.template.loader import render_to_string
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.decorators import login_required
from haystack.management.commands import update_index
from wiki.models import Page, LinkGroup
from django.http import JsonResponse
from markdown_shortcodes import shortcode
from wiki.utils.slugify import slugify
import reversion
import reversion_compare

Expand All @@ -28,7 +31,7 @@ def view_page(request, slug):
except Page.DoesNotExist:
return render(request, 'create_page.html', {
'slug': slug,
'page_title': slug.replace('_', ' '),
'page_title': slug.replace('-', ' '),
'link_groups': link_groups,
})

Expand Down Expand Up @@ -130,13 +133,17 @@ def page_change(request, slug, version_id):
@login_required(login_url='/login')
def edit_page(request, slug):
link_groups = LinkGroup.objects.all()
if request.GET:
title = request.GET.get('title', slug.replace('-', ' '))
else:
title = slug.replace('-', ' ')
try:
page = Page.objects.get(slug=slug)
except Page.DoesNotExist:
page = None
return render(request, 'edit_page.html', {
'page': page,
'page_title': slug.replace('_', ' '),
'page_title': title,
'slug': slug,
'link_groups': link_groups,
})
Expand All @@ -146,9 +153,16 @@ def edit_page(request, slug):
def save_page(request, slug):
if request.method == 'POST':
content = request.POST.get('content', '')
title = request.POST.get('title', slug.replace('-', '').title())
if content == '':
return redirect('/edit/{slug}.html'.format(slug=slug))
page, created = Page.objects.update_or_create(slug=slug, defaults={'content': content})
try:
page = Page.objects.get(slug=slug)
setattr(page, 'content', content)
page.save()
except Page.DoesNotExist:
page = Page(slug=slug, content=content, title=title)
page.save()
update_index.Command().handle(using=['default'], remove=True)
return redirect('/view/{slug}.html'.format(slug=page.get_url()))

Expand All @@ -162,3 +176,22 @@ def delete_page(request):
Page.objects.filter(slug=slug).delete()
update_index.Command().handle(using=['default'], remove=True)
return redirect('/')


# Shortcodes
@shortcode
def shortcode_side(*args):
link = slugify(args[0].split('#')[0].lower())
segment = slugify(args[0].split('#')[-1].lower()) if '#' in args[0] else ''
title = args[-1]
try:
Page.objects.get(slug=link)
link_class = ''
except Page.DoesNotExist:
link_class = 'DoesNotExist'
return render_to_string('shortcodes/link.html', {
'link': link,
'segment': segment,
'title': title,
'class': link_class,
})

0 comments on commit 73df543

Please sign in to comment.