Beispiel #1
0
def create_wiki_page(request, group, page_name, template_name="plus_wiki/create_wiki.html", current_app='plus_groups', **kwargs):
    """creates OR saves WikiPages
    """
    form = EditWikiForm(request.POST)
    try:
        obj = WikiPage.objects.plus_get(request.user, name=page_name, in_agent=group.get_ref())
    except:
        raise Http404

    if form.is_valid():
        title = form.cleaned_data['title']
        content = form.cleaned_data['content']
        license = form.cleaned_data['license']
        if request.POST.get('preview', None):
            return render_to_response(template_name, 
                                      {'page':TemplateSecureWrapper(obj),
                                       'data':form.data,
                                       'preview_content': content,
                                       'form_action':reverse(current_app + ":create_WikiPage", args=[obj.in_agent.obj.id, obj.name])}, 
                                      context_instance=RequestContext(request, current_app=current_app))
        else:
            if obj.stub: # we should change the "created_by" on the genericreference/permissions system to "owner"
                obj.created_by = request.user
                revision.comment = 'Original'
            else:
                revision.comment = form.cleaned_data['what_changed']

            revision.user = request.user
            diff = htmldiffer(AttrDict({'title':title, 'content':content, 'license': license}), obj)
            diff = json.dumps(diff)
            #XXX this diff needs to only include things in the proximity of an insertion or deletion
            revision.add_meta(VersionDelta, delta=diff)
            obj.title = title
            obj.name_from_title()
            obj.content = content
            obj.license = license
            obj.stub = False
            obj.save()
            return HttpResponseRedirect(reverse(current_app + ':view_WikiPage', args=[group.id, obj.name]))

    return render_to_response(template_name, 
                              {'page':TemplateSecureWrapper(obj),
                               'revision':revision,
                               'data':form.data,
                               'errors': form.errors,
                               'form_action':reverse(current_app + ":create_WikiPage", args=[obj.in_agent.obj.id, obj.name])}, 
                              context_instance=RequestContext(request, current_app=current_app))
Beispiel #2
0
def create_wiki_page(request, group, page_name, template_name="plus_wiki/create_wiki.html", current_app='plus_groups', **kwargs):
    """creates OR saves WikiPages
    """

    try:
        obj = WikiPage.objects.plus_get(request.user, name=page_name, in_agent=group.get_ref())
    except:
        raise Http404
    post_kwargs = request.POST.copy()
    post_kwargs['obj'] = obj
    form = EditWikiForm(post_kwargs)

    if "delete_submit" in post_kwargs :
        if post_kwargs.has_key('delete_check') :
            obj.delete()
            return HttpResponseRedirect(reverse(current_app + ':group', args=[group.id]))

    if "move_resource_submit" in post_kwargs :
        form = MoveResourceForm(post_kwargs)
        form.user = request.user # essential, user is checked inside form validation                                     
        if form.is_valid() :
            new_parent_group = form.cleaned_data['new_parent_group']
            obj.move_to_new_group(new_parent_group)
            revision.user = request.user
            return HttpResponseRedirect(reverse(current_app + ':group', 
                                                args=[form.cleaned_data['new_parent_group'].id]))


    if form.is_valid():
        title = form.cleaned_data['title']
        content = form.cleaned_data['content']
        license = form.cleaned_data['license']
        copyright_holder = form.cleaned_data['copyright_holder']
        name = form.cleaned_data['name']
        if request.POST.get('preview', None):
            return render_to_response(template_name, 
                                      {'page':TemplateSecureWrapper(obj),
                                       'data':form.data,
                                       'preview_content': content,
                                       'form_action':reverse(current_app + ":create_WikiPage", args=[obj.in_agent.obj.id, obj.name])}, 
                                      context_instance=RequestContext(request, current_app=current_app))
        else:
            if obj.stub: # we should change the "created_by" on the genericreference/permissions system to "owner"
                obj.created_by = request.user
                revision.comment = 'Original'
            else:
                revision.comment = form.cleaned_data['what_changed']

            revision.user = request.user
            diff = htmldiffer(AttrDict({'title':title, 'content':content, 'license': license}), obj)
            diff = json.dumps(diff)
            #XXX this diff needs to only include things in the proximity of an insertion or deletion
            revision.add_meta(VersionDelta, delta=diff)
            obj.title = title
            obj.set_name(name)
            obj.content = content
            obj.license = license
            obj.copyright_holder = copyright_holder
            obj.stub = False
            obj.save()

            from apps.plus_feed.models import FeedItem
            FeedItem.post_WIKI_PAGE(request.user, obj)


            return HttpResponseRedirect(reverse(current_app + ':view_WikiPage', args=[group.id, obj.name]))

    return render_to_response(template_name, 
                              {'page':TemplateSecureWrapper(obj),
                               'revision':revision,
                               'data':form.data,
                               'errors': form.errors,
                               'form_action':reverse(current_app + ":create_WikiPage", 
                                                     args=[obj.in_agent.obj.id, obj.name])}, 
                              context_instance=RequestContext(request, current_app=current_app))
Beispiel #3
0
def create_wiki_page(request,
                     group,
                     page_name,
                     template_name="plus_wiki/create_wiki.html",
                     current_app='plus_groups',
                     **kwargs):
    """creates OR saves WikiPages
    """

    try:
        obj = WikiPage.objects.plus_get(request.user,
                                        name=page_name,
                                        in_agent=group.get_ref())
    except:
        raise Http404
    post_kwargs = request.POST.copy()
    post_kwargs['obj'] = obj
    form = EditWikiForm(post_kwargs)

    if "delete_submit" in post_kwargs:
        if post_kwargs.has_key('delete_check'):
            obj.delete()
            return HttpResponseRedirect(
                reverse(current_app + ':group', args=[group.id]))

    if "move_resource_submit" in post_kwargs:
        form = MoveResourceForm(post_kwargs)
        form.user = request.user  # essential, user is checked inside form validation
        if form.is_valid():
            new_parent_group = form.cleaned_data['new_parent_group']
            obj.move_to_new_group(new_parent_group)
            revision.user = request.user
            return HttpResponseRedirect(
                reverse(current_app + ':group',
                        args=[form.cleaned_data['new_parent_group'].id]))

    if form.is_valid():
        title = form.cleaned_data['title']
        content = form.cleaned_data['content']
        license = form.cleaned_data['license']
        copyright_holder = form.cleaned_data['copyright_holder']
        name = form.cleaned_data['name']
        if request.POST.get('preview', None):
            return render_to_response(template_name, {
                'page':
                TemplateSecureWrapper(obj),
                'data':
                form.data,
                'preview_content':
                content,
                'form_action':
                reverse(current_app + ":create_WikiPage",
                        args=[obj.in_agent.obj.id, obj.name])
            },
                                      context_instance=RequestContext(
                                          request, current_app=current_app))
        else:
            if obj.stub:  # we should change the "created_by" on the genericreference/permissions system to "owner"
                obj.created_by = request.user
                revision.comment = 'Original'
            else:
                revision.comment = form.cleaned_data['what_changed']

            revision.user = request.user
            diff = htmldiffer(
                AttrDict({
                    'title': title,
                    'content': content,
                    'license': license
                }), obj)
            diff = json.dumps(diff)
            #XXX this diff needs to only include things in the proximity of an insertion or deletion
            revision.add_meta(VersionDelta, delta=diff)
            obj.title = title
            obj.set_name(name)
            obj.content = content
            obj.license = license
            obj.copyright_holder = copyright_holder
            obj.stub = False
            obj.save()

            from apps.plus_feed.models import FeedItem
            FeedItem.post_WIKI_PAGE(request.user, obj)

            return HttpResponseRedirect(
                reverse(current_app + ':view_WikiPage',
                        args=[group.id, obj.name]))

    return render_to_response(template_name, {
        'page':
        TemplateSecureWrapper(obj),
        'revision':
        revision,
        'data':
        form.data,
        'errors':
        form.errors,
        'form_action':
        reverse(current_app + ":create_WikiPage",
                args=[obj.in_agent.obj.id, obj.name])
    },
                              context_instance=RequestContext(
                                  request, current_app=current_app))