示例#1
0
import json
import urllib2
import traceback
from xml.dom import minidom

from flask import render_template, request, flash, url_for, Response
from flask_wtf import Form
from wtforms import TextField
from wtforms.validators import url as url_validator, required

from appcomposer.babel import gettext, lazy_gettext
from appcomposer.utils import make_url_absolute, inject_absolute_urls, get_json, inject_original_url_in_xmldoc, inject_absolute_locales_in_xmldoc
from appcomposer.composers.adapt import create_adaptor

adaptor = create_adaptor('Labs adaptation', 
                initial = {'url' : None, 'configuration' : None}, 
                description = lazy_gettext("Create adaptations of customizable gateway4labs laboratories."),
                about_endpoint = 'gateway4labs.about')

SHINDIG_SERVER = 'http://shindig2.epfl.ch'
def shindig_url(relative_url):
    return '%s%s' % (SHINDIG_SERVER, relative_url)

def replace_default_configuration_script(contents, new_url):
    return DEFAULT_CONFIG_REGEX.sub('<script data-configuration type="text/javascript" src="%s">' % new_url, contents)

class UrlForm(Form):
    # TODO: use the url_validator again
    url            = TextField(lazy_gettext(u'URL'), validators = [ required() ])
    # labmanager_url = TextField(lazy_gettext(u'Labmanager URL'), validators = [ url_validator() ])

@adaptor.edit_route
示例#2
0
import traceback
from xml.dom import minidom

from flask import render_template, request, flash, url_for, Response
from flask_wtf import Form
from wtforms import TextField
from wtforms.validators import url, required

from appcomposer.babel import gettext, lazy_gettext
from appcomposer.composers.adapt.utils import shindig_url
from appcomposer.utils import make_url_absolute, inject_absolute_urls, get_json, inject_original_url_in_xmldoc, inject_absolute_locales_in_xmldoc
from appcomposer.composers.adapt import create_adaptor


adaptor = create_adaptor(lazy_gettext('App adaptation'),
                         initial={'url': None, 'configuration': None, 'configuration_name': None},
                         description=lazy_gettext("Create adaptations of customizable Go-Lab applications."),
                         about_endpoint='jsconfig.about')


CONFIG_DEFINITION_REGEX = re.compile(r"""(<\s*script[^<]*\sdata-configuration-definition(?:>|\s[^>]*>))""")
SRC_REGEX = re.compile(r"""src\s*=\s*["']?([^"']+)["']?""")


def find_definition_script(contents, url):
    data_config_definition_scripts = CONFIG_DEFINITION_REGEX.findall(contents)
    if len(data_config_definition_scripts) > 1:
        flash(gettext(
            "Too many scripts with data-configuration-definition found. This may happen if you have commented one. There can be a single one."))
    elif len(data_config_definition_scripts) < 1:
        flash(gettext(
            "No script with data-configuration-definition found. Is the app adapted for the Go-Lab JavaScript configuration tools?"))
示例#3
0
from xml.dom import minidom

from flask import render_template, request, flash, url_for, Response
from flask_wtf import Form
from wtforms import TextField
from wtforms.validators import url as url_validator, required

from appcomposer.babel import gettext, lazy_gettext
from appcomposer.utils import make_url_absolute, inject_absolute_urls, get_json, inject_original_url_in_xmldoc, inject_absolute_locales_in_xmldoc
from appcomposer.composers.adapt import create_adaptor

adaptor = create_adaptor(
    'Labs adaptation',
    initial={
        'url': None,
        'configuration': None
    },
    description=lazy_gettext(
        "Create adaptations of customizable gateway4labs laboratories."),
    about_endpoint='gateway4labs.about')

SHINDIG_SERVER = 'http://shindig2.epfl.ch'


def shindig_url(relative_url):
    return '%s%s' % (SHINDIG_SERVER, relative_url)


def replace_default_configuration_script(contents, new_url):
    return DEFAULT_CONFIG_REGEX.sub(
        '<script data-configuration type="text/javascript" src="%s">' %
示例#4
0
import json
from flask import render_template, request, flash

from appcomposer.composers.adapt import create_adaptor

adaptor = create_adaptor('Hypothesis', initial = {
    'conditionals' : [
                {'text': 'IF','type': 'conditional'},
                {'text': 'THEN','type': 'conditional'},
                {'text': 'is equal to','type': 'conditional'},
        ],
    'inputs' : [],
    'outputs' : [],
   })


@adaptor.edit_route
def edit(app_id):
    data = adaptor.load_data(app_id)
    name = data["name"]

    if request.method == 'GET':
        conditionals_stored = data["conditionals"]
        inputs_stored = data["inputs"]
        outputs_stored = data["outputs"]

        # Format to load: inputs = [ {'text': 'immersed object','type': 'input'}, {'text': 'pressure','type': 'input'},... ]
        def load_hypothesis_list(list_stored):
            return ', '.join([ item['text'] for item in list_stored])

        conditionals = load_hypothesis_list(conditionals_stored)
示例#5
0
import json
from collections import OrderedDict
from flask import abort, make_response, render_template, request, flash

from appcomposer.composers.adapt import create_adaptor

#This is required by the config web service (check if app_id exists). Can we use the url_for('.edit') method without repeating code?
import appcomposer.appstorage.api as appstorage

adaptor = create_adaptor(
    'Concept Mapper', {
        'debug': 'true',
        'actionlogging': 'consoleShort',
        'show_prompts': 'true',
        'textarea_concepts': 'true',
        'combobox_concepts': 'true',
        'drop_external': 'true',
        'concepts': '',
        'relations': ''
    })


@adaptor.edit_route
def edit(app_id):
    data = adaptor.load_data(app_id)
    concepts = data["concepts"]
    relations = data["relations"]

    if request.method == 'POST':
        # Retrieve the lists of concepts and relations and convert them to the format supported by the app.
        # Request-- concepts: "a,b,c"  -> Concepts  (str): "a,b,c"
示例#6
0
from flask import render_template, request

from appcomposer.composers.adapt import create_adaptor

adaptor = create_adaptor("Simple text", initial={"simple_text": "No text"})


@adaptor.edit_route
def edit(app_id):
    # Load data from the database for this application
    data = adaptor.load_data(app_id)

    # If data does not have 'simple_text', add the default value.
    if "simple_text" not in data:
        data["simple_text"] = "No text"

    if request.method == "POST":
        value = request.form["simple_text"]
        data["simple_text"] = value
        # Store it in the database
        adaptor.save_data(app_id, data)

    return render_template("simpletext/edit.html", value=data["simple_text"], app_id=app_id)


@adaptor.route("/export/<app_id>/app.xml")
def app_xml(app_id):
    data = adaptor.load_data(app_id)
    return render_template("simpletext/app.xml", value=data["simple_text"])

示例#7
0
import json
from flask import render_template, request, flash

from appcomposer.composers.adapt import create_adaptor

adaptor = create_adaptor('Hypothesis',
                         initial={
                             'conditionals': [
                                 {
                                     'text': 'IF',
                                     'type': 'conditional'
                                 },
                                 {
                                     'text': 'THEN',
                                     'type': 'conditional'
                                 },
                                 {
                                     'text': 'is equal to',
                                     'type': 'conditional'
                                 },
                             ],
                             'inputs': [],
                             'outputs': [],
                         })


@adaptor.edit_route
def edit(app_id):
    data = adaptor.load_data(app_id)
    name = data["name"]
示例#8
0
import json
from collections import OrderedDict
from flask import abort, make_response, render_template, request, flash

from appcomposer.composers.adapt import create_adaptor

#This is required by the config web service (check if app_id exists). Can we use the url_for('.edit') method without repeating code?
import appcomposer.appstorage.api as appstorage

adaptor = create_adaptor('Concept Mapper', {
        'debug' : 'true',
        'actionlogging' : 'consoleShort',
        'show_prompts' : 'true',
        'textarea_concepts' : 'true',
        'combobox_concepts' : 'true',
        'drop_external' : 'true',
        'concepts' : '',
        'relations' : ''
   })


@adaptor.edit_route
def edit(app_id):
    data = adaptor.load_data(app_id)
    concepts = data["concepts"]
    relations = data["relations"]    

    if request.method == 'POST':
        # Retrieve the lists of concepts and relations and convert them to the format supported by the app.
        # Request-- concepts: "a,b,c"  -> Concepts  (str): "a,b,c"
        concepts = ', '.join(list(OrderedDict.fromkeys([ s.strip() for s in request.form["concepts"].split(',') ])))
示例#9
0
from flask import render_template, request, flash, url_for, Response
from flask_wtf import Form
from wtforms import TextField
from wtforms.validators import url, required

from appcomposer.babel import gettext, lazy_gettext
from appcomposer.composers.adapt.utils import shindig_url
from appcomposer.utils import make_url_absolute, inject_absolute_urls, get_json, inject_original_url_in_xmldoc, inject_absolute_locales_in_xmldoc
from appcomposer.composers.adapt import create_adaptor

adaptor = create_adaptor(
    lazy_gettext('App adaptation'),
    initial={
        'url': None,
        'configuration': None,
        'configuration_name': None
    },
    description=lazy_gettext(
        "Create adaptations of customizable Go-Lab applications."),
    about_endpoint='jsconfig.about')

CONFIG_DEFINITION_REGEX = re.compile(
    r"""(<\s*script[^<]*\sdata-configuration-definition(?:>|\s[^>]*>))""")
SRC_REGEX = re.compile(r"""src\s*=\s*["']?([^"']+)["']?""")


def find_definition_script(contents, url):
    data_config_definition_scripts = CONFIG_DEFINITION_REGEX.findall(contents)
    if len(data_config_definition_scripts) > 1:
        flash(
            gettext(
示例#10
0
import json
from flask import request, render_template, flash

from appcomposer.composers.adapt import create_adaptor

adaptor = create_adaptor('Experiment Design Tool')

@adaptor.edit_route
def edit(app_id):
    data = adaptor.load_data(app_id)

    if request.method == 'GET':

        if len(data) == 4:
            #If appdata has four items, we are viewing an empty experiment design (Domain 1 of 2).
            return render_template("edt/edit.html", app_id = app_id, n_trows = len(data), emptycontent_trows = [1,2,3])
        
        elif len(data) == 7:
            # Viewing Domain 2 of 2. 1 of 2 is loaded from the DB.
            #Reading the current values and storing them in lists -  these loops will be used with the other variables to build the columns
            objprops_names = []; objprops_types = []; objprops_symbols = []; objprops_units = []; objprops_allvalues = [];
            sysprops_names = []; sysprops_types = []; sysprops_symbols = []; sysprops_units = []; sysprops_allvalues = [];
            objmeasu_names = []; objmeasu_types = []; objmeasu_units = []; objmeasu_values = [];
            for item in data["object_properties"]:
                objprops_names.append(item["name"])
                objprops_types.append(item["type"])
                objprops_allvalues.append(item["values"])
                #WARNING: the "symbol", "unit" items do not exist when multitude is selected & "values"" is not present in magnitude
                if "symbol" in item:
                    objprops_symbols.append(item["symbol"])            
                else: 
示例#11
0
import json
from flask import request, render_template, flash

from appcomposer.composers.adapt import create_adaptor

adaptor = create_adaptor('Experiment Design Tool')


@adaptor.edit_route
def edit(app_id):
    data = adaptor.load_data(app_id)

    if request.method == 'GET':

        if len(data) == 4:
            #If appdata has four items, we are viewing an empty experiment design (Domain 1 of 2).
            return render_template("edt/edit.html",
                                   app_id=app_id,
                                   n_trows=len(data),
                                   emptycontent_trows=[1, 2, 3])

        elif len(data) == 7:
            # Viewing Domain 2 of 2. 1 of 2 is loaded from the DB.
            #Reading the current values and storing them in lists -  these loops will be used with the other variables to build the columns
            objprops_names = []
            objprops_types = []
            objprops_symbols = []
            objprops_units = []
            objprops_allvalues = []
            sysprops_names = []
            sysprops_types = []
示例#12
0
from flask import render_template, request

from appcomposer.composers.adapt import create_adaptor

adaptor = create_adaptor('Simple text', 
                initial = {'simple_text' : 'No text'})

@adaptor.edit_route
def edit(app_id):
    # Load data from the database for this application
    data = adaptor.load_data(app_id)

    # If data does not have 'simple_text', add the default value.
    if 'simple_text' not in data:
        data['simple_text'] = 'No text'

    if request.method == 'POST':
        value = request.form['simple_text']
        data['simple_text'] = value
        # Store it in the database
        adaptor.save_data(app_id, data)
    
    return render_template("simpletext/edit.html",  
                                value = data['simple_text'],
                                app_id = app_id)

@adaptor.route('/export/<app_id>/app.xml')
def app_xml(app_id):
    data = adaptor.load_data(app_id)
    return render_template("simpletext/app.xml", 
                                value = data['simple_text'])