Beispiel #1
0
def addAgent(request):
    	if request.method == 'GET':
        	form = AgentForm()
    	else:
       	        form = AgentForm(request.POST)
                if form.is_valid():
			form.save()
            		return HttpResponseRedirect('agentlist')
    	return render(request,'crime/addagent.html', {'form': form}) 
Beispiel #2
0
def updateAgent(request,id):
    agent = Agent.objects.get(id=id)
    if request.method == 'GET':
        form = AgentForm(instance = agent)
    else:
        form = AgentForm(request.POST)         
    	if form.is_valid():
		agent.firstname = request.POST["firstname"]
		agent.lastname = request.POST["lastname"]
		agent.location_id = request.POST["location"]
		agent.save()
        	return HttpResponseRedirect('agentlist')
    return render(request,'crime/updateagent.html',{'agent':agent,'form':form,'action':'update/'+id})
Beispiel #3
0
def agents_edit(request, agent_id):
    old = Agent.objects.get(pk=agent_id)
    if request.method == 'POST':
        form = AgentForm(request.POST, instance=old)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            location = form.cleaned_data['location']
            form.save()
            message = "Agent successfully updated"
            return render(request, 'message.html', {"message":message})
    else:
        form = AgentForm(instance=old)
    return render(request, 'agents_edit.html', {'form':form})
Beispiel #4
0
def agents_add(request):
    if request.method == 'POST':
        form = AgentForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            location = form.cleaned_data['location']
            status = "active"
            Agent(first_name=first_name, last_name=last_name,location=location, status=status).save()
            message = "Agent successfully added."
            return render(request, 'message.html', {"message":message})
    else:
	    form = AgentForm()
    return render(request, 'agents_add.html', {'form':form,})