make revert feature work
This commit is contained in:
		
							parent
							
								
									9160ed2fd9
								
							
						
					
					
						commit
						89713013dc
					
				
					 3 changed files with 30 additions and 2 deletions
				
			
		|  | @ -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 %} | ||||||
|  |  | ||||||
|  | @ -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'), | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | @ -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, | ||||||
|  | @ -169,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, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Jeremy Carbaugh
						Jeremy Carbaugh