コード例 #1
0
def load_categories_content(cli, size, fake, *_, **__):
    """
    Load categories, subcategories and licenses for tutorials and articles
    """

    # Load a few licenses, while avoiding creating duplicates of what may have been loaded before
    lics = ["Tous droits réservés", "CC BY"]
    for lic in lics:
        if Licence.objects.filter(code=lic).count() == 0:
            licence = Licence(code=lic, title=lic, description="")
            licence.save()
            cli.stdout.write("Note : ajout de la licence `{}`".format(lic))
    categories = []
    sub_categories = []
    nb_categories = size * 5
    nb_sub_categories = size * 10
    cli.stdout.write(
        "Nombres de catégories de contenus à créer : {}".format(nb_categories))
    cli.stdout.write(
        "Nombres de sous-catégories de contenus à créer : {}".format(
            nb_sub_categories))
    tps1 = time.time()
    for i in range(0, nb_categories):
        ttl = str(i) + " " + fake.job()
        cat = TCategory(title=ttl,
                        description=fake.sentence(nb_words=15,
                                                  variable_nb_words=True),
                        slug=old_slugify(ttl))
        cat.save()
        categories.append(cat)
        sys.stdout.write(" Cat. {}/{}  \r".format(i + 1, nb_categories))
        sys.stdout.flush()

    for i in range(0, nb_sub_categories):
        with contextlib.suppress(IntegrityError):
            ttl = str(i * 10) + str(i) + " " + fake.word()
            subcat = SubCategory(title=ttl,
                                 subtitle=fake.sentence(
                                     nb_words=5, variable_nb_words=True),
                                 slug=old_slugify(ttl))
            subcat.save()
            sub_categories.append(subcat)
        sys.stdout.write(" SubCat. {}/{}  \r".format(i + 1, nb_sub_categories))
        sys.stdout.flush()

    for i in range(0, nb_sub_categories):
        with contextlib.suppress(IntegrityError):
            catsubcat = CategorySubCategory(category=categories[i %
                                                                nb_categories],
                                            subcategory=sub_categories[i],
                                            is_main=True)
            catsubcat.save()
        sys.stdout.write(" CatSubCat. {}/{}  \r".format(
            i + 1, nb_sub_categories))
        sys.stdout.flush()

    tps2 = time.time()
    cli.stdout.write("\nFait en {} sec".format(tps2 - tps1))
コード例 #2
0
def load_categories_content(cli, size, fake):
    """
    Load categories and subcategories for tutorial and article
    """

    lics = [
        "CB-BY", "CC-BY-ND", "CC-BY-ND-SA", "CC-BY-SA", "CC", "CC-BY-IO",
        "Tout-Droits"
    ]
    for lic in lics:
        ex = Licence.objects.filter(code=lic).all()
        if len(ex) is 0:
            licence = Licence(code=lic, title=lic, description="")
            licence.save()
            cli.stdout.write(u'Note: ajout de la licence {}'.format(lic))
    categories = []
    sub_categories = []
    nb_categories = size * 5
    nb_sub_categories = size * 10
    cli.stdout.write(u"Nombres de catégories de contenus à créer : {}".format(
        nb_categories))
    cli.stdout.write(
        u"Nombres de sous-catégories de contenus à créer : {}".format(
            nb_sub_categories))
    tps1 = time.time()
    for i in range(0, nb_categories):
        ttl = fake.word() + str(i)
        cat = TCategory(title=ttl,
                        description=fake.sentence(nb_words=15,
                                                  variable_nb_words=True),
                        slug=slugify(ttl))
        cat.save()
        categories.append(cat)
        sys.stdout.write(" Cat. {}/{}  \r".format(i + 1, nb_categories))
        sys.stdout.flush()

    for i in range(0, nb_sub_categories):
        ttl = fake.word() + str(i * 10) + str(i)
        subcat = SubCategory(title=ttl,
                             subtitle=fake.sentence(nb_words=5,
                                                    variable_nb_words=True),
                             slug=slugify(ttl))
        subcat.save()
        sub_categories.append(subcat)
        sys.stdout.write(" SubCat. {}/{}  \r".format(i + 1, nb_sub_categories))
        sys.stdout.flush()

    for i in range(0, nb_sub_categories):
        catsubcat = CategorySubCategory(category=categories[i % nb_categories],
                                        subcategory=sub_categories[i],
                                        is_main=True)
        catsubcat.save()
        sys.stdout.write(" CatSubCat. {}/{}  \r".format(
            i + 1, nb_sub_categories))
        sys.stdout.flush()

    tps2 = time.time()
    cli.stdout.write(u"\nFait en {} sec".format(tps2 - tps1))
コード例 #3
0
ファイル: load_fixtures.py プロジェクト: Karnaj/zds-site
def load_categories_content(cli, size, fake, *_, **__):
    """
    Load categories and subcategories for tutorial and article
    """

    lics = ['CB-BY', 'CC-BY-ND', 'CC-BY-ND-SA', 'CC-BY-SA', 'CC', 'CC-BY-IO', 'Tout-Droits']
    for lic in lics:
        ex = Licence.objects.filter(code=lic).all()
        if len(ex) == 0:
            licence = Licence(code=lic, title=lic, description='')
            licence.save()
            cli.stdout.write('Note: ajout de la licence {}'.format(lic))
    categories = []
    sub_categories = []
    nb_categories = size * 5
    nb_sub_categories = size * 10
    cli.stdout.write('Nombres de catégories de contenus à créer : {}'.format(nb_categories))
    cli.stdout.write('Nombres de sous-catégories de contenus à créer : {}'.format(nb_sub_categories))
    tps1 = time.time()
    for i in range(0, nb_categories):
        ttl = str(i) + ' ' + fake.job()
        cat = TCategory(title=ttl,
                        description=fake.sentence(nb_words=15, variable_nb_words=True),
                        slug=slugify(ttl))
        cat.save()
        categories.append(cat)
        sys.stdout.write(' Cat. {}/{}  \r'.format(i + 1, nb_categories))
        sys.stdout.flush()

    for i in range(0, nb_sub_categories):
        with contextlib.suppress(IntegrityError):
            ttl = str(i * 10) + str(i) + ' ' + fake.word()
            subcat = SubCategory(title=ttl,
                                 subtitle=fake.sentence(nb_words=5, variable_nb_words=True),
                                 slug=slugify(ttl))
            subcat.save()
            sub_categories.append(subcat)
        sys.stdout.write(' SubCat. {}/{}  \r'.format(i + 1, nb_sub_categories))
        sys.stdout.flush()

    for i in range(0, nb_sub_categories):
        with contextlib.suppress(IntegrityError):
            catsubcat = CategorySubCategory(category=categories[i % nb_categories],
                                            subcategory=sub_categories[i],
                                            is_main=True)
            catsubcat.save()
        sys.stdout.write(' CatSubCat. {}/{}  \r'.format(i + 1, nb_sub_categories))
        sys.stdout.flush()

    tps2 = time.time()
    cli.stdout.write('\nFait en {} sec'.format(tps2 - tps1))
コード例 #4
0
    def update_categories(self):
        """
        Delete all categories and create new ones.

        :return: None
        """
        for cat in SubCategory.objects.all():
            self.stdout.write(
                '[ZEP-25] : Old category "{}" deleted'.format(cat))
            cat.delete()
        for cat in Category.objects.all():
            self.stdout.write(
                '[ZEP-25] : Old subcategory "{}" deleted'.format(cat))
            cat.delete()
        for cat in CategorySubCategory.objects.all():
            cat.delete()
        self.stdout.write('[ZEP-25] : Categories and subcatagories deleted')
        categories = [
            'Informatique', 'Sciences de la nature',
            'Sciences humaines et sociales', 'Autres'
        ]
        subcategories = [
            # Informatique
            [
                ('Bureautique et rédaction', 'Excel, LaTeX, Powerpoint, Word'),
                ('Matériel et électronique',
                 'Arduino, Disque dur, DIY, Electronique*, Mémoires, Ordinateur'
                 ),
                ('Programmation et algorithmique',
                 '.NET, Ada, Algorithmique, C, C#, C++, Cobol, Fonctionnel, Génie logicie'
                 'l, Haskell, Java, Julia, Lisp, Ocaml, Orienté objet, Python, Ruby, Vers'
                 'ioning'),
                ('Site web',
                 'Accessibilité, Actionscript, Angular JS, CakePHP, Django, HTML/CSS, Java EE, JavaScript, Ngin'
                 'x, Node.js, Oxygen, PHP, Ruby On Rails, SEO/Réferencement*, Symfony, Websocket'
                 ),
                ("Systèmes d'exploitation",
                 'Android, GNU/Linux, iOS, MAC OS, Windows, Windows Phone'),
                ('Autres (informatique)',
                 'API, Base de données, FTP, Jeux vidéos, MySQL, Oracle, Protocole, Sécurité, TCP/'
                 'IP'),
            ],
            # Sciences de la nature
            [('Astronomie', 'Astronomie'),
             ('Géologie et géographie physique', 'Géologie'),
             ('Biologie', 'Biologie'), ('Physique', 'Physique'),
             ('Chimie', 'Chimie'), ('Mathématiques', 'Mathématiques'),
             ('Autres (sciences de la nature)', 'Autres sciences de la nature')
             ],
            # Sciences humaines et sociales
            [('Droit', 'Droit'), ('Histoire', 'Histoire'),
             ('Langues', 'Langues'), ('Psychologie', 'Psychologie, Pédagogie'),
             ('Économie', 'Économie'),
             ('Autres (sciences humaines et sociales)',
              'Autres sciences humaines et sociales comme la géographie')],
            # Autres
            [('Arts, graphisme et multimédia',
              'Graphisme 2D, Graphisme 3D, Musique, Son'),
             ('Communication et management', 'Monde du travail'),
             ('Zeste de Savoir', 'Zeste de Savoir'),
             ('Autres', 'Littérature, Interview')]
        ]
        i = 0
        for category in categories:
            cat = Category()
            cat.title = category
            cat.description = category
            cat.position = i
            cat.slug = slugify('{}'.format(category))
            cat.save()
            self.stdout.write('[ZEP-25] : New category "{}" added'.format(cat))
            for subcategory in subcategories[i]:
                sub = SubCategory()
                sub.title = subcategory[0]
                sub.subtitle = subcategory[1]
                sub.slug = slugify('{}'.format(subcategory[0]))
                sub.save()
                self.stdout.write(
                    '[ZEP-25] : New subcategory "{}" added'.format(sub))
                catsubcat = CategorySubCategory()
                catsubcat.category = cat
                catsubcat.subcategory = sub
                catsubcat.save()
                self.stdout.write(
                    '[ZEP-25] : Relation "{}" <--> "{}" added'.format(
                        cat, sub))
            i += 1
コード例 #5
0
    def update_categories(self):
        """
        Delete all categories and create new ones.

        :return: None
        """
        for cat in SubCategory.objects.all():
            self.stdout.write('[ZEP-25] : Old category "{}" deleted'.format(cat))
            cat.delete()
        for cat in Category.objects.all():
            self.stdout.write('[ZEP-25] : Old subcategory "{}" deleted'.format(cat))
            cat.delete()
        for cat in CategorySubCategory.objects.all():
            cat.delete()
        self.stdout.write('[ZEP-25] : Categories and subcatagories deleted')
        categories = ['Informatique', 'Sciences de la nature', 'Sciences humaines et sociales', 'Autres']
        subcategories = [
            # Informatique
            [
                ('Bureautique et rédaction', 'Excel, LaTeX, Powerpoint, Word'),
                ('Matériel et électronique', 'Arduino, Disque dur, DIY, Electronique*, Mémoires, Ordinateur'),
                ('Programmation et algorithmique',
                 '.NET, Ada, Algorithmique, C, C#, C++, Cobol, Fonctionnel, Génie logicie'
                 'l, Haskell, Java, Julia, Lisp, Ocaml, Orienté objet, Python, Ruby, Vers'
                 'ioning'),
                ('Site web',
                 'Accessibilité, Actionscript, Angular JS, CakePHP, Django, HTML/CSS, Java EE, JavaScript, Ngin'
                 'x, Node.js, Oxygen, PHP, Ruby On Rails, SEO/Réferencement*, Symfony, Websocket'),
                ("Systèmes d'exploitation", 'Android, GNU/Linux, iOS, MAC OS, Windows, Windows Phone'),
                ('Autres (informatique)',
                 'API, Base de données, FTP, Jeux vidéos, MySQL, Oracle, Protocole, Sécurité, TCP/'
                 'IP'),
            ],
            # Sciences de la nature
            [
                ('Astronomie', 'Astronomie'),
                ('Géologie et géographie physique', 'Géologie'),
                ('Biologie', 'Biologie'),
                ('Physique', 'Physique'),
                ('Chimie', 'Chimie'),
                ('Mathématiques', 'Mathématiques'),
                ('Autres (sciences de la nature)', 'Autres sciences de la nature')
            ],
            # Sciences humaines et sociales
            [
                ('Droit', 'Droit'),
                ('Histoire', 'Histoire'),
                ('Langues', 'Langues'),
                ('Psychologie', 'Psychologie, Pédagogie'),
                ('Économie', 'Économie'),
                ('Autres (sciences humaines et sociales)', 'Autres sciences humaines et sociales comme la géographie')
            ],
            # Autres
            [
                ('Arts, graphisme et multimédia', 'Graphisme 2D, Graphisme 3D, Musique, Son'),
                ('Communication et management', 'Monde du travail'),
                ('Zeste de Savoir', 'Zeste de Savoir'),
                ('Autres', 'Littérature, Interview')
            ]
        ]
        i = 0
        for category in categories:
            cat = Category()
            cat.title = category
            cat.description = category
            cat.position = i
            cat.slug = slugify('{}'.format(category))
            cat.save()
            self.stdout.write('[ZEP-25] : New category "{}" added'.format(cat))
            for subcategory in subcategories[i]:
                sub = SubCategory()
                sub.title = subcategory[0]
                sub.subtitle = subcategory[1]
                sub.slug = slugify('{}'.format(subcategory[0]))
                sub.save()
                self.stdout.write('[ZEP-25] : New subcategory "{}" added'.format(sub))
                catsubcat = CategorySubCategory()
                catsubcat.category = cat
                catsubcat.subcategory = sub
                catsubcat.save()
                self.stdout.write('[ZEP-25] : Relation "{}" <--> "{}" added'.format(cat, sub))
            i += 1
コード例 #6
0
    def update_categories(self):
        """
        Delete all categories and create new ones.

        :return: None
        """
        for cat in SubCategory.objects.all():
            self.stdout.write('[ZEP-25] : Old category "{}" deleted'.format(cat))
            cat.delete()
        for cat in Category.objects.all():
            self.stdout.write('[ZEP-25] : Old subcategory "{}" deleted'.format(cat))
            cat.delete()
        for cat in CategorySubCategory.objects.all():
            cat.delete()
        self.stdout.write("[ZEP-25] : Categories and subcatagories deleted")
        categories = ["Informatique", "Sciences de la nature", "Sciences humaines et sociales", "Autres"]
        subcategories = [
            # Informatique
            [
                ("Bureautique et rédaction", "Excel, LaTeX, Powerpoint, Word"),
                ("Matériel et électronique", "Arduino, Disque dur, DIY, Electronique*, Mémoires, Ordinateur"),
                (
                    "Programmation et algorithmique",
                    ".NET, Ada, Algorithmique, C, C#, C++, Cobol, Fonctionnel, Génie logicie"
                    "l, Haskell, Java, Julia, Lisp, Ocaml, Orienté objet, Python, Ruby, Vers"
                    "ioning",
                ),
                (
                    "Site web",
                    "Accessibilité, Actionscript, Angular JS, CakePHP, Django, HTML/CSS, Java EE, JavaScript, Ngin"
                    "x, Node.js, Oxygen, PHP, Ruby On Rails, SEO/Réferencement*, Symfony, Websocket",
                ),
                ("Systèmes d'exploitation", "Android, GNU/Linux, iOS, MAC OS, Windows, Windows Phone"),
                (
                    "Autres (informatique)",
                    "API, Base de données, FTP, Jeux vidéos, MySQL, Oracle, Protocole, Sécurité, TCP/" "IP",
                ),
            ],
            # Sciences de la nature
            [
                ("Astronomie", "Astronomie"),
                ("Géologie et géographie physique", "Géologie"),
                ("Biologie", "Biologie"),
                ("Physique", "Physique"),
                ("Chimie", "Chimie"),
                ("Mathématiques", "Mathématiques"),
                ("Autres (sciences de la nature)", "Autres sciences de la nature"),
            ],
            # Sciences humaines et sociales
            [
                ("Droit", "Droit"),
                ("Histoire", "Histoire"),
                ("Langues", "Langues"),
                ("Psychologie", "Psychologie, Pédagogie"),
                ("Économie", "Économie"),
                ("Autres (sciences humaines et sociales)", "Autres sciences humaines et sociales comme la géographie"),
            ],
            # Autres
            [
                ("Arts, graphisme et multimédia", "Graphisme 2D, Graphisme 3D, Musique, Son"),
                ("Communication et management", "Monde du travail"),
                ("Zeste de Savoir", "Zeste de Savoir"),
                ("Autres", "Littérature, Interview"),
            ],
        ]
        i = 0
        for category in categories:
            cat = Category()
            cat.title = category
            cat.description = category
            cat.position = i
            cat.slug = slugify("{}".format(category))
            cat.save()
            self.stdout.write('[ZEP-25] : New category "{}" added'.format(cat))
            for subcategory in subcategories[i]:
                sub = SubCategory()
                sub.title = subcategory[0]
                sub.subtitle = subcategory[1]
                sub.slug = slugify("{}".format(subcategory[0]))
                sub.save()
                self.stdout.write('[ZEP-25] : New subcategory "{}" added'.format(sub))
                catsubcat = CategorySubCategory()
                catsubcat.category = cat
                catsubcat.subcategory = sub
                catsubcat.save()
                self.stdout.write('[ZEP-25] : Relation "{}" <--> "{}" added'.format(cat, sub))
            i += 1