Example #1
0
 def radiusadd( self, request ):
     if request.method == 'POST':
         good, data = self._sanitize( request.POST.copy() )
         if good:
             form = AddHostForm( data )
             form.save()
             if self._radiussync() == 0:
                 return render( request, 'radius_cmd_result.html',
                     { 'success': 'Success',
                       'message': "Data was saved to the database.<br>\nYou will be redirected to the list view in 3 seconds.",
                       'redirect_secs': 3,
                       'redirect_url': '/django/radius/radiusview/'
                     }
                 )
             else:
                 return render( request, 'radius_cmd_result.html',
                     { 'success': 'Warning: External command failed',
                       'message': '/usr/local/bin/radiussync did not return 0.<br>\nPlease ensure your host can authenticate.' +
                                  '<br>\nYou will be redirected to the list view in 7 seconds.',
                       'redirect_secs': 7,
                       'redirect_url': '/django/radius/radiusview'
                     }
                 )
         else:
             # don't worry there's Javascript validation as well
             return render( request, 'radius_cmd_result.html',
                 { 'success': 'Error: Invalid form data',
                   'message': "%s\n<BR>Something has slipped past the Javascript form validator.<br>\nPlease inform the development team if you see this error." % data,
                 }
             )
     else:
         return render( request, 'radius_add.html', { 'form': AddHostForm() } )
def add(request):
    if request.method == 'POST':
        form = AddHostForm(request.POST)
        if form.is_valid():
            host = form.save()
            url = reverse("host_detail",kwargs={'host_id': host.pk})
            return HttpResponseRedirect(url)
    else:
        form = AddHostForm()
    return render_to_response("add.html", {'form': form}, context_instance=RequestContext(request))
def edit(request,host_id):
    host = get_object_or_404(Host, pk=int(host_id))
    if request.method == 'POST':
        form = AddHostForm(request.POST, instance=host)
        print 'before valid'
        if form.is_valid():
            print 'before save'
            host = form.save()
            url = reverse("host_detail", kwargs={'host_id': host.pk})
            return HttpResponseRedirect(url)
    #host = Host.objects.get(id=host_id)
    else:
        form = AddHostForm(instance=host)
    return render_to_response("edit.html", {'form': form, 'host_id': host_id}, context_instance=RequestContext(request))