Example #1
0
    def create_loisir(self, loisir):

        model = Loisir()

        for field in self.fields:
            text = self.get_node_text(loisir, field)
            setattr(model, field, text)

        text = self.get_node_text(loisir, "TARIF_BASE")
        print "tarif", text
        if text is not None:
            model.TARIF_BASE = decimal.Decimal(text)

        categorie_name = self.get_node_text(loisir, self.categorie_key)
        if categorie_name is not None:
            model.CATEGORIE = Categorie.objects.get(UID=categorie_name)

        model.save()
        pprint(model)

        return model
Example #2
0
    loisirs = parser.parse( f.read() )

    category_parser = CategoryParser()
    categories = category_parser.categorie_loisirs(loisirs)

    for c in categories:

        if c is not None and Categorie.objects.filter(UID=c).count() == 0:
            model = Categorie()
            model.UID = c
            model.save()
        print c

    for l in loisirs:
        L = Loisir()

        L.CODE_SESSION = l['code_session']
        L.DESCRIPTION = l['description']
        L.DESCRIPTION_ACT = l['act']
        L.DESCRIPTION_NAT = l['nat']
        L.NOM_COUR = l['cours']
        L.ARRONDISSEMENT = l['arrondissement']
        L.ADRESSE = l['adresse']
        L.CATEGORIE = Categorie.objects.get(UID=l['nat'])

        if len(l['lieux']) > 0:
            L.LIEU_1 = l['lieux'][0]

        if len(l['lieux']) > 1:
            L.LIEU_2 = l['lieux'][1]