Commit 76b06989 by benjaoming

Merge branch 'edx_release'

Conflicts:
	wiki/plugins/links/mdx/djangowikilinks.py
parents 81bf613a 7fad1ac1
...@@ -81,6 +81,7 @@ else: ...@@ -81,6 +81,7 @@ else:
# children and for instance that an article can be safely deleted. # children and for instance that an article can be safely deleted.
SHOW_MAX_CHILDREN = getattr(django_settings, 'WIKI_SHOW_MAX_CHILDREN', 20) 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 # # PLANNED SETTINGS #
......
...@@ -260,8 +260,10 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm): ...@@ -260,8 +260,10 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm):
owner_username = forms.CharField(required=False, label=_(u'Owner'), owner_username = forms.CharField(required=False, label=_(u'Owner'),
help_text=_(u'Enter the username of the owner.')) help_text=_(u'Enter the username of the owner.'))
group = forms.ModelChoiceField(models.Group.objects.all(), widget=SelectWidgetBootstrap(), group = forms.ModelChoiceField(models.Group.objects.all(), empty_label=_(u'(none)'),
empty_label=_(u'(none)'), required=False) 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.'), 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) required=False)
...@@ -283,6 +285,7 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm): ...@@ -283,6 +285,7 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm):
self.can_change_groups = False self.can_change_groups = False
self.can_assign = 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): if permissions.can_assign(article, request.user):
self.can_assign = True self.can_assign = True
self.fields['group'].queryset = models.Group.objects.all() self.fields['group'].queryset = models.Group.objects.all()
......
...@@ -8,6 +8,8 @@ class ArticleEmptyQuerySet(QuerySet): ...@@ -8,6 +8,8 @@ class ArticleEmptyQuerySet(QuerySet):
return self return self
def can_write(self, user): def can_write(self, user):
return self return self
def active(self):
return self
class ArticleQuerySet(QuerySet): class ArticleQuerySet(QuerySet):
...@@ -80,7 +82,7 @@ class ArticleFkEmptyQuerySetMixin(): ...@@ -80,7 +82,7 @@ class ArticleFkEmptyQuerySetMixin():
return self return self
def can_write(self, user): def can_write(self, user):
return self return self
def active(self, user): def active(self):
return self return self
class ArticleFkQuerySet(ArticleFkQuerySetMixin, QuerySet): class ArticleFkQuerySet(ArticleFkQuerySetMixin, QuerySet):
......
...@@ -28,14 +28,15 @@ try: ...@@ -28,14 +28,15 @@ try:
# but import the 2.0.3 version if it fails # but import the 2.0.3 version if it fails
from markdown.util import etree #@UnusedImport from markdown.util import etree #@UnusedImport
except ImportError: except ImportError:
from markdown import etree #@UnresolvedImport @Reimport from markdown import etree #@UnresolvedImport @Reimport @UnusedImport
class WikiPathExtension(markdown.Extension): class WikiPathExtension(markdown.Extension):
def __init__(self, configs): def __init__(self, configs):
# set extension defaults # set extension defaults
self.config = { self.config = {
'base_url' : ['/', 'String to append to beginning of URL.'], '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 # Override defaults with user settings
...@@ -47,7 +48,7 @@ class WikiPathExtension(markdown.Extension): ...@@ -47,7 +48,7 @@ class WikiPathExtension(markdown.Extension):
self.md = md self.md = md
# append to end of inline patterns # 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 = WikiPath(WIKI_RE, self.config, markdown_instance=md)
wikiPathPattern.md = md wikiPathPattern.md = md
md.inlinePatterns.add('djangowikipath', wikiPathPattern, "<reference") md.inlinePatterns.add('djangowikipath', wikiPathPattern, "<reference")
...@@ -69,29 +70,40 @@ class WikiPath(markdown.inlinepatterns.Pattern): ...@@ -69,29 +70,40 @@ class WikiPath(markdown.inlinepatterns.Pattern):
# from the link, regardless of whether or not something can be # from the link, regardless of whether or not something can be
# looked up # looked up
path_from_link = "" path_from_link = ""
if absolute: if absolute:
base_path = self.config['base_url'][0] base_path = self.config['base_url'][0]
path_from_link = os_path.join(base_path, article_title) path_from_link = os_path.join(base_path, article_title)
urlpath = None
path = path_from_link
try: try:
urlpath = models.URLPath.get_by_path(path_from_link) urlpath = models.URLPath.get_by_path(path_from_link)
path = urlpath.get_absolute_url() path = urlpath.get_absolute_url()
except models.URLPath.DoesNotExist: except models.URLPath.DoesNotExist:
urlpath = None pass
path = path_from_link
else: else:
urlpath = models.URLPath.objects.get(article=self.markdown.article) 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: if urlpath.parent:
lookup = urlpath.parent.get_descendants().filter(slug=article_title) lookup = urlpath.parent.get_descendants().filter(slug=article_title)
else: else:
lookup = urlpath.get_descendants().filter(slug=article_title) lookup = urlpath.get_descendants().filter(slug=article_title)
if lookup.count() > 0: if lookup.count() > 0:
urlpath = lookup[0] urlpath = lookup[0]
path = urlpath.get_absolute_url() path = urlpath.get_absolute_url()
else: else:
urlpath = None urlpath = None
path = "/" + path_from_link path = self.config['base_url'][0] + path_from_link
label = m.group('linkTitle') label = m.group('linkTitle')
a = etree.Element('a') a = etree.Element('a')
...@@ -120,4 +132,4 @@ def makeExtension(configs=None) : ...@@ -120,4 +132,4 @@ def makeExtension(configs=None) :
if __name__ == "__main__": if __name__ == "__main__":
import doctest import doctest
doctest.testmod() doctest.testmod()
\ No newline at end of file
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 _ ...@@ -5,7 +5,8 @@ from django.utils.translation import ugettext as _
from wiki.core.plugins import registry from wiki.core.plugins import registry
from wiki.core.plugins.base import BasePlugin from wiki.core.plugins.base import BasePlugin
from wiki.plugins.links import views 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 wiki.plugins.links.mdx.djangowikilinks import WikiPathExtension
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
...@@ -22,7 +23,12 @@ class LinkPlugin(BasePlugin): ...@@ -22,7 +23,12 @@ class LinkPlugin(BasePlugin):
'form_class': None, 'form_class': None,
'get_form_kwargs': (lambda a: {})} '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): def __init__(self):
pass pass
......
...@@ -52,7 +52,8 @@ ...@@ -52,7 +52,8 @@
{% for urlpath in directory %} {% for urlpath in directory %}
<tr> <tr>
<td> <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 %} {% if urlpath.article.current_revision.deleted %}
<span class="icon-trash"></span> <span class="icon-trash"></span>
{% endif %} {% 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