예제 #1
0
def create(request):
    form = StudentForm()
    if request.method == 'POST':
        form = StudentForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect(index)
    return render(request, 'stu/create.html', {'form': form})
예제 #2
0
def update(request, pk):
    data = Student.objects.get(id=pk)
    form = StudentForm(instance=data)
    if request.method == 'POST':
        form = StudentForm(request.POST, instance=data)
        if form.is_valid():
            form.save()
            return redirect(index)
    return render(request, 'stu/update.html', {'form': form})
예제 #3
0
def homepage(request):
    if request.method == "POST":
        wd = StudentForm(request.POST, True)
        if wd.is_valid():
            wd.save()
            return HttpResponseRedirect('/formsub/')

    else:
        wd = StudentForm()
    student = Student.objects.all()
    return render(request, 'student/home.html', {"stu": wd, "stud": student})
예제 #4
0
def manage_student(request, group_id, student_id=None):
    if student_id:
        instance = Student.objects.get(id=student_id)
    else:
        instance = None

    form = StudentForm(instance=instance)

    if request.POST:
        form = StudentForm(request.POST, request.FILES, instance=instance)
        form.save()
        return HttpResponseRedirect(reverse("students", args=[group_id]))

    return render_to_response('manage_student.html',
                              {'form': form},
                              RequestContext(request))
예제 #5
0
def splash(request):
    new_student = request.user.student
    if request.method == "POST":

        skillform = SkillForm(request.POST or None)

        if 'new_skill' in request.body:
            if skillform.is_valid():
                skill_text = skillform.cleaned_data['skill_text']
                new_skill = Skill.objects.get_or_create(skill_text__iexact=skill_text,defaults={'skill_text':skill_text,'creator':request.user})[0]
                new_skill.save()

                userform = UserForm(request.POST or None)
                studentform = StudentForm(request.POST or None)
                skill_ids = []
                for skill in Skill.objects.filter(student=new_student):
                    skill_ids.append(skill.id)

                for skill_id in request.POST.getlist('skills'):
                    skill_ids.append(skill_id)

                skill_ids.append(new_skill.id)
    
                studentform = StudentForm(
                    initial = {'year_in_school': new_student.year_in_school,
                               'school': new_student.school,
                               'skills': skill_ids
                              },
                )
                studentform.fields['skills'].queryset = Skill.objects.filter(Q(approved=True) | Q(creator=request.user))

                skillform = SkillForm()

        else:

            userform = UserForm(request.POST or None, instance=request.user)

            if userform.is_valid():
                userlink = userform.save(commit=False)
                userlink.save()

            studentform = StudentForm(request.POST or None, instance=new_student)
            studentform.fields['skills'].queryset = Skill.objects.filter(Q(approved=True) | Q(creator=request.user))

            if studentform.is_valid():
                link = studentform.save(commit=False)
                link.save()

                studentform.save_m2m()

                messages.success(request, 'You\'re all set!')

    else:
        userform = UserForm(
            request.POST or None,
            initial = {'first_name': request.user.first_name,
                       'last_name': request.user.last_name
                      }
        )

        skill_ids = []
        for skill in Skill.objects.filter(student=new_student):
            skill_ids.append(skill.id)

        studentform = StudentForm(
            request.POST or None, 
            initial = {'year_in_school': new_student.year_in_school,
                       'school': new_student.school,
                       'skills': skill_ids
                      }
        )
        studentform.fields['skills'].queryset = Skill.objects.filter(Q(approved=True) | Q(creator=request.user))
        skillform = SkillForm(
            request.POST or None
        )
    return render(request, 'splashpage/base_loggedin.html',{'studentform': studentform,'userform':userform,'skillform':skillform})