Exemple #1
0
    def handle(self, *args, **options):
        dependancies = {}
        rubrique = ''

        for row in csv.DictReader(open(args[0], "r"), delimiter=",", quotechar='"'):

            rubrique = row['Rubrique'] if row['Rubrique'] else rubrique

            if Skill.objects.filter(code=row["Code"]).exists():
                skill = Skill.objects.get(code=row["Code"])
                skill.depends_on.clear()
                print "update", row["Code"]
            else:
                skill = Skill()
                print "create", row["Code"]
                skill.code = row["Code"]

            skill.name=row['Intitul\xc3\xa9']
            skill.description=row['Commentaires']
            skill.stage=row['\xc3\x89tape']
            skill.level=row['Niveau']
            skill.section=rubrique

            skill.save()

            for next_ in filter(lambda x: x, {row["suivant1"], row["suivant2"], row["suivant3"]}):
                dependancies.setdefault(row["Code"], []).append(next_)

        for key, value in filter(lambda (x, y): y, dependancies.iteritems()):
            print "on", key
            skill = Skill.objects.get(code=key)
            for dep in value:
                print " *", dep, "->", key
                Skill.objects.get(code=dep).depends_on.add(skill)
Exemple #2
0
 def test_skills_validations(self):
     skillset = Skillset.objects.create(
         name='python', description='best ever', verified=True, weight=10)
     skill = Skill(name='loops', verified=True, skillset_id=skillset.id)
     err_msg = 'Verified skills must have a weight.'
     with self.assertRaisesMessage(ValidationError, err_msg):
         skill.save()
Exemple #3
0
 def mutate(self, args, context, info):
     name = args.get('name')
     description = args.get('description')
     skillset_id = args.get('skillset_id')
     new_skill = SkillModel(name, description, skillset_id)
     new_skill.save()
     return CreateSkill(skill=new_skill)
Exemple #4
0
def courses_advice(skills):
    skills_to_learn = []
    for skill in skills:
        # Не ищет по альтернативным именам + уйти от формата когда на каждый
        # скил генерируется отдельный запрос
        skill_query = Skill.objects.filter(name__icontains=skill)
        if len(skill_query) > 0:
            skills_to_learn = skills_to_learn + [
                skill.id for skill in skill_query
            ]
        else:
            # Создаем скил который есть у сотрудника, но нет у нас в базе
            s = Skill(name=skill, learn_materials=False)
            s.save()
            skills_to_learn.append(s.id)

    skill_qs = Skill.objects.filter(pk__in=skills_to_learn)
    return skill_qs
Exemple #5
0
 def import_skills(self, skillfile):
     """Import skills from skilltable_character.dnt to django models."""
     log.info('import_skills\tfile\t%s' % skillfile.filename)
     skillfile.read_all()
     log.info('import_skills\tParsed DNT File')
     for row in skillfile.rows:
         if row.id > 30000:
             # These are reserved and conflict with real skills
             break
         try:
             name = self._uistring[row.NameID]
             job_id = self._jobmap[row.NeedJob]
             icon = row.IconImageIndex
             ultimate = name in _ultimates
         except KeyError:
             continue
         skill = Skill(name=name, job_id=job_id, icon=icon, ultimate=ultimate)
         skill.save()
         self._skillmap[row.id] = skill.id
     log.info('Parsed %d Skills' % Skill.objects.all().count())
Exemple #6
0
    def handle(self, *args, **options):
        dependancies = {}
        rubrique = ''

        to_link_to_stage = {}
        level_stages = {}

        for row in csv.DictReader(open(args[0], "r"), delimiter=",", quotechar='"'):

            if not filter(None, row.values()):
                continue

            rubrique = row['Rubrique'] if row['Rubrique'] else rubrique

            if Skill.objects.filter(code=row["Code"]).exists():
                skill = Skill.objects.get(code=row["Code"])
                skill.depends_on.clear()
                print "update", row["Code"]
            else:
                skill = Skill()
                print "create", row["Code"]
                skill.code = row["Code"]

            level = row['Niveau']

            stage_name = row['\xc3\x89tape'].strip().decode("Utf-8")

            if Stage.objects.filter(level=level, name=stage_name).exists():
                stage = Stage.objects.get(level=level, name=stage_name)
                stage.name = stage_name
            else:
                stage = Stage.objects.create(name=stage_name, level=level)

            if not stage.short_name:
                stage.short_name = stage_short_name[stage.name]
                stage.save()

            if stage not in to_link_to_stage:
                to_link_to_stage[stage] = []

            if level not in level_stages:
                level_stages[level] = stage

            to_link_to_stage[stage].append(skill)

            skill.name=row['Intitul\xc3\xa9']
            skill.description=row['Commentaires']
            skill.section=rubrique
            skill.image=row["Image FontAwesome"]

            skill.save()

            for next_ in filter(lambda x: x, {row[key] for key in row.keys() if key.startswith("suivant") and key.endswith(tuple(map(str, range(10))))}):
                dependancies.setdefault(row["Code"], []).append(next_)

        for key, value in filter(lambda (x, y): y, dependancies.iteritems()):
            print "on", key
            skill = Skill.objects.get(code=key)
            for dep in value:
                print " *", dep, "->", key
                Skill.objects.get(code=dep).depends_on.add(skill)
class TestResources(TestCase):
    def setUp(self):
        self.user = User(username="******")
        self.user.set_password('12345')
        self.user.save()
        self.teacher_user = User(username="******")
        self.teacher_user.set_password('12345')
        self.teacher_user.save()

        self.student = Student(user=self.user)
        self.student.save()
        self.teacher = Professor(user=self.teacher_user)
        self.teacher.save()

        res1_content = {"title": "Res1"}
        self.res1 = Resource(added_by=self.teacher_user, content=res1_content)
        self.res1.save()

        self.section = Section(id=1, name="Section1")
        self.section.save()
        self.section.resource.add(self.res1)
        self.section.save()

        self.skill2 = Skill(id=2, name="Skill2", code="2")
        self.skill2.save()

        res2_content = {"title": "Res2"}
        self.res2 = Resource(added_by=self.teacher_user, content=res2_content)
        self.res2.save()

        self.skill3 = Skill(id=3, name="Skill3", code="3")
        self.skill3.save()
        self.skill3.resource.add(self.res2)
        self.skill3.save()

        self.skill4 = Skill(id=4, name="Skill4", code="4")
        self.skill4.section = self.section
        self.skill4.save()

        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.stage.skills.add(self.skill3)
        self.stage.skills.add(self.skill4)
        self.stage.save()

        self.lesson = Lesson(id=1, name="English", stage_id=1)
        self.lesson.save()
        self.lesson.students.add(self.student)
        self.lesson.professors.add(self.teacher)
        self.lesson.save()

        self.s1 = Client()
        self.s1.login(username=self.user.username, password='******')

        self.t1 = Client()
        self.t1.login(username=self.teacher_user.username, password='******')

    def test_get_all_resources(self):
        response = self.s1.get('/forum/write/resources/')
        json_data = json.loads(response.content)
        data = json_data["data"]

        self.assertEquals(len(data), 2)

        correct_ids = [self.res1.id, self.res2.id]
        self.assertTrue(data[0]["id"] in correct_ids)
        self.assertTrue(data[1]["id"] in correct_ids)

    def test_get_section_resources(self):
        response = self.s1.get(
            '/forum/write/resources/?section={0}&skills[]={1}'.format(
                self.section.id, 0))
        json_data = json.loads(response.content)
        data = json_data["data"]

        self.assertEquals(len(data), 1)

        self.assertEquals(data[0]["title"], self.res1.content['title'])

    def test_get_skills_resources(self):
        response = self.s1.get(
            '/forum/write/resources/?skills[]={0}&section={1}'.format(
                self.skill3.id, 0))
        json_data = json.loads(response.content)
        data = json_data["data"]

        self.assertEquals(len(data), 1)

        self.assertEquals(data[0]["title"], self.res2.content['title'])
Exemple #8
0
    def handle(self, *args, **options):
        dependancies = {}
        rubrique = ''

        to_link_to_stage = {}
        level_stages = {}

        for row in csv.DictReader(open(args[0], "r"),
                                  delimiter=",",
                                  quotechar='"'):

            if not filter(None, row.values()):
                continue

            rubrique = row['Rubrique'] if row['Rubrique'] else rubrique

            if Skill.objects.filter(code=row["Code"]).exists():
                skill = Skill.objects.get(code=row["Code"])
                skill.depends_on.clear()
                print "update", row["Code"]
            else:
                skill = Skill()
                print "create", row["Code"]
                skill.code = row["Code"]

            level = row['Niveau']

            stage_name = row['\xc3\x89tape'].strip().decode("Utf-8")

            if Stage.objects.filter(level=level, name=stage_name).exists():
                stage = Stage.objects.get(level=level, name=stage_name)
                stage.name = stage_name
            else:
                stage = Stage.objects.create(name=stage_name, level=level)

            if not stage.short_name:
                stage.short_name = stage_short_name[stage.name]
                stage.save()

            if stage not in to_link_to_stage:
                to_link_to_stage[stage] = []

            if level not in level_stages:
                level_stages[level] = stage

            to_link_to_stage[stage].append(skill)

            skill.name = row['Intitul\xc3\xa9']
            skill.description = row['Commentaires']
            skill.section = rubrique
            skill.image = row["Image FontAwesome"]

            skill.save()

            for next_ in filter(
                    lambda x: x, {
                        row[key]
                        for key in row.keys() if key.startswith("suivant")
                        and key.endswith(tuple(map(str, range(10))))
                    }):
                dependancies.setdefault(row["Code"], []).append(next_)

        for key, value in filter(lambda (x, y): y, dependancies.iteritems()):
            print "on", key
            skill = Skill.objects.get(code=key)
            for dep in value:
                print " *", dep, "->", key
                Skill.objects.get(code=dep).depends_on.add(skill)