Compare commits

..

12 Commits

Author SHA1 Message Date
James Turk
2aff42e4a9 urls 2013-12-04 14:48:15 -05:00
James Turk
74a4f00ac3 fix url tag 2013-12-04 14:35:21 -05:00
James Turk
6cc6f46348 markupfield dep 2013-12-04 14:22:00 -05:00
James Turk
236239e774 test on new python/django combos 2013-12-04 14:19:17 -05:00
James Turk
a20417af0b fix travis settings 2012-03-23 16:21:02 -04:00
James Turk
b674c84144 start testing w/ django 1.4 2012-03-23 15:59:15 -04:00
James Turk
56f37a55d1 update changelog 2012-03-21 15:28:17 -04:00
James Turk
2c3e259b36 travis ci 2012-03-21 15:23:29 -04:00
James Turk
d40076186b Merge pull request #1 from jcarbaugh/master
fix redirect_to and make revert work
2012-01-05 08:47:01 -08:00
Jeremy Carbaugh
89713013dc make revert feature work 2012-01-05 11:43:00 -05:00
Jeremy Carbaugh
9160ed2fd9 set blank=True on Article.redirect_to 2012-01-05 10:46:32 -05:00
Jeremy Carbaugh
0864edd921 allow null editors 2011-04-29 11:02:32 -04:00
10 changed files with 91 additions and 22 deletions

18
.travis.yml Normal file
View File

@ -0,0 +1,18 @@
language: python
python:
- "2.6"
- "2.7"
- "3.3"
env:
- DJANGO_PACKAGE="Django<1.5"
- DJANGO_PACKAGE="Django>=1.5,<1.6"
- DJANGO_PACKAGE="Django>=1.6,<1.7"
install: pip install $DJANGO_PACKAGE markdown docutils django-markupfield --use-mirrors
script: django-admin.py test --settings=example.settings --pythonpath=.
matrix:
exclude:
- python: "3.3"
env: DJANGO_PACKAGE="Django<1.5"
notifications:
email:
- james.p.turk@gmail.com

View File

@ -1,7 +1,12 @@
0.3.0 0.3.0
===== =====
- lots of tests - lots of tests
- - new escape_html option
- csrf token
- autolockarticles management command
- null editors
- fix revert
0.2.0 0.2.0
=================== ===================

View File

@ -1,3 +1,5 @@
import os
DEBUG = True DEBUG = True
TEMPLATE_DEBUG = DEBUG TEMPLATE_DEBUG = DEBUG
@ -27,7 +29,7 @@ MIDDLEWARE_CLASSES = (
ROOT_URLCONF = 'example.urls' ROOT_URLCONF = 'example.urls'
TEMPLATE_DIRS = ( 'templates', ) TEMPLATE_DIRS = ( os.path.join(os.path.dirname(__file__), 'templates'), )
INSTALLED_APPS = ( INSTALLED_APPS = (
'django.contrib.auth', 'django.contrib.auth',

View File

@ -1,4 +1,4 @@
from django.conf.urls.defaults import * from django.conf.urls import *
# Uncomment the next two lines to enable the admin: # Uncomment the next two lines to enable the admin:
# from django.contrib import admin # from django.contrib import admin

View File

@ -34,9 +34,9 @@ ARTICLE_STATUSES = (
class Article(models.Model): class Article(models.Model):
title = models.CharField(max_length=200) title = models.CharField(max_length=200)
creator = models.ForeignKey(User, related_name='wiki_articles') creator = models.ForeignKey(User, related_name='wiki_articles', blank=True, null=True)
status = models.IntegerField(choices=ARTICLE_STATUSES, default=PUBLIC) status = models.IntegerField(choices=ARTICLE_STATUSES, default=PUBLIC)
redirect_to = models.ForeignKey('self', null=True) redirect_to = models.ForeignKey('self', blank=True, null=True)
def __unicode__(self): def __unicode__(self):
return self.title return self.title
@ -50,6 +50,11 @@ class Article(models.Model):
if '/' in self.title: if '/' in self.title:
return self.title.rsplit('/',1)[0] return self.title.rsplit('/',1)[0]
# def save(self, **kwargs):
# if self.creator is not None and self.creator.is_anonymous():
# self.creator = None
# super(Article, self).save(**kwargs)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('view_article', args=[self.title]) return reverse('view_article', args=[self.title])
@ -68,21 +73,25 @@ class Article(models.Model):
else: else:
return EDITOR_TEST_FUNC(user) return EDITOR_TEST_FUNC(user)
def get_write_lock(self, user, release=False): def get_write_lock(self, user_or_request, release=False):
if hasattr(user_or_request, 'session'):
lock_id = user_or_request.session.session_key
else:
lock_id = user_or_request.id
cache_key = 'markupwiki_articlelock_%s' % self.id cache_key = 'markupwiki_articlelock_%s' % self.id
lock = cache.get(cache_key) lock = cache.get(cache_key)
if lock: if lock:
if release: if release:
cache.delete(cache_key) cache.delete(cache_key)
return lock == user.id return lock == lock_id
if not release: if not release:
cache.set(cache_key, user.id, WRITE_LOCK_SECONDS) cache.set(cache_key, lock_id, WRITE_LOCK_SECONDS)
return True return True
class ArticleVersion(models.Model): class ArticleVersion(models.Model):
article = models.ForeignKey(Article, related_name='versions') article = models.ForeignKey(Article, related_name='versions')
author = models.ForeignKey(User, related_name='article_versions') author = models.ForeignKey(User, related_name='article_versions', blank=True, null=True)
number = models.PositiveIntegerField() number = models.PositiveIntegerField()
body = MarkupField(default_markup_type=DEFAULT_MARKUP_TYPE, body = MarkupField(default_markup_type=DEFAULT_MARKUP_TYPE,
markup_choices=WIKI_MARKUP_TYPES, markup_choices=WIKI_MARKUP_TYPES,
@ -99,5 +108,10 @@ class ArticleVersion(models.Model):
def __unicode__(self): def __unicode__(self):
return '%s rev #%s' % (self.article, self.number) return '%s rev #%s' % (self.article, self.number)
# def save(self, **kwargs):
# if self.author is not None and self.author.is_anonymous():
# self.author = None
# super(ArticleVersion, self).save(**kwargs)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('article_version', args=[self.article.title, self.number]) return reverse('article_version', args=[self.article.title, self.number])

View File

@ -6,7 +6,7 @@
{% if article and mod_form %} {% if article and mod_form %}
<div class="article_moderation"> <div class="article_moderation">
<form method="POST" action="{% url update_article_status article.title %}"> <form method="POST" action="{% url "update_article_status" article.title %}">
<ul> <ul>
<li>{{mod_form.status.label_tag}} {{ mod_form.status }}</li> <li>{{mod_form.status.label_tag}} {{ mod_form.status }}</li>
<li> <li>
@ -16,7 +16,7 @@
</li> </li>
</ul> </ul>
</form> </form>
<form method="POST" action="{% url rename_article article.title %}"> <form method="POST" action="{% url "rename_article" article.title %}">
<ul> <ul>
{{ rename_form.as_ul}} {{ rename_form.as_ul}}
<li> <li>
@ -31,7 +31,7 @@
<h2 class="article_title"> <h2 class="article_title">
{% block article_title %} {% block article_title %}
{% if article.section_name %}<a href="{% url view_article article.section_name %}">{{article.section_name}}</a> / {% endif %} {% if article.section_name %}<a href="{% url "view_article" article.section_name %}">{{article.section_name}}</a> / {% endif %}
{{article.display_title}} {{article.display_title}}
{% if article.is_deleted %} [deleted] {% endif %} {% if article.is_deleted %} [deleted] {% endif %}
@ -42,10 +42,10 @@
<div class="article_meta"> <div class="article_meta">
{% block article_meta %} {% block article_meta %}
{% if article.editable %} {% if article.editable %}
<a href="{% url edit_article article.title %}">edit article</a> | <a href="{% url "edit_article" article.title %}">edit article</a> |
{% endif %} {% endif %}
{% if article %} {% if article %}
<a href="{% url article_history article.title %}">view history</a> <a href="{% url "article_history" article.title %}">view history</a>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
</div> </div>

View File

@ -10,8 +10,8 @@
{% block article_meta %} {% block article_meta %}
{% if article %} {% if article %}
<a href="{% url view_article article.title %}">view article</a> | <a href="{% url "view_article" article.title %}">view article</a> |
<a href="{% url article_history article.title %}">view history</a> <a href="{% url "article_history" article.title %}">view history</a>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -12,6 +12,32 @@
{% endblock %} {% endblock %}
{% block article_body %} {% block article_body %}
<form action="{% url revert article.title %}" method="post">
{% csrf_token %}
<label for="revert-version">Revert to</label>
<select name="revision" id="revert-version">
{% for version in versions reversed %}
{% if not forloop.first %}
<option value="{{ version.number }}">
{% if version.number == 0 %}
Initial
{% else %}
{{ version.number }}
{% endif %}
</option>
{% endif %}
{% endfor %}
</select>
<button class="compareBtn" type="submit">
<span>Revert to version</span>
</button>
</form>
<table> <table>
<thead> <tr> <thead> <tr>
<th>Version</th> <th>Version</th>
@ -46,4 +72,5 @@
<span>Compare Selected Versions</span> <span>Compare Selected Versions</span>
</button> </button>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -1,4 +1,4 @@
from django.conf.urls.defaults import * from django.conf.urls import *
from markupwiki.feeds import LatestEditsFeed, LatestArticleEditsFeed from markupwiki.feeds import LatestEditsFeed, LatestArticleEditsFeed
WIKI_REGEX = r'^(?P<title>.+)' WIKI_REGEX = r'^(?P<title>.+)'
@ -12,5 +12,6 @@ urlpatterns = patterns('markupwiki.views',
url(WIKI_REGEX + '/history/$', 'article_history', name='article_history'), url(WIKI_REGEX + '/history/$', 'article_history', name='article_history'),
url(WIKI_REGEX + '/history/(?P<n>\d+)/$', 'view_article', name='article_version'), url(WIKI_REGEX + '/history/(?P<n>\d+)/$', 'view_article', name='article_version'),
url(WIKI_REGEX + '/diff/$', 'article_diff', name='article_diff'), url(WIKI_REGEX + '/diff/$', 'article_diff', name='article_diff'),
url(WIKI_REGEX + '/revert/$', 'revert', name='revert'),
url(WIKI_REGEX + '/$', 'view_article', name='view_article'), url(WIKI_REGEX + '/$', 'view_article', name='view_article'),
) )

View File

@ -8,7 +8,7 @@ from django.contrib import messages
from django.http import Http404 from django.http import Http404
from django.template import RequestContext from django.template import RequestContext
from django.utils.functional import wraps from django.utils.functional import wraps
from markupwiki.models import Article, PUBLIC, DELETED, LOCKED from markupwiki.models import Article, ArticleVersion, PUBLIC, DELETED, LOCKED
from markupwiki.forms import ArticleForm, StaffModerationForm, ArticleRenameForm from markupwiki.forms import ArticleForm, StaffModerationForm, ArticleRenameForm
CREATE_MISSING_ARTICLE = getattr(settings, CREATE_MISSING_ARTICLE = getattr(settings,
@ -115,11 +115,13 @@ def edit_article(request, title):
form = ArticleForm() form = ArticleForm()
elif request.method == 'POST': elif request.method == 'POST':
form = ArticleForm(request.POST) form = ArticleForm(request.POST)
user = None if request.user.is_anonymous() else request.user
if form.is_valid(): if form.is_valid():
if not article: if not article:
# if article doesn't exist create it and start num at 0 # if article doesn't exist create it and start num at 0
article = Article.objects.create(title=title, article = Article.objects.create(title=title,
creator=request.user) creator=user)
num = 0 num = 0
else: else:
if not article.get_write_lock(request.user): if not article.get_write_lock(request.user):
@ -133,11 +135,11 @@ def edit_article(request, title):
# create a new version attached to article specified in name # create a new version attached to article specified in name
version = form.save(False) version = form.save(False)
version.article = article version.article = article
version.author = request.user version.author = user
version.number = num version.number = num
version.save() version.save()
article.get_write_lock(request.user, release=True) article.get_write_lock(user or request, release=True)
# redirect to view article on save # redirect to view article on save
return redirect(article) return redirect(article)
@ -167,7 +169,7 @@ def revert(request, title):
''' '''
article = get_object_or_404(Article, title=title) article = get_object_or_404(Article, title=title)
revision_id = int(request.POST['revision']) revision_id = int(request.POST['revision'])
revision = get_object_or_404(revision, number=revision_id) revision = get_object_or_404(article.versions, number=revision_id)
ArticleVersion.objects.create(article=article, author=request.user, ArticleVersion.objects.create(article=article, author=request.user,
number=article.versions.latest().number, number=article.versions.latest().number,
comment='reverted to r%s' % revision_id, comment='reverted to r%s' % revision_id,