Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

bunch of improvements #2

Merged
merged 4 commits into from

2 participants

@spookylukey

No description provided.

spookylukey added some commits
@spookylukey spookylukey Provided default values for DJIKI_ALLOW_ANONYMOUS_EDITS and DJIKI_SPA…
…CES_AS_UNDERSCORES
c0d4392
@spookylukey spookylukey Marked messages as 'safe' in view instead of in template.
This is much more preferable, as it provides compatibility with the Django
admin (and probably other apps) that do it this way i.e.  do not use 'safe'
in the template that outputs the message.
18fd105
@spookylukey spookylukey Added setup/usage instructions 1233391
@spookylukey spookylukey Fixed ReST errors in README
(Indentation is interpreted as blockquote by ReST)
d268fea
@emesik emesik merged commit 34398e8 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 9, 2011
  1. @spookylukey
  2. @spookylukey

    Marked messages as 'safe' in view instead of in template.

    spookylukey authored
    This is much more preferable, as it provides compatibility with the Django
    admin (and probably other apps) that do it this way i.e.  do not use 'safe'
    in the template that outputs the message.
  3. @spookylukey
  4. @spookylukey

    Fixed ReST errors in README

    spookylukey authored
    (Indentation is interpreted as blockquote by ReST)
This page is out of date. Refresh to see the latest.
Showing with 56 additions and 33 deletions.
  1. +36 −21 README.rst
  2. +5 −2 djiki/utils.py
  3. +14 −9 djiki/views.py
  4. +1 −1  templates/base.html
View
57 README.rst
@@ -3,27 +3,42 @@ Djiki
Djiki is a lightweight, portable Wiki engine based on Django.
Features:
- * Creole markup,
- * anonymous and registered edits,
- * automatic merges of parallel edits when possible,
- * inclusion of images,
- * diff views between revisions,
- * reverts to any revision in the history,
- * automatic undos of any historical revision, if possible.
+
+* Creole markup,
+* anonymous and registered edits,
+* automatic merges of parallel edits when possible,
+* inclusion of images,
+* diff views between revisions,
+* reverts to any revision in the history,
+* automatic undos of any historical revision, if possible.
Requirements
------------
+* google-diff-match-patch:
+ http://code.google.com/p/google-diff-match-patch/
+
+* WikiCreole parser in Python:
+ http://oink.sheep.art.pl/WikiCreole%20parser%20in%20python
+
+* sorl-thumbnail:
+ *It is used in the example templates, but you may run djiki
+ with any other thumbnailing module or without one at all.*
+ https://github.com/sorl/sorl-thumbnail
- * google-diff-match-patch:
- http://code.google.com/p/google-diff-match-patch/
+Usage
+-----
+* Add 'djiki' and 'sorl.thumbnail' to your INSTALLED_APPS setting.
+* Run './manage.py syncdb' in your project.
+* Add the following to your URLconf::
- * WikiCreole parser in Python:
- http://oink.sheep.art.pl/WikiCreole%20parser%20in%20python
+ (r'wiki/', include('djiki.urls')),
- * sorl-thumbnail:
- *It is used in the example templates, but you may run djiki
- with any other thumbnailing module or without one at all.*
- https://github.com/sorl/sorl-thumbnail
+* Add the required setting DJIKI_IMAGES_PATH
+* Create a 'base.html' that Djiki expects to exist and acts as a base template
+ for all the wiki pages. It must have a 'page' block. Alternatively, supply
+ your own 'djiki/base.html' that overrides the supplied template.
+* Optionally include/add the provided CSS in media/css/styles.css to your page
+ template.
Settings
--------
@@ -33,14 +48,14 @@ The following settings configure Djiki's behavior:
``DJIKI_IMAGES_PATH`` — path to images, relative to MEDIA_ROOT.
``DJIKI_ALLOW_ANONYMOUS_EDITS`` — whether unauthorized users are
-able to edit pages.
+able to edit pages. Defaults to True.
``DJIKI_SPACES_AS_UNDERSCORES`` — makes Djiki replace whitespaces in
URLs by underscores. It's a choice between having nice or exact URLs.
Depending on the settings, the adresses may look as
``http://djiki.org/wiki/Main_Page`` or ``http://djiki.org/wiki/Main%20Page``
This setting will also squash multiple spaces into one. It affects image
-names in the same way, too.
+names in the same way, too. Defaults to True.
Images
------
@@ -54,7 +69,7 @@ still valid, however you may add size by typing
Roadmap
-------
- * ACLs: block anonymous edits, limit access to groups
- * more markup backends; MediaWiki is the main priority
- * page operations: rename, delete
- * translations
+* ACLs: block anonymous edits, limit access to groups
+* more markup backends; MediaWiki is the main priority
+* page operations: rename, delete
+* translations
View
7 djiki/utils.py
@@ -1,13 +1,16 @@
import re
from django.conf import settings
+def spaces_as_underscores():
+ return getattr(settings, 'DJIKI_SPACES_AS_UNDERSCORES', True)
+
def urlize_title(title):
- if settings.DJIKI_SPACES_AS_UNDERSCORES:
+ if spaces_as_underscores():
return re.sub(r'\s+', '_', title)
return title
def deurlize_title(title):
- if settings.DJIKI_SPACES_AS_UNDERSCORES:
+ if spaces_as_underscores():
return re.sub(r'[_\s]+', ' ', title)
return title
View
23 djiki/views.py
@@ -6,10 +6,15 @@
from django.shortcuts import get_object_or_404
from django.template import RequestContext, loader
from django.utils.translation import ugettext as _
+from django.utils.safestring import mark_safe
from django.views.generic.simple import direct_to_template
from urllib import urlencode, quote
from . import models, forms, utils
+
+def allow_anonymous_edits():
+ return getattr(settings, 'DJIKI_ALLOW_ANONYMOUS_EDITS', True)
+
def view(request, title, revision_pk=None):
url_title = utils.urlize_title(title)
if title != url_title:
@@ -29,11 +34,11 @@ def view(request, title, revision_pk=None):
revision = page.revisions.get(pk=revision_pk)
except models.PageRevision.DoesNotExist:
return HttpResponseNotFound()
- messages.info(request, _("The version you are viewing is not the latest one, "
+ messages.info(request, mark_safe(_("The version you are viewing is not the latest one, "
"but represents an older revision of this page, which may have been "
"significantly modified. If it is not what you intended to view, "
"<a href=\"%(url)s\">proceed to the latest version</a>.") % {
- 'url': reverse('djiki-page-view', kwargs={'title': url_title})})
+ 'url': reverse('djiki-page-view', kwargs={'title': url_title})}))
else:
revision = page.last_revision()
if request.REQUEST.get('raw', ''):
@@ -45,7 +50,7 @@ def view(request, title, revision_pk=None):
{'page': page, 'revision': revision})
def edit(request, title):
- if not settings.DJIKI_ALLOW_ANONYMOUS_EDITS and not request.user.is_authenticated():
+ if not allow_anonymous_edits() and not request.user.is_authenticated():
return HttpResponseForbidden()
url_title = utils.urlize_title(title)
if title != url_title:
@@ -68,10 +73,10 @@ def edit(request, title):
if form.is_valid():
if is_preview:
preview_content = form.cleaned_data.get('content', form.data['content'])
- messages.info(request, _("The content you see on this page is shown only as "
+ messages.info(request, mark_safe(_("The content you see on this page is shown only as "
"a preview. <strong>No changes have been saved yet.</strong> Please "
"review the modifications and use the <em>Save</em> button to store "
- "them permanently."))
+ "them permanently.")))
else:
form.save()
return HttpResponseRedirect(
@@ -105,7 +110,7 @@ def diff(request, title):
{'page': page, 'from_revision': from_rev, 'to_revision': to_rev, 'diff': diff})
def revert(request, title, revision_pk):
- if not settings.DJIKI_ALLOW_ANONYMOUS_EDITS and not request.user.is_authenticated():
+ if not allow_anonymous_edits() and not request.user.is_authenticated():
return HttpResponseForbidden()
url_title = utils.urlize_title(title)
if title != url_title:
@@ -134,7 +139,7 @@ def revert(request, title, revision_pk):
{'page': page, 'form': form, 'src_revision': src_revision})
def undo(request, title, revision_pk):
- if not settings.DJIKI_ALLOW_ANONYMOUS_EDITS and not request.user.is_authenticated():
+ if not allow_anonymous_edits() and not request.user.is_authenticated():
return HttpResponseForbidden()
url_title = utils.urlize_title(title)
if title != url_title:
@@ -183,7 +188,7 @@ def undo(request, title, revision_pk):
return direct_to_template(request, 'djiki/edit.html', {'page': page, 'form': form})
def image_new(request):
- if not settings.DJIKI_ALLOW_ANONYMOUS_EDITS and not request.user.is_authenticated():
+ if not allow_anonymous_edits() and not request.user.is_authenticated():
return HttpResponseForbidden()
form = forms.NewImageUploadForm(data=request.POST or None, files=request.FILES or None)
if request.method == 'POST':
@@ -202,7 +207,7 @@ def image_view(request, name):
return direct_to_template(request, 'djiki/image_view.html', {'image': image})
def image_edit(request, name):
- if not settings.DJIKI_ALLOW_ANONYMOUS_EDITS and not request.user.is_authenticated():
+ if not allow_anonymous_edits() and not request.user.is_authenticated():
return HttpResponseForbidden()
url_name = utils.urlize_title(name)
if name != url_name:
View
2  templates/base.html
@@ -30,7 +30,7 @@
<div class="grid_12">
<ul>
{% for msg in messages %}
- <li class="{{ msg.tags }}">{{ msg|safe }}</li>
+ <li class="{{ msg.tags }}">{{ msg }}</li>
{% endfor %}
</ul>
</div>
Something went wrong with that request. Please try again.