server/python/django/renkanmanager/utils.py
changeset 324 a4a575e755aa
parent 323 d5e2007c01d8
child 333 935cffdf3904
equal deleted inserted replaced
323:d5e2007c01d8 324:a4a575e755aa
     8 from django.core.exceptions import ValidationError
     8 from django.core.exceptions import ValidationError
     9 from django.http.response import Http404
     9 from django.http.response import Http404
    10 from django.shortcuts import get_object_or_404
    10 from django.shortcuts import get_object_or_404
    11 from django.utils.encoding import smart_str
    11 from django.utils.encoding import smart_str
    12 from renkanmanager.models import Renkan
    12 from renkanmanager.models import Renkan
       
    13 import math
    13 import md5
    14 import md5
    14 import re
    15 import re
    15 import uuid
    16 import uuid
    16 
    17 
    17 import logging
    18 import logging
    58             if isinstance(cat_nb_nodes_initial[c], tuple):
    59             if isinstance(cat_nb_nodes_initial[c], tuple):
    59                 order, nb = nb
    60                 order, nb = nb
    60             offset = float(self.max_length - nb) / 2
    61             offset = float(self.max_length - nb) / 2
    61             for i in xrange(nb):
    62             for i in xrange(nb):
    62                 self.cat_nb_nodes[c].append({ "x": order*500, "y": 100*(i+offset) })
    63                 self.cat_nb_nodes[c].append({ "x": order*500, "y": 100*(i+offset) })
    63         #logger.debug(self.cat_nb_nodes)
       
    64 
    64 
    65 
    65 
    66 
    66 
    67 class CircleNodePlacer(NodePlacer):
    67 class CircleNodePlacer(NodePlacer):
    68     #TODO: Does not work. Meant to be a real circle placer
    68     
    69     def init(self, cat_nb_nodes_initial):
    69     def init(self, cat_nb_nodes_initial):
    70         for c in cat_nb_nodes_initial:
       
    71             self.max_length = cat_nb_nodes_initial[c] if cat_nb_nodes_initial[c] > self.max_length else self.max_length
       
    72         for i_cat,c in enumerate(cat_nb_nodes_initial):
    70         for i_cat,c in enumerate(cat_nb_nodes_initial):
    73             self.cat_nb_nodes[c] = []
    71             self.cat_nb_nodes[c] = []
    74             offset = float(self.max_length - cat_nb_nodes_initial[c]) / 2
    72             order = i_cat
    75             for i in xrange(cat_nb_nodes_initial[c]):
    73             nb = cat_nb_nodes_initial[c]
    76                 self.cat_nb_nodes[c].append({ "x": i_cat*400, "y": 200*(i+offset) })
    74             if isinstance(cat_nb_nodes_initial[c], tuple):
    77         #logger.debug(self.cat_nb_nodes)
    75                 order, nb = nb
       
    76             order -= 1
       
    77             for i in xrange(nb):
       
    78                 radius = (order*500) if order>0 else 100
       
    79                 angle = 2 * math.pi * i / nb
       
    80                 self.cat_nb_nodes[c].append({ "x": radius*math.cos(angle), "y": radius*math.sin(angle) })
    78 
    81 
    79 
    82 
    80 
    83 
    81 def renkan_copier(user, old_rk_id):
    84 def renkan_copier(user, old_rk_id):
    82     old_rk = get_object_or_404(Renkan, rk_id=old_rk_id)
    85     old_rk = get_object_or_404(Renkan, rk_id=old_rk_id)