def adapt_preview(appid): """ adapt_preview(appid) Previews an application. You can preview the app of any user. # TODO: Eventually the preview feature should probably be merged into view_edit, through a read-only mode. LOGIN IS OPTIONAL FOR THIS METHOD. @param appid: Appid of the app to preview. """ if not appid: return render_template("composers/errors.html", message=gettext("appid not provided")), 400 # Check whether we are logged in. logged_in = current_user() is not None # TODO: Improve this: do not load the whole thing. We just need the variables. app = appstorage.get_app(appid) if app is None: return render_template("composers/errors.html", message=gettext("app not found")), 500 adaptor_types = [var for var in app.appvars if var.name == 'adaptor_type'] if not adaptor_types: return render_template("composers/errors.html", message=gettext("Error: no attached adaptor_type variable")), 500 adaptor_type = adaptor_types[0].value if adaptor_type not in ADAPTORS: return render_template("composers/errors.html", message=gettext("Error: adaptor %s not currently supported") % adaptor_type), 500 adaptor_plugin = ADAPTORS[adaptor_type]['adaptor'] # TODO: URLs seem to be dependent on adaptor type. This is meant to work with jsconfig at least. # Calculate the URL for the Preview iframe. app_url = url_for('%s.app_xml' % adaptor_type, app_id=appid, _external=True) preview_url = shindig_url("/gadgets/ifr?nocache=1&url=%s" % app_url) # Retrieve the URL from the appdata. appdata = json.loads(app.data) spec_url = appdata["url"] return render_template("composers/adapt/preview.html", logged_in=logged_in, app_id=appid, app_url=app_url, spec_url=spec_url, name=app.name, preview_url=preview_url)
def edit(app_id): # Load data from the database for this application data = adaptor.load_data(app_id) new_url = False contents = None url_form = UrlForm() if not url_form.url.data: url_form.url.data = data['url'] if request.method == 'POST': value = request.form['url'] if value != data['url']: if url_form.validate_on_submit(): try: contents = urllib2.urlopen(value).read() except: if not url_form.url.errors: url_form.url.errors = [] url_form.url.errors.append(gettext("Could not download the provided URL")) else: try: minidom.parseString(contents) except: if not url_form.url.errors: url_form.url.errors = [] url_form.url.errors.append(gettext("The provided URL is not a valid XML!")) else: # Reset the configuration data['url'] = value new_url = True data['configuration'] = None data['configuration_name'] = None data["initialised"] = True adaptor.save_data(app_id, data) url = data['url'] definition_script = None if url and url.startswith(('http://', 'https://')): if not contents: try: contents = urllib2.urlopen(url).read() except: flash(gettext("Could not download the provided URL")) if contents: definition_script = find_definition_script(contents, url) external_url = url_for('.app_xml', app_id=app_id, _external=True) preview_url = shindig_url("/gadgets/ifr?nocache=1&url=%s" % external_url) if new_url: try: # Force shindig to refresh the ifr. We had problems with new URLs urllib2.urlopen(preview_url).read() except: pass configuration_name = data['configuration_name'] configuration = json.dumps(data['configuration'], indent=4) return render_template("jsconfig/edit.html", initialised=data.get("initialised"), # Indicate whether the first URL was successfully loaded, so that we can prevent further URL changes url=url or '', definition_script=definition_script, app_id=app_id, preview_url=preview_url, configuration_name=configuration_name, configuration=configuration, url_form=url_form, name=adaptor.get_name(app_id))
def edit(app_id): # Load data from the database for this application data = adaptor.load_data(app_id) new_url = False contents = None url_form = UrlForm() if not url_form.url.data: url_form.url.data = data['url'] if request.method == 'POST': value = request.form['url'] if value != data['url']: if url_form.validate_on_submit(): try: contents = urllib2.urlopen(value).read() except: if not url_form.url.errors: url_form.url.errors = [] url_form.url.errors.append( gettext("Could not download the provided URL")) else: try: minidom.parseString(contents) except: if not url_form.url.errors: url_form.url.errors = [] url_form.url.errors.append( gettext("The provided URL is not a valid XML!")) else: # Reset the configuration data['url'] = value new_url = True data['configuration'] = None data['configuration_name'] = None data["initialised"] = True adaptor.save_data(app_id, data) url = data['url'] definition_script = None if url and url.startswith(('http://', 'https://')): if not contents: try: contents = urllib2.urlopen(url).read() except: flash(gettext("Could not download the provided URL")) if contents: definition_script = find_definition_script(contents, url) external_url = url_for('.app_xml', app_id=app_id, _external=True) preview_url = shindig_url("/gadgets/ifr?nocache=1&url=%s" % external_url) if new_url: try: # Force shindig to refresh the ifr. We had problems with new URLs urllib2.urlopen(preview_url).read() except: pass configuration_name = data['configuration_name'] configuration = json.dumps(data['configuration'], indent=4) return render_template( "jsconfig/edit.html", initialised=data.get("initialised"), # Indicate whether the first URL was successfully loaded, so that we can prevent further URL changes url=url or '', definition_script=definition_script, app_id=app_id, preview_url=preview_url, configuration_name=configuration_name, configuration=configuration, url_form=url_form, name=adaptor.get_name(app_id))