Esempio n. 1
0
def add_student(request):
    teacher = Teacher.objects.all().order_by('name')
    student = Student.objects.all().order_by('name')
    course = Course.objects.all().order_by('c_name')
    klass = Klass.objects.all()
    name = request.POST['name']
    n_id = request.POST['n_id']
    error = {
        'courses_list': course,
        'teachers_list': teacher,
        'students_list': student,
        'klasses_list': klass,
        'now': trans(timezone.now()),
    }
    em = {
        **error,
        'error_message2': "Invalid value!",
    }
    ee = {**error, 'exist_error2': "This ID has been recorded"}
    if name == None or n_id == None:
        return render(request, 'props/create.html', em)
    try:
        n_id = int(n_id)
    except:
        return render(request, 'props/create.html', em)
    if n_id < 1:
        return render(request, 'props/create.html', em)
    try:
        if Profile.objects.filter(n_id=n_id):
            return render(request, 'props/create.html', ee)
        else:
            Student.objects.create(name=name, n_id=n_id)
            return HttpResponseRedirect(reverse('props:create', ))
    except:
        return render(request, 'props/create.html', em)
Esempio n. 2
0
 def get_context_data(self, **kwargs):
     course = Course.objects.all()
     context = {
         'courses_list': course,
         'now': trans(timezone.now()),
     }
     return context
Esempio n. 3
0
def add_t_course(request, t_id, c_id):
    temp_c = Course.objects.get(pk=c_id)
    temp_t = Teacher.objects.get(pk=t_id)
    teacher = Teacher.objects.all().order_by('name')
    student = Student.objects.all().order_by('name')
    course = Course.objects.all().order_by('c_name')
    klass = Klass.objects.all()
    error = {
        'courses_list':
        course,
        'teachers_list':
        teacher,
        'students_list':
        student,
        'klasses_list':
        klass,
        'now':
        trans(timezone.now()),
        'exist_error':
        "{1} has got {0} course before! ".format(temp_c.c_name, temp_t.name),
    }
    if temp_c in temp_t.courses.all():
        return render(request, 'props/create.html', error)
    else:
        temp_t.courses.add(temp_c)
    return HttpResponseRedirect(reverse('props:create', ))
Esempio n. 4
0
def add_course(request):
    teacher = Teacher.objects.all().order_by('name')
    student = Student.objects.all().order_by('name')
    course = Course.objects.all().order_by('c_name')
    klass = Klass.objects.all()

    name = request.POST['c_name']
    unit = request.POST['unit']
    error = {
        'courses_list': course,
        'teachers_list': teacher,
        'students_list': student,
        'klasses_list': klass,
        'now': trans(timezone.now()),
        'error_message_c': "Invalid value!",
    }
    if name == None or unit == None:
        return render(request, 'props/create.html', error)
    try:
        unit = int(unit)
    except:
        return render(request, 'props/create.html', error)
    if unit < 1:
        return render(request, 'props/create.html', error)
    Course.objects.create(c_name=name, unit=unit)
    return HttpResponseRedirect(reverse('props:create', ))
Esempio n. 5
0
class TeacherView(generic.DetailView):
    model = Teacher
    template_name = 'props/teacher.html'
    extra_context = {'now': trans(timezone.now())}

    def post(self, request, *args, **kwargs):
        return TeacherView.as_view(model=self.model,
                                   template_name=self.template_name,
                                   extra_context=self.extra_context)(request,
                                                                     *args,
                                                                     **kwargs)
Esempio n. 6
0
class StudentsView(generic.DetailView):
    model = Klass
    template_name = 'props/students.html'
    extra_context = {
        'now': trans(timezone.now()),
    }  # 's_list' : tmpp(model)}

    def post(self, request, *args, **kwargs):
        return TeachersView.as_view(model=self.model,
                                    template_name=self.template_name,
                                    extra_context=self.extra_context)(request,
                                                                      *args,
                                                                      **kwargs)
Esempio n. 7
0
 def get_context_data(self, **kwargs):
     teacher = Teacher.objects.all().order_by('name')
     student = Student.objects.all().order_by('name')
     course = Course.objects.all().order_by('c_name')
     klass = Klass.objects.all()
     context = {
         'courses_list': course,
         'teachers_list': teacher,
         'students_list': student,
         'klasses_list': klass,
         'now': trans(timezone.now()),
     }
     return context
Esempio n. 8
0
def add_s_class(request, s_id, k_id):
    temp_k = Klass.objects.get(pk=k_id)
    temp_s = Student.objects.get(pk=s_id)
    teacher = Teacher.objects.all().order_by('name')
    student = Student.objects.all().order_by('name')
    course = Course.objects.all().order_by('c_name')
    klass = Klass.objects.all()
    error = {
        'courses_list': course,
        'teachers_list': teacher,
        'students_list': student,
        'klasses_list': klass,
        'now': trans(timezone.now()),
        'exist_error2': "{1} has got {0} before! ".format(temp_k, temp_s.name),
    }
    if temp_k in temp_s.klasses.all():
        return render(request, 'props/create.html', error)
    else:
        temp_s.klasses.add(temp_k)
    return HttpResponseRedirect(reverse('props:create', ))