Пример #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")
Пример #2
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