@@ 30,7 30,7 @@ class WikiURLPatterns:
article_source_view_class = article.Source
article_plugin_view_class = article.Plugin
revision_change_view_class = article.ChangeRevisionView
- revision_merge_view = staticmethod(article.merge)
+ revision_merge_view_class = article.MergeView
search_view_class = settings.SEARCH_VIEW
article_diff_view_class = article.DiffView
@@ 119,10 119,8 @@ class WikiURLPatterns:
name='preview_revision'),
url(
r'^_revision/merge/(?P<article_id>[0-9]+)/(?P<revision_id>[0-9]+)/preview/$',
- self.revision_merge_view,
- name='merge_revision_preview',
- kwargs={
- 'preview': True}),
+ self.revision_merge_view_class.as_view(preview=True),
+ name='merge_revision_preview'),
]
return urlpatterns
@@ 162,7 160,7 @@ class WikiURLPatterns:
name='change_revision'),
url(
r'^(?P<article_id>[0-9]+)/revision/merge/(?P<revision_id>[0-9]+)/$',
- self.revision_merge_view,
+ self.revision_merge_view_class.as_view(),
name='merge_revision'),
url(r'^(?P<article_id>[0-9]+)/plugin/(?P<slug>\w+)/$',
self.article_plugin_view_class.as_view(),
@@ 212,7 210,7 @@ class WikiURLPatterns:
name='change_revision'),
url(
r'^(?P<path>.+/|)_revision/merge/(?P<revision_id>[0-9]+)/$',
- self.revision_merge_view,
+ self.revision_merge_view_class.as_view(),
name='merge_revision'),
url(r'^(?P<path>.+/|)_plugin/(?P<slug>\w+)/$',
self.article_plugin_view_class.as_view(),
@@ 891,76 891,76 @@ class DiffView(DetailView):
{'diff': list(diff), 'other_changes': other_changes}
)
-# TODO: Throw in a class-based view
+class MergeView(View):
+ preview = False
+ template_name = "wiki/preview_inline.html"
+ template_error_name = "wiki/error.html"
+ urlpath = None
-@get_article(can_write=True)
-def merge(
- request,
- article,
- revision_id,
- urlpath=None,
- template_file="wiki/preview_inline.html",
- preview=False):
-
- revision = get_object_or_404(
- models.ArticleRevision,
- article=article,
- id=revision_id)
-
- current_text = article.current_revision.content if article.current_revision else ""
- new_text = revision.content
-
- content = simple_merge(current_text, new_text)
-
- # Save new revision
- if not preview:
- old_revision = article.current_revision
+ @method_decorator(get_article(can_write=True))
+ def dispatch(self, request, article, revision_id, *args, **kwargs):
+ return super().dispatch(request, article, revision_id, *args, **kwargs)
- if revision.deleted:
- c = {
- 'error_msg': _('You cannot merge with a deleted revision'),
- 'article': article,
- 'urlpath': urlpath
- }
- return render(request, "wiki/error.html", context=c)
-
- new_revision = models.ArticleRevision()
- new_revision.inherit_predecessor(article)
- new_revision.deleted = False
- new_revision.locked = False
- new_revision.title = article.current_revision.title
- new_revision.content = content
- new_revision.automatic_log = (
- _('Merge between revision #%(r1)d and revision #%(r2)d') % {
- 'r1': revision.revision_number,
- 'r2': old_revision.revision_number})
- article.add_revision(new_revision, save=True)
-
- old_revision.simpleplugin_set.all().update(
- article_revision=new_revision)
- revision.simpleplugin_set.all().update(article_revision=new_revision)
+ def get(self, request, article, revision_id, *args, **kwargs):
+ revision = get_object_or_404(
+ models.ArticleRevision,
+ article=article,
+ id=revision_id)
+
+ current_text = article.current_revision.content if article.current_revision else ""
+ new_text = revision.content
+
+ content = simple_merge(current_text, new_text)
+
+ # Save new revision
+ if not self.preview:
+ old_revision = article.current_revision
+
+ if revision.deleted:
+ c = {
+ 'error_msg': _('You cannot merge with a deleted revision'),
+ 'article': article,
+ 'urlpath': self.urlpath
+ }
+ return render(request, self.template_error_name, context=c)
+
+ new_revision = models.ArticleRevision()
+ new_revision.inherit_predecessor(article)
+ new_revision.deleted = False
+ new_revision.locked = False
+ new_revision.title = article.current_revision.title
+ new_revision.content = content
+ new_revision.automatic_log = (
+ _('Merge between revision #%(r1)d and revision #%(r2)d') % {
+ 'r1': revision.revision_number,
+ 'r2': old_revision.revision_number})
+ article.add_revision(new_revision, save=True)
+
+ old_revision.simpleplugin_set.all().update(
+ article_revision=new_revision)
+ revision.simpleplugin_set.all().update(article_revision=new_revision)
- messages.success(
- request,
- _('A new revision was created: Merge between revision #%(r1)d and revision #%(r2)d') % {
- 'r1': revision.revision_number,
- 'r2': old_revision.revision_number})
- if urlpath:
- return redirect('wiki:edit', path=urlpath.path)
- else:
- return redirect('wiki:edit', article_id=article.id)
-
- c = {
- 'article': article,
- 'title': article.current_revision.title,
- 'revision': None,
- 'merge1': revision,
- 'merge2': article.current_revision,
- 'merge': True,
- 'content': content
- }
- return render(request, template_file, c)
+ messages.success(
+ request,
+ _('A new revision was created: Merge between revision #%(r1)d and revision #%(r2)d') % {
+ 'r1': revision.revision_number,
+ 'r2': old_revision.revision_number})
+ if self.urlpath:
+ return redirect('wiki:edit', path=self.urlpath.path)
+ else:
+ return redirect('wiki:edit', article_id=article.id)
+
+ c = {
+ 'article': article,
+ 'title': article.current_revision.title,
+ 'revision': None,
+ 'merge1': revision,
+ 'merge2': article.current_revision,
+ 'merge': True,
+ 'content': content
+ }
+ return render(request, self.template_name, c)
class CreateRootView(FormView):