예제 #1
0
def new(request):
    """
    Create a new Pad, with 1 initial "TextArea" for
    a given choice.

    """
    if request.method == 'POST':
        pad_form = PadForm(request.POST)

        if pad_form.is_valid():
            pad_inst = pad_form.save(commit=False)
            title = pad_form.cleaned_data["title"]

            # TODO is there a reason that this is not factored out to the
            # forms.py?

            pad_inst.creator = request.user
            pad_inst.guid = create_pad_guid(title)
            pad_inst.save()

            textarea_inst = TextArea(pad=pad_inst, editor=request.user )
            textarea_inst.save()
            return HttpResponseRedirect( pad_inst.get_absolute_url() ) # Redirect after POST

    else:
        pad_form = PadForm()

    args = {"pad_form":pad_form, "user":request.user}

    return create_object( request,
            form_class = PadForm,
            template_name = 'pads/new.html',
            extra_context = args,
            #login_required = True,
    )
예제 #2
0
def add(request, app_label, model_name, id):
    '''Add a pad to another object'''
    try:
        typ = ContentType.objects.get(app_label=app_label, model=model_name)
        obj = typ.get_object_for_this_type(id=id)
    except:
        return HttpResponseNotFound()
    if request.method == 'POST':
        pad_form = PadForm(request.POST)
        if pad_form.is_valid():
            pad_inst = pad_form.save(commit=False)
            pad_inst.creator = request.user
            title = pad_form.cleaned_data["title"]
            pad_inst.guid = create_pad_guid(title)
            pad_inst.content_type = typ
            pad_inst.object_id = id
            pad_inst.save()
            textarea_inst = TextArea(pad=pad_inst, editor=request.user )
            textarea_inst.save()
            return HttpResponseRedirect( pad_inst.get_absolute_url() )
    else:
        pad_form = PadForm()

    return create_object( request,
            form_class = PadForm,
            template_name = 'pads/new.html',
            extra_context = locals(),
    )