Example #1
0
 def get_graph_data(self, options, results=()):
     graph = NavigationGraph(self.controller, results)
     graph.set_options(options)
     graph.create_edges()
     html, json = graph.render()
     root = lxml.html.fragment_fromstring("<div>%s</div>" % html)
     self.assertNodeIsMain(root)
     self.root = root
     self.json = json
     self.nodes = root.find_class("node")
     self.edges = root.find_class("edge")
Example #2
0
 def get_graph_data(self, options, results=()):
     graph = NavigationGraph(self.controller, results)
     graph.set_options(options)
     graph.create_edges()
     html, json = graph.render()
     root = lxml.html.fragment_fromstring("<div>%s</div>" % html)
     self.assertNodeIsMain(root)
     self.root = root
     self.json = json
     self.nodes = root.find_class("node")
     self.edges = root.find_class("edge")
Example #3
0
def get_navigate_data(request, obj_type, obj_ref, obj_revi):
    obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi)
    FilterForm = get_navigate_form(obj)

    has_session = any(field in request.session for field in FilterForm.base_fields)
    initial = dict((k, v.initial) for k, v in FilterForm.base_fields.items())
    if request.method == 'POST' and request.POST:
        form = FilterForm(request.POST)
        if form.is_valid():
            request.session.update(form.cleaned_data)
    elif has_session:
        request.session.update(dict(doc_parts = ""))
        initial.update(request.session)
        form = FilterForm(initial)
    else:
        form = FilterForm(initial)
        request.session.update(initial)
    if not form.is_valid():
        raise ValueError("Invalid form")
    graph = NavigationGraph(obj, [r.object for r in ctx.get("results", [])])
    options = form.cleaned_data
    if options["update"]:
        options["doc_parts"] = [int(o)
                                for o in options["doc_parts"].split("#")
                                if o.isnumeric()]
    else:
        options["doc_parts"] = []
        request.session.update(dict(doc_parts = ""))
    graph.set_options(options)
    graph.create_edges()
    map_string, url, path = graph.render()
    top, left, w, h = map(int, re.search(coords_rx, map_string).groups())
    x_part_node_position = (2 * left + w) // 2
    y_part_node_position = (2 * top + h) // 2
    x_img_position_corrected = 1172 // 2 - x_part_node_position
    y_img_position_corrected = 500 // 2 - y_part_node_position
    img = Image.open(path)
    width, height = img.size
    ctx.update({
        'filter_object_form': form,
        'map_areas': map_string,
        'picture_path': "/"+url,
        'x_img_position': x_img_position_corrected,
        'y_img_position': y_img_position_corrected,
        'img_width' : width,
        'img_height' : height,
        'center_x' : left + w // 2,
        'center_y' : top + h //2,
        'navigate_bool': True,
    })
    return ctx
Example #4
0
def get_navigate_data(request, obj_type, obj_ref, obj_revi):
    obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi)
    FilterForm = get_navigate_form(obj)

    has_session = any(field in request.session
                      for field in FilterForm.base_fields)
    initial = dict((k, v.initial) for k, v in FilterForm.base_fields.items())
    if request.method == 'POST' and request.POST:
        form = FilterForm(request.POST)
        if form.is_valid():
            request.session.update(form.cleaned_data)
    elif has_session:
        request.session.update(dict(doc_parts=""))
        initial.update(request.session)
        form = FilterForm(initial)
    else:
        form = FilterForm(initial)
        request.session.update(initial)
    if not form.is_valid():
        options = initial
    else:
        options = form.cleaned_data
    if options[OSR]:
        results = [r.object for r in ctx.get("results", [])]
    else:
        results = []
    graph = NavigationGraph(obj, results)
    if options["update"]:
        options["doc_parts"] = [
            int(o) for o in options["doc_parts"].split("#") if o.isnumeric()
        ]
    else:
        options["doc_parts"] = []
        request.session.update(dict(doc_parts=""))
    graph.set_options(options)
    graph.create_edges()
    map_string, edges = graph.render()
    width, height = edges["width"], edges["height"]
    past = graph.time and timezone.now() - graph.time > datetime.timedelta(
        minutes=5)
    ctx.update({
        'filter_object_form': form,
        'map_areas': map_string,
        'img_width': width,
        'img_height': height,
        'navigate_bool': True,
        'edges': edges,
        'past': past,
    })
    return ctx
Example #5
0
def get_navigate_data(request, obj_type, obj_ref, obj_revi):
    obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi)
    FilterForm = get_navigate_form(obj)

    has_session = any(field in request.session for field in FilterForm.base_fields)
    initial = dict((k, v.initial) for k, v in FilterForm.base_fields.items())
    if request.method == 'POST' and request.POST:
        form = FilterForm(request.POST)
        if form.is_valid():
            request.session.update(form.cleaned_data)
    elif has_session:
        request.session.update(dict(doc_parts = ""))
        initial.update(request.session)
        form = FilterForm(initial)
    else:
        form = FilterForm(initial)
        request.session.update(initial)
    if not form.is_valid():
        options = initial
    else:
        options = form.cleaned_data
    if options[OSR]:
        results = [r.object for r in ctx.get("results", [])]
    else:
        results = []
    graph = NavigationGraph(obj, results)
    if options["update"]:
        options["doc_parts"] = [int(o)
                                for o in options["doc_parts"].split("#")
                                if o.isnumeric()]
    else:
        options["doc_parts"] = []
        request.session.update(dict(doc_parts = ""))
    graph.set_options(options)
    graph.create_edges()
    map_string, edges = graph.render()
    width, height = edges["width"], edges["height"]
    past = graph.time and timezone.now() - graph.time > datetime.timedelta(minutes=5)
    ctx.update({
        'filter_object_form': form,
        'map_areas': map_string,
        'img_width' : width,
        'img_height' : height,
        'navigate_bool': True,
        'edges' : edges,
        'past' : past,
    })
    return ctx