def workflow_manager(workflow): form = AddScriptForm(request.form) form.scripts.choices = Script.choices() workflow = get_obj(Workflow, name=workflow) return render_template('workflow_manager.html', form=form, workflow=workflow)
def view(view_type): view_options_form = ViewOptionsForm(request.form) google_earth_form = GoogleEarthForm(request.form) scheduling_form = SchedulingForm(request.form) scheduling_form.scripts.choices = Script.choices() scheduling_form.workflows.choices = Workflow.choices() labels = {'node': 'name', 'link': 'name'} if 'script' in request.form: data = dict(request.form) selection = map(int, session['selection']) scripts = request.form.getlist('scripts') workflows = request.form.getlist('workflows') data['scripts'] = [get_obj(Script, name=name) for name in scripts] data['workflows'] = [ get_obj(Workflow, name=name) for name in workflows ] data['nodes'] = [get_obj(Node, id=id) for id in selection] data['user'] = current_user task = Task(**data) db.session.add(task) db.session.commit() return redirect(url_for('tasks_blueprint.task_management')) elif 'view_options' in request.form: # update labels labels = { 'node': request.form['node_label'], 'link': request.form['link_label'] } # for the sake of better performances, the view defaults to markercluster # if there are more than 2000 nodes view = 'leaflet' if len(Node.query.all()) < 2000 else 'markercluster' if 'view' in request.form: view = request.form['view'] # we clean the session's selected nodes session['selection'] = [] return render_template( '{}_view.html'.format(view_type), filters=Filter.query.all(), view=view, scheduling_form=scheduling_form, view_options_form=view_options_form, google_earth_form=google_earth_form, labels=labels, names=pretty_names, subtypes=node_subtypes, node_table={ obj: OrderedDict([(property, getattr(obj, property)) for property in type_to_public_properties[obj.type]]) for obj in Node.query.all() }, link_table={ obj: OrderedDict([(property, getattr(obj, property)) for property in type_to_public_properties[obj.type]]) for obj in Link.query.all() })
def task_management(): scheduling_form = SchedulingForm(request.form) scheduling_form.scripts.choices = Script.choices() scheduling_form.workflows.choices = Workflow.choices() tasks = Task.query.all() return render_template('task_management.html', tasks=tasks, compare_form=CompareForm(request.form), scheduling_form=scheduling_form)
def view(view_type): add_node_form = AddNode(request.form) add_link_form = AddLink(request.form) all_nodes = Node.choices() add_link_form.source.choices = add_link_form.destination.choices = all_nodes view_options_form = ViewOptionsForm(request.form) google_earth_form = GoogleEarthForm(request.form) scheduling_form = SchedulingForm(request.form) scheduling_form.scripts.choices = Script.choices() scheduling_form.workflows.choices = Workflow.choices() labels = {'node': 'name', 'link': 'name'} if 'view_options' in request.form: # update labels labels = { 'node': request.form['node_label'], 'link': request.form['link_label'] } # for the sake of better performances, the view defaults to markercluster # if there are more than 2000 nodes view = 'leaflet' if len(Node.query.all()) < 2000 else 'markercluster' if 'view' in request.form: view = request.form['view'] # we clean the session's selected nodes session['selection'] = [] # name to id name_to_id = {node.name: id for id, node in enumerate(Node.query.all())} return render_template( '{}_view.html'.format(view_type), filters=Filter.query.all(), view=view, scheduling_form=scheduling_form, view_options_form=view_options_form, google_earth_form=google_earth_form, add_node_form=add_node_form, add_link_form=add_link_form, labels=labels, names=pretty_names, subtypes=node_subtypes, name_to_id=name_to_id, node_table={ obj: OrderedDict([ (property, getattr(obj, property)) for property in type_to_public_properties[obj.type] ]) for obj in Node.query.all() }, link_table={ obj: OrderedDict([ (property, getattr(obj, property)) for property in type_to_public_properties[obj.type] ]) for obj in Link.query.all() })
def calendar(): scheduling_form = SchedulingForm(request.form) scheduling_form.scripts.choices = Script.choices() scheduling_form.workflows.choices = Workflow.choices() tasks = {} for task in Task.query.all(): # javascript dates range from 0 to 11, we must account for that by # substracting 1 to the month for the date to be properly displayed in # the calendar python_month = search(r'.*-(\d{2})-.*', task.start_date).group(1) month = '{:02}'.format((int(python_month) - 1) % 12) tasks[task] = sub(r"(\d+)-(\d+)-(\d+) (\d+):(\d+).*", r"\1, " + month + r", \3, \4, \5", task.start_date) return render_template('calendar.html', tasks=tasks, scheduling_form=scheduling_form)
def view(view_type): add_node_form = AddNode(request.form) add_link_form = AddLink(request.form) view_options_form = ViewOptionsForm(request.form) google_earth_form = GoogleEarthForm(request.form) scheduling_form = SchedulingForm(request.form) scheduling_form.scripts.choices = Script.choices() scheduling_form.workflows.choices = Workflow.choices() labels = {'node': 'name', 'link': 'name'} if 'script' in request.form: data = dict(request.form) selection = map(int, session['selection']) scripts = request.form.getlist('scripts') workflows = request.form.getlist('workflows') data['scripts'] = [get_obj(Script, name=name) for name in scripts] data['workflows'] = [ get_obj(Workflow, name=name) for name in workflows ] data['nodes'] = [get_obj(Node, id=id) for id in selection] data['user'] = current_user task = Task(**data) db.session.add(task) db.session.commit() return redirect(url_for('tasks_blueprint.task_management')) elif 'view_options' in request.form: # update labels labels = { 'node': request.form['node_label'], 'link': request.form['link_label'] } elif 'google earth' in request.form: kml_file = Kml() for node in Node.query.all(): point = kml_file.newpoint(name=node.name) point.coords = [(node.longitude, node.latitude)] point.style = styles[node.subtype] point.style.labelstyle.scale = request.form['label_size'] for link in Link.query.all(): line = kml_file.newlinestring(name=link.name) line.coords = [(link.source.longitude, link.source.latitude), (link.destination.longitude, link.destination.latitude)] line.style = styles[link.type] line.style.linestyle.width = request.form['line_width'] filepath = join(current_app.ge_path, request.form['name'] + '.kmz') kml_file.save(filepath) # for the sake of better performances, the view defaults to markercluster # if there are more than 2000 nodes view = 'leaflet' if len(Node.query.all()) < 2000 else 'markercluster' if 'view' in request.form: view = request.form['view'] # we clean the session's selected nodes session['selection'] = [] # name to id name_to_id = {node.name: id for id, node in enumerate(Node.query.all())} return render_template( '{}_view.html'.format(view_type), filters=Filter.query.all(), view=view, scheduling_form=scheduling_form, view_options_form=view_options_form, google_earth_form=google_earth_form, add_node_form=add_node_form, add_link_form=add_link_form, labels=labels, names=pretty_names, subtypes=node_subtypes, name_to_id=name_to_id, node_table={ obj: OrderedDict([(property, getattr(obj, property)) for property in type_to_public_properties[obj.type]]) for obj in Node.query.all() }, link_table={ obj: OrderedDict([(property, getattr(obj, property)) for property in type_to_public_properties[obj.type]]) for obj in Link.query.all() })