def AllStudents(request): now = timezone.now() if request.method == 'GET': form = PostForm() else: form = PostForm(request.POST) classID = form['classID'].value() py_obj = test_code() py_obj.code2(classID) print("Cid is " + cid1) #users = ClassToStudent_Mapping.objects.filter(ClassId = cid1) try: users = MarkAttendanceCode.getCumulativeAttendanceOfStudents(cid1) try: print(users[1]) except: return render(request, 'classroom/None_cid.html', {'message': 'Enter Valid ClassId'}) except IndexError: return render(request, 'classroom/None_cid.html', {'message': 'Enter Valid ClassId'}) if (bool(users)): return render(request, 'classroom/AllStudentDetails.html', { 'users': users, 'classId': cid1 }) else: return render(request, 'classroom/None_cid.html', { 'users': users, 'message': 'Enter Valid ClassId' })
def new_post(): form = PostForm() if form.validate_on_submit(): ct = Ct(course=form.course.data, date=form.date.data, time=form.time.data, syllabus=form.syllabus.data, poster=current_user) db.session.add(ct) db.session.commit() flash('Successfully created post!', 'success') return redirect(url_for('index')) return render_template('create_post.html', form=form, legend='Add CT')
def update_post(post_id): post = Ct.query.get_or_404(post_id) if post.poster != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.course = form.course.data post.date = form.date.data post.time = form.time.data post.syllabus = form.syllabus.data db.session.commit() flash("CT schedule has been updated!", 'success') return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': form.course.data = post.course form.date.data = post.date form.time.data = post.time form.syllabus.data = post.syllabus return render_template('create_post.html', form=form, legend='Update CT')
def create_post(request, pk): if request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): classroom = get_object_or_404(Classroom, pk=pk) topic = classroom.topic_set.first() title = form.cleaned_data.get('title') description = form.cleaned_data.get('description') files = request.FILES.getlist('file_field') post = Post.objects.create(title=title, description=description, created_by=request.user, topic=topic) for f in files: Resource.objects.create(post=post, files=f) messages.success(request, f'Post Created {title}') else: messages.danger(request, f'Cannot create post') return redirect('classroom:open_classroom', pk)
def Tpost_form_upload(request): if request.user.is_authenticated: if request.user.is_teacher: if request.method == 'GET': form = PostForm() else: form = PostForm(request.POST) usrname = request.user.username classID = form['classID'].value() py_obj = test_code() data = py_obj.code(classID, usrname) print(data[0], data[1], data[2], data[3]) MarkAttendanceCode.callAbsenteesListAloud(list(data[0])) return render( request, 'classroom/absentees.html', { 'data': list(data[0]), 'data1': list(data[1]), 'classId': data[2], 'usrname': data[3] }) else: return render(request, 'classroom/NotAuthenticated.html')
def IndividualStudent(request): now = timezone.now() if request.method == 'GET': form = PostForm() else: form = PostForm(request.POST) studentID = form['classID'].value() py_obj = test_code() py_obj.code1(studentID) try: users = MarkAttendanceCode.getCumulativeAttendanceOfAStudent(studentID) except IndexError: return render(request, 'classroom/None.html', {'message': 'Enter Valid StudentId'}) print(users) #users = User.objects.filter(username = sid1) if (bool(users)): return render(request, 'classroom/IndividualStudentDetails.html', { 'users': users, 'sid': studentID }) else: return render(request, 'classroom/None.html', {'users': users})
def DailyAttendance(request): now = timezone.now() if request.method == 'GET': form = PostForm() else: form = PostForm(request.POST) if request.user.is_teacher: if form.is_valid(): studentID = form.cleaned_data['classID'] print(studentID) date1 = form.cleaned_data['Date'] py_obj = test_code() py_obj.code3(studentID, date1) else: form = PostForm(request.POST) studentID = request.user.username print(studentID) date1 = form['classID'].value() print(date1) py_obj = test_code() py_obj.code3(studentID, date1) #users = ClassToStudent_Mapping.objects.filter(ClassId = cid1) try: users = MarkAttendanceCode.getDailyAttendance(studentID, date1) except IndexError: return render(request, 'classroom/None_date.html', {'message': 'Enter Valid Details'}) if (bool(users)): paramList = [studentID + " on ", date1] print(paramList) return render(request, 'classroom/IndividualStudentDetails.html', { 'users': users, 'param': paramList }) else: return render(request, 'classroom/None_date.html', { 'users': users, 'message': 'Enter Valid Details' })
def test_invalid_post_form(self): form = PostForm({'title': 'A new beginning'}) self.assertFalse(form.is_valid())
def test_valid_post_form_works(self): form = PostForm({ 'title': 'A new beginning', 'content': 'We have to start over again' }) self.assertTrue(form.is_valid())