Blame view

semantics/management/commands/update_roles.py 931 Bytes
Tomasz Bartosiak authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#! /usr/bin/python
# -*- coding: utf-8 -*-

from django.core.management.base import BaseCommand
from settings import PROJECT_PATH

from semantics.models import SemanticRole, Complement, SemanticRolesDisplay

#==========================================================#

class Command(BaseCommand):
    args = 'none'
    help = ''

    def handle(self, **options):
        update_roles()

def update_roles():

    cause_complements = Complement.objects.filter(roles__role="Cause")

    cause = SemanticRole.objects.get(role="Cause")
    condition = SemanticRole.objects.get(role="Condition")
    condition.color = cause.color
    condition.save()

    for complement in cause_complements:
        complement.roles.remove(cause)
        complement.roles.add(condition)

    display = SemanticRolesDisplay.objects.get(roles__role="Cause")
    display.roles.remove(cause)

    cause.delete()