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

Small rmpyc improvement - make it safe for paths containing spaces #34

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a006c3b
Small rmpyc improvement - make it safe for paths containing spaces
Mar 24, 2012
e38d5fa
Add support for tag format filtering and auto-tagging questions asked…
cdman May 31, 2012
c4c0ada
Added option to mark user links (in questions/answers/comments) with …
cdman May 31, 2012
bdbbf85
Added optional MathJax support
cdman May 31, 2012
1823bf2
Fixed youtube embedding and added a clearly licensed viewbox.jx - OSQ…
cdman May 31, 2012
1702685
Merge branch 'matchjax_support'
cdman May 31, 2012
8461c8d
Merge branch 'youtube_fix'
cdman May 31, 2012
066d7f7
Adding viewbox's images, missing from previous commit
cdman May 31, 2012
a4f8306
Merge branch 'youtube_fix'
cdman May 31, 2012
f6ef72e
Make user accept rate calculation configurable
cdman May 31, 2012
1d94a8d
Merge branch 'configurable_accept_rate'
cdman May 31, 2012
f4ff7ec
Removed deprecated minified files
cdman May 31, 2012
cb504e8
Merge branch 'remove_leftover_files'
cdman May 31, 2012
18ea97c
Updated viewbox css
cdman May 31, 2012
0a210a5
Merge branch 'youtube_fix'
cdman May 31, 2012
4f498da
Fix missing "Conver to comment" buttons
cdman May 31, 2012
086202e
Merge branch 'fix_missing_convert_buttons'
cdman May 31, 2012
f68c109
Fix markdow help and privacy pages
cdman May 31, 2012
e947fbc
Merge branch 'small_fixes'
cdman May 31, 2012
51d77f9
Add a try-catch block around os.linesep since Google App Engine doesn…
cdman May 31, 2012
2260a92
Merge branch 'gae_compaitibility_fix'
cdman May 31, 2012
7a6eadd
Merge branch 'settings_import_export'
cdman May 31, 2012
bda15b0
Merge branch 'master' into rmpyc_improvement
cdman Jun 1, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions forum/forms/qanda.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.utils.translation import ugettext as _

from django.utils.encoding import smart_unicode
from django.utils.safestring import mark_safe
from general import NextUrlField, UserNameField

from forum import settings
Expand Down Expand Up @@ -71,7 +72,7 @@ def clean(self, value):


class TagNamesField(forms.CharField):
def __init__(self, user=None, *args, **kwargs):
def __init__(self, user=None, initial='', *args, **kwargs):
super(TagNamesField, self).__init__(*args, **kwargs)

self.required = True
Expand All @@ -82,7 +83,7 @@ def __init__(self, user=None, *args, **kwargs):
self.help_text = _('Tags are short keywords, with no spaces within. At least %(min)s and up to %(max)s tags can be used.') % {
'min': settings.FORM_MIN_NUMBER_OF_TAGS, 'max': settings.FORM_MAX_NUMBER_OF_TAGS
}
self.initial = ''
self.initial = initial
self.user = user

def clean(self, value):
Expand All @@ -95,6 +96,16 @@ def clean(self, value):
list = {}
for tag in split_re.split(data):
list[tag] = tag

if settings.ENFORCE_TAG_FORMAT_FLAG and settings.ENFORCE_TAG_FORMAT_RX and len(str(settings.ENFORCE_TAG_FORMAT_RX.strip())) > 0:
try:
regexp = re.compile(str(settings.ENFORCE_TAG_FORMAT_RX.strip()))
good_tags = [tag for tag in list.values() if regexp.match(tag)]
if len(good_tags) == 0:
raise forms.ValidationError(mark_safe(_(settings.ENFORCE_TAG_FORMAT_ERROR_MESSAGE)))
except re.error:
logging.error("Error while trying to match tags against '%s'" % settings.ENFORCE_TAG_FORMAT_RX)
pass

if len(list) > settings.FORM_MAX_NUMBER_OF_TAGS or len(list) < settings.FORM_MIN_NUMBER_OF_TAGS:
raise forms.ValidationError(_('please use between %(min)s and %(max)s tags') % { 'min': settings.FORM_MIN_NUMBER_OF_TAGS, 'max': settings.FORM_MAX_NUMBER_OF_TAGS})
Expand Down Expand Up @@ -175,10 +186,10 @@ class AskForm(forms.Form):
title = TitleField()
text = QuestionEditorField()

def __init__(self, data=None, user=None, *args, **kwargs):
def __init__(self, data=None, user=None, default_tag='', *args, **kwargs):
super(AskForm, self).__init__(data, *args, **kwargs)

self.fields['tags'] = TagNamesField(user)
self.fields['tags'] = TagNamesField(user, initial=default_tag)

if int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff):
spam_fields = call_all_handlers('create_anti_spam_field')
Expand Down
18 changes: 18 additions & 0 deletions forum/markdownext/mdx_nofollow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import markdown
import re

R_NOFOLLOW = re.compile('<a ')
S_NOFOLLOW = '<a rel="nofollow" '

class NofollowPostprocessor(markdown.postprocessors.Postprocessor):
def run(self, text):
return R_NOFOLLOW.sub(S_NOFOLLOW, text)

class NofollowExtension(markdown.Extension):
""" Add nofollow for links to Markdown. """

def extendMarkdown(self, md, md_globals):
md.postprocessors.add('nofollow', NofollowPostprocessor(md), '_end')

def makeExtension(configs={}):
return NofollowExtension(configs=configs)
6 changes: 5 additions & 1 deletion forum/markdownext/mdx_settingsparser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from os import linesep
try:
from os import linesep
except ImportError:
linesep = "\n"

from csv import reader, QUOTE_NONE
import markdown
from markdown import Extension
Expand Down
5 changes: 3 additions & 2 deletions forum/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.utils.html import strip_tags
from forum.utils.html import sanitize_html
from forum.utils.userlinking import auto_user_link
from forum.settings import SUMMARY_LENGTH
from forum.settings import SUMMARY_LENGTH, USE_NOFOLLOW_ON_USER_LINKS
from utils import PickledObjectField

class NodeContent(models.Model):
Expand All @@ -29,7 +29,8 @@ def html(self):
return self.body

def rendered(self, content):
return auto_user_link(self, self._as_markdown(content, *['auto_linker']))
extensions = ['auto_linker', 'nofollow'] if USE_NOFOLLOW_ON_USER_LINKS else ['auto_linker']
return auto_user_link(self, self._as_markdown(content, *extensions))

@classmethod
def _as_markdown(cls, content, *extensions):
Expand Down
17 changes: 16 additions & 1 deletion forum/settings/form.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os.path
from base import Setting, SettingSet
from django.forms.widgets import Textarea
from django.utils.translation import ugettext_lazy as _

FORUM_SET = SettingSet('form', _('Form settings'), _("General settings for the OSQA forms."), 10)
Expand All @@ -14,6 +14,21 @@
help_text = _("Limit tag creation to super users, staff or users with a minimum reputation."),
required=False))

ENFORCE_TAG_FORMAT_FLAG = Setting('ENFORCE_TAG_FORMAT_FLAG', False, FORUM_SET, dict(
label = _("Enforce tag format"),
help_text = _("Should question's tags be checked against a regular expression"),
required=False))

ENFORCE_TAG_FORMAT_RX = Setting('ENFORCE_TAG_FORMAT_RX', '', FORUM_SET, dict(
label = _("Enforce tag format RX"),
help_text = _("Regular eXpression which must match at least one tag on the question"),
required=False))

ENFORCE_TAG_FORMAT_ERROR_MESSAGE = Setting('ENFORCE_TAG_FORMAT_ERROR_MESSAGE', '', FORUM_SET, dict(
label = _("Enforce tag format error message"),
help_text = _("Error message to show if the tags from a question fail to meet the above regular expression (can contain HTML)"),
widget=Textarea(attrs={'rows': '10'}),
required=False))

""" settings for questions """
FORM_MIN_QUESTION_TITLE = Setting('FORM_MIN_QUESTION_TITLE', 10, FORUM_SET, dict(
Expand Down
7 changes: 6 additions & 1 deletion forum/settings/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@
label = _("Custom Head"),
help_text = _("Your custom Head elements."),
widget=Textarea(attrs={'rows': '25'}),
required=False))
required=False))

MATHJAX_ENABLED = Setting('MATHJAX_ENABLED', False, HEAD_SET, dict(
label = _("Enable LaTeX support"),
help_text = _("Enable LaTeX support via MathJax, by loading MathJax javascript"),
required=False))
5 changes: 5 additions & 0 deletions forum/settings/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
help_text = _("If you check this the user accept rate will be displayed on the user posts."),
required=False))

USE_USERS_QUESTIONS_FOR_ACCEPT_RATE = Setting('USE_USERS_QUESTIONS_FOR_ACCEPT_RATE', True, USERS_SET, dict(
label = _("Calculate accept rate SO style"),
help_text = _("Calculate rate as own questions with accepted answers / own questions"),
required=False))

FREEZE_ACCEPT_RATE_FOR = Setting('FREEZE_ACCEPT_RATE_FOR',
["admin",],
USERS_SET, dict(
Expand Down
7 changes: 7 additions & 0 deletions forum/settings/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@
label = _("Limit related tags block"),
help_text = _("Limit related tags block size in questions list pages. Set to 0 to display all all tags.")))

AUTO_SET_TAG_ON_QUESTION = Setting('AUTO_SET_TAG_ON_QUESTION', False, VIEW_SET, dict(
label = _("Automatically set tag on questions asked from tag page"), required=False,
help_text = _("Automatically set the tag on new questions asked from the tag page")))

USE_NOFOLLOW_ON_USER_LINKS = Setting('USE_NOFOLLOW_ON_USER_LINKS', False, VIEW_SET, dict(
label = _("Set nofollow on links in questions/answers"), required=False,
help_text = _("Set the nofollow attribute on links in questions/answers (only applies for new/edited questions/answers)")))
Binary file modified forum/skins/default/media/images/sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added forum/skins/default/media/images/viewbox/load.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added forum/skins/default/media/images/viewbox/miniL.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,7 @@ else
elapsedTime = currTime - prevTime;

pushPreviewHtml(text);
if (MathJax) { MathJax.Hub.Queue(["Typeset",MathJax.Hub]); }
};

// setTimeout is already used. Used as an event listener.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@
elapsedTime = currTime - prevTime;

pushPreviewHtml(text);
if (MathJax) { MathJax.Hub.Queue(["Typeset",MathJax.Hub]); }
};

// setTimeout is already used. Used as an event listener.
Expand Down
Loading