コード例 #1
0
def pregister(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = form.save(True, False)
            if form.data['gender'] == 'Male':
                user.sex = 0
            else:
                user.sex = 1
            user.save()
            context = {
                'sam_station': sam_station.get_data(),
                'create': sam_station.get_data()['created_at'],
                'f1': sam_station.get_data()['field1'],
                'f2': sam_station.get_data()['field2'],
                'f3': sam_station.get_data()['field3'],
                'f4': sam_station.get_data()['field4'],
                'f5': sam_station.get_data()['field5'],
                'h': sam_station.get_data()['field1'],
                'w': sam_station.get_data()['field2'],
                'risk': user.risk,
                'safe': user.safe,
                'patient': User.objects.filter(patient=1),
                'pamount': len(User.objects.filter(patient=1)),
                'ran': ran,
            }
            return render(request, 'profile.html', context)
        else:
            form = RegistrationForm()
            return render(request, 'pregister.html', {'form': form})
    else:
        form = RegistrationForm()
        return render(request, 'pregister.html', {'form': form})
コード例 #2
0
def mregister(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = form.save(False, True)
            if form.data['gender'] == 'Male':
                user.sex = 0
            else:
                user.sex = 1
            user.save()
            login(request, user)
            return render(request, 'profile.html')
        else:
            form = RegistrationForm()
            return render(request, 'mregister.html', {'form': form})
    else:
        form = RegistrationForm()
        return render(request, 'mregister.html', {'form': form})