def signup():
    form = SignupForm(request.form)
    if request.method == 'POST' and form.validate():
        if form.role.data == "student":
            user = Student(name=form.name.data,
                           email=form.email.data,
                           student_ref=form.uni_id.data)
        else:
            user = Teacher(name=form.name.data,
                           title=form.title.data,
                           teacher_ref=form.uni_id.data,
                           email=form.email.data)
        user.set_password(form.password.data)
        try:
            db.session.add(user)
            db.session.commit()
            response = make_response(redirect(url_for('main.index')))
            response.set_cookie("name", form.name.data)
            return response
        except IntegrityError:
            db.session.rollback()
            flash(
                'ERROR! Unable to register {}. Please check your details are correct and resubmit'
                .format(form.email.data), 'error')
    return render_template('signup.html', form=form)
Exemple #2
0
def setup_database():
    db.create_all()

    u1 = Student('Heather', 'Freeman', '*****@*****.**', 'Abc123',
                 'student')
    u2 = Student('Amanda', 'Evans', '*****@*****.**', 'Cde456',
                 'student')
    u3 = Student('Jerry', 'White', '*****@*****.**', 'qwerty123', 'student')
    u4 = Student('Jane', 'Berry', '*****@*****.**', 'tyu1234', 'student')
    u5 = Student('Lori', 'Welch', '*****@*****.**', 'erg34345', 'student')
    u6 = Student('Dorothy', 'Medina', '*****@*****.**', 'bfdg2',
                 'student')
    u7 = Student('Lawrence', 'Foster', '*****@*****.**', 'regergs2',
                 'student')
    u8 = Student('Annie', 'Pierce', '*****@*****.**', 'bfg3', 'student')
    u9 = Student('Melissa', 'Taylor', '*****@*****.**', 'eret3',
                 'student')
    u10 = Student('Deborah', 'Richards', '*****@*****.**', 'opi234',
                  'student')

    t1 = Teacher('Albert', 'Morris', '*****@*****.**', 'abc123', 'teacher')
    t2 = Teacher('Jane', 'Ripper', '*****@*****.**', 'abc123', 'teacher')

    task1 = Task(1, 1, 1)
    task2 = Task(2, 1, 1)
    task3 = Task(1, 2, 1)
    task3.mark_id = 1
    task3.completed = True

    m1 = Mark(7, 10, 1, 2)
    m2 = Mark(1, 10, 3, 3)
    m3 = Mark(1, 10, 5, 3)
    m4 = Mark(4, 10, 5, 3)
    m5 = Mark(5, 10, 4, 3)
    m6 = Mark(3, 10, 2, 4)

    db.session.add_all([u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, t1, t2])
    db.session.add_all([task1, task2, task3])
    db.session.add_all([m1, m2, m3, m4, m5, m6])

    links = [
        t1.add_student(u1),
        t1.add_student(u2),
        t1.add_student(u3),
        t1.add_student(u8),
        t1.add_student(u9)
    ]
    db.session.add_all(links)

    db.session.commit()

    graph1 = Graph(
        '{"version":2,"graph":{"showGrid":true,"showXAxis":true,"showYAxis":true,"xAxisStep":0,"yAxisStep":0,"xAxisMinorSubdivisions":0,"yAxisMinorSubdivisions":0,"xAxisArrowMode":"NONE","yAxisArrowMode":"NONE","xAxisLabel":"Re","yAxisLabel":"Im","xAxisNumbers":true,"yAxisNumbers":true,"polarMode":false,"polarNumbers":true,"degreeMode":false,"projectorMode":false,"squareAxes":true,"viewport":{"xmin":-1.6708536134523648,"ymin":-1.9601353023240395,"xmax":1.9920012573229602,"ymax":1.847026847468353}},"expressions":{"list":[{"id":"0","type":"expression","latex":"\\sqrt{x^2+y^2}-\\sqrt{x^2+\\left(y+1\\right)^2}=0","domain":{"min":0,"max":1},"hidden":false,"color":"#2d70b3","style":"normal","residualVariable":"","regressionParameters":{},"isLogModeRegression":false},{"id":"1","type":"expression","latex":"\\sqrt{x^2+y^2}-\\sqrt{y^2+\\left(x-1\\right)^2}=0","domain":{"min":0,"max":1},"hidden":false,"color":"#388c46","style":"normal","residualVariable":"","regressionParameters":{},"isLogModeRegression":false}]}}',
        '<thead><tr><th>Plot</th><th></th><th></th></tr></thead><tbody> <tr id="row0"><td><span class="MathJax_Preview" style="color: inherit; display: none;"></span><span class="MathJax" id="MathJax-Element-2-Frame" tabindex="0" style="position: relative;" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mstyle displaystyle=&quot;true&quot;><mrow><mo>|</mo><mi>z</mi><mo>|</mo></mrow><mo>=</mo><mrow><mo>|</mo><mi>z</mi><mo>+</mo><mi>i</mi><mo>|</mo></mrow></mstyle></math>" role="presentation"><nobr aria-hidden="true"><span class="math" id="MathJax-Span-128" style="width: 6.074em; display: inline-block;"><span style="display: inline-block; position: relative; width: 5.06em; height: 0px; font-size: 120%;"><span style="position: absolute; clip: rect(1.691em, 1004.93em, 2.927em, -1000em); top: -2.56em; left: 0em;"><span class="mrow" id="MathJax-Span-129"><span class="mstyle" id="MathJax-Span-130"><span class="mrow" id="MathJax-Span-131"><span class="mrow" id="MathJax-Span-132"><span class="mo" id="MathJax-Span-133" style="font-family: STIXVariants;">|</span><span class="mi" id="MathJax-Span-134" style="font-family: STIXGeneral; font-style: italic;">z</span><span class="mo" id="MathJax-Span-135" style="font-family: STIXVariants;">|</span></span><span class="mo" id="MathJax-Span-136" style="font-family: STIXGeneral; padding-left: 0.375em; padding-right: 0.375em;">=</span><span class="mrow" id="MathJax-Span-137"><span class="mo" id="MathJax-Span-138" style="font-family: STIXVariants;">|</span><span class="mi" id="MathJax-Span-139" style="font-family: STIXGeneral; font-style: italic;">z</span><span class="mo" id="MathJax-Span-140" style="font-family: STIXGeneral; padding-left: 0.3em; padding-right: 0.3em;">+</span><span class="mi" id="MathJax-Span-141" style="font-family: STIXGeneral; font-style: italic;">i</span><span class="mo" id="MathJax-Span-142" style="font-family: STIXVariants;">|</span></span></span></span></span><span style="display: inline-block; width: 0px; height: 2.56em;"></span></span></span><span style="display: inline-block; overflow: hidden; vertical-align: -0.298em; border-left: 0px solid; width: 0px; height: 1.198em;"></span></span></nobr><span class="MJX_Assistive_MathML" role="presentation"><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mrow><mo>|</mo><mi>z</mi><mo>|</mo></mrow><mo>=</mo><mrow><mo>|</mo><mi>z</mi><mo>+</mo><mi>i</mi><mo>|</mo></mrow></mstyle></math></span></span><script type="math/asciimath" id="MathJax-Element-2">|z|=|z+i|</script></td><td><input name="plot" id="0" checked="" type="checkbox"></td><td><input class="btn btn-block" name="del" id="del0" value="X" type="button"></td></tr><tr id="row1"><td><span class="MathJax_Preview" style="color: inherit; display: none;"></span><span class="MathJax" id="MathJax-Element-3-Frame" tabindex="0" style="position: relative;" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mstyle displaystyle=&quot;true&quot;><mrow><mo>|</mo><mi>z</mi><mo>|</mo></mrow><mo>=</mo><mrow><mo>|</mo><mi>z</mi><mo>-</mo><mn>1</mn><mo>|</mo></mrow></mstyle></math>" role="presentation"><nobr aria-hidden="true"><span class="math" id="MathJax-Span-201" style="width: 6.372em; display: inline-block;"><span style="display: inline-block; position: relative; width: 5.298em; height: 0px; font-size: 120%;"><span style="position: absolute; clip: rect(1.691em, 1005.17em, 2.927em, -1000em); top: -2.56em; left: 0em;"><span class="mrow" id="MathJax-Span-202"><span class="mstyle" id="MathJax-Span-203"><span class="mrow" id="MathJax-Span-204"><span class="mrow" id="MathJax-Span-205"><span class="mo" id="MathJax-Span-206" style="font-family: STIXVariants;">|</span><span class="mi" id="MathJax-Span-207" style="font-family: STIXGeneral; font-style: italic;">z</span><span class="mo" id="MathJax-Span-208" style="font-family: STIXVariants;">|</span></span><span class="mo" id="MathJax-Span-209" style="font-family: STIXGeneral; padding-left: 0.375em; padding-right: 0.375em;">=</span><span class="mrow" id="MathJax-Span-210"><span class="mo" id="MathJax-Span-211" style="font-family: STIXVariants;">|</span><span class="mi" id="MathJax-Span-212" style="font-family: STIXGeneral; font-style: italic;">z</span><span class="mo" id="MathJax-Span-213" style="font-family: STIXGeneral; padding-left: 0.3em; padding-right: 0.3em;">−</span><span class="mn" id="MathJax-Span-214" style="font-family: STIXGeneral;">1</span><span class="mo" id="MathJax-Span-215" style="font-family: STIXVariants;">|</span></span></span></span></span><span style="display: inline-block; width: 0px; height: 2.56em;"></span></span></span><span style="display: inline-block; overflow: hidden; vertical-align: -0.298em; border-left: 0px solid; width: 0px; height: 1.198em;"></span></span></nobr><span class="MJX_Assistive_MathML" role="presentation"><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mrow><mo>|</mo><mi>z</mi><mo>|</mo></mrow><mo>=</mo><mrow><mo>|</mo><mi>z</mi><mo>-</mo><mn>1</mn><mo>|</mo></mrow></mstyle></math></span></span><script type="math/asciimath" id="MathJax-Element-3">|z|=|z-1|</script></td><td><input name="plot" id="1" checked="" type="checkbox"></td><td><input class="btn btn-block" name="del" id="del1" value="X" type="button"></td></tr></tbody>',
        2, '2 Lines', '',
        'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAPWklEQVR4nO3dXVBU9xnH8UN7k15wZ/ei5cIyGTJDpzR1hsy01Aw3DZ0YymQYrNU6MTB21LCT1gQZ0whRY9CAxJd1asXqRMeYERUl9V3rYlxZhTgQXwFRAovgUtcsohsWdp9eWLb895wDC7rP7kN/35n/ReC/e86B83HPW1SjOKmjo4M6OjpivRpRKRgMkqZppGkaJSQkRG05xYdX0jsHVyhjaHgoassjmtq/NyIiLdYrMNJU/kEDiNwAhCEAkRuAMAQgcgMQhgBEbgDCEIDIDUAYAhC5AQhDACI3AGEIQOQGIAwBiNwAhCEAkRuAMAQgcgMQhgBEbgDCEIDIDUAYAhC5AQhDACI3AGEIQOQGIAwBiNwAhCEAkRuAMAQgcgMQhgBEbgDCEIDIDUAYAhC5AQhDACI3AGEIQOQGIAwBiNwAhCEAkRuAMAQgcgMQhgBEbgDCEIDIDUAYAhC5iQFy4MABWr16NW3evNl0fPjhh2S32xnXOrIARG5igJw4cYLee++90I5mNPLz88nhcDCudWQBiNzEABmpr6+PLBaLAsNisVBrayvDWk4uAJGbOCADAwO6T46SkhKGNZx8ACI3cUDu3LmjA9LQ0MCwhpMPQOQmDsjhw4cVHElJSeT1ehnWcPIBiNzEAbFarQqQgoICCgaDDGs4+QBEbqKADAwMUGpqqgJk//79TGs4+QBEbqKAfP3117rzj/b29nHf+9GjR9Tb22v4vfv375PL5aKhIfMdaXBwkLq7u+n+/fvjLssoAJGbNrKBsR4Oh4McDofu6319faFDqK1btyo4U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RG4AwBCByAxCGAERuAMIQgMgNQBgCELkBCEMAIjcAYQhA5AYgDAGI3ACEIQCRG4AwBCByAxCGAERuAMIQgMgNQBgCELn9B4KLRTkmtn8TAAAAAElFTkSuQmCC'
    )

    db.session.add(graph1)
    db.session.commit()
Exemple #3
0
def sign_up(request):
    if request.method == 'POST':
        form = SignUp(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            messages.success(request, f"new account created : {username}")
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            student = Student()
            student.user = username
            student.save()
            return redirect("/")

        else:
            for msg in form.error_messages:
                messages.error(request, f"{msg}: {form.error_messages[msg]}")
        return render(request=request,
                      template_name='main/register.html',
                      context={"form": form})

    form = SignUp()
    return render(request=request,
                  template_name='main/register.html',
                  context={"form": form})
Exemple #4
0
def get_courses():
    stu = Student(session["user_number"])
    courses = stu.get_course()
    res = []
    for sel in courses:
        esc = EstablishedCourse.query.filter(
            EstablishedCourse.id == sel.established_course_id).first()
        course = esc.course.name
        class_time = esc.class_time
        course_time_ = ""
        class_time_details = class_time.split(';')
        for index in class_time_details:
            course_time_ += ('周' + index[:1] + '第' + index[-1:] + "节 ")
        grade = None
        if sel.final_grade:
            grade = sel.performance_score * (
                esc.daily_grade_ratio /
                100) + sel.final_grade * (1 - esc.daily_grade_ratio / 100)
        res.append({
            "course_place": esc.class_room,
            "course": course,
            "esc_id": esc.id,
            "course_time": course_time_,
            "course_teacher": esc.teacher.name,
            "daily_grade": sel.performance_score,
            "final_grade": sel.final_grade,
            "grade": grade
        })
    return json.dumps(res)
Exemple #5
0
def student_profile():
    # current_user = User.get(178646)
    # student = current_user.student
    firstname = request.json['firstname']
    lastname = request.json['lastname']
    sex = request.json['sex']
    phone = request.json['phone']
    department = request.json['department']
    level = request.json['level']

    # if (request.json['role']):
    #   role = request.json['role']
    #   if

    student = Student(student_id=current_user.id,
                      firstname=firstname,
                      lastname=lastname,
                      department_code=department,
                      sex=sex,
                      phone_no=phone)
    student.save()

    data = {'message': 'success'}

    return jsonify(data)
Exemple #6
0
    def save(self, commit=True):
        student = Student()

        form_username = self.cleaned_data['username']
        form_email = self.cleaned_data['email']
        form_password = self.cleaned_data['password1']
        form_first_name = self.cleaned_data['first_name']
        form_last_name = self.cleaned_data['last_name']
        section = Section.objects.get(section=self.cleaned_data['section'])

        if commit:
            # Note, we have to use create_user because
            # it automatically hashes the password.
            user = User.objects.create_user(
                username=form_username,
                email=form_email,
                password=form_password,
                first_name=form_first_name,
                last_name=form_last_name,
            )

            # Setup student row
            student.section = section
            student.user = user
            student.save()

            # Link user with student
            user.student = student
            user.save()
            user = authenticate(username=user.username, password=form_password)

        return user
Exemple #7
0
def addstudent(request):
    list1 = ['张', '李', '赵', '顾', '夏']
    list2 = ['雪', '峰', '军', '国', '辉']
    student = Student()
    student.sname = list1[randint(0, 4)] + list2[randint(0, 4)]
    student.save()
    return HttpResponse("增加学生%d" % student.id)
Exemple #8
0
def create_students():
    name = names.get_full_name()
    email = "_".join(name.split(" ")).lower() + "@gmail.com"
    student = Student(name, email, "111", "", 2, 20, 1, 100)
    db.session.add(student)
    db.session.commit()
    db.session.add(LectureStudent(student.id, 2))
    db.session.add(LectureStudent(student.id, 5))
    db.session.add(LectureStudent(student.id, 6))
    db.session.commit()

    name = names.get_full_name()
    email = "_".join(name.split(" ")).lower() + "@gmail.com"
    student = Student(name, email, "111", "", 2, 20, 1, 100)
    db.session.add(student)
    db.session.commit()
    db.session.add(LectureStudent(student.id, 2))
    db.session.add(LectureStudent(student.id, 5))
    db.session.add(LectureStudent(student.id, 6))
    db.session.commit()

    name = names.get_full_name()
    email = "_".join(name.split(" ")).lower() + "@gmail.com"
    student = Student(name, email, "111", "", 2, 20, 1, 100)
    db.session.add(student)
    db.session.commit()
    db.session.add(LectureStudent(student.id, 2))
    db.session.add(LectureStudent(student.id, 5))
    db.session.add(LectureStudent(student.id, 6))
    db.session.commit()
Exemple #9
0
 def test_student_expired_confirmation_token(self):
     u = Student(password='******')
     db.session.add(u)
     db.session.commit()
     token = u.generate_auth_token(1)
     time.sleep(2)
     self.assertFalse(u.verify_auth_token(token) == u)
Exemple #10
0
def register():
    form = Register()
    if form.validate_on_submit():
        email_check = Student.query.filter_by(email=form.email.data).first()
        if email_check != None:
            flash(
                'This email is already assigned to a student. Are you sure you are not already a student at this school?'
            )
            return render_template('student_templates/register.html',
                                   form=form)
        # work around so that user loader doesn't get confused
        count1 = Student.query.order_by(Student.id.desc()).all()[0].id
        count2 = Teacher.query.order_by(Teacher.id.desc()).all()[0].id
        id = max(count1, count2) + 1
        new_student = Student(id=id,
                              first_name=form.first_name.data.title(),
                              last_name=form.last_name.data.title(),
                              email=form.email.data,
                              birthday=form.birthday.data,
                              grade=int(form.grade.data),
                              pic_url=form.pic_url.data,
                              password_hash=generate_password_hash(
                                  form.password.data))
        if len(form.twitter.data) > 0:
            new_student.twitter = form.twitter.data
        db.session.add(new_student)
        db.session.commit()
        flash(
            f'Thank you {new_student.first_name}  {new_student.last_name}. You are now a registered student! Please Log in!'
        )
        return redirect('/login')
    return render_template('student_templates/register.html', form=form)
Exemple #11
0
 def create_student(self, school):
     student = Student(first_name=self.student_datas['first_name'],
                       last_name=self.student_datas['last_name'],
                       forename=self.student_datas['forename'],
                       sex=self.student_datas['sex'])
     student.school = school
     return student
Exemple #12
0
def usersAction(action, value, id):
    account = Account.query.get(id)

    if account:
        if action in ['bind']:
            if value in ['student', 'trainer']:
                user = Student() if value == 'student' else Trainer()

                if request.json[value + '_id']:
                    query = Student.query if value == 'student' else Trainer.query
                    user = query.filter_by(id=request.json[value +
                                                           '_id']).first()
                else:
                    user.name = request.json['account_name']
                    db.session.add(user)

                if value == 'student':
                    account.student = user
                else:
                    account.trainer = user

                # account.name = request.json['account_name']
                db.session.commit()

                showNotify('Успешно!',
                           'Аккаунт привязан к {}!'.format(user.name),
                           type='success')
            else:
                showNotify('Ошибка!',
                           'Неизвестное значение "%r"!' % value,
                           type='error')
        elif action in ['unbind']:
            if value in ['user']:
                account.trainer = None
                account.student = None
                db.session.commit()

                showNotify('Успешно!', 'Аккаунт отвязан!', type='success')
            else:
                showNotify('Ошибка!',
                           'Неизвестное значение "%r"!' % value,
                           type='error')

        elif action in ['delete']:
            if value in ['user']:
                db.session.delete(account)
                db.session.commit()

                showNotify('Успешно!', 'Аккаунт удален!', type='success')
        else:
            showNotify('Ошибка!',
                       'Неизвестное действие {}!'.format(action),
                       type='error')
    else:
        showNotify('Ошибка!',
                   'Аккаунт #{} не найден!'.format(id),
                   type='error')

    return json.dumps([{'exec': 'document.location.href = \'/users\''}])
Exemple #13
0
def addstudent(request):
    data = Student(sname=request.POST['key1'],
                   srn=request.POST['key2'],
                   sclass=request.POST['key3'],
                   smarks=request.POST['key4'])
    data.save()
    print(request.POST)
    return HttpResponseRedirect('/index/')
Exemple #14
0
 def students(student_creat):
     stu_number = [
         int(stu_number) for stu_number in student_creat.col_values(0)
     ]
     stu_name = [stu_name for stu_name in student_creat.col_values(1)]
     student_list = zip(stu_number, stu_name)
     for student in student_list:
         Student.create_stu(*student)
Exemple #15
0
def add_fake_data():
    """
    Adds fake data to the local database.
    """
    db.session.add(Student(first_name="Michael", last_name="Yu", year=2021))
    db.session.add(Student(first_name="Bevo", last_name="Longhorn", year=2023))
    # TODO: Try adding your own fake data here
    db.session.commit()
def student_del():
    student_id = request.form.get('student_id', -1, type=int)
    if student_id != -1:
        student = Student.get_by_id(student_id)
        ret = Student.delete_student(student)
    else:
        ret = u'删除失败'
    return jsonify(ret=ret)
def add_stu():
    # 插入数据
    stu = Student()
    stu.s_name = '小张'
    # db.session.add(stu)
    # db.session.commit()
    stu.save()
    return '创建学生成功'
Exemple #18
0
def student_del():
    student_id = request.form.get('student_id', -1, type=int)
    if student_id != -1:
        student = Student.get_by_id(student_id)
        ret = Student.delete_student(student)
    else:
        ret = u'删除失败'
    return jsonify(ret = ret)
Exemple #19
0
def add_student():
    student = Student()
    student.name = '小明' + str(random.randrange(10000))
    db.session.add(student)
    db.session.commit()
    print(db.session)
    print(type(db.session))
    return 'Add Success'
Exemple #20
0
    def test_password_verification(self):
        s = Student(password='******')
        e = Examiner(password='******')
        self.assertTrue(s.verify_password('cat'))
        self.assertFalse(s.verify_password('dog'))

        self.assertTrue(e.verify_password('cat'))
        self.assertFalse(e.verify_password('dog'))
Exemple #21
0
def add_details():
    user = User.query.get_or_404(current_user.id)
    if user.student:
        print('Student exist')
        form = StudentForm(request.form, obj=user.student)
    else:
        print('new student')
        form = StudentForm(request.form)

    if request.method == 'POST':
        student = Student(name=form.name.data,
                          email=form.email.data,
                          phone=form.phone.data,
                          perm_addr=form.perm_addr.data,
                          qualification=form.qualification.data,
                          passout=form.passout.data,
                          stream=form.stream.data,
                          college=form.college.data,
                          tenth_percent=form.tenth_percent.data,
                          plus2_percent=form.plus2_percent.data,
                          degree_percent=form.degree_percent.data,
                          n_backlogs=form.n_backlogs.data,
                          courses=form.courses.data,
                          skills=form.skills.data,
                          hobbies=form.hobbies.data)
        #print(student.name)
        if user.student:
            print("updating")
            user.student.name = form.name.data
            user.student.email = student.email
            user.student.phone = student.phone
            user.student.perm_addr = student.perm_addr

            user.student.qualification = student.qualification
            user.student.passout = student.passout
            user.student.stream = student.stream
            user.student.college = student.college

            user.student.tenth_percent = student.tenth_percent
            user.student.plus2_percent = student.plus2_percent
            user.student.degree_percent = student.degree_percent
            user.student.n_backlogs = student.n_backlogs

            user.student.courses = student.courses
            user.student.skills = student.skills
            user.student.hobbies = student.hobbies
        else:
            print("Creating")
            student.user = user
            db.session.add(student)

        db.session.commit()
        flash('**** Congratulations, your details have been added! ****')
        return redirect(url_for('index'))
    elif request.method == 'GET':
        return render_template('v2student-details.html',
                               title='Add Details',
                               form=form)
def add_stu():
    if request.method == 'GET':
        # 插入数据
        stu = Student()
        stu.s_name = '莉哥'
        stu.s_gender = 0
        db.session.add(stu)
        db.session.commit()
        return '创建学生信息成功'
Exemple #23
0
def index(request):
    if request.method == 'POST':
        fname = request.POST.get('fname')
        email = request.POST.get('email')
        message = request.POST.get('message')
        s = Student(firstname=fname, email=email, message=message)
        s.save()

    return render(request, 'app/index.html')
Exemple #24
0
 def post(self):
     stu_list = list()
     for i in range(10):
         stu = Student()
         stu.s_name = 'xiaomi_%s' % i
         stu_list.append(stu)
     session.add_all(stu_list)
     session.commit()
     self.write('新增多条数据成功')
Exemple #25
0
    def test_password_salts_are_random(self):
        s = Student(password='******')
        s2 = Student(password='******')

        e = Examiner(password='******')
        e2 = Examiner(password='******')

        self.assertTrue(s.password_hash != s2.password_hash)
        self.assertTrue(e.password_hash != e2.password_hash)
Exemple #26
0
def enroll(request, course_id):
    course = get_object_or_404(Course, id=course_id)
    student = Student()
    student.name = request.POST['student_name']
    student.save()
    template = loader.get_template("course.html")
    context = {
        'course': course,
    }
    return HttpResponse(template.render(context, request))
Exemple #27
0
 def test_student_join_school(self):
     sc = School(name='aschool')
     st = Student(nickname='astudent')
     db.session.add_all([sc, st])
     db.session.commit()
     co = Course(course_name='acourse', school_id=sc.id)
     db.session.add(co)
     db.session.commit()
     st.join_school(sc.id)
     self.assertTrue(st.is_school_joined(sc.id))
def student():
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['ADMIN_STUDENT_PER_PAGE']
    if page == -1:
        page = ((Student.get_count() - 1) // per_page) + 1
    pagination = Student.get_list_pageable(page, per_page)
    student_list = pagination.items
    return render_template('admin/student.html',
                           title=u'学生管理',
                           student_list=student_list,
                           pagination=pagination)
Exemple #29
0
def addstudent():

    form = AddStudentForm()
    if form.validate_on_submit():
        user = Student(username=form.username.data, program=form.program.data, batch=form.batch.data, email=form.email.data) 
        user.set_password(form.password_hash.data) 
        db.session.add(user)
        db.session.commit()
        flash('Student is added Successfully')
        return redirect(url_for('addstudent'))
    return render_template('addstudent.html', form=form)
Exemple #30
0
def student():
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['ADMIN_STUDENT_PER_PAGE']
    if page == -1:
        page = ((Student.get_count() - 1) // per_page) + 1
    pagination = Student.get_list_pageable(page, per_page)
    student_list = pagination.items
    return render_template('admin/student.html',
                           title = u'学生管理',
                           student_list = student_list,
                           pagination = pagination)
Exemple #31
0
def add_all():
    stus = []
    for i in range(10):
        stu = Student()
        stu.s_age = random.randint(18, 28)
        stu.s_name = '小明%s' % random.randint(0, 10000)
        stu.s_phone = '12334456743'
        stus.append(stu)
        # db.session.add(stu)
    db.session.add_all(stus)
    db.session.commit()
    return '创建成功'
Exemple #32
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = Student(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #33
0
def stus():
    names = ['张三1', '李四2', '王五3']
    stus_list = []
    for name in names:
        stu = Student()
        stu.s_name = name
        # stu.save()
        stus_list.append(stu)
    # add_all([添加对象1, 添加对象2....])
    db.session.add_all(stus_list)
    db.session.commit()
    return '批量插入数据成功'
Exemple #34
0
Fichier : forms.py Projet : TSS2/a
 def get_student_list(self):
     students = []
     uia = UIA.uia()
     for item in self.students.data:
         if item == '':
             continue
         has_t = Student.get_by_stu_no(item)
         if has_t is not None:
             students.append(has_t)
         else:
             stu_info = uia.get_student_info(item)
             stu = Student.get_by_stu_post(item, stu_info)
             students.append(stu)
     return students
Exemple #35
0
def change_pass():
    old_password = request.form['old_password']
    password = request.form['password']

    user = Student.get_user(session['username'])
    if user and user.password == old_password:
        user.password = password
        db.session.add(user)
        db.session.commit()
        return redirect('/user/info')
    return '密码更改错误'
Exemple #36
0
def student_edit(id):
    student = Student.get_by_id(id)
    student_form = StudentForm()
    if request.method == 'GET':
        student_form.stu_no.data = student.stu_no
        student_form.name.data = student.name
        student_form.department.data = student.department
        student_form.major.data = student.major
        student_form.grade.data = student.grade
    if request.method == 'POST' and student_form.validate():
        ret = Student.update_student(student, student_form)
        if ret == 'OK':
            return redirect(url_for('admin.student'))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
    return render_template('admin/student_form.html',
                           title = u'修改学生',
                           action = url_for('admin.student_edit', id=id),
                           student_form = student_form)
Exemple #37
0
def student_add():
    student_form = StudentForm()
    if request.method == 'POST' and student_form.validate():
        ret = Student.create_student(student_form)
        if ret == 'OK':
            return redirect(url_for('admin.student'))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
    return render_template('admin/student_form.html',
                           title = u'添加学生',
                           action = url_for('admin.student_add'),
                           student_form = student_form)
Exemple #38
0
 def get_student_list(self):
     students = []
     for item in self.students.data:
         if item == '':
             continue
         has_t = Student.get_by_stu_no(item)
         if not has_t:
             new_t = Student.Student()
             new_t.stu_no = item
             new_t.save()
             students.append(new_t)
         else:
             students.append(has_t)
     return students
Exemple #39
0
def info():
    if session.has_key('username'):
        username = session['username']
        user_type = session['user_type']
        if user_type == 'student':
            user = Student.get_user(session['username'])
            file_dir = os.path.join(
                current_app.config['UPLOAD_FOLDER'], username + '/gd/')
            all_files = os.listdir(file_dir)
            return render_template("includes/index/info.html", user=user, filenames=all_files)
        elif user_type == 'admin':
            pass
        else:
            pass

    return "please login"
Exemple #40
0
def statistics():
    page=request.args.get('page',1,type=int)
    per_page=current_app.config['ADMIN_STATISTICS_PER_PAGE']
    if page == -1:
        page = ((Awards.get_count() - 1) // per_page) + 1
    pagination = Awards.get_list_pageable(page, per_page)
    awards_list = pagination.items
    awards = Awards.get_stu_awards_list()
    count = Awards.get_count()
    student_list = Student.get_list_pageable(page,per_page).items
    return render_template('admin/statistics.html',
                            title = u'统计',
                            awards_list = awards_list,
                            student_list = student_list,
                            alist = awards,
                            count = count,
                            pagination = pagination)
Exemple #41
0
import sys
sys.path.append('..')  # fix import directory

from app import app,db
from app.models import Student,Course
from random import randint, randrange

for i in range(10):
    Student.create('PB'+str(randint(100000,999999)),'用户'+str(randrange(100)),str(randrange(20)))

Exemple #42
0
Fichier : views.py Projet : TSS2/a
def students_json():
    query = request.args.get('query', None)
    students = Student.get_all_list(query)
    return jsonify(students = [t.to_json() for t in students])