summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--static/website/templates/ajax-keyword-search.html4
-rw-r--r--static/website/templates/base.html6
-rw-r--r--static/website/templates/filter.html4
-rw-r--r--static/website/templates/get-question.html4
-rw-r--r--static/website/templates/index.html4
-rw-r--r--website/helpers.py11
-rw-r--r--website/templatetags/helpers.py9
-rw-r--r--website/urls.py1
-rw-r--r--website/views.py14
9 files changed, 48 insertions, 9 deletions
diff --git a/static/website/templates/ajax-keyword-search.html b/static/website/templates/ajax-keyword-search.html
index b4295c7..414ae81 100644
--- a/static/website/templates/ajax-keyword-search.html
+++ b/static/website/templates/ajax-keyword-search.html
@@ -1,3 +1,5 @@
+{% load helpers %}
+
{% if questions %}
<br>
<table class="table table-striped table-bordered table-hover">
@@ -48,7 +50,7 @@
<td>
<span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.title }}">
- <a href="{% url 'website:get_question' question.id %}">{{ question.title|truncatechars:40 }}</a>
+ <a href="{% url 'website:get_question' question.id %}{% prettify question.title %}">{{ question.title|truncatechars:40 }}</a>
</span>
</td>
diff --git a/static/website/templates/base.html b/static/website/templates/base.html
index d0697dd..d29571e 100644
--- a/static/website/templates/base.html
+++ b/static/website/templates/base.html
@@ -2,7 +2,11 @@
{% load static %}
<html>
<head>
- <title>Spoken-Tutorial Forums</title>
+ <title>
+ {% block title %}
+ Spoken Tutorial Forums
+ {% endblock %}
+ </title>
{% compress css %}
<link rel="stylesheet" href="{% static 'website/css/bootstrap.min.css' %}" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="{% static 'website/slick/slick.css' %}" type="text/css" media="screen" charset="utf-8" />
diff --git a/static/website/templates/filter.html b/static/website/templates/filter.html
index 1397b26..85ff760 100644
--- a/static/website/templates/filter.html
+++ b/static/website/templates/filter.html
@@ -1,4 +1,6 @@
{% extends 'website/templates/base.html' %}
+{% load helpers %}
+
{% block content %}
{% if questions %}
<h5>
@@ -71,7 +73,7 @@
<td>
<span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.title }}">
- <a href="{% url 'website:get_question' question.id %}">{{ question.title|truncatechars:40 }}</a>
+ <a href="{% url 'website:get_question' question.id %}{% prettify question.title %}">{{ question.title|truncatechars:40 }}</a>
</span>
</td>
diff --git a/static/website/templates/get-question.html b/static/website/templates/get-question.html
index 0f43581..2983412 100644
--- a/static/website/templates/get-question.html
+++ b/static/website/templates/get-question.html
@@ -4,6 +4,10 @@
{% load permission_tags %}
+{% block title %}
+ {{ question.category }} - {{ question.title }} - Spoken Tutorial Forums
+{% endblock %}
+
{% block content %}
<span class="saving hideme">saving . . .</span>
<span class="saved hideme">saved</span>
diff --git a/static/website/templates/index.html b/static/website/templates/index.html
index 5dd19e6..c12ca8b 100644
--- a/static/website/templates/index.html
+++ b/static/website/templates/index.html
@@ -2,6 +2,7 @@
{% load static %}
{% load count_tags %}
{% load notify %}
+{% load helpers %}
{% block content %}
<div id="carousel-container">
@@ -99,7 +100,7 @@
<td>
<span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.title }}">
- <a href="{% url 'website:get_question' question.id %}">{{ question.title|truncatechars:40 }}</a>
+ <a href="{% url 'website:get_question' question.id %}{% prettify question.title %}">{{ question.title|truncatechars:40 }}</a>
</span>
</td>
@@ -173,6 +174,7 @@
e.preventDefault();
});
});
+ $('span').tooltip();
</script>
<script src="{% static 'website/js/nice-bar.js' %}"></script>
{% endblock %}
diff --git a/website/helpers.py b/website/helpers.py
index 0d67da0..bf5217b 100644
--- a/website/helpers.py
+++ b/website/helpers.py
@@ -1,3 +1,5 @@
+import re
+
def get_video_info(path):
"""Uses ffmpeg to determine information about a video. This has not been broadly
tested and your milage may vary"""
@@ -27,3 +29,12 @@ def get_video_info(path):
info_m['width'] = int(info_m['width'])
info_m['height'] = int(info_m['height'])
return info_m
+
+def prettify(string):
+ string = string.lower()
+ string = string.replace('-', ' ')
+ string = string.strip()
+ string = string.replace(' ', '-')
+ string = re.sub('[^A-Za-z0-9\-]+', '', string)
+ string = re.sub('-+', '-', string)
+ return string
diff --git a/website/templatetags/helpers.py b/website/templatetags/helpers.py
new file mode 100644
index 0000000..a0f65be
--- /dev/null
+++ b/website/templatetags/helpers.py
@@ -0,0 +1,9 @@
+from django import template
+
+from website.models import Question, Answer, Notification
+from website.helpers import prettify
+
+register = template.Library()
+
+# imported from website/helpers
+register.simple_tag(prettify)
diff --git a/website/urls.py b/website/urls.py
index 1184044..5d7a654 100644
--- a/website/urls.py
+++ b/website/urls.py
@@ -4,6 +4,7 @@ urlpatterns = patterns('',
url(r'^$', 'website.views.home', name='home'),
url(r'^questions/$', 'website.views.questions', name='questions'),
url(r'^question/(?P<question_id>\d+)/$', 'website.views.get_question', name='get_question'),
+ url(r'^question/(?P<question_id>\d+)/(?P<pretty_url>.+)/$', 'website.views.get_question', name='get_question'),
url(r'^question-answer/$', 'website.views.question_answer', name='question_answer'),
url(r'^answer-comment/$', 'website.views.answer_comment', name='answer_comment'),
url(r'^filter/(?P<category>[^/]+)/$', 'website.views.filter', name='filter'),
diff --git a/website/views.py b/website/views.py
index 221a265..69c5a41 100644
--- a/website/views.py
+++ b/website/views.py
@@ -8,15 +8,16 @@ from django.contrib.auth.decorators import login_required
from django.db.models import Q, Max
from django.core.mail import EmailMultiAlternatives
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
+from django.core.urlresolvers import reverse
from django.contrib.auth import get_user_model
User = get_user_model()
from website.models import Question, Answer, Notification, TutorialDetails, TutorialResources, AnswerComment
from website.forms import NewQuestionForm, AnswerQuesitionForm
-from website.helpers import get_video_info
+from website.helpers import get_video_info, prettify
admins = (
- 9, 4376, 4915, 14595, 12329, 22467, 5518
+ 9, 4376, 4915, 14595, 12329, 22467, 5518, 30705
)
categories = (
@@ -60,8 +61,11 @@ def questions(request):
}
return render(request, 'website/templates/questions.html', context)
-def get_question(request, question_id=None):
+def get_question(request, question_id=None, pretty_url=None):
question = get_object_or_404(Question, id=question_id)
+ pretty_title = prettify(question.title)
+ if pretty_url != pretty_title:
+ return HttpResponseRedirect('/question/'+ question_id + '/' + pretty_title)
answers = question.answer_set.all()
form = AnswerQuesitionForm()
context = {
@@ -121,8 +125,8 @@ def question_answer(request):
email.attach_alternative(message, "text/html")
email.send(fail_silently=True)
# End of email send
-
- return HttpResponseRedirect('/question/'+str(qid) + "#answer" + str(answer.id))
+ return HttpResponseRedirect('/question/'+ str(qid) + "#answer" + str(answer.id))
+ return HttpResponseRedirect('/')
@login_required
def answer_comment(request):