Exemple #1
0
def edit(request, bleep_id):
    """
    Edit a bleep

    """
    b = get_object_or_404(Bleep, pk=bleep_id)
    return render_to_response('bleep/form.html', {
            'form': BleepForm(instance=b),
        'content_form': CommentForm(),
            'bleep': b,}, context_instance=RequestContext(request))             
Exemple #2
0
def add(request):
    """
    Add a bleep to the bleepdom

    """
    print 'debuggery: inside add function...'
    if request.method == 'POST':
        # merge the GET and POST params
        reqParams = request.POST.copy()
        reqParams.update(request.GET)
        form = BleepForm(reqParams)
        if form.is_valid():
            print 'debuggery: add form is valid'
            # Initialize the date and status            
            new_instance = form.save(commit=False)
            new_instance.bleep_status='qued'
            new_instance.bleep_pub_date = datetime.datetime.now()
            # Collect the input params
            new_instance.bleep_get_data = request.META['QUERY_STRING']
            if request.raw_post_data:
                new_instance.bleep_post_data = request.raw_post_data
            # Save the data to the model
            new_instance.save()
            if not settings.NO_AUTO_SEND_MESSAGE:
                # send it!
                print 'debuggery: Automatically sending the bleep...'
                result = BleepService.dispatch(new_instance)
            else:
                print 'debuggery: bleep is being held in queue for later processing'
            # Return to the new bleep page
            return HttpResponseRedirect('/bleeps/'+str(new_instance.id))
        else:
            logger.debug('the add form was NOT valid')
    else:
        return render_to_response('bleep/create.html', {
                'form':BleepForm(
                    initial={'bleep_status':'qued',
                             'bleep_pub_date':datetime.datetime.now()})},
                                  context_instance=RequestContext(request))        
Exemple #3
0
def update(request, bleep_id):
    """
    Process a bleep form update

    """
    if request.method == 'POST':
        form = BleepForm(request.POST)
        if form.is_valid():
            # Process and clean the data
            # ...
            # update the form with current bleep data
            b = Bleep.objects.get(pk=bleep_id)
            form = BleepForm(request.POST, instance=b)
            form.save()
            return HttpResponseRedirect('/bleeps/'+bleep_id)
        else:
            form = BleepForm() # Create an unbound form
    return render_to_response('bleep/form.html', {
            'form': form,
        'content_form': CommentForm()}, context_instance=RequestContext(request))