From 8914980b7fa0b319d6bdfc7327d502c4e215ef56 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Fri, 1 Oct 2010 02:21:05 -0400 Subject: some more templates converted to jinja2 --- askbot/models/__init__.py | 5 +- .../default/templates/base_content.jinja.html | 2 +- askbot/skins/default/templates/email_base.html | 13 +- askbot/skins/default/templates/feedback.html | 31 +- askbot/skins/default/templates/html.list | 29 +- .../default/templates/instant_notification.html | 34 +- askbot/skins/default/templates/logout.html | 13 +- askbot/skins/default/templates/macros.html | 50 +++ askbot/skins/default/templates/privacy.html | 11 +- askbot/skins/default/templates/question.html | 459 +++++++++++---------- askbot/skins/default/templates/question_edit.html | 57 ++- .../default/templates/question_edit_tips.html | 4 +- .../skins/default/templates/questions.jinja.html | 2 +- .../templates/user_email_subscriptions.html | 2 +- .../skins/default/templates/users_questions.html | 8 +- askbot/templatetags/extra_filters_jinja.py | 7 + askbot/templatetags/extra_tags.py | 5 +- askbot/views/meta.py | 15 +- askbot/views/readers.py | 39 +- askbot/views/writers.py | 7 +- 20 files changed, 437 insertions(+), 356 deletions(-) diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 6e84bd42..10a76018 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -5,7 +5,7 @@ import datetime from django.core.urlresolvers import reverse from askbot.search.indexer import create_fulltext_indexes from django.db.models import signals as django_signals -from django.template import loader, Context +from django.template import Context from django.utils.translation import ugettext as _ from django.utils.translation import ungettext from django.contrib.auth.models import User @@ -1540,7 +1540,8 @@ def send_instant_notifications_about_activity_in_post( if update_activity.activity_type not in acceptable_types: return - template = loader.get_template('instant_notification.html') + from askbot.skins.loaders import ENV + template = ENV.get_template('instant_notification.html') update_type_map = const.RESPONSE_ACTIVITY_TYPE_MAP_FOR_TEMPLATES update_type = update_type_map[update_activity.activity_type] diff --git a/askbot/skins/default/templates/base_content.jinja.html b/askbot/skins/default/templates/base_content.jinja.html index 163aafa0..492e9136 100644 --- a/askbot/skins/default/templates/base_content.jinja.html +++ b/askbot/skins/default/templates/base_content.jinja.html @@ -11,7 +11,7 @@ {% if settings.GOOGLE_SITEMAP_CODE %} {% endif %} - + {% spaceless %} {% block forestyle %}{% endblock %} diff --git a/askbot/skins/default/templates/email_base.html b/askbot/skins/default/templates/email_base.html index 6d9bbea2..406041e4 100644 --- a/askbot/skins/default/templates/email_base.html +++ b/askbot/skins/default/templates/email_base.html @@ -1,14 +1,11 @@ -{% load extra_filters %} -{% load extra_tags %} -{% load i18n %} - +{# this template is not used yet #} - + - - {{settings.APP_TITLE}} logo + + {{settings.APP_TITLE}} logo

{{ settings.APP_TITLE }}

@@ -23,4 +20,4 @@
- \ No newline at end of file + diff --git a/askbot/skins/default/templates/feedback.html b/askbot/skins/default/templates/feedback.html index 4bf31d2d..8b76fbd7 100644 --- a/askbot/skins/default/templates/feedback.html +++ b/askbot/skins/default/templates/feedback.html @@ -1,36 +1,33 @@ -{% extends "base.html" %} - -{% load i18n %} -{% load extra_tags %} -{% load humanize %} -{% block title %}{% spaceless %}{% trans "Feedback" %}{% endspaceless %}{% endblock %} +{% extends "base.jinja.html" %} + +{% block title %}{% spaceless %}{% trans %}Feedback{% endtrans %}{% endspaceless %}{% endblock %} {% block forejs %} {% endblock %} {% block content %}
-{% trans "Give us your feedback!" %} +{% trans %}Give us your feedback!{% endtrans %}
- {% if user.is_authenticated %} + {% if user.is_authenticated() %}

- {% blocktrans with user.username as user_name %} + {% trans user_name=user.username %} Dear {{user_name}}, we look forward to hearing your feedback. Please type and send us your message below. - {% endblocktrans %} + {% endtrans %}

{% else %}

- {% blocktrans %} + {% trans %} Dear visitor, we look forward to hearing your feedback. Please type and send us your message below. - {% endblocktrans %} + {% endtrans %}


{{form.name}}

{{form.email}}
@@ -38,7 +35,7 @@
{% endif %}
@@ -46,10 +43,10 @@
{{form.next}}
-   - +   +
{% endblock %} - + diff --git a/askbot/skins/default/templates/html.list b/askbot/skins/default/templates/html.list index 9a315a9a..477f2080 100644 --- a/askbot/skins/default/templates/html.list +++ b/askbot/skins/default/templates/html.list @@ -1,20 +1,6 @@ ==todo== 404.html 500.html -email_base.html -feedback.html -instant_notification.html -logout.html -macros.html -notarobot.html -pagesize.html -paginator.html -post_contributor_info.html -privacy.html -question_counter_widget.html -question_edit.html -question_edit_tips.html -question.html question_list.html question_retag.html questions_ajax.html @@ -36,8 +22,18 @@ users.html users_questions.html user_stats.html user_votes.html +pagesize.html +paginator.html +notarobot.html +post_contributor_info.html + +==unused== +question_counter_widget.html +email_base.html ==done== +question_edit.html +privacy.html tag_selector.jinja.html questions.jinja.html ask_form.jinja.html @@ -55,3 +51,8 @@ edit_user_email_feeds_form.html user.html user_tabs.html faq.html +feedback.html +instant_notification.html +macros.html +question_edit_tips.html +question.html diff --git a/askbot/skins/default/templates/instant_notification.html b/askbot/skins/default/templates/instant_notification.html index 86556fda..92799a96 100644 --- a/askbot/skins/default/templates/instant_notification.html +++ b/askbot/skins/default/templates/instant_notification.html @@ -1,44 +1,42 @@ -{% load i18n %} -{% load smart_if %} -{% blocktrans %}

Dear {{receiving_user_name}},

{% endblocktrans %} +{% trans %}

Dear {{receiving_user_name}},

{% endtrans %} {% if update_type == 'question_comment' %} -{% blocktrans %} +{% trans %}

{{update_author_name}} left a new comment:

-{% endblocktrans %} +{% endtrans %} {% endif %} {% if update_type == 'answer_comment' %} -{% blocktrans %} +{% trans %}

{{update_author_name}} left a new comment

-{% endblocktrans %} +{% endtrans %} {% endif %} {% if update_type == 'new_answer' %} -{% blocktrans %} +{% trans %}

{{update_author_name}} answered a question {{origin_post_title}}

-{% endblocktrans %} +{% endtrans %} {% endif %} {% if update_type == 'new_question' %} -{% blocktrans %} +{% trans %}

{{update_author_name}} posted a new question {{origin_post_title}}

-{% endblocktrans %} +{% endtrans %} {% endif %} {%if update_type == 'answer_update' %} -{% blocktrans %} +{% trans %}

{{update_author_name}} updated an answer to the question {{origin_post_title}}

-{% endblocktrans %} +{% endtrans %} {% endif %} {% if update_type == 'question_update' %} -{% blocktrans %} +{% trans %}

{{update_author_name}} updated a question {{origin_post_title}}

-{% endblocktrans %} +{% endtrans %} {% endif %}

-{% blocktrans %} +{% trans %}
{{content_preview}}

Please note - you can easily change how often you receive these notifications or unsubscribe. Thank you for your interest in our forum!

-{% endblocktrans %} -{% trans "

Sincerely,
Forum Administrator

" %} +{% endtrans %} +{% trans %}

Sincerely,
Forum Administrator

{% endtrans %} diff --git a/askbot/skins/default/templates/logout.html b/askbot/skins/default/templates/logout.html index c8273a39..297e1862 100644 --- a/askbot/skins/default/templates/logout.html +++ b/askbot/skins/default/templates/logout.html @@ -1,9 +1,6 @@ -{% extends "base_content.html" %} +{% extends "base_content.jinja.html" %} -{% load extra_tags %} -{% load humanize %} -{% load i18n %} -{% block title %}{% spaceless %}{% trans "Logout" %}{% endspaceless %}{% endblock %} +{% block title %}{% spaceless %}{% trans %}Logout{% endtrans %}{% endspaceless %}{% endblock %} {% block forejs %} + - - - + + + {% endif %} - - + + - - + + + - - - + + + {% endblock %} - {% block content %}
- {% trans "Edit question" %} [{% trans "back" %}] + {% trans %}Edit question{% endtrans %} [{% trans %}back{% endtrans %}]
-
- {% if revision_form.revision.errors %}{{ revision_form.revision.errors.as_ul }}{% endif %} +
+ {% if revision_form.revision.errors %}{{ revision_form.revision.errors.as_ul() }}{% endif %}
- {{ revision_form.revision }} + value="{% trans %}select revision{% endtrans %}">
-
- {{ form.title }} {{ form.title.errors }} +
+ {{ form.title }} {{ form.title.errors }}
{{ form.title.help_text }}
@@ -98,34 +94,33 @@ - {% if settings.WIKI_ON %} + {% if settings.WIKI_ON and 'wiki' in form %} {% endif %} - -
- {% trans "toggle preview" %} + {% trans %}toggle preview{% endtrans %} - {{ form.wiki }} {{ form.wiki.label_tag }} + {{ form.wiki }} {{ form.wiki.label_tag() }}
+
- {{ form.tags.label_tag }}:
+ {{ form.tags.label_tag() }}:
{{ form.tags }} {{ form.tags.errors }}
{{ form.tags.help_text }}
- {{ form.summary.label_tag }}
+ {{ form.summary.label_tag() }}
{{ form.summary }} {{ form.summary.errors }}
{{ form.summary.help_text }}
-   - +   +
diff --git a/askbot/skins/default/templates/question_edit_tips.html b/askbot/skins/default/templates/question_edit_tips.html index 1817c5e8..2c239115 100644 --- a/askbot/skins/default/templates/question_edit_tips.html +++ b/askbot/skins/default/templates/question_edit_tips.html @@ -1,6 +1,6 @@
-

{% trans %}question tips{% endtrans %}

+

{% trans %}question tips{% endtrans %}

  • {% trans %}please ask a relevant question{% endtrans %} @@ -19,7 +19,7 @@
-

{% trans %}Markdown tips{% endtrans %}

+

{% trans %}Markdown tips{% endtrans %}

    {% if settings.MARKDUP_CODE_FRIENDLY or settings.ENABLE_MATHJAX %}
  • diff --git a/askbot/skins/default/templates/questions.jinja.html b/askbot/skins/default/templates/questions.jinja.html index aa68cb9f..aa5b3436 100644 --- a/askbot/skins/default/templates/questions.jinja.html +++ b/askbot/skins/default/templates/questions.jinja.html @@ -202,7 +202,7 @@
-

{{question.title}}

+

{{question.title|escape}}

{{ question.last_activity_at|diff_date }} {{question.last_activity_by.username}} diff --git a/askbot/skins/default/templates/user_email_subscriptions.html b/askbot/skins/default/templates/user_email_subscriptions.html index 252b2893..4c2c9cce 100644 --- a/askbot/skins/default/templates/user_email_subscriptions.html +++ b/askbot/skins/default/templates/user_email_subscriptions.html @@ -2,7 +2,7 @@ {% block usercontent %}

{% trans %}Email subscription settings{% endtrans %}

-

{% trans %}email subscription settings info{% endtrans %}

+

{% trans %}email subscription settings info{% endtrans %}

{% if action_status %}

{{action_status}}

diff --git a/askbot/skins/default/templates/users_questions.html b/askbot/skins/default/templates/users_questions.html index 6f987558..074bd60c 100644 --- a/askbot/skins/default/templates/users_questions.html +++ b/askbot/skins/default/templates/users_questions.html @@ -8,14 +8,16 @@ {% if question.favourite_count %} {% if question.favorited_myself %}
- {% trans + src="{% media "/images/vote-favorite-on.png" %}"/>
{{question.favourite_count|intcomma}}
{% else %}
- {% trans
{{question.favourite_count|intcomma}}
diff --git a/askbot/templatetags/extra_filters_jinja.py b/askbot/templatetags/extra_filters_jinja.py index 6f8c14af..8fd44ab2 100644 --- a/askbot/templatetags/extra_filters_jinja.py +++ b/askbot/templatetags/extra_filters_jinja.py @@ -31,6 +31,13 @@ def media(url): else: return '' +@register.filter +def fullmedia(url): + domain = askbot_settings.APP_URL + #protocol = getattr(settings, "PROTOCOL", "http") + path = media(url) + return "%s%s" % (domain, path) + diff_date = register.filter(functions.diff_date) setup_paginator = register.filter(functions.setup_paginator) diff --git a/askbot/templatetags/extra_tags.py b/askbot/templatetags/extra_tags.py index be7a2561..085701e3 100644 --- a/askbot/templatetags/extra_tags.py +++ b/askbot/templatetags/extra_tags.py @@ -446,7 +446,10 @@ def fullmedia(url): @register.inclusion_tag('question_counter_widget.html') #too slow def question_counter_widget(question): - """returns colorized counter widget for a question + """todo: maybe worth trying again. it could have been too slow + because of all the calls to the askbot_settings + + returns colorized counter widget for a question .. versionchanged:: 0.6.6 switched from inclusion tag style to in-code template string diff --git a/askbot/views/meta.py b/askbot/views/meta.py index 5942b277..6b2564a4 100644 --- a/askbot/views/meta.py +++ b/askbot/views/meta.py @@ -50,11 +50,15 @@ def feedback(request): form = FeedbackForm(initial={'next':get_next_url(request)}) data['form'] = form - return render_to_response('feedback.html', data, context_instance=RequestContext(request)) + context = RequestContext(request, data) + template = ENV.get_template('feedback.html') + return HttpResponse(template.render(context)) feedback.CANCEL_MESSAGE=_('We look forward to hearing your feedback! Please, give it next time :)') def privacy(request): - return render_to_response('privacy.html', {'view_name':'privacy'}, context_instance=RequestContext(request)) + context = RequestContext(request, {'view_name':'privacy'}) + template = ENV.get_template('privacy.html') + return HttpResponse(template.render(context)) def logout(request):#refactor/change behavior? #currently you click logout and you get @@ -64,10 +68,13 @@ def logout(request):#refactor/change behavior? #however it might be a little annoying #why not just show a message: you are logged out of forum, but #if you really want to log out -> go to your openid provider - return render_to_response('logout.html', { + data = { 'view_name':'logout', 'next' : get_next_url(request), - }, context_instance=RequestContext(request)) + } + context = RequestContext(request, data) + template = ENV.get_template('logout.html') + return HttpResponse(template.render(context)) def badges(request):#user status/reputation system badges = Badge.objects.all().order_by('name') diff --git a/askbot/views/readers.py b/askbot/views/readers.py index 934be675..73c1b2d0 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -143,14 +143,14 @@ def questions(request): contributors = Question.objects.get_question_and_answer_contributors(questions.object_list) paginator_context = { - 'is_paginated' : True, + 'is_paginated' : (objects_list.count > search_state.page_size), 'pages': objects_list.num_pages, 'page': search_state.page, 'has_previous': questions.has_previous(), 'has_next': questions.has_next(), 'previous': questions.previous_page_number(), 'next': questions.next_page_number(), - 'base_url' : request.path + '?sort=%s&' % search_state.sort,#todo in T sort=>sort_method + 'base_url' : request.path + '?sort=%s&' % search_state.sort,#todo in T sort=>sort_method 'page_size' : search_state.page_size,#todo in T pagesize -> page_size } @@ -166,6 +166,8 @@ def questions(request): } paginator_tpl = loader.get_template('paginator.html') + #todo: remove this patch on context after all templates are moved to jinja + paginator_context['base_url'] = request.path + '?sort=%s&' % search_state.sort paginator_html = paginator_tpl.render( Context( extra_tags.cnprog_paginator( @@ -529,7 +531,20 @@ def question(request, id):#refactor - long subroutine. display question body, an #get response notifications request.user.visit_question(question) - return render_to_response('question.html', { + paginator_data = { + 'is_paginated' : (objects_list.count > ANSWERS_PAGE_SIZE), + 'pages': objects_list.num_pages, + 'page': page, + 'has_previous': page_objects.has_previous(), + 'has_next': page_objects.has_next(), + 'previous': page_objects.previous_page_number(), + 'next': page_objects.next_page_number(), + 'base_url' : request.path + '?sort=%s&' % view_id, + 'extend_url' : "#sort-top" + } + paginator_context = extra_tags.cnprog_paginator(paginator_data) + + data = { 'view_name': 'question', 'active_tab': 'questions', 'question' : question, @@ -542,18 +557,12 @@ def question(request, id):#refactor - long subroutine. display question body, an 'tab_id' : view_id, 'favorited' : favorited, 'similar_questions' : question.get_similar_questions(), - 'context' : { - 'is_paginated' : True, - 'pages': objects_list.num_pages, - 'page': page, - 'has_previous': page_objects.has_previous(), - 'has_next': page_objects.has_next(), - 'previous': page_objects.previous_page_number(), - 'next': page_objects.next_page_number(), - 'base_url' : request.path + '?sort=%s&' % view_id, - 'extend_url' : "#sort-top" - } - }, context_instance=RequestContext(request)) + 'language_code': translation.get_language(), + 'paginator_context' : paginator_context + } + context = RequestContext(request, data) + template = ENV.get_template('question.html') + return HttpResponse(template.render(context)) QUESTION_REVISION_TEMPLATE = ('

%(title)s

\n' '
%(html)s
\n' diff --git a/askbot/views/writers.py b/askbot/views/writers.py index 4ef00809..46df6a3d 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -248,13 +248,16 @@ def edit_question(request, id): revision_form = forms.RevisionForm(question, latest_revision) form = forms.EditQuestionForm(question, latest_revision) - return render_to_response('question_edit.html', { + data = { 'active_tab': 'questions', 'question': question, 'revision_form': revision_form, 'form' : form, 'tags' : _get_tags_cache_json() - }, context_instance=RequestContext(request)) + } + context = RequestContext(request, data) + template = ENV.get_template('question_edit.html') + return HttpResponse(template.render(context)) except exceptions.PermissionDenied, e: request.user.message_set.create(message = unicode(e)) -- cgit v1.2.3-1-g7c22