def set(request): if request.method == 'POST': form = MacForm(request.POST) if form.is_valid(): item = get_object_or_404(Mac,ip=request.META.get('REMOTE_ADDR')) if form.cleaned_data['owner']: item.owner = form.cleaned_data['owner'] if form.cleaned_data['machine']: item.machine = form.cleaned_data['machine'] item.save() return HttpResponse('OK') else: return HttpResponse('Bad form') else: return HttpResponse('Bad method')
def set(request): ''' Set the owner-machine data if the form and the http method are correct. Returns a httpresponse ''' if request.method == 'POST': form = MacForm(request.POST) if form.is_valid(): item = get_object_or_404(Mac,ip=request.META.get('REMOTE_ADDR')) if form.cleaned_data['owner']: item.owner = form.cleaned_data['owner'] if form.cleaned_data['machine']: item.machine = form.cleaned_data['machine'] item.save() return HttpResponse('OK') else: return HttpResponse('Bad form') else: return HttpResponse('Bad method')