summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-05-05 02:10:45 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-05-05 02:10:45 -0400
commit9c56383cd0525d0e6e5463e1c8a70d2e9d66fd99 (patch)
tree9ee2d285f8b0650485c35c827a0f4375881053b6
parent54891e1576a3b8ad96fcfa159c5eaf5ab9cd2446 (diff)
downloadaskbot-9c56383cd0525d0e6e5463e1c8a70d2e9d66fd99.tar.gz
askbot-9c56383cd0525d0e6e5463e1c8a70d2e9d66fd99.tar.bz2
askbot-9c56383cd0525d0e6e5463e1c8a70d2e9d66fd99.zip
hopefully fixed the askbot site mounted at a sub-url
-rw-r--r--askbot/context.py2
-rw-r--r--askbot/deps/django_authopenid/util.py6
-rw-r--r--askbot/deps/django_authopenid/views.py7
-rw-r--r--askbot/feed.py14
-rw-r--r--askbot/mail/lamson_handlers.py6
-rw-r--r--askbot/management/commands/send_accept_answer_reminders.py3
-rw-r--r--askbot/management/commands/send_email_alerts.py21
-rw-r--r--askbot/management/commands/send_unanswered_question_reminders.py3
-rw-r--r--askbot/models/__init__.py27
-rw-r--r--askbot/models/post.py4
-rw-r--r--askbot/templates/base.html2
-rw-r--r--askbot/templates/question.html2
-rw-r--r--askbot/templates/question/sidebar.html2
-rw-r--r--askbot/templatetags/extra_filters_jinja.py6
-rw-r--r--askbot/utils/decorators.py3
-rw-r--r--askbot/utils/html.py10
-rw-r--r--askbot/views/writers.py1
17 files changed, 59 insertions, 60 deletions
diff --git a/askbot/context.py b/askbot/context.py
index d98b8737..ea4ff0e5 100644
--- a/askbot/context.py
+++ b/askbot/context.py
@@ -16,6 +16,7 @@ from askbot.conf import settings as askbot_settings
from askbot.skins.loaders import get_skin
from askbot.utils import url_utils
from askbot.utils.slug import slugify
+from askbot.utils.html import site_url
def application_settings(request):
"""The context processor function"""
@@ -74,6 +75,7 @@ def application_settings(request):
min_search_word_length = my_settings['MIN_SEARCH_WORD_LENGTH']
context = {
+ 'base_url': site_url(''),
'min_search_word_length': min_search_word_length,
'current_language_code': current_language,
'settings': my_settings,
diff --git a/askbot/deps/django_authopenid/util.py b/askbot/deps/django_authopenid/util.py
index 8c9e78da..06379e1d 100644
--- a/askbot/deps/django_authopenid/util.py
+++ b/askbot/deps/django_authopenid/util.py
@@ -5,12 +5,12 @@ import urlparse
import functools
import re
import random
+from askbot.utils.html import site_url
from openid.store.interface import OpenIDStore
from openid.association import Association as OIDAssociation
from openid.extensions import sreg
from openid import store as openid_store
import oauth2 as oauth # OAuth1 protocol
-
from django.db.models.query import Q
from django.conf import settings
from django.core.urlresolvers import reverse
@@ -731,7 +731,7 @@ class OAuthConnection(object):
request_url = self.parameters['request_token_url']
if callback_url:
- callback_url = '%s%s' % (askbot_settings.APP_URL, callback_url)
+ callback_url = site_url(callback_url)
request_body = urllib.urlencode(dict(oauth_callback=callback_url))
self.request_token = self.send_request(
@@ -819,7 +819,7 @@ def get_oauth2_starter_url(provider_name, csrf_token):
providers = get_enabled_login_providers()
params = providers[provider_name]
client_id = getattr(askbot_settings, provider_name.upper() + '_KEY')
- redirect_uri = askbot_settings.APP_URL + reverse('user_complete_oauth2_signin')
+ redirect_uri = site_url(reverse('user_complete_oauth2_signin'))
client = Client(
auth_endpoint=params['auth_endpoint'],
client_id=client_id,
diff --git a/askbot/deps/django_authopenid/views.py b/askbot/deps/django_authopenid/views.py
index a1ff41e9..287902a1 100644
--- a/askbot/deps/django_authopenid/views.py
+++ b/askbot/deps/django_authopenid/views.py
@@ -51,6 +51,7 @@ from django.utils.html import escape
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
from askbot.mail import send_mail
+from askbot.utils.html import site_url
from recaptcha_works.decorators import fix_recaptcha_remote_ip
from askbot.deps.django_authopenid.ldap_auth import ldap_create_user
from askbot.deps.django_authopenid.ldap_auth import ldap_authenticate
@@ -299,7 +300,7 @@ def complete_oauth2_signin(request):
client = OAuth2Client(
token_endpoint=params['token_endpoint'],
resource_endpoint=params['resource_endpoint'],
- redirect_uri=askbot_settings.APP_URL + reverse('user_complete_oauth2_signin'),
+ redirect_uri=site_url(reverse('user_complete_oauth2_signin')),
client_id=client_id,
client_secret=client_secret
)
@@ -1254,10 +1255,8 @@ def send_email_key(email, key, handler_url_name='user_account_recover'):
subject = _("Recover your %(site)s account") % \
{'site': askbot_settings.APP_SHORT_NAME}
- url = urlparse(askbot_settings.APP_URL)
data = {
- 'validation_link': url.scheme + '://' + url.netloc + \
- reverse(handler_url_name) +\
+ 'validation_link': site_url(reverse(handler_url_name)) + \
'?validation_code=' + key
}
template = get_template('authopenid/email_validation.html')
diff --git a/askbot/feed.py b/askbot/feed.py
index 0e1102b1..a76bb8ae 100644
--- a/askbot/feed.py
+++ b/askbot/feed.py
@@ -17,12 +17,14 @@ from django.contrib.syndication.views import Feed
import itertools
from django.contrib.contenttypes.models import ContentType
+from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from django.core.exceptions import ObjectDoesNotExist
from django.http import Http404
-from askbot.models import Post
from askbot.conf import settings as askbot_settings
+from askbot.models import Post
+from askbot.utils.html import site_url
class RssIndividualQuestionFeed(Feed):
"""rss feed class for particular questions
@@ -48,10 +50,10 @@ class RssIndividualQuestionFeed(Feed):
def item_link(self, item):
"""get full url to the item
"""
- return askbot_settings.APP_URL + item.get_absolute_url()
+ return site_url(item.get_absolute_url())
def link(self):
- return askbot_settings.APP_URL
+ return site_url(reverse('questions'))
def item_pubdate(self, item):
"""get date of creation for the item
@@ -115,10 +117,10 @@ class RssLastestQuestionsFeed(Feed):
def item_link(self, item):
"""get full url to the item
"""
- return askbot_settings.APP_URL + item.get_absolute_url()
+ return site_url(item.get_absolute_url())
def link(self):
- return askbot_settings.APP_URL
+ return site_url(reverse('questions'))
def item_author_name(self, item):
"""get name of author
@@ -128,7 +130,7 @@ class RssLastestQuestionsFeed(Feed):
def item_author_link(self, item):
"""get url of the author's profile
"""
- return askbot_settings.APP_URL + item.author.get_profile_url()
+ return site_url(item.author.get_profile_url())
def item_pubdate(self, item):
"""get date of creation for the item
diff --git a/askbot/mail/lamson_handlers.py b/askbot/mail/lamson_handlers.py
index 728203e6..0aa51629 100644
--- a/askbot/mail/lamson_handlers.py
+++ b/askbot/mail/lamson_handlers.py
@@ -1,6 +1,7 @@
import re
import functools
from django.core.files.uploadedfile import SimpleUploadedFile
+from django.core.urlresolvers import reverse
from django.conf import settings as django_settings
from django.template import Context
from django.template.loader import get_template
@@ -10,6 +11,7 @@ from lamson.server import Relay
from askbot.models import ReplyAddress, Group, Tag
from askbot import mail
from askbot.conf import settings as askbot_settings
+from askbot.utils.html import site_url
#we might end up needing to use something like this
#to distinguish the reply text from the quoted original message
@@ -239,7 +241,7 @@ def VALIDATE_EMAIL(
data = {
'site_name': askbot_settings.APP_SHORT_NAME,
- 'site_url': askbot_settings.APP_URL,
+ 'site_url': site_url(reverse('questions')),
'ask_address': 'ask@' + askbot_settings.REPLY_BY_EMAIL_HOSTNAME,
'can_post_by_email': user.can_post_by_email()
}
@@ -307,7 +309,7 @@ def PROCESS(
#todo: this is copy-paste - factor it out to askbot.mail.messages
data = {
'site_name': askbot_settings.APP_SHORT_NAME,
- 'site_url': askbot_settings.APP_URL,
+ 'site_url': site_url(reverse('questions')),
'ask_address': 'ask@' + askbot_settings.REPLY_BY_EMAIL_HOSTNAME
}
template = get_template('email/re_welcome_lamson_on.html')
diff --git a/askbot/management/commands/send_accept_answer_reminders.py b/askbot/management/commands/send_accept_answer_reminders.py
index 2b8b0851..22ae311d 100644
--- a/askbot/management/commands/send_accept_answer_reminders.py
+++ b/askbot/management/commands/send_accept_answer_reminders.py
@@ -9,6 +9,7 @@ from django.utils.translation import ugettext as _
from django.utils.translation import ungettext
from askbot import mail
from askbot.utils.classes import ReminderSchedule
+from askbot.utils.html import site_url
from django.template import Context
DEBUG_THIS_COMMAND = False
@@ -67,7 +68,7 @@ class Command(NoArgsCommand):
reminder_phrase = _('Please accept the best answer for these questions:')
data = {
- 'site_url': askbot_settings.APP_URL,
+ 'site_url': site_url(''),#here we need only the domain name
'questions': final_question_list,
'reminder_phrase': reminder_phrase
}
diff --git a/askbot/management/commands/send_email_alerts.py b/askbot/management/commands/send_email_alerts.py
index 26f475a1..b7432296 100644
--- a/askbot/management/commands/send_email_alerts.py
+++ b/askbot/management/commands/send_email_alerts.py
@@ -14,6 +14,7 @@ from django.contrib.contenttypes.models import ContentType
from askbot import const
from askbot import mail
from askbot.utils.slug import slugify
+from askbot.utils.html import site_url
DEBUG_THIS_COMMAND = False
@@ -403,8 +404,6 @@ class Command(NoArgsCommand):
else:
num_q += 1
if num_q > 0:
- url_prefix = askbot_settings.APP_URL
-
threads = Thread.objects.filter(id__in=[qq.thread_id for qq in q_list.keys()])
tag_summary = Thread.objects.get_tag_summary_from_threads(threads)
@@ -452,7 +451,7 @@ class Command(NoArgsCommand):
format_action_count('%(num)d ans rev',meta_data['ans_rev'],act_list)
act_token = ', '.join(act_list)
text += '<li><a href="%s?sort=latest">%s</a> <font color="#777777">(%s)</font></li>' \
- % (url_prefix + q.get_absolute_url(), q.thread.title, act_token)
+ % (site_url(q.get_absolute_url()), q.thread.title, act_token)
text += '</ul>'
text += '<p></p>'
#if len(q_list.keys()) >= askbot_settings.MAX_ALERTS_PER_EMAIL:
@@ -462,13 +461,13 @@ class Command(NoArgsCommand):
# 'the askbot and see what\'s new!<br>'
# )
- link = url_prefix + reverse(
- 'user_subscriptions',
- kwargs = {
- 'id': user.id,
- 'slug': slugify(user.username)
- }
- )
+ link = reverse(
+ 'user_subscriptions',
+ kwargs = {
+ 'id': user.id,
+ 'slug': slugify(user.username)
+ }
+ )
text += _(
'<p>Please remember that you can always <a '
@@ -477,7 +476,7 @@ class Command(NoArgsCommand):
'error, please email about it the forum administrator at %(admin_email)s.</'
'p><p>Sincerely,</p><p>Your friendly %(sitename)s server.</p>'
) % {
- 'email_settings_link': link,
+ 'email_settings_link': site_url(link),
'admin_email': django_settings.ADMINS[0][1],
'sitename': askbot_settings.APP_SHORT_NAME
}
diff --git a/askbot/management/commands/send_unanswered_question_reminders.py b/askbot/management/commands/send_unanswered_question_reminders.py
index 982dbafb..42ce5119 100644
--- a/askbot/management/commands/send_unanswered_question_reminders.py
+++ b/askbot/management/commands/send_unanswered_question_reminders.py
@@ -7,6 +7,7 @@ from django.utils.translation import ungettext
from askbot import mail
from askbot.utils.classes import ReminderSchedule
from askbot.models.question import Thread
+from askbot.utils.html import site_url
from django.template import Context
DEBUG_THIS_COMMAND = False
@@ -72,7 +73,7 @@ class Command(NoArgsCommand):
}
data = {
- 'site_url': askbot_settings.APP_URL,
+ 'site_url': site_url(''),
'questions': final_question_list,
'subject_line': subject_line
}
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index a1a8f636..852aed4b 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -63,6 +63,7 @@ from askbot.utils.markup import URL_RE
from askbot.utils.slug import slugify
from askbot.utils.html import replace_links_with_text
from askbot.utils.html import sanitize_html
+from askbot.utils.html import site_url
from askbot.utils.diff import textDiff as htmldiff
from askbot.utils.url_utils import strip_path
from askbot import mail
@@ -3069,17 +3070,7 @@ def format_instant_notification_email(
only update_types in const.RESPONSE_ACTIVITY_TYPE_MAP_FOR_TEMPLATES
are supported
"""
- site_url = askbot_settings.APP_URL
origin_post = post.get_origin_post()
- #todo: create a better method to access "sub-urls" in user views
- user_subscriptions_url = site_url + \
- reverse(
- 'user_subscriptions',
- kwargs = {
- 'id': to_user.id,
- 'slug': slugify(to_user.username)
- }
- )
if update_type == 'question_comment':
assert(isinstance(post, Post) and post.is_comment())
@@ -3143,9 +3134,8 @@ def format_instant_notification_email(
else:
raise ValueError('unrecognized post type')
- base_url = strip_path(site_url)
- post_url = base_url + post.get_absolute_url()
- user_url = base_url + from_user.get_absolute_url()
+ post_url = site_url(post.get_absolute_url())
+ user_url = site_url(from_user.get_absolute_url())
user_action = user_action % {
'user': '<a href="%s">%s</a>' % (user_url, from_user.username),
'post_link': '<a href="%s">%s</a>' % (post_url, _(post.post_type))
@@ -3174,6 +3164,13 @@ def format_instant_notification_email(
else:
reply_separator = user_action
+ user_subscriptions_url = reverse(
+ 'user_subscriptions',
+ kwargs = {
+ 'id': to_user.id,
+ 'slug': slugify(to_user.username)
+ }
+ )
update_data = {
'update_author_name': from_user.username,
'receiving_user_name': to_user.username,
@@ -3184,7 +3181,7 @@ def format_instant_notification_email(
'update_type': update_type,
'post_url': post_url,
'origin_post_title': origin_post.thread.title,
- 'user_subscriptions_url': user_subscriptions_url,
+ 'user_subscriptions_url': site_url(user_subscriptions_url),
'reply_separator': reply_separator,
'reply_address': reply_address
}
@@ -3607,7 +3604,7 @@ def greet_new_user(user, **kwargs):
data = {
'site_name': askbot_settings.APP_SHORT_NAME,
- 'site_url': askbot_settings.APP_URL,
+ 'site_url': site_url(reverse('questions')),
'ask_address': 'ask@' + askbot_settings.REPLY_BY_EMAIL_HOSTNAME,
'can_post_by_email': user.can_post_by_email()
}
diff --git a/askbot/models/post.py b/askbot/models/post.py
index 6b5055de..d48c8b79 100644
--- a/askbot/models/post.py
+++ b/askbot/models/post.py
@@ -34,6 +34,7 @@ from askbot.conf import settings as askbot_settings
from askbot import exceptions
from askbot.utils import markup
from askbot.utils.html import sanitize_html, strip_tags
+from askbot.utils.html import site_url
from askbot.models.base import BaseQuerySetManager, DraftContent
#todo: maybe merge askbot.utils.markup and forum.utils.html
@@ -408,8 +409,7 @@ class Post(models.Model):
"""a naive tweet representation of post
todo: add mentions to relevant people
"""
- url = self.get_absolute_url(no_slug=True)
- url = askbot_settings.APP_URL + url
+ url = site_url(self.get_absolute_url(no_slug=True))
if self.post_type == 'question':
tweet = _('Question: ')
elif self.post_type == 'answer':
diff --git a/askbot/templates/base.html b/askbot/templates/base.html
index 9f943c22..a3bb2173 100644
--- a/askbot/templates/base.html
+++ b/askbot/templates/base.html
@@ -19,7 +19,7 @@
rel="alternate"
type="application/rss+xml"
title="{% trans site_title=settings.APP_SHORT_NAME %}RSS feed from {{ site_title }}{% endtrans %}"
- href="{{ settings.APP_URL }}{% url "latest_questions_feed" %}"
+ href="{{ base_url }}{% url "latest_questions_feed" %}"
/>
{% block before_css %}{% endblock %}
{% include "meta/html_head_stylesheets.html" %}
diff --git a/askbot/templates/question.html b/askbot/templates/question.html
index 8312a8a9..3364cc2f 100644
--- a/askbot/templates/question.html
+++ b/askbot/templates/question.html
@@ -6,7 +6,7 @@
{% endblock %}
{% block keywords %}{{thread.tagname_meta_generator()}}{% endblock %}
{% block forestyle %}
- <link rel="canonical" href="{{settings.APP_URL|strip_path}}{{question.get_absolute_url()}}" />
+ <link rel="canonical" href="{{ base_url }}{{question.get_absolute_url()}}" />
<link rel="stylesheet" type="text/css" href="{{'/js/wmd/wmd.css'|media}}" />
{% endblock %}
{% block forejs %}
diff --git a/askbot/templates/question/sidebar.html b/askbot/templates/question/sidebar.html
index 17820096..c11a4336 100644
--- a/askbot/templates/question/sidebar.html
+++ b/askbot/templates/question/sidebar.html
@@ -42,7 +42,7 @@
{% if settings.RSS_ENABLED %}
<p class="rss">
<a
- href="{{settings.APP_URL}}/feeds/question/{{ question.id }}"
+ href="{{ base_url }}/feeds/question/{{ question.id }}"
title="{% trans %}subscribe to this question rss feed{% endtrans %}"
>{% trans %}subscribe to rss feed{% endtrans %}</a>
</p>
diff --git a/askbot/templatetags/extra_filters_jinja.py b/askbot/templatetags/extra_filters_jinja.py
index 19c216d4..19462da6 100644
--- a/askbot/templatetags/extra_filters_jinja.py
+++ b/askbot/templatetags/extra_filters_jinja.py
@@ -18,6 +18,7 @@ from askbot.conf import settings as askbot_settings
from django.conf import settings as django_settings
from askbot.skins import utils as skin_utils
from askbot.utils.html import absolutize_urls
+from askbot.utils.html import site_url
from askbot.utils import functions
from askbot.utils import url_utils
from askbot.utils.slug import slugify
@@ -150,10 +151,7 @@ def media(url):
@register.filter
def fullmedia(url):
- domain = askbot_settings.APP_URL
- #protocol = getattr(settings, "PROTOCOL", "http")
- path = media(url)
- return "%s%s" % (domain, path)
+ return site_url(media(url))
diff_date = register.filter(functions.diff_date)
diff --git a/askbot/utils/decorators.py b/askbot/utils/decorators.py
index da1cd7db..1cf20059 100644
--- a/askbot/utils/decorators.py
+++ b/askbot/utils/decorators.py
@@ -17,6 +17,7 @@ from django.utils.encoding import smart_str
from askbot import exceptions as askbot_exceptions
from askbot.conf import settings as askbot_settings
from askbot.utils import url_utils
+from askbot.utils.html import site_url
from askbot import get_version
def auto_now_timestamp(func):
@@ -204,7 +205,7 @@ def check_spam(field):
from akismet import Akismet
api = Akismet(
askbot_settings.AKISMET_API_KEY,
- smart_str(askbot_settings.APP_URL),
+ smart_str(site_url(reverse('questions'))),
"Askbot/%s" % get_version()
)
diff --git a/askbot/utils/html.py b/askbot/utils/html.py
index 9fb46337..29e8bd70 100644
--- a/askbot/utils/html.py
+++ b/askbot/utils/html.py
@@ -52,14 +52,14 @@ def absolutize_urls(html):
url_re2 = re.compile(r"(?P<prefix><img[^<]+src=)'(?P<url>/[^']+)'", re.I)
url_re3 = re.compile(r'(?P<prefix><a[^<]+href=)"(?P<url>/[^"]+)"', re.I)
url_re4 = re.compile(r"(?P<prefix><a[^<]+href=)'(?P<url>/[^']+)'", re.I)
- img_replacement = '\g<prefix>"%s/\g<url>" style="max-width:500px;"' % askbot_settings.APP_URL
- replacement = '\g<prefix>"%s\g<url>"' % askbot_settings.APP_URL
+ base_url = site_url('')#important to have this without the slash
+ img_replacement = '\g<prefix>"%s/\g<url>" style="max-width:500px;"' % base_url
+ replacement = '\g<prefix>"%s\g<url>"' % base_url
html = url_re1.sub(img_replacement, html)
html = url_re2.sub(img_replacement, html)
html = url_re3.sub(replacement, html)
#temporal fix for bad regex with wysiwyg editor
- return url_re4.sub(replacement, html).replace('%s//' % askbot_settings.APP_URL,
- '%s/' % askbot_settings.APP_URL)
+ return url_re4.sub(replacement, html).replace('%s//' % base_url, '%s/' % base_url)
def replace_links_with_text(html):
"""any absolute links will be replaced with the
@@ -131,8 +131,6 @@ def site_link(url_name, title):
todo: may be improved to process url parameters, keyword
and other arguments
"""
- from askbot.conf import settings
- base_url = urlparse(settings.APP_URL)
url = site_url(reverse(url_name))
return '<a href="%s">%s</a>' % (url, title)
diff --git a/askbot/views/writers.py b/askbot/views/writers.py
index fb1742f6..8379ba82 100644
--- a/askbot/views/writers.py
+++ b/askbot/views/writers.py
@@ -12,7 +12,6 @@ import random
import sys
import tempfile
import time
-import urlparse
from django.shortcuts import get_object_or_404
from django.shortcuts import render
from django.contrib.auth.decorators import login_required