From 8a3043c012ebb748d57f55c6c52bd4672ace4568 Mon Sep 17 00:00:00 2001
From: Jayaram Pai
Date: Sun, 4 May 2014 16:49:50 +0530
Subject: added pretty urls to questions
---
static/website/templates/ajax-keyword-search.html | 4 +++-
static/website/templates/base.html | 6 +++++-
static/website/templates/filter.html | 4 +++-
static/website/templates/get-question.html | 4 ++++
static/website/templates/index.html | 4 +++-
website/helpers.py | 11 +++++++++++
website/templatetags/helpers.py | 9 +++++++++
website/urls.py | 1 +
website/views.py | 14 +++++++++-----
9 files changed, 48 insertions(+), 9 deletions(-)
create mode 100644 website/templatetags/helpers.py
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 %}
- {{ question.title|truncatechars:40 }} + {{ question.title|truncatechars:40 }} | 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 %} -- {{ question.title|truncatechars:40 }} + {{ question.title|truncatechars:40 }} | 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 %} 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 %}- {{ question.title|truncatechars:40 }} + {{ question.title|truncatechars:40 }} | @@ -173,6 +174,7 @@ e.preventDefault(); }); }); + $('span').tooltip(); {% 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