def save():
    form = ModuleInfoForm()
    module_id = session.get('moduleId')
    module_name = form.name.data
    module_desc = form.description.data
    module = Module(module_name, module_desc, current_user.id, None)
    module.id = module_id
    # if form.validate_on_submit():
    if Module.update_a_module_by_enity(module):
        return redirect(url_for('module_info.info', id=module_id))
    else:
        return 'Save module info error ..........'
Beispiel #2
0
 def getModulesFromDb(self, db, courseName):
     modules = []
     if db.is_connected():
         rows = db.find_all('''SELECT Id, Name, Title, AuthorHandle, ModuleIndex
                             FROM Module
                             WHERE CourseName = ?''', [courseName])
         for row in rows:
             module = Module(row[0], row[1], row[2], row[3], row[4])
             module.Clips = self.getClipsFromDb(db, row[0])
             #print(module)
             modules.append(module)
     return modules
Beispiel #3
0
def update_modules(repository):
    repository_hashes = get_tree_hashes_per_repo(repository)

    for repository_hash in repository_hashes:
        try:
            gittree_element = repository.get_git_tree(repository_hash)
        except GithubException:
            pass
        try:
            for type_tree in gittree_element.tree:
                if type_tree.type == "tree":
                    if Module.query.filter(Module.addon == type_tree.path).first():
                        # existing module
                        pass
                    else:
                        # new module
                        module = Module(addon=type_tree.path, repo_name=repository.name)
                        db.session.add(module)
                        db.session.commit()
                        pass
                    # update module
                    url_test_module(type_tree.path)

        except UnboundLocalError:
            pass
    pass
Beispiel #4
0
def add_module():
    section_id = request.get_json()['section_id']
    title = "new module"
    module = Module(section_id = section_id, title = title)
    db.session.add(module)
    db.session.commit()
    new_module = Module.query.filter_by(module_id = module.module_id).first()
    module_json = new_module.convert_to_dict()
    return jsonify({"success": True, "module": module_json})
def create_modules(modules):
    """Add modules to db"""
    for module in modules:
        m = Module(code=module['code'],
                   name=module['name'],
                   description=module['description'],
                   start=datetime.strptime(module['start'], '%Y-%m-%d'),
                   end=datetime.strptime(module['end'], '%Y-%m-%d'),
                   faculty=module['faculty'])
        db.session.add(m)
        db.session.commit()
Beispiel #6
0
 def test_create_module(self):
     """Test if new modules can be created"""
     module = Module(
         code='tm01',
         name='testmodule01',
         description='This is a test module',
         start=datetime(2009, 10, 1),
         end=datetime(2010, 10, 1),
         faculty='Faculteit ICT',
     )
     db.session.add(module)
     db.session.commit()
Beispiel #7
0
def get_modules_of_project(projectId):

    modules = Module.get_modules_of_project(projectId)
    result = []
    for i in modules:
        result.append(i.to_dict())

    return jsonify({
        "code": 200,
        "msg": "获取模块列表成功",
        "data": {
            "modules": result,
        }
    })
Beispiel #8
0
def create_module_for_config_tree(type='', id=0):
    flash('New Node Created ****** type: '+type+' id: '+str(id))

    if type == 'semester':
        semester = Semester.query.get_or_404(id)
        # create new unit
        rand = str( random.randint(1,999) )
        unit = Unit(
            semester_id=id, 
            name='name-'+rand, 
            display_name='display_name-'+rand,
            order=1)
        db.session.add(unit)
        db.session.commit()
        return redirect( url_for('conf_semester', semester_id=semester.id) )

    if type == 'unit':
        unit = Unit.query.get_or_404(id)
        semester = unit.semester
        # create new module
        rand = str( random.randint(1,999) )
        module = Module(
            unit_id=id, 
            code='code-'+rand, 
            name='name-'+rand, 
            display_name='display_name-'+rand,
            order=1)
        db.session.add(module)
        db.session.commit()
        return redirect( url_for('conf_semester', semester_id=semester.id) )

    if type == 'module':
        module = Module.query.get_or_404(id)
        semester = module.unit.semester

        # create new percentage
        rand = str( random.randint(1,999) )
        percentage = Percentage(
            module_id=id, 
            # name='name-'+rand, 
            # percentage= ,
            order=1)
        db.session.add(percentage)
        db.session.commit()

        return redirect( url_for('conf_semester', semester_id=semester.id) )

    return 'type not catched'
def add_module():
    """Add new module"""
    form = EditModuleForm()
    if form.validate_on_submit():
        m = Module(
            code=form.code.data,
            name=form.name.data,
            description=form.description.data,
            start=form.start.data,
            end=form.end.data,
            faculty=form.faculty.data
        )
        db.session.add(m)
        db.session.commit()
        return redirect(url_for('admin.modules_overview'))
    return render_template(
        'default-form.html', form=form,
        title=_('Admin Panel: Add Module')
    )
Beispiel #10
0
def create_module():
    module_data=request.get_json()
    new_module=Module(title=module_data['title'],
                        description=module_data['description'],
                        syllabus=module_data['syllabus'],
                        start_date=datetime.strptime(
                            module_data['startDate'], '%d-%m-%Y'),
                        end_date=datetime.strptime(
                            module_data['endDate'], '%d-%m-%Y'),
                        price=module_data['price'],
                        mentor_id=current_user.id,
                        default_img=module_data['img_url'])
    db.session.add(new_module)
    db.session.commit()

    resp={
        "status": 201,
        "message": "New module created"}

    return jsonify(resp)
Beispiel #11
0
def duplicate_module(module, new_unit):
    new_module = Module(
        code = module.code,
        name = module.name,
        display_name = module.display_name,
        coefficient = module.coefficient,
        credit = module.credit,
        time = module.time,
        order = module.order,
        unit_id = new_unit.id
    )
    db.session.add(new_module)
    db.session.commit()

    # add children
    msg_percentages = ''
    for percentage in module.percentages:
        msg_percentages = msg_percentages +  duplicate_percentage(percentage, new_module) + ' - '

    return ' M: ' + str(new_module.id) + ' <' + msg_percentages + '>'
Beispiel #12
0
def import_modules_to_db(data):
    """
    Writes the module data from the json file to the db.

    :param data: <dict> Dictionary containing the module data
    :return: Number of imported modules
    """
    for row in data:
        try:
            module = Module(code=row['code'],
                            name=row['name'],
                            description=row['description'],
                            start=datetime.strptime(row['start'], '%Y-%m-%d'),
                            end=datetime.strptime(row['end'], '%Y-%m-%d'),
                            faculty=row['faculty'])
            db.session.add(module)
            db.session.commit()
        except IntegrityError:
            db.session.rollback()

    return str(len(data))
Beispiel #13
0
def auth_tree_create():

    module_id = request.form.get('module_id')
    module_name = request.form.get('module_name')
    module_url = request.form.get('module_url')
    module_status = request.form.get('module_status')
    module_icon = request.form.get('module_icon')
    module_description = request.form.get('module_description')
    module_parent = request.form.get('module_parent')

    #create new node;
    if not module_id:
        if not module_name or not module_url or not module_parent or not module_status:
            return make_response(
                jsonify({
                    "code": 1,
                    "message": "提交数据不完整,请检查!"
                }))
        try:
            module = Module(module_name, module_url, module_parent,
                            module_status, module_icon, module_description)
            db.session.add(module)
            db.session.commit()
            module_id = module.module_id
        except Exception as e:
            app.logger.exception(e)
            db.session.rollback()
        finally:
            db.session.close()

        if module_id:
            try:
                db.session.add(RoleAndModule(session.get('role_id'),
                                             module_id))
                db.session.commit()
            except Exception as e:
                raise
            finally:
                db.session.close()
        else:
            return make_response(
                jsonify({
                    "code": 1,
                    "message": "数据库操作有误,请联系管理员!"
                }))

    #edit node
    else:
        if not module_name or not module_url or not module_status:
            return make_response(
                jsonify({
                    "code": 1,
                    "message": "提交数据不完整,请检查!"
                }))

        try:
            db.session.query(Module).filter(
                Module.module_id == module_id).update({
                    'module_name':
                    module_name,
                    'module_url':
                    module_url,
                    'module_status':
                    module_status,
                    'module_icon':
                    module_icon,
                    'module_description':
                    module_description
                })
            db.session.commit()
        except Exception as e:
            app.logger.exception(e)
            db.session.rollback()
        finally:
            db.session.close()
    return make_response(jsonify({"code": 0, "message": "操作成功!"}))
Beispiel #14
0
                              "y": -14.604934692382812,
                              "z": 5.905102252960205
                          },
                          "gyro": {
                              "pitch": 0.08530018482155957,
                              "roll": 358.92965845080533,
                              "yaw": 88.41337005085171
                          },
                          "gyroRaw": {
                              "x": -0.012549860402941704,
                              "y": -0.03786290064454079,
                              "z": 0.0020742900669574738
                          },
                          "humidity": 37.94554901123047,
                          "orient": {
                              "pitch": 0.1468588055109267,
                              "roll": 358.95223457388977,
                              "yaw": 88.40925827697137
                          },
                          "orientRaw": {
                              "pitch": 0.00207962142303586,
                              "roll": -0.018486613407731056,
                              "yaw": 1.5430498123168945
                          },
                          "pressure": 1026.365234375,
                          "temp": 16.053691864013672,
                          "tempHumidity": 16.053691864013672,
                          "tempPressure": 15.012500762939453
                      })
Module().save()
Beispiel #15
0
 def create_test_module(self):
     """Creates a module for testing purposes"""
     module = Module(code='tm01')
     db.session.add(module)
     db.session.commit()
     return module
Beispiel #16
0
 def test_create_module(self):
     m = Module(name='Testmodul', status=0)
     self.assertEqual(m.name, 'Testmodul')
     self.assertEqual(m.status, 0)
def test1():
    module = Module('bbb', 'bbb')
    Module.add_a_module_by_enity(module)
    return 'module test'
Beispiel #18
0
 def test_status_inactive(self):
     m = Module(name='Inaktives Modul')
     m.set_status_inactive()
     self.assertEqual(m.status, 0)
Beispiel #19
0
 def test_status_active(self):
     m = Module(name='Aktives Modul')
     m.set_status_active()
     self.assertEqual(m.status, 1)
Beispiel #20
0
 def test_default_status(self):
     m = Module(name='Testmodul')
     self.assertEqual(m.status, None)
Beispiel #21
0
def module_insert_data():
    modules = {
        u'bd-blink-server': (Project.query.filter_by(name=u"bd-blink").first(), 'http://10.10.10.5/svn/bd-blink/',
                             User.query.filter_by(username=u'dev1').first(), User.query.filter_by(username=u'qa1').first(),
                             User.query.filter_by(username=u'ops1').first(),
                             Software.query.filter_by(version=u'tomcat_7.0.68').first()),

        u'bd-tiger-web': (Project.query.filter_by(name=u"bd-tiger").first(), 'http://10.10.10.5/svn/bd-tiger/',
                          User.query.filter_by(username=u'dev2').first(), User.query.filter_by(username=u'qa2').first(),
                          User.query.filter_by(username=u'ops2').first(),
                          Software.query.filter_by(version=u'tomcat_7.0.68').first()),

        u'bd-cmdb': (Project.query.filter_by(name=u"bd-cmdb").first(), 'http://10.10.10.5/svn/bd-cmdb/',
                     User.query.filter_by(username=u'dev2').first(), User.query.filter_by(username=u'qa2').first(),
                     User.query.filter_by(username=u'ops2').first(),
                     Software.query.filter_by(version=u'tomcat_7.0.68').first()),

        u'bd-bdmp': (Project.query.filter_by(name=u"bd-bdmp").first(), 'http://10.10.10.5/svn/bd-bdmp/',
                     User.query.filter_by(username=u'dev1').first(), User.query.filter_by(username=u'qa1').first(),
                     User.query.filter_by(username=u'ops2').first(),
                     Software.query.filter_by(version=u'tomcat_7.0.68').first()),

        u'bd-test': (Project.query.filter_by(name=u"bd-test").first(), 'http://10.10.10.5/svn/bd-test/',
                     User.query.filter_by(username=u'dev1').first(), User.query.filter_by(username=u'qa1').first(),
                     User.query.filter_by(username=u'ops2').first(),
                     Software.query.filter_by(version=u'tomcat_7.0.68').first()),

        u'bd-test2': (Project.query.filter_by(name=u"bd-test2").first(), 'http://10.10.10.5/svn/bd-test2/',
                     User.query.filter_by(username=u'dev1').first(), User.query.filter_by(username=u'qa1').first(),
                     User.query.filter_by(username=u'ops2').first(),
                     Software.query.filter_by(version=u'tomcat_7.0.68').first()),

        u'bd-test3': (Project.query.filter_by(name=u"bd-test3").first(), 'http://10.10.10.5/svn/bd-test3/',
                     User.query.filter_by(username=u'dev1').first(), User.query.filter_by(username=u'qa1').first(),
                     User.query.filter_by(username=u'ops2').first(),
                     Software.query.filter_by(version=u'tomcat_7.0.68').first()),

        u'bd-jenkins': (Project.query.filter_by(name=u"bd-jenkins").first(), 'http://10.10.10.5/svn/bd-jenkins/',
                     User.query.filter_by(username=u'dev1').first(), User.query.filter_by(username=u'qa1').first(),
                     User.query.filter_by(username=u'ops2').first(),
                     Software.query.filter_by(version=u'tomcat_7.0.68').first()),

        u'bd-qa': (Project.query.filter_by(name=u"bd-qa").first(), 'http://10.10.10.5/svn/bd-qa/',
                     User.query.filter_by(username=u'dev1').first(), User.query.filter_by(username=u'qa1').first(),
                     User.query.filter_by(username=u'ops2').first(),
                     Software.query.filter_by(version=u'tomcat_7.0.68').first()),

        u'bd-oracle': (Project.query.filter_by(name=u"bd-oracle").first(), 'http://10.10.10.5/svn/bd-oracle/',
                     User.query.filter_by(username=u'dev1').first(), User.query.filter_by(username=u'qa1').first(),
                     User.query.filter_by(username=u'ops2').first(),
                     Software.query.filter_by(version=u'tomcat_7.0.68').first()),

        u'bd-mongodb': (Project.query.filter_by(name=u"bd-mongodb").first(), 'http://10.10.10.5/svn/bd-mongodb/',
                     User.query.filter_by(username=u'dev1').first(), User.query.filter_by(username=u'qa1').first(),
                     User.query.filter_by(username=u'ops2').first(),
                     Software.query.filter_by(version=u'tomcat_7.0.68').first()),
    }
    for m in modules:
        module = Module.query.filter_by(name=m).first()
        if module is None:
            module = Module(name=m)
        module.project = modules[m][0]
        module.svn = modules[m][1]
        module.dev = modules[m][2]
        module.qa = modules[m][3]
        module.ops = modules[m][4]
        module.software = modules[m][5]
        db.session.add(module)
    db.session.commit()
    print "Insert module test data."
Beispiel #22
0
def register():
    # get register information from frontend
    username = request.get_json()['username']
    email = request.get_json()['email']
    password = request.get_json()['password']
    password2 = request.get_json()['password2']

    # The two passwords are different
    if password != password2:
        return jsonify({"validity": False,
                        "nonValidMessage": "Non consistent password"}
                       )

    # get data of user with the username from database
    user = User.query.filter_by(username=username).first()
    # The user name has been used
    if user is not None:
        return jsonify({"validity": False,
                        "nonValidMessage": "Please use another username"}
                       )
    # get data of user with the email address from database
    user = User.query.filter_by(email=email).first()
    # The email address has been used or not invalid email? XXXX@ XXX.com
    if user is not None:
        return jsonify({"validity": False,
                        "nonValidMessage": "Please use another email address"}
                       )

    user = User(username=username, email=email)
    user.set_password(password)
    db.session.add(user)
    db.session.commit()

    about_me = Section(title="about me", user_id=user.user_id)
    contact_me = Section(title="contact me", user_id=user.user_id)
    education = Section(title="education background", user_id=user.user_id)
    internship = Section(title="internship experience", user_id=user.user_id)
    db.session.add(about_me)
    db.session.add(contact_me)
    db.session.add(education)
    db.session.add(internship)
    db.session.commit()

    text1 = "<p>Hello, and welcome to my eportfolio! My name is \"YOUR NAME\". &nbsp;</p><p>I am from \"COUNTRY/CITY\". I am a \"OCCUPATION\" working/studying at \"INSTITUTION\".&nbsp;</p><p>At this eportfolio you will find my education background, previous working experience, programs that I participated, \"OTHER SECTIONS\".&nbsp;</p><p>Don't be hesitate to contact me! My contact details can be found on \"Contact Me\".</p>"

    text2 = "<p>phone number :&nbsp;</p><p>contact email :&nbsp;</p><p>linkedin :</p>",
    text3 = "put the detail of your education background here"
    text4 = "put the detail of your internship experience here"

    user_info = Module(title="basic information", text=text1, image_name="portrait.jpg", section_id=about_me.section_id)
    contact_info = Module(title="contact information", text=text2, section_id=contact_me.section_id)
    education_info = Module(title="education background 1", date="e.g. 1.1.2000-1.1.2020", text=text3, section_id=education.section_id)
    internship_info = Module(title="internship experience 1", date="e.g. 1.1.2000-1.1.2020", text=text4, section_id=internship.section_id)
    db.session.add(user_info)
    db.session.add(contact_info)
    db.session.add(education_info)
    db.session.add(internship_info)
    db.session.commit()
    return jsonify({"validity": True,
                    "nonValidMessage": ""}
                   )