#! /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()
    
    

