コード例 #1
0
def bchangeform(request):

    #if not logged in redirect
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login')
    try:
        queryset =userpost.objects.get(rollno = request.user.first_name)
    except:
        queryset = None

    if request.method == 'POST':
        form = userpostform(request.POST, instance = queryset)
        if form.is_valid():
            form.save()
            return render(request , 'success.html' , {'form':form})
        else:
            print form.errors
            return render(request , 'form.html' , {'form':form})

    else:
        try:
            form = userpostform(initial = {'rollno' : request.user.first_name , 'name' : queryset.name, 'cpi': queryset.cpi, 'Present_Branch' : queryset.Present_Branch, 'Category': queryset.Category, 'Preference_1': queryset.Preference_1, 'Preference_2': queryset.Preference_2, 'Preference_3': queryset.Preference_3, 'Preference_4': queryset.Preference_4, 'Preference_5': queryset.Preference_5, 'Preference_6': queryset.Preference_6, 'Preference_7': queryset.Preference_7, 'Preference_8': queryset.Preference_8, 'Preference_9': queryset.Preference_9, 'Preference_10': queryset.Preference_10, 'Preference_11': queryset.Preference_11, 'Preference_12': queryset.Preference_12, 'Preference_13': queryset.Preference_13, 'Preference_14': queryset.Preference_14, 'Preference_15': queryset.Preference_15, 'Preference_16': queryset.Preference_16})
        except:
            form = userpostform(initial = {'rollno': request.user.first_name})
    context = {
     'form' :form,
     'queryset' :queryset

    }
    return render(request, 'form.html', context)
コード例 #2
0
def fdetail(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login')
    try:
        queryset =userpost.objects.get(rollno = request.user.first_name)
        form = userpostform(initial = {'rollno' : request.user.first_name , 'name' : queryset.name, 'cpi': queryset.cpi, 'Present_Branch' : queryset.Present_Branch, 'Category': queryset.Category, 'Preference_1': queryset.Preference_1, 'Preference_2': queryset.Preference_2, 'Preference_3': queryset.Preference_3, 'Preference_4': queryset.Preference_4, 'Preference_5': queryset.Preference_5, 'Preference_6': queryset.Preference_6, 'Preference_7': queryset.Preference_7, 'Preference_8': queryset.Preference_8, 'Preference_9': queryset.Preference_9, 'Preference_10': queryset.Preference_10, 'Preference_11': queryset.Preference_11, 'Preference_12': queryset.Preference_12, 'Preference_13': queryset.Preference_13, 'Preference_14': queryset.Preference_14, 'Preference_15': queryset.Preference_15, 'Preference_16': queryset.Preference_16})
        return render(request, 'success.html' ,{'form' : form})
    except:
        queryset = None
        return HttpResponseRedirect('/bchangeform')