Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #89: Auto link key terms #15

Merged
merged 19 commits into from Sep 26, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b15c131
removed incorrect localization of a message
evgenyfadeev Sep 17, 2011
094b354
added url explaining how to enable cookies in the browser
evgenyfadeev Sep 17, 2011
fdaabe9
added askbot_requirements.txt to MANIFEST.in
evgenyfadeev Sep 19, 2011
94641e2
made the welcome message for anonymous users editable via admin settings
Sep 19, 2011
d967dc8
fixed incorrect usage of diff_date in the templates, added a better t…
evgenyfadeev Sep 20, 2011
02d9266
fixed appearance of anonymous user message when user logs out
ragsagar Sep 20, 2011
9131ca6
fixed appearance of anonymous user message when user logs out
ragsagar Sep 20, 2011
646c192
fixed appearance of anonymous user message when user logs out
ragsagar Sep 20, 2011
dca33d4
fixed the double prefix issue in the instant emails
evgenyfadeev Sep 20, 2011
7b48fff
removed uses of __class__.__name__ on posts
evgenyfadeev Sep 20, 2011
d2dcfcf
Merge branch 'stultus'
evgenyfadeev Sep 21, 2011
47cdfb6
pylinted files
evgenyfadeev Sep 21, 2011
0d7897d
updated changelog and the contributors file
evgenyfadeev Sep 21, 2011
2e5cc2b
removed unused file
evgenyfadeev Sep 21, 2011
03c0039
merged fix by Rag Sagar so that anonymous user greeting shows just once
evgenyfadeev Sep 21, 2011
48c58a0
incremented revision
evgenyfadeev Sep 23, 2011
d188a4a
Merge branch 'auto-link'
sagarun Sep 24, 2011
85ceec2
Fix help text in settings UI of auto link key terms
sagarun Sep 24, 2011
10ff7a3
Log when number of patterns mismatch number of URLs
sagarun Sep 24, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Expand Up @@ -4,6 +4,7 @@ include LICENSE
include AUTHORS
include COPYING
include README.rst
include askbot_requirements.txt
recursive-include askbot *
recursive-exclude askbot *.pyc
recursive-exclude .git
Expand Down
2 changes: 1 addition & 1 deletion askbot/__init__.py
Expand Up @@ -9,7 +9,7 @@
import sys
import logging

VERSION = (0, 7, 22)
VERSION = (0, 7, 23)

#necessary for interoperability of django and coffin
try:
Expand Down
27 changes: 14 additions & 13 deletions askbot/conf/markup.py
Expand Up @@ -113,12 +113,12 @@ def regex_settings_validation(*args):
'PATTERN',
description=_('Regex to detect the pattern'),
help_text=_(
'Enter a valid regular expression to '
'detect the pattern. For example to'
'detect something like #rhbz 637402 '
'use a regular expression like #rhbz\s(\d+)'
'If you want to process multiple regex enter'
' them line by line'
' Enter valid regular expressions to'
' detect patterns. If you want to auto'
' link more than one key terms enter them'
' line by line. For example to'
' detect a bug pattern like #rhbz 637402'
' you will have use the following regex #rhbz\s(\d+)'
),
update_callback=regex_settings_validation,
default = ''
Expand All @@ -131,13 +131,14 @@ def regex_settings_validation(*args):
'AUTO_LINK_URL',
description=_('URL for autolinking'),
help_text=_(
'Let us assume that to detect a pattern #rhbz 637402'
' the regex is #rhbz\s(\d+) '
'then the autolink URL should be https://bugzilla.redhat.com/show_bug.cgi?id=\1'
' Where \1 is the saved match (bugid) from the regular expression'
' If you want to process multiple regex enter'
' them line by line. The URL in first line will be used to link the'
' pattern on the first line'
' The regex to detect pattern #rhbz 637402'
' is #rhbz\s(\d+), If you want to auto link it to the actual bug'
' then the autolink URL should be entered here. Example URL can be'
' https://bugzilla.redhat.com/show_bug.cgi?id=\\1'
' where \\1 is the saved match (bugid) from the regular expression.'
' Multiple URLs should be entered in separate lines.'
' The URL entered in first line'
' will be used to auto link the first pattern or key term'
),
default = ''
)
Expand Down
19 changes: 7 additions & 12 deletions askbot/conf/site_settings.py
Expand Up @@ -5,8 +5,6 @@
from askbot.conf.settings_wrapper import settings
from askbot.deps import livesettings
from django.utils.translation import ugettext as _
from django.utils.html import escape
from askbot import const

QA_SITE_SETTINGS = livesettings.ConfigurationGroup(
'QA_SITE_SETTINGS',
Expand Down Expand Up @@ -74,19 +72,16 @@
settings.register(
livesettings.StringValue(
QA_SITE_SETTINGS,
'GREETING_URL',
default='/' + _('faq/'),#cannot reverse url here, must be absolute also
hidden=True,
'GREETING_FOR_ANONYMOUS_USER',
default='First time here? Check out the FAQ!',
hidden=False,
description=_(
'Link shown in the greeting message '
'Text shown in the greeting message '
'shown to the anonymous user'
),
help_text=_('If you change this url from the default - '
'then you will also probably want to adjust translation of '
'the following string: ') + '"'
+ escape(const.GREETING_FOR_ANONYMOUS_USER + '"'
' You can find this string in your locale django.po file'
)
help_text=_(
'Use HTML to format the message '
)
)
)

Expand Down
1 change: 1 addition & 0 deletions askbot/const/__init__.py
Expand Up @@ -263,6 +263,7 @@
'facebook-apps': 'http://www.facebook.com/developers/createapp.php',
'google-webmaster-tools': 'https://www.google.com/webmasters/tools/home',
'identica-apps': 'http://identi.ca/settings/oauthapps',
'noscript': 'https://www.google.com/support/bin/answer.py?answer=23852',
'linkedin-apps': 'https://www.linkedin.com/secure/developer',
'mathjax': 'http://www.mathjax.org/resources/docs/?installation.html',
'recaptcha': 'http://google.com/recaptcha',
Expand Down
9 changes: 1 addition & 8 deletions askbot/const/message_keys.py
Expand Up @@ -9,14 +9,7 @@

#NOTE: all strings must be explicitly put into this dictionary,
#because you don't want to import _ from here with import *
__all__ = ['GREETING_FOR_ANONYMOUS_USER', ]

#this variable is shown in settings, because
#the url within is configurable, the default is reverse('faq')
#if user changes url they will have to be able to fix the
#message translation too
GREETING_FOR_ANONYMOUS_USER = \
_('First time here? Check out the <a href="%s">FAQ</a>!')
__all__ = []

#messages loaded in the templates via direct _ calls
_('most relevant questions')
Expand Down
4 changes: 3 additions & 1 deletion askbot/context.py
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
import askbot
from askbot import api
from askbot import const
from askbot.conf import settings as askbot_settings
from askbot.skins.loaders import get_skin
from askbot.utils import url_utils
Expand All @@ -22,5 +23,6 @@ def application_settings(request):
return {
'settings': my_settings,
'skin': get_skin(request),
'moderation_items': api.get_info_on_moderation_items(request.user)
'moderation_items': api.get_info_on_moderation_items(request.user),
'noscript_url': const.DEPENDENCY_URLS['noscript'],
}
8 changes: 5 additions & 3 deletions askbot/doc/source/changelog.rst
@@ -1,16 +1,18 @@
Changes in Askbot
=================

Development version
0.7.23 (Current Version)
-------------------
* Greeting for anonymuos users can be changed from live settings (Hrishi)
* Greeting for anonymous users is shown only once (Rag Sagar)
* Added support for Akismet spam detection service (Adolfo Fitoria)
* Added noscript message (Arun SAG)
* Support for url shortening with TinyUrl on link sharing (Rtnpro)
* Allowed logging in with password and email in the place of login name (Evgeny)
* Added config settings allowing adjust license information (Evgeny)

0.7.22 (Current Version)
------------------------
0.7.22
------
* Media resource revision is now incremented
automatically any time when media is updated (Adolfo Fitoria, Evgeny Fadeev)
* First user automatically becomes site administrator (Adolfo Fitoria)
Expand Down
2 changes: 2 additions & 0 deletions askbot/doc/source/contributors.rst
Expand Up @@ -15,10 +15,12 @@ Programming and documentation
* Andy Knotts
* Benoit Lavine (with Windriver Software, Inc.)
* Jeff Madynski
* `Hrishi <https://github.com/stultus>`_
* Andrei Mamoutkine
* Ramiro Morales (with Machinalis)
* `NoahY <https://github.com/NoahY>`_
* `Gael Pasgrimaud <http://www.gawel.org/>`_ (bearstech)
* `Rag Sagar <https://github.com/ragsagar>`_
* Alex Robbins (celery support)
* `Tomasz Szynalski <http://antimoon.com>`_

Expand Down
31 changes: 19 additions & 12 deletions askbot/forms.py
Expand Up @@ -968,19 +968,26 @@ def __init__(self, *arg, **kwarg):

class EditUserEmailFeedsForm(forms.Form):
FORM_TO_MODEL_MAP = {
'all_questions':'q_all',
'asked_by_me':'q_ask',
'answered_by_me':'q_ans',
'individually_selected':'q_sel',
'mentions_and_comments':'m_and_c',
}
'all_questions':'q_all',
'asked_by_me':'q_ask',
'answered_by_me':'q_ans',
'individually_selected':'q_sel',
'mentions_and_comments':'m_and_c',
}
NO_EMAIL_INITIAL = {
'all_questions':'n',
'asked_by_me':'n',
'answered_by_me':'n',
'individually_selected':'n',
'mentions_and_comments':'n',
}
'all_questions':'n',
'asked_by_me':'n',
'answered_by_me':'n',
'individually_selected':'n',
'mentions_and_comments':'n',
}
INSTANT_EMAIL_INITIAL = {
'all_questions':'i',
'asked_by_me':'i',
'answered_by_me':'i',
'individually_selected':'i',
'mentions_and_comments':'i',
}

asked_by_me = EmailFeedSettingField(
label=_('Asked by me')
Expand Down
10 changes: 5 additions & 5 deletions askbot/locale/en/LC_MESSAGES/django.po
Expand Up @@ -499,7 +499,7 @@ msgstr ""

#: conf/email.py:22
msgid "Prefix for the email subject line"
msgstr "Welcome to the Q&A forum"
msgstr ""

#: conf/email.py:24
msgid ""
Expand Down Expand Up @@ -1600,10 +1600,10 @@ msgstr ""
msgid "bronze"
msgstr ""

#: const/message_keys.py:19
#, python-format
msgid "First time here? Check out the <a href=\"%s\">FAQ</a>!"
msgstr ""





#: const/message_keys.py:22 skins/default/templates/main_page/tab_bar.html:27
msgid "most relevant questions"
Expand Down
42 changes: 35 additions & 7 deletions askbot/middleware/anon_user.py
@@ -1,13 +1,25 @@
from django.utils.translation import ugettext as _
"""middleware that allows anonymous users
receive messages using the now deprecated `message_set()`
interface of the user objects.

To allow anonymous users accept messages, a special
message manager is defined here, and :meth:`__deepcopy__()` method
added to the :class:`AnonymousUser` so that user could be pickled.

Secondly, it sends greeting message to anonymous users.
"""
from askbot.user_messages import create_message, get_and_delete_messages
from askbot.conf import settings as askbot_settings
from askbot import const

class AnonymousMessageManager(object):
"""message manager for the anonymous user"""
def __init__(self, request):
self.request = request

def create(self, message=''):
"""send message to anonymous user"""
create_message(self.request, message)

def get_and_delete(self):
messages = get_and_delete_messages(self.request)
return messages
Expand All @@ -19,18 +31,34 @@ def dummy_deepcopy(*arg):
return None

class ConnectToSessionMessagesMiddleware(object):
"""middleware that attaches messages to anonymous users"""
def process_request(self, request):
if not request.user.is_authenticated():
#plug on deepcopy which may be called by django db "driver"
request.user.__deepcopy__ = dummy_deepcopy
request.user.__deepcopy__ = dummy_deepcopy
#here request is linked to anon user
request.user.message_set = AnonymousMessageManager(request)
request.user.message_set = AnonymousMessageManager(request)
request.user.get_and_delete_messages = \
request.user.message_set.get_and_delete

#also set the first greeting one time per session only
if 'greeting_set' not in request.session:
if 'greeting_set' not in request.session and \
'askbot_visitor' not in request.COOKIES:
request.session['greeting_set'] = True
msg = _(const.GREETING_FOR_ANONYMOUS_USER) \
% askbot_settings.GREETING_URL
msg = askbot_settings.GREETING_FOR_ANONYMOUS_USER
request.user.message_set.create(message=msg)

def process_response(self, request, response):
""" Adds the ``'askbot_visitor'``key to cookie if user ever authenticates so
that the anonymous user message won't be shown. """
if request.user.is_authenticated() and \
'askbot_visitor' not in request.COOKIES :
#import datetime
#max_age = 365*24*60*60
#expires = datetime.datetime.strftime\
# (datetime.datetime.utcnow() +
# datetime.timedelta(seconds=max_age),\
# "%a, %d-%b-%Y %H:%M:%S GMT")
response.set_cookie('askbot_visitor', False)
return response

3 changes: 2 additions & 1 deletion askbot/models/__init__.py
Expand Up @@ -1202,6 +1202,8 @@ def user_post_question(
is_anonymous = False,
timestamp = None
):
"""makes an assertion whether user can post the question
then posts it and returns the question object"""

self.assert_can_post_question()

Expand Down Expand Up @@ -2230,7 +2232,6 @@ def format_instant_notification_email(
'origin_post_title': origin_post.title,
'user_subscriptions_url': user_subscriptions_url,
}
subject_line = mail.prefix_the_subject_line(subject_line)
return subject_line, template.render(Context(update_data))

#todo: action
Expand Down
4 changes: 2 additions & 2 deletions askbot/models/meta.py
Expand Up @@ -159,9 +159,9 @@ def get_owner(self):
return self.user

def get_updated_activity_data(self, created = False):
if self.content_object.__class__.__name__ == 'Question':
if self.content_object.post_type == 'question':
return const.TYPE_ACTIVITY_COMMENT_QUESTION, self
elif self.content_object.__class__.__name__ == 'Answer':
elif self.content_object.post_type == 'answer':
return const.TYPE_ACTIVITY_COMMENT_ANSWER, self

def get_response_receivers(self, exclude_list = None):
Expand Down
2 changes: 1 addition & 1 deletion askbot/skins/default/templates/blocks/bottom_scripts.html
Expand Up @@ -4,7 +4,7 @@
#}
<div id="no-javascript">
<noscript class="noscript">
{% trans app_name = settings.APP_SHORT_NAME %}Please note: {{app_name}} requires javascript to work properly, please enable javascript in your browser{% endtrans %}
{% trans app_name = settings.APP_SHORT_NAME %}Please note: {{app_name}} requires javascript to work properly, please enable javascript in your browser, <a href="{{noscript_url}}">here is how</a>{% endtrans %}
</noscript>
</div>
<script type="text/javascript">
Expand Down
14 changes: 7 additions & 7 deletions askbot/skins/default/templates/macros.html
Expand Up @@ -246,9 +246,9 @@
<div class='post-update-info'>
{% if is_wiki %}
<p>
{%- if post.__class__.__name__ == 'Question' -%}
{%- if post.post_type == 'question' -%}
{%- trans %}asked{% endtrans %}
{% elif post.__class__.__name__ == 'Answer' %}
{% elif post.post_type == 'answer' %}
{%- trans %}answered{% endtrans %}
{% else %}
{%- trans %}posted{% endtrans %}
Expand All @@ -265,9 +265,9 @@
{% else %}
<p style="line-height:12px;">
{# todo: access to class names needs to be removed here #}
{% if post.__class__.__name__=="Question" %}
{% if post.post_type == 'question' %}
{% trans %}asked{% endtrans %}
{% elif post.__class__.name__=="Answer" %}
{% elif post.post_type == 'answer' %}
{% trans %}answered{% endtrans %}
{% else %}
{% trans %}posted{% endtrans %}
Expand All @@ -282,11 +282,11 @@
{% endif %}
</div>
{% elif contributor_type=="last_updater" %}
{% if post.__class__.__name__ in ('Question', 'Answer') %}
{% if post.post_type in ('Question', 'Answer') %}
{% set last_edited_at = post.last_edited_at %}
{% set original_author = post.author %}
{% set update_author = post.last_edited_by %}
{% elif post.__class__.__name__ in ('QuestionRevision', 'AnswerRevision') %}
{% elif post.post_type in ('QuestionRevision', 'AnswerRevision') %}
{% set last_edited_at = post.revised_at %}
{% set original_author = None %}{# fake value to force display widget in the revision views #}
{% set update_author = post.author %}
Expand All @@ -295,7 +295,7 @@
<div class='post-update-info'>
<p style="line-height:12px;">
<a
{% if post.__class__.__name__ == 'Question' %}
{% if post.post_type == 'Question' %}
href="{% url question_revisions post.id %}"
{% else %}
href="{% url answer_revisions post.id %}"
Expand Down