def addWish(self, student, tags):
        """
            Add a user
            @param student: the student's thats register a wish
            @param tags: wish tags
        """

        if not tags:
            print "Please specify at least one tag"
            return

        if student.__class__ == str:
            student = student.strip()
            student = self.user_management.getStudent(student)

        w = self.getWish(student, tags)

        if w != None:
            print "Wish for: %s exist" % student
            return w

        w = Wish()
        w.student=student
        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 added for user %s" % student

        return w
Beispiel #2
0
def add( request ):
    # fetch tags
    # tags = request.POST["tags"]
    # tags = tags.split(",")

    tags = extract_tags( request.POST["tags"] )

    # create student
    user = User.objects.get( username="******" )
    student = Student( user=user )
    student.save()

    # create wish
    wish = Wish( student=student )
    wish.save()

    # generate tag objects (fires off only if there are elements in tags)
    for t in tags:
        candidate = Tag.objects.get_or_create(keyword=t)[0]
        wish.tags.add(candidate)
        wish.save()

    return redirect( display )