def __init__(self): self.user_management = UserManagement() self.tag_management = TagManagement()
def __init__(self): self.user_management = UserManagement()
class WishManagement: """ Takes care of wish management (adding, removing, updating ...) """ def __init__(self): self.user_management = UserManagement() self.tag_management = TagManagement() 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 def deleteWish(self, wish): """ Delete a wish from the database @param wish: the wish to remove """ wish.delete() def getWish(self, person, tags): """ Return the wish (or None, if the wish doesnt exist) with the given person and tags @param person: the persons username @param tags: a list with tag names """ if person.__class__ == str: person = self.user_management.getPerson(person) wishes = Wish.objects.filter(person=person) for w in wishes: wishtags = [t.name for t in w.tags.all()] if set (wishtags) == set (tags): return w #If no wish found return None def getAPersonWishes(self, person): """ Get all the wishes for a given person @param person: the person @return: list of wishes """ if person.__class__ == str: person = self.user_management.getPerson(person) return Wish.objects.filter(person=person) def getAllWishesWithTag(self, tag): """ Get all wishes with a given tag @param tag: the tag @return: a list of wishes """ if tag.__class__ == str: tag = self.tag_management.getTag(tag) if tag is None: return [] return [wish for wish in Wish.objects.all() for t in wish.tags.all() if t == tag] def flush(self): """ Removes all entries in the wish table """ Wish.objects.all().delete() print "Wish table flushed"
def __init__(self): self.user_management = UserManagement()
class GroupManagement: """ Takes care of group management """ def __init__(self): self.user_management = UserManagement() def addGroup(self, wishes=[], persons=[]): # [-] remove mutable values """ Create a new group @param tags: the group tags @param persons: the persons belonging to this group """ group = Group() group.save() for wish in wishes: group.wishes.add(wish) for person in persons: if person is not None: group.persons.add(person) return group def getPersons(self, group): """ Get the persons on a group @param group: the group @return: the persons """ return group.persons def getTags(self, group): """ Get the tags on a group @param group: the group @return: the tags """ return group.tags def getGroups(self, person): """ Get all groups that a person is part of @param person: the person @return: a set of groups """ #if person is a string, get the person object person = self.user_management.getPerson(person) print person groups = [] return [ group for group in Group.objects.all() if person in group.persons.all() ] def flushGroups(self): """ Delete all group objects """ Group.objects.all().delete() print "Group table flushed"
class GroupManagement: """ Takes care of group management """ def __init__(self): self.user_management = UserManagement() def addGroup(self, wishes=[], persons=[]): # [-] remove mutable values """ Create a new group @param tags: the group tags @param persons: the persons belonging to this group """ group = Group() group.save() for wish in wishes: group.wishes.add(wish) for person in persons: if person is not None: group.persons.add(person) return group def getPersons(self, group): """ Get the persons on a group @param group: the group @return: the persons """ return group.persons def getTags(self, group): """ Get the tags on a group @param group: the group @return: the tags """ return group.tags def getGroups(self, person): """ Get all groups that a person is part of @param person: the person @return: a set of groups """ #if person is a string, get the person object person = self.user_management.getPerson(person) print person groups = [] return [group for group in Group.objects.all() if person in group.persons.all()] def flushGroups(self): """ Delete all group objects """ Group.objects.all().delete() print "Group table flushed"
class WishManagement: """ Takes care of wish management (adding, removing, updating ...) """ def __init__(self): self.user_management = UserManagement() self.tag_management = TagManagement() 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 def deleteWish(self, wish): """ Delete a wish """ wish.delete() def getWish(self, student, tags): """ get a wish (and your dream will come true) @param student: the students username @param tags: a list with tag names """ if student.__class__ == str: student = self.user_management.getStudent(student) wishes = Wish.objects.filter(student=student) for w in wishes: wishtags = [t.name_of_tag for t in w.tags.all()] if set (wishtags) == set (tags): return w #If no wish found return None def getAStudentWishes(self, student): """ Get all the wishes for a given student @param student: the student @return: list of wishes """ if student.__class__ == str: student = self.user_management.getStudent(student) return Wish.objects.filter(student=student) def getAllWishesWithTag(self, tag): """ Get all wishes with a given tag @param tag: the tag @return: a list of wishes """ if tag.__class__ == str: tag = self.tag_management.getTag(tag) if tag == None: return [] return [wish for wish in Wish.objects.all() for t in wish.tags.all() if t == tag] def flush(self): """ Removes all entries in the wish table """ Wish.objects.all().delete() print "Wish table flushed"
class GroupManagement: """ Takes care of group management """ def __init__(self): self.user_management = UserManagement() def addGroup(self, tags=[], students=[], oracle=None): """ Create a new group @param tags: the group tags @param students: the students belonging to this group @param oracle: the oracle tutoring this group """ group = Group() group.save() for tag in tags: group.tags.add(tag) for student in students: if not student == None: group.students.add(student) if not oracle == None: group.oracle = oracle return group def setOracle(self, oracle, group): """ Assign an oracle to this group @param oracle: the oracle @param group: the group """ try: group.oracle = oracle except: pass def getOracle(self, group): """ Get a groups oracle @param group: the group @return: the oracle """ return group.oracle def getStudents(self, group): """ Get the students on a group @param group: the group @return: the students """ return group.students def getTags(self, group): """ Get the tags on a group @param group: the group @return: the tags """ return group.tags def getGroups(self, student): """ Get all groups that a student is part of @param student: the student @return: a set of groups """ # if student is a string, get the student object student = self.user_management.getStudent(student) print student groups = [] return [group for group in Group.objects.all() if student in group.students.all()] def flushGroups(self): """ Delete all group objects """ Group.objects.all().delete()
def __init__(self): self.user_management = UserManagement() self.tag_management = TagManagement()
class WishManagement: """ Takes care of wish management (adding, removing, updating ...) """ def __init__(self): self.user_management = UserManagement() self.tag_management = TagManagement() 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 def deleteWish(self, wish): """ Delete a wish from the database @param wish: the wish to remove """ wish.delete() def getWish(self, person, tags): """ Return the wish (or None, if the wish doesnt exist) with the given person and tags @param person: the persons username @param tags: a list with tag names """ if person.__class__ == str: person = self.user_management.getPerson(person) wishes = Wish.objects.filter(person=person) for w in wishes: wishtags = [t.name for t in w.tags.all()] if set(wishtags) == set(tags): return w #If no wish found return None def getAPersonWishes(self, person): """ Get all the wishes for a given person @param person: the person @return: list of wishes """ if person.__class__ == str: person = self.user_management.getPerson(person) return Wish.objects.filter(person=person) def getAllWishesWithTag(self, tag): """ Get all wishes with a given tag @param tag: the tag @return: a list of wishes """ if tag.__class__ == str: tag = self.tag_management.getTag(tag) if tag is None: return [] return [ wish for wish in Wish.objects.all() for t in wish.tags.all() if t == tag ] def flush(self): """ Removes all entries in the wish table """ Wish.objects.all().delete() print "Wish table flushed"