예제 #1
0
파일: views.py 프로젝트: aaksham/HFMG2012V1
def signup_page(request):
    form=StudentForm()
    if request.method=='POST':
        form=StudentForm(request.POST)
        if form.is_valid():
            email= form.cleaned_data['username']
            first= form.cleaned_data['first_name']
            last= form.cleaned_data['last_name']
            password= form.cleaned_data['password']
            reg1=check_lbs(email)
            if not reg1:
                return render(request,'students/signup.html',{'form':form,'error':'Please enter a valid london.edu address','year':YEAR})
            #reg=check_register(email)
            #if not reg:
            #    return render(request,'students/signup.html',{'form':form,'error':"You are not registered for this course!",'year':YEAR})
            u=User.objects.create_user(email,email=email,password=password)
            u.first_name=first
            u.last_name=last
            u.is_staff=False
            u.is_superuser=False
            u.save()
            u= authenticate(username=email,password=password)
            login(request, u)
            return HttpResponseRedirect(BASE_URL+'student/%s/'%email)
        else:
            return render(request, 'students/signup.html',{'form': form,'year':YEAR})
    return render_to_response('students/signup.html',{'form':form,'year':YEAR},RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: sholokhova/gecko2
def student_add(request):
    if request.method == "POST":
        form = StudentForm(request.POST)
        if form.is_valid():
            form.save()
            return render_to_response("common/success.html")
    else:
        form = StudentForm()

    variables = RequestContext(request, {"form": form})
    return render_to_response("crud/student/student_add.html", variables)
예제 #3
0
파일: views.py 프로젝트: sholokhova/gecko2
def student_edit(request, id):
    student = Student.objects.get(pk=id)
    if request.method == "POST":
        form = StudentForm(request.POST, instance=student)
        if form.is_valid():
            form.save()
            return render_to_response("common/success.html")
    else:
        form = StudentForm(instance=student)

    variables = RequestContext(request, {"form": form})

    return render_to_response("crud/student/student_edit.html", variables)
예제 #4
0
 def _copyStudentToForm(self, student):
     """Copy relevant fields from Student to StudentForm."""
     sf = StudentForm()
     #return capitalized name. names are stored all lower for querying
     sf.name = string.capwords(student.name)
     sf.email = student.email
     sf.cellphone = student.cellphone
     sf.sbId = student.sbId
     sf.check_initialized()
     return sf
예제 #5
0
 def _copyStudentToForm(self, student):
     """Copy relevant fields from Student to StudentForm."""
     sf = StudentForm()
     #return capitalized name. names are stored all lower for querying
     sf.name = string.capwords(student.name)
     sf.email = student.email
     sf.cellphone = student.cellphone
     sf.sbId = student.sbId
     sf.check_initialized()
     return sf
예제 #6
0
def student_add(request):
    if request.method == 'POST':
        form = StudentForm(request.POST)
        if form.is_valid():
            form.save()
            return render_to_response('common/success.html')
    else:
        form = StudentForm()

    variables = RequestContext(request, {'form': form})
    return render_to_response('crud/student/student_add.html', variables)
예제 #7
0
def signup_page(request):
    form=StudentForm()
    if request.method=='POST':
        form=StudentForm(request.POST)
        if form.is_valid():
            email= form.cleaned_data['email']
            first= form.cleaned_data['first_name']
            middle= form.cleaned_data['middle_name']
            last= form.cleaned_data['last_name']
            password= form.cleaned_data['password']
            reg1=check_lbs(email)
            if not reg1:
                return render(request,'students/signup.html',{'form':form,'error':'Please enter a valid london.edu address','year':YEAR})
            #reg=check_register(email)
            #if not reg:
            #    return render(request,'students/signup.html',{'form':form,'error':"You are not registered for this course!",'year':YEAR})
            new_student=Student(email=email,first_name=first, middle_name=middle,last_name=last, password=password)
            new_student.save()
            return HttpResponseRedirect(BASE_URL+'student/%s/'%email)
        else:
            return render(request, 'students/signup.html',{'form': form,'year':YEAR})
    return render_to_response('students/signup.html',{'form':form,'year':YEAR})
예제 #8
0
def student_edit(request, id):
    student = Student.objects.get(pk=id)
    if request.method == "POST":
        form = StudentForm(request.POST, instance=student)
        if form.is_valid():
            form.save()
            return render_to_response('common/success.html')
    else:
        form = StudentForm(instance=student)

    variables = RequestContext(request, {'form': form})

    return render_to_response("crud/student/student_edit.html", variables)
예제 #9
0
파일: views.py 프로젝트: jackyjun/partyWeb
def student_info(request):
    user = request.user
    if request.method == 'POST':
        userStudent = UserStudent.objects.get(user = user)
        student = userStudent.student
        form = StudentForm(request.POST,instance=student) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            student = form.save(commit=False)
            if student.party_branch_id:
                student.save()
            else:
                student.party_branch_id = 1
                student.save()
            return redirect('/student_info?update=True')
        else:
            userStudent = UserStudent.objects.get(user = user)
            student = userStudent.student
            student_list = []
            student_dic = {}
            student_dic[u'学科类型'] = student.get_subject_display()
            student_list.append(student_dic)
            student_dic = {}
            student_dic[u'培养类型'] = student.get_training_display()
            student_list.append(student_dic)
            student_dic = {}
            student_dic[u'专业'] = student.major
            student_list.append(student_dic)
            student_dic = {}
            student_dic[u'性别'] = student.get_gender_display()
            student_list.append(student_dic)
            student_dic = {}
            student_dic[u'实验室'] = student.laboratory
            student_list.append(student_dic)
            student_dic = {}
            student_dic[u'座位号'] = student.seat_number
            student_list.append(student_dic)
            student_dic = {}
            student_dic[u'职位'] = student.duty
            student_list.append(student_dic)
            student_dic = {}
            student_dic[u'政治面貌'] = student.get_political_status_display
            student_list.append(student_dic)
            student_dic = {}
            if student.apply_party_time:
                student.apply_party_time = student.apply_party_time.strftime('%Y-%m-%d')
            student_dic[u'入党时间'] = student.apply_party_time
            student_list.append(student_dic)
            student_dic = {}
            if student.join_party_time:
                student.join_party_time = student.join_party_time.strftime('%Y-%m-%d')
            student_dic[u'转正时间'] =   student.join_party_time
            student_list.append(student_dic)
            student_dic = {}
            student_dic[u'所属党支部'] = student.party_branch
            student_list.append(student_dic)
            context = {
                'form': form,
                'student_list':student_list,
            }
            return render(request, 'student_info.html',context)
    else:
        userStudent = UserStudent.objects.get(user = user)
        student = userStudent.student
        student_list = []
        student_dic = {}
        student_dic[u'学科类型'] = student.get_subject_display()
        student_list.append(student_dic)
        student_dic = {}
        student_dic[u'培养类型'] = student.get_training_display()
        student_list.append(student_dic)
        student_dic = {}
        student_dic[u'专业'] = student.major
        student_list.append(student_dic)
        student_dic = {}
        student_dic[u'性别'] = student.get_gender_display()
        student_list.append(student_dic)
        student_dic = {}
        student_dic[u'实验室'] = student.laboratory
        student_list.append(student_dic)
        student_dic = {}
        student_dic[u'座位号'] = student.seat_number
        student_list.append(student_dic)
        student_dic = {}
        student_dic[u'职位'] = student.duty
        student_list.append(student_dic)
        student_dic = {}
        student_dic[u'政治面貌'] = student.get_political_status_display
        student_list.append(student_dic)
        student_dic = {}
        if student.apply_party_time:
            student.apply_party_time = student.apply_party_time.strftime('%Y-%m-%d')
        student_dic[u'入党时间'] = student.apply_party_time
        student_list.append(student_dic)
        student_dic = {}
        if student.join_party_time:
            student.join_party_time = student.join_party_time.strftime('%Y-%m-%d')
        student_dic[u'转正时间'] =   student.join_party_time
        student_list.append(student_dic)
        student_dic = {}
        student_dic[u'所属党支部'] = student.party_branch
        student_list.append(student_dic)
        form = StudentForm(instance=student)
        if 'update'in request.GET:
            context = {
                'prompt':True,
                'prompt_msg':'修改成功',
                'form': form,
                'student':student,
                'student_list':student_list,
            }
        else:
            context = {
                'form': form,
                'student':student,
                'student_list':student_list,
            }
        return render(request, 'student_info.html', context)