Ejemplo n.º 1
0
    def addWish(self, person, tags, courses=None):
        """
            Add a user
            @param person: the person's thats register a wish
            @param tags: wish tags
            @return: the created wish
        """

        if not tags:
            return

        if person.__class__ == str:
            person = person.strip()
            person = self.user_management.getPerson(person)

        w = self.getWish(person, tags)

        if w is not None:
            print "Wish for: %s exist" % person
            return w

        w = Wish()
        w.person = person
        w.save()

        for t in tags:
            try:
                t = self.tag_management.addTag(t)
                w.tags.add(t)
            except Tag.DoesNotExist:
                print "Tag %s does not exist" % t

        print "Wish( person={0},\n\ttags=[{1}]\n)".format(
            person, ", ".join(tags))

        return w
Ejemplo n.º 2
0
        tag_quantity = (1, 2)

    UserManager.addPerson("ilyakh").set_password("123")
    UserManager.addPerson("kritisk").set_password("123")
    UserManager.addPerson("michael").set_password("123")
    UserManager.addPerson("peder").set_password("123")
    UserManager.addPerson("rantonse").set_password("123")
    UserManager.addPerson("rantonse1").set_password("123")
    UserManager.addPerson("rantonse2").set_password("123")
    UserManager.addPerson("rantonse3").set_password("123")

    persons = (StudentGenerator(5)).generate(number_of_persons)
    tags = (TagGenerator()).generate(number_of_tags)

    print "Creating wishes for {0} persons, with a set of {1} tags".format(
        len(persons), len(tags))

    for p in persons:
        UserManager.addPerson(p)

    for p in Person.objects.all():

        w = Wish(person=p)
        w.save()

        tq = tag_quantity
        chosen_tags = sample(tags, randint(tq[0], tq[1]))

        for t in chosen_tags:
            w.tags.add(TagManager.addTag(t))