Esempio n. 1
0
 def __init__(self, current_revision, *args, **kwargs):
     
     self.no_clean = kwargs.pop('no_clean', False)
     self.preview = kwargs.pop('preview', False)
     self.initial_revision = current_revision
     self.presumed_revision = None
     if current_revision:
         initial = {'content': current_revision.content,
                    'title': current_revision.title,
                    'current_revision': current_revision.id}
         initial.update(kwargs.get('initial', {}))
         
         # Manipulate any data put in args[0] such that the current_revision
         # is reset to match the actual current revision.
         data = None
         if len(args) > 0:
             data = args[0]
         if not data:
             data = kwargs.get('data', None)
         if data:
             self.presumed_revision = data.get('current_revision', None)
             if not str(self.presumed_revision) == str(self.initial_revision.id):
                 newdata = {}
                 for k,v in data.items():
                     newdata[k] = v
                 newdata['current_revision'] = self.initial_revision.id
                 newdata['content'] = simple_merge(self.initial_revision.content,
                                                   data.get('content', ""))
                 newdata['title'] = current_revision.title
                 kwargs['data'] = newdata
             
         kwargs['initial'] = initial
     
     super(EditForm, self).__init__(*args, **kwargs)
Esempio n. 2
0
    def __init__(self, current_revision, *args, **kwargs):

        self.no_clean = kwargs.pop("no_clean", False)
        self.preview = kwargs.pop("preview", False)
        self.initial_revision = current_revision
        self.presumed_revision = None
        if current_revision:
            initial = {
                "content": current_revision.content,
                "title": current_revision.title,
                "current_revision": current_revision.id,
            }
            initial.update(kwargs.get("initial", {}))

            # Manipulate any data put in args[0] such that the current_revision
            # is reset to match the actual current revision.
            data = None
            if len(args) > 0:
                data = args[0]
            if not data:
                data = kwargs.get("data", None)
            if data:
                self.presumed_revision = data.get("current_revision", None)
                if not str(self.presumed_revision) == str(self.initial_revision.id):
                    newdata = {}
                    for k, v in data.items():
                        newdata[k] = v
                    newdata["current_revision"] = self.initial_revision.id
                    newdata["content"] = simple_merge(self.initial_revision.content, data.get("content", ""))
                    newdata["title"] = current_revision.title
                    kwargs["data"] = newdata

            kwargs["initial"] = initial

        super(EditForm, self).__init__(*args, **kwargs)
Esempio n. 3
0
    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 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)
Esempio n. 4
0
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

        if revision.deleted:
            c = RequestContext(
                request,
                {"error_msg": _(u"You cannot merge with a deleted revision"), "article": article, "urlpath": urlpath},
            )
            return render_to_response("wiki/error.html", context_instance=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 = _(u"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,
            _(u"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 = RequestContext(
        request,
        {
            "article": article,
            "title": article.current_revision.title,
            "revision": None,
            "merge1": revision,
            "merge2": article.current_revision,
            "merge": True,
            "content": content,
        },
    )
    return render_to_response(template_file, context_instance=c)
Esempio n. 5
0
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
        
        if revision.deleted:
            c = RequestContext(request, {'error_msg': _(u'You cannot merge with a deleted revision'),
                                         'article': article,
                                         'urlpath': urlpath})
            return render_to_response("wiki/error.html", context_instance=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 = (_(u'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, _(u'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 = RequestContext(request, {'article': article,
                                 'title': article.current_revision.title,
                                 'revision': None,
                                 'merge1': revision,
                                 'merge2': article.current_revision,
                                 'merge': True,
                                 'content': content})
    return render_to_response(template_file, context_instance=c)
Esempio n. 6
0
    def __init__(self, request, current_revision, *args, **kwargs):

        self.request = request
        self.no_clean = kwargs.pop('no_clean', False)
        self.preview = kwargs.pop('preview', False)
        self.initial_revision = current_revision
        self.presumed_revision = None
        if current_revision:
            initial = {
                'content': current_revision.content,
                'title': current_revision.title,
                'current_revision': current_revision.id
            }
            initial.update(kwargs.get('initial', {}))

            # Manipulate any data put in args[0] such that the current_revision
            # is reset to match the actual current revision.
            data = None
            if len(args) > 0:
                data = args[0]
                args = args[1:]
            if data is None:
                data = kwargs.get('data', None)
            if data:
                self.presumed_revision = data.get('current_revision', None)
                if not str(self.presumed_revision) == str(
                        self.initial_revision.id):
                    newdata = {}
                    for k, v in list(data.items()):
                        newdata[k] = v
                    newdata['current_revision'] = self.initial_revision.id
                    newdata['content'] = simple_merge(
                        self.initial_revision.content, data.get('content', ""))
                    newdata['title'] = current_revision.title
                    kwargs['data'] = newdata
                else:
                    # Always pass as kwarg
                    kwargs['data'] = data

            kwargs['initial'] = initial

        super(EditForm, self).__init__(*args, **kwargs)
Esempio n. 7
0
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

        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)

        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)
Esempio n. 8
0
    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 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)