# HG changeset patch # User cavaliet # Date 1409069486 -7200 # Node ID fef4317b915f3eb5b63611caae972d9467a5964c # Parent 25c28dd19898b6647e7eb6ac342849eeb5e4d3aa add CircleNodePlacer and clean utils diff -r 25c28dd19898 -r fef4317b915f src/hdalab/utils.py --- a/src/hdalab/utils.py Tue Aug 26 15:50:55 2014 +0200 +++ b/src/hdalab/utils.py Tue Aug 26 18:11:26 2014 +0200 @@ -5,7 +5,6 @@ @author: ymh and tc ''' from django.core.cache import cache -from django.http.response import Http404 from django.utils.encoding import smart_str import md5 import re @@ -20,59 +19,5 @@ if len(cache_key) > (250-(2+len(cache.key_prefix)+len(str(cache.version)))-33): cache_key = cache_key[:(250-(2+len(cache.key_prefix)+len(str(cache.version)))-33)] + '-' + md5.new(cache_key).hexdigest() return cache_key - - - -class NodePlacer(): - - cat_nb_nodes = {} - - def init(self, cat_nb_nodes_initial): - raise NotImplementedError( "Should have implemented get_place" ) - - def get_place(self, category): - if not category or category not in self.cat_nb_nodes: - raise Http404 - return self.cat_nb_nodes[category].pop(0) - - - -class LineNodePlacer(NodePlacer): - - max_length = 0 - - def init(self, cat_nb_nodes_initial): - for c in cat_nb_nodes_initial: - nb = cat_nb_nodes_initial[c] - if isinstance(cat_nb_nodes_initial[c], tuple): - _, nb = nb - self.max_length = nb if nb > self.max_length else self.max_length - for i_cat,c in enumerate(cat_nb_nodes_initial): - self.cat_nb_nodes[c] = [] - order = i_cat - nb = cat_nb_nodes_initial[c] - if isinstance(cat_nb_nodes_initial[c], tuple): - order, nb = nb - offset = float(self.max_length - nb) / 2 - for i in xrange(nb): - self.cat_nb_nodes[c].append({ "x": order*300, "y": 100*(i+offset) }) - #logger.debug(self.cat_nb_nodes) - - - -class CircleNodePlacer(NodePlacer): - #TODO: Does not work. Meant to be a real circle placer - def init(self, cat_nb_nodes_initial): - for c in cat_nb_nodes_initial: - self.max_length = cat_nb_nodes_initial[c] if cat_nb_nodes_initial[c] > self.max_length else self.max_length - for i_cat,c in enumerate(cat_nb_nodes_initial): - self.cat_nb_nodes[c] = [] - offset = float(self.max_length - cat_nb_nodes_initial[c]) / 2 - for i in xrange(cat_nb_nodes_initial[c]): - self.cat_nb_nodes[c].append({ "x": i_cat*400, "y": 200*(i+offset) }) - #logger.debug(self.cat_nb_nodes) - - - \ No newline at end of file diff -r 25c28dd19898 -r fef4317b915f src/hdalab/views/profile.py --- a/src/hdalab/views/profile.py Tue Aug 26 15:50:55 2014 +0200 +++ b/src/hdalab/views/profile.py Tue Aug 26 18:11:26 2014 +0200 @@ -28,7 +28,8 @@ from hdalab.models.renkan import HdalabRenkan from hdalab.views.ajax import filter_generic from renkanmanager.models import Renkan -from renkanmanager.utils import LineNodePlacer, renkan_copier, renkan_deleter +from renkanmanager.utils import LineNodePlacer, renkan_copier, renkan_deleter,\ + CircleNodePlacer from renkanmanager.views import RenkanGetPut import json import uuid @@ -115,6 +116,8 @@ rk = get_object_or_404(Renkan, rk_id=rk_id) return HttpResponse(rk.content, content_type="application/json") + shape = request.GET.get("shape", "") + # Start dict for renkan json now = datetime.now().strftime("%Y-%m-%d %H:%M") @@ -150,6 +153,8 @@ ordered_tags = TaggedSheet.objects.filter(datasheet=notice).select_related("tag", "tag__dbpedia_fields", "tag__category").order_by('order')[:15] # Prepare Node placer : np = LineNodePlacer() + if shape=="circle": + np = CircleNodePlacer() np.init({"datasheet": (1, 1), "tags": (2, len(ordered_tags))}) # Place notice : content["nodes"].append({ @@ -209,6 +214,8 @@ # Prepare Node placer : np = LineNodePlacer() + if shape=="circle": + np = CircleNodePlacer() np.init({"datasheet": (1, len(notices)), "tags": (2, len(all_tags))}) # Place notices @@ -318,6 +325,8 @@ # Prepare Node placer : np = LineNodePlacer() + if shape=="circle": + np = CircleNodePlacer() np.init({"tags": (1, len(all_tags)), "datasheet": (2, len(filter_output["contents"])), "related": (3, len(related_tags))}) for t in all_tags: