コード例 #1
0
ファイル: views.py プロジェクト: moshe742/vpms
def add_volunteer(request, eknight_id):
    form = Add_volunteer(initial={'eknights': eknight_id})
    if request.method == 'POST':
        form = Add_volunteer(request.POST, request.user)
        if form.is_valid():
            done = form.save()
            # if request.POST['other']:
            #     expert = Expertise(name=request.POST['other'])
            #     expert.full_clean()
            #     expert.save()
            #     other_expertise = Expertise.objects.get(name=expert)
            #     done.expertise.add(other_expertise.id)
            # user = Volunteer.objects.get(email=done.email)
            e_id = EKnight.objects.get(id=eknight_id)
            arrival = Arrival(user=done, eknight=e_id)
            arrival.save()
            return HttpResponseRedirect('/')
    return render(request, 'volunteers/add_volunteer.html', {'form': form})
コード例 #2
0
ファイル: views.py プロジェクト: eyalliebermann/vpms
def home(request):
	form = Add_volunteer()
	if 'volunteer' in request.GET and request.GET['volunteer']:
		name = request.GET['volunteer']
		users = Volunteer.objects.filter(name__icontains=name, arrived__lt=datetime.datetime.now())
		return render(request, 'home.html', {'searched': name, 'users': users, 'form': form})
	elif 'user_name' in request.GET and request.GET['user_name']:
		volunteer_id = Volunteer.objects.get(id=request.GET['user_name']).save()
	elif 'project' in request.GET and request.GET['project']:
		name = request.GET['project']
		projects = Project.objects.filter(name__icontains=name)
		return render(request, 'home.html', {'form': form, 'search_project': name, 'projects': projects})
	elif request.method == 'POST':
		form = Add_volunteer(request.POST, request.user)
		if form.is_valid():
			clean_form = form.cleaned_data
			added = Volunteer(name=clean_form['name'], email=clean_form['email'], phone=clean_form['phone'])
			added.save()
	return render(request, 'home.html', {'form': form})