server/python/django2/renkanmanager/models.py
changeset 626 112912309726
parent 621 192ce5938726
child 662 df0060476f35
equal deleted inserted replaced
625:4d67ae41b9b3 626:112912309726
    13 
    13 
    14 
    14 
    15 
    15 
    16 logger = logging.getLogger(__name__)
    16 logger = logging.getLogger(__name__)
    17 auth_user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
    17 auth_user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
       
    18 
       
    19 # Copy the content of a révision.
       
    20 # This will return a map (not a serialized) to allow further treatment
       
    21 # This changes the ids of the project, nodes, views and edges but NOT users
       
    22 #
       
    23 def content_copy(content_str): #TODO: ??? Extract this in another class, like a RevisionManager ???
       
    24     node_ids_map = {}
       
    25     content = json.loads(content_str)
       
    26 
       
    27     content['id'] = str(uuid.uuid4())
       
    28 
       
    29     #nodes
       
    30     for node in content.get('nodes', []):
       
    31         id_key = 'id' if 'id' in node else '_id'
       
    32         node_ids_map[node[id_key]] = node['id'] = str(uuid.uuid4())
       
    33         node.pop('_id', None)
       
    34 
       
    35     for edge in content.get('edges', []):
       
    36         edge['id'] = str(uuid.uuid4())
       
    37         edge.pop('_id', None)
       
    38         edge['from'] = node_ids_map[edge['from']]
       
    39         edge['to'] = node_ids_map[edge['to']]
       
    40 
       
    41     for view in content.get('views', []):
       
    42         view['id'] = str(uuid.uuid4())
       
    43         view.pop('_id', None)
       
    44         view['hidden_nodes'] = [ node_ids_map[n] for n in view.get('hidden_nodes', [])]
       
    45 
       
    46     for user in content.get('users', []):
       
    47         if '_id' in user:
       
    48             user['id'] = user.pop('_id')
       
    49 
       
    50     return content
    18 
    51 
    19 class Workspace(models.Model):
    52 class Workspace(models.Model):
    20 
    53 
    21     workspace_guid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True, blank=False, null=False)
    54     workspace_guid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True, blank=False, null=False)
    22     title = models.CharField(max_length=1024, null=True)
    55     title = models.CharField(max_length=1024, null=True)
    58         initial_revision.creation_date = creation_date
    91         initial_revision.creation_date = creation_date
    59         initial_revision.modification_date = creation_date
    92         initial_revision.modification_date = creation_date
    60         initial_revision.creator = creator
    93         initial_revision.creator = creator
    61         initial_revision.last_updated_by = creator
    94         initial_revision.last_updated_by = creator
    62         if new_renkan_content:
    95         if new_renkan_content:
    63             new_renkan_content_dict = json.loads(new_renkan.validate_json_content(new_renkan_content))
    96             new_renkan_content_dict = content_copy(new_renkan.validate_json_content(new_renkan_content))
       
    97             new_renkan_content_dict["id"] = str(new_renkan.renkan_guid)
    64             new_renkan_content_dict["created"] = str(creation_date)
    98             new_renkan_content_dict["created"] = str(creation_date)
    65             new_renkan_content_dict["updated"] = str(creation_date)
    99             new_renkan_content_dict["updated"] = str(creation_date)
    66         else:
   100         else:
    67             new_renkan_content_dict = {
   101             new_renkan_content_dict = {
    68                 "id": str(new_renkan.renkan_guid),
   102                 "id": str(new_renkan.renkan_guid),