Beispiel #1
0
def wiki_page_edit(request, slug, template="mezawiki/wiki_page_edit.html"):
    """
    Displays the form for editing and deleting a page.

    Custom templates are checked for using the name
    ``mezawiki/wiki_page_edit_XXX.html``
    where ``XXX`` is the wiki pages's slug.
    """
    try:
        wiki_pages = WikiPage.objects.published(for_user=request.user)
        wiki_page = wiki_pages.get(slug=slug)
        initial = {}
    except WikiPage.DoesNotExist:
        wiki_page = WikiPage(slug=slug)
        wiki_page.is_initial = True
        initial = {"content": _("Describe your new page %s here..." % slug)}
        #'message': _('Initial revision')}

    if request.method == "POST":
        form = WikiPageForm(request.POST, instance=wiki_page)
        if form.is_valid():
            page = form.save(commit=False)
            page.user = request.user
            page.title = slug
            page.save()
            return HttpResponseRedirect(reverse("wiki_page_detail", args=[slug]))
    else:
        form = WikiPageForm(initial=initial, instance=wiki_page)

    context = {"wiki_page": wiki_page, "form": form}
    templates = [u"mezawiki/wiki_page_edit_%s.html" % unicode(slug), template]
    return render(request, templates, context)
Beispiel #2
0
def wiki_page_edit(request, slug, template="mezawiki/wiki_page_edit.html"):
    """
    Displays the form for editing a page.
    """
    try:
        #wiki_pages = WikiPage.objects.published(for_user=request.user)
        wiki_page = WikiPage.objects.get(slug=slug)
        wiki_page.is_initial = False
        initial = {}
    except WikiPage.DoesNotExist:
        wiki_page = WikiPage(slug=slug)
        wiki_page.is_initial = True
        initial = {'status': 1}

    if not wiki_page.can_edit_wikipage(request.user):
        return HttpResponseForbidden(
            _("You don't have permission to edit this wiki page."))

    if request.method == 'POST':
        form = WikiPageForm(request.POST, instance=wiki_page)
        if form.is_valid():
            page = form.save(commit=False)
            if wiki_page.is_initial:
                try:
                    page.user = request.user
                except:
                    page.user_id = -1
                page.title = deurlize_title(slug)
            page.save()
            if 'content' in form.changed_data:
                revision = WikiPageRevision()
                revision.content = page.content
                revision.description = form.cleaned_data["summary"]
                revision.page = page
                try:
                    revision.user = request.user
                except:
                    # anonymous
                    revision.user_id = -1
                revision.save()
            return HttpResponseRedirect(
                reverse('wiki_page_detail', args=[slug]))
    else:
        form = WikiPageForm(initial=initial, instance=wiki_page)

    context = {
        'wiki_page': wiki_page,
        'form': form,
        'title': deurlize_title(slug)
    }
    return render(request, template, context)
Beispiel #3
0
def wiki_page_edit(request, slug, 
                     template="mezawiki/wiki_page_edit.html"):
    """
    Displays the form for editing a page.
    """
    try:
        #wiki_pages = WikiPage.objects.published(for_user=request.user)
        wiki_page = WikiPage.objects.get(slug=slug)
        wiki_page.is_initial = False
        initial = {}
    except WikiPage.DoesNotExist:
        wiki_page = WikiPage(slug=slug)
        wiki_page.is_initial = True
        initial = {'status': 1}

    if not wiki_page.can_edit_wikipage(request.user):
        return HttpResponseForbidden(
            _("You don't have permission to edit this wiki page."))

    if request.method == 'POST':
        form = WikiPageForm(request.POST, instance=wiki_page)
        if form.is_valid():
            page = form.save(commit=False)
            if wiki_page.is_initial:
                try:
                    page.user = request.user
                except:
                    page.user_id = -1
                page.title = deurlize_title(slug)
            page.save()
            if 'content' in form.changed_data:
                revision = WikiPageRevision()
                revision.content = page.content
                revision.description = form.cleaned_data["summary"]
                revision.page = page
                try:
                    revision.user = request.user
                except:
                    # anonymous
                    revision.user_id = -1
                revision.save()
            return HttpResponseRedirect(
                reverse('wiki_page_detail', args=[slug]))
    else:
        form = WikiPageForm(initial=initial, instance=wiki_page)

    context = {'wiki_page': wiki_page, 'form': form,
               'title': deurlize_title(slug)}
    return render(request, template, context)
Beispiel #4
0
    def post(self, request, slug, template="mezawiki/wiki_page_edit.html"):
        try:
            #wiki_pages = WikiPage.objects.published(for_user=request.user)
            wiki_page = WikiPage.objects.get(slug=slug)
            wiki_page.is_initial = False
            initial = {}
        except WikiPage.DoesNotExist:
            wiki_page = WikiPage(slug=slug)
            wiki_page.is_initial = True
            initial = {'status': 1}
        form = WikiPageForm(request.POST, instance=wiki_page)
        if form.is_valid():
            page = form.save(commit=False)
            if wiki_page.is_initial:
                try:
                    page.user = request.user
                except:
                    page.user_id = -1
                page.title = deurlize_title(slug)
            page.save()
            if 'content' in form.changed_data:
                revision = WikiPageRevision()
                revision.content = page.content
                revision.description = form.cleaned_data["summary"]
                revision.page = page
                try:
                    revision.user = request.user
                except:
                    # anonymous
                    revision.user_id = -1
                revision.save()
            return HttpResponseRedirect(
                reverse('wiki_page_detail', args=[slug]))
        else:
            form = WikiPageForm(initial=initial, instance=wiki_page)

        context = {
            'wiki_page': wiki_page,
            'form': form,
            'title': deurlize_title(slug)
        }
        return render(request, template, context)
Beispiel #5
0
 def get(self, request, slug, template="mezawiki/wiki_page_edit.html"):
     """
     Displays the form for editing a page.
     """
     try:
         #wiki_pages = WikiPage.objects.published(for_user=request.user)
         wiki_page = WikiPage.objects.get(slug=slug)
         wiki_page.is_initial = False
         initial = {}
     except WikiPage.DoesNotExist:
         wiki_page = WikiPage(slug=slug)
         wiki_page.is_initial = True
         initial = {'status': 1}
     form = WikiPageForm(request.POST, instance=wiki_page)
     if not wiki_page.can_edit_wikipage(request.user):
         return HttpResponseForbidden(
             _("You don't have permission to edit this wiki page."))
     context = {
         'wiki_page': wiki_page,
         'form': form,
         'title': deurlize_title(slug)
     }
     return render(request, template, context)