ore.models.configuration.Configuration.to_dict()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nop 1
1
from django.db import models
2
import json
3
4
from .graph import Graph
5
6
7
class Configuration(models.Model):
8
9
    """
10
    Class: Project
11
12
    Fields:
13
     {Graph} graph       -
14
     {int}   costs       -
15
    """
16
17
    class Meta:
18
        app_label = 'ore'
19
20
    graph = models.ForeignKey(Graph, related_name='configurations')
21
    costs = models.IntegerField()
22
23
    def to_dict(self):
24
        '''
25
          Returns the specific node configurations in this graph configuration
26
          as JSON dictionary data structure. The keys are node client ID's, so that the
27
          JS code can identify them.
28
        '''
29
        result = {}
30
        for node_conf in self.node_configurations.all():
31
            result[node_conf.node.client_id] = json.loads(node_conf.setting)
32
        return result
33