Commit 76b06989 by benjaoming

Merge branch 'edx_release'

Conflicts:
	wiki/plugins/links/mdx/djangowikilinks.py
parents 81bf613a 7fad1ac1
......@@ -81,6 +81,7 @@ else:
# children and for instance that an article can be safely deleted.
SHOW_MAX_CHILDREN = getattr(django_settings, 'WIKI_SHOW_MAX_CHILDREN', 20)
USE_BOOTSTRAP_SELECT_WIDGET = getattr(django_settings, 'WIKI_USE_BOOTSTRAP_SELECT_WIDGET', True)
####################
# PLANNED SETTINGS #
......
......@@ -260,8 +260,10 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm):
owner_username = forms.CharField(required=False, label=_(u'Owner'),
help_text=_(u'Enter the username of the owner.'))
group = forms.ModelChoiceField(models.Group.objects.all(), widget=SelectWidgetBootstrap(),
empty_label=_(u'(none)'), required=False)
group = forms.ModelChoiceField(models.Group.objects.all(), empty_label=_(u'(none)'),
required=False)
if settings.USE_BOOTSTRAP_SELECT_WIDGET:
group.widget= SelectWidgetBootstrap()
recursive = forms.BooleanField(label=_(u'Inherit permissions'), help_text=_(u'Check here to apply the above permissions recursively to articles under this one.'),
required=False)
......@@ -283,6 +285,7 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm):
self.can_change_groups = False
self.can_assign = False
print "checking can_assing", permissions.can_assign(article, request.user), request.user.is_staff
if permissions.can_assign(article, request.user):
self.can_assign = True
self.fields['group'].queryset = models.Group.objects.all()
......
......@@ -8,6 +8,8 @@ class ArticleEmptyQuerySet(QuerySet):
return self
def can_write(self, user):
return self
def active(self):
return self
class ArticleQuerySet(QuerySet):
......@@ -80,7 +82,7 @@ class ArticleFkEmptyQuerySetMixin():
return self
def can_write(self, user):
return self
def active(self, user):
def active(self):
return self
class ArticleFkQuerySet(ArticleFkQuerySetMixin, QuerySet):
......
......@@ -28,14 +28,15 @@ try:
# but import the 2.0.3 version if it fails
from markdown.util import etree #@UnusedImport
except ImportError:
from markdown import etree #@UnresolvedImport @Reimport
from markdown import etree #@UnresolvedImport @Reimport @UnusedImport
class WikiPathExtension(markdown.Extension):
def __init__(self, configs):
# set extension defaults
self.config = {
'base_url' : ['/', 'String to append to beginning of URL.'],
'html_class' : ['wikipath', 'CSS hook. Leave blank for none.']
'html_class' : ['wikipath', 'CSS hook. Leave blank for none.'],
'default_level' : [2, 'The level that most articles are created at. Relative links will tend to start at that level.']
}
# Override defaults with user settings
......@@ -47,7 +48,7 @@ class WikiPathExtension(markdown.Extension):
self.md = md
# append to end of inline patterns
WIKI_RE = r'\[(?P<linkTitle>.+?)\]\(wiki:(?P<wikiTitle>[a-zA-Z\d\./_-]*)\)'
WIKI_RE = r'\[(?P<linkTitle>[^\]]+?)\]\(wiki:(?P<wikiTitle>[a-zA-Z\d\./_-]*)\)'
wikiPathPattern = WikiPath(WIKI_RE, self.config, markdown_instance=md)
wikiPathPattern.md = md
md.inlinePatterns.add('djangowikipath', wikiPathPattern, "<reference")
......@@ -69,29 +70,40 @@ class WikiPath(markdown.inlinepatterns.Pattern):
# from the link, regardless of whether or not something can be
# looked up
path_from_link = ""
if absolute:
base_path = self.config['base_url'][0]
path_from_link = os_path.join(base_path, article_title)
urlpath = None
path = path_from_link
try:
urlpath = models.URLPath.get_by_path(path_from_link)
path = urlpath.get_absolute_url()
except models.URLPath.DoesNotExist:
urlpath = None
path = path_from_link
pass
else:
urlpath = models.URLPath.objects.get(article=self.markdown.article)
path_from_link = os_path.join(urlpath.path, article_title)
source_components = urlpath.path.strip("/").split("/")
# We take the first (self.config['default_level'] - 1) components, so adding
# one more component would make a path of length self.config['default_level']
starting_level = max(0, self.config['default_level'][0] - 1 )
starting_path = "/".join(source_components[ : starting_level ])
path_from_link = os_path.join(starting_path, article_title)
lookup = models.URLPath.objects.none()
if urlpath.parent:
lookup = urlpath.parent.get_descendants().filter(slug=article_title)
else:
lookup = urlpath.get_descendants().filter(slug=article_title)
if lookup.count() > 0:
urlpath = lookup[0]
path = urlpath.get_absolute_url()
else:
urlpath = None
path = "/" + path_from_link
path = self.config['base_url'][0] + path_from_link
label = m.group('linkTitle')
a = etree.Element('a')
......@@ -120,4 +132,4 @@ def makeExtension(configs=None) :
if __name__ == "__main__":
import doctest
doctest.testmod()
\ No newline at end of file
doctest.testmod()
from django.conf import settings as django_settings
LOOKUP_LEVEL = getattr(django_settings, 'WIKI_LINKS_LOOKUP_LEVEL', 2)
......@@ -5,7 +5,8 @@ from django.utils.translation import ugettext as _
from wiki.core.plugins import registry
from wiki.core.plugins.base import BasePlugin
from wiki.plugins.links import views
from wiki.plugins.links.mdx.urlize import makeExtension
from wiki.plugins.links import settings
from wiki.plugins.links.mdx.urlize import makeExtension as urlize_makeExtension
from wiki.plugins.links.mdx.djangowikilinks import WikiPathExtension
from django.core.urlresolvers import reverse_lazy
......@@ -22,7 +23,12 @@ class LinkPlugin(BasePlugin):
'form_class': None,
'get_form_kwargs': (lambda a: {})}
markdown_extensions = [makeExtension(), WikiPathExtension([('base_url', reverse_lazy('wiki:get', kwargs={'path': ''}))])]
wikipath_config = [
('base_url', reverse_lazy('wiki:get', kwargs={'path': ''}) ),
('default_level', settings.LOOKUP_LEVEL ),
]
markdown_extensions = [urlize_makeExtension(), WikiPathExtension(wikipath_config)]
def __init__(self):
pass
......
......@@ -52,7 +52,8 @@
{% for urlpath in directory %}
<tr>
<td>
<a href="{% url 'wiki:dir' path=urlpath.path %}"> {{ urlpath.article.current_revision.title }} </a>
<a href="{% url 'wiki:get' path=urlpath.path %}"> {{ urlpath.article.current_revision.title }} </a>
<a href="{% url 'wiki:dir' path=urlpath.path %}" class="list-children"></a>
{% if urlpath.article.current_revision.deleted %}
<span class="icon-trash"></span>
{% endif %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment