def test_break_relation_post_deletes_relation(self):
        '''
        Tests that the relation is deleted from the post view
        '''
        relation = Relation(from_person_id=self.vultan.id, to_person_id=self.lura.id,relation_type=PARTNERED)
        relation.save()

        self.client.login(email='*****@*****.**', password='******')
        response = self.client.post('/break_relation_post={0}/'.format(self.vultan.id),{'relation_id': relation.id})
        self.assertEqual(302, response.status_code)
        self.assertEqual(0, Relation.objects.filter(from_person_id=self.vultan.id, to_person_id=self.lura.id).count())
Exemple #2
0
def create_relation(user, from_person, to_person, relation_type):

    if user.family_id != from_person.family_id or user.family_id != to_person.family_id:
        return None

    relation = Relation(from_person_id=from_person.id, to_person_id=to_person.id, relation_type=relation_type)
    relation.save()

    reevaluate_hierarchy_scores_of_orphans(user.family_id)

    return relation
    def test_break_relation_view_loads(self):
        '''
        Tests that the  break_relation_view loads and uses the correct template
        '''
        relation = Relation(from_person_id=self.vultan.id, to_person_id=self.lura.id,relation_type=PARTNERED)
        relation.save()

        self.client.login(email='*****@*****.**', password='******')
        response = self.client.get('/break_relation={0}/'.format(self.vultan.id))
        self.assertEqual(200, response.status_code)
        self.assertTemplateUsed(response, 'family_tree/break_relation.html')
        self.assertEquals(True, b'Lura' in response.content)
    def test_break_relation_view_loads(self):
        '''
        Tests that the  break_relation_view loads and uses the correct template
        '''
        relation = Relation(from_person_id=self.vultan.id, to_person_id=self.lura.id,relation_type=PARTNERED)
        relation.save()

        self.client.login(email='*****@*****.**', password='******')
        response = self.client.get('/break_relation={0}/'.format(self.vultan.id))
        self.assertEqual(200, response.status_code)
        self.assertTemplateUsed(response, 'family_tree/break_relation.html')
        self.assertEquals(True, b'Lura' in response.content)
Exemple #5
0
def add_relation_post(request, person_id = 0, person = None):
    '''
    Receives post information for a new relation
    '''
    relation_type = int(request.POST.get("relation_type"))
    if relation_type not in ( PARTNERED, RAISED, RAISED_BY):
        raise Http404

    #If person does not exist, create a new person
    existing_person = int(request.POST.get("existing_person"))
    if not existing_person:

        new_name = request.POST.get("name").strip()
        if len(new_name) == 0:
            raise Http404

        language =  request.POST.get("language")
        #http://stackoverflow.com/a/2917399/1245362
        if language not in [x[0] for x in settings.LANGUAGES]:
            raise Http404

        gender = request.POST.get("gender")
        if gender not in (MALE, FEMALE, OTHER):
            raise Http404

        new_person = Person(name=new_name, gender=gender,language=language,family_id=person.family_id)
        if relation_type == PARTNERED:
            new_person.hierarchy_score = person.hierarchy_score
        elif relation_type == RAISED:
            new_person.hierarchy_score = person.hierarchy_score + 1
        elif relation_type == RAISED_BY:
            new_person.hierarchy_score = person.hierarchy_score - 1
        new_person.save()

        relation_id = new_person.id

    else: #Existing person
        relation_id = int(request.POST.get("relation_id"))

    new_relation = Relation(from_person_id=person.id, to_person_id=relation_id, relation_type=relation_type)
    new_relation.save()

    return HttpResponseRedirect('/person={0}/'.format(person_id))
def _get_unrelated_parents_of_child(person_id, child_id, relations_by_person):
    '''
    Gets all the unrelated parents of child
    '''
    suggestions = []

    for second_relation in relations_by_person[child_id]:

        if  second_relation.relation_type == RAISED_BY and \
            not _is_related(person_id, second_relation.to_person_id, relations_by_person) and \
            second_relation.to_person_id != person_id:

            relation = Relation(from_person_id=person_id,
                                to_person_id=second_relation.to_person_id,
                                relation_type=PARTNERED)

            suggestions.append(relation)

    return suggestions
def _get_unrelated_childred_of_partner(person_id, partner_id,
                                       relations_by_person):
    '''
    Gets all the unrelated children of partner
    '''
    suggestions = []

    for second_relation in relations_by_person[partner_id]:

        if  second_relation.relation_type == RAISED and \
            not _is_related(person_id, second_relation.to_person_id, relations_by_person) and \
            second_relation.to_person_id != person_id:

            relation = Relation(from_person_id=person_id,
                                to_person_id=second_relation.to_person_id,
                                relation_type=RAISED)

            suggestions.append(relation)

    return suggestions
    def test_break_relation_post_deletes_relation(self):
        '''
        Tests that the relation is deleted from the post view and check that hierarchy scores set to -1 for
        people with no relations
        '''
        relation = Relation(from_person_id=self.vultan.id, to_person_id=self.lura.id,relation_type=PARTNERED)
        relation.save()

        father_son_relation = Relation(from_person_id=self.vultan.id, to_person_id=self.vultan_junior.id,relation_type=RAISED)
        father_son_relation.save()

        self.client.login(email='*****@*****.**', password='******')
        response = self.client.post('/break_relation_post={0}/'.format(self.vultan.id),{'relation_id': relation.id})
        self.assertEqual(302, response.status_code)
        self.assertEqual(0, Relation.objects.filter(from_person_id=self.vultan.id, to_person_id=self.lura.id).count())

        # Reload lura
        self.lura = Person.objects.get(id=self.lura.id)
        self.assertEqual(ORPHANED_HIERARCHY_SCORE, self.lura.hierarchy_score)

        # Reload vultan
        self.vultan = Person.objects.get(id=self.vultan.id)
        self.assertEqual(200, self.vultan.hierarchy_score)
Exemple #9
0
def add_relation_post(request, person_id=0, person=None):
    '''
    Receives post information for a new relation
    '''
    relation_type = int(request.POST.get("relation_type"))
    if relation_type not in (PARTNERED, RAISED, RAISED_BY):
        raise Http404

    #If person does not exist, create a new person
    existing_person = int(request.POST.get("existing_person"))
    if not existing_person:

        new_name = request.POST.get("name").strip()
        if len(new_name) == 0:
            raise Http404

        language = request.POST.get("language")
        #http://stackoverflow.com/a/2917399/1245362
        if language not in [x[0] for x in settings.LANGUAGES]:
            raise Http404

        gender = request.POST.get("gender")
        if gender not in (MALE, FEMALE, OTHER):
            raise Http404

        birth_year, birth_year_valid = intTryParse(
            request.POST.get("birth_year"))
        if not birth_year_valid:
            birth_year = 0

        new_person = Person(name=new_name,
                            gender=gender,
                            language=language,
                            family_id=person.family_id,
                            birth_year=birth_year)

        address = request.POST.get("address")
        if address:
            new_person.address = address

        if relation_type == PARTNERED:
            new_person.hierarchy_score = person.hierarchy_score
        elif relation_type == RAISED:
            new_person.hierarchy_score = person.hierarchy_score + 1
        elif relation_type == RAISED_BY:
            new_person.hierarchy_score = person.hierarchy_score - 1
        new_person.save()

        relation_id = new_person.id

    else:  #Existing person
        relation_id = int(request.POST.get("relation_id"))

    new_relation = Relation(from_person_id=person.id,
                            to_person_id=relation_id,
                            relation_type=relation_type)
    new_relation.save()

    reevaluate_hierarchy_scores_of_orphans(request.user.family_id)

    return HttpResponseRedirect('/tree/{0}/'.format(person_id))