示例#1
0
def get_form(request, object_def):
    """
    Return form for the dialog box
    """
    object, field = object_from_param(object_def)
    widget = get_widget(object, field)
    
    return HttpResponse(final_form(widget, object_def))
示例#2
0
def run():
	global initialized, connected
	while True:
		# init slack
		init()
		if not initialized: 
			time.sleep(sleep_on_error)
			continue
		# connect to slack
		connect()
		if not connected: 
			time.sleep(sleep_on_error)
			continue			
		# read a rtm stream
		try: 
			output_list = slack.rtm_read()
		except Exception,e:
			log.warning("unable to read from slack: "+utils.get_exception(e))
			initialized = False
			connected = False
			time.sleep(sleep_on_error)
			continue
		if output_list and len(output_list) > 0:
			for output in output_list:
				if not output or 'text' not in output: continue
				if output['user'] == bot_id: continue
				# for each output
				if bot_id in output['text'] or bot_name in output['text'] or output['channel'].startswith("D"):
					# if the message is to the bot
					request = output['text']
					request = request.replace(bot_name,'')
					request = request.replace(bot_id,'')
					request = request.lower()
					channel = output['channel']
					# ask the oracle what to respond
					response = oracle.ask(request)
					if response["type"] == "text":
						# post the text response
						slack_message(channel,response["content"])
					elif response["type"] == "chart":
						# post a waiting message
						slack_message(channel,oracle.get_wait_message())
						# generate the image
						module_id,widget_id = response["content"].split(",")
						try: 
							files = generate_widget.run(module_id,widget_id)
						except Exception,e:
							log.warning("unable to generate the widget for "+module_id+":"+widget_id+": "+utils.get_exception(e))
							continue
						# upload the chart to the channel
						if len(files) > 0:
							filename = utils.get_widget_file(files[0])
							log.debug("uploading "+filename)
							widget = utils.get_widget(module_id,widget_id)
							slack_upload(channel,filename,utils.lang(widget["display_name"]))
						else: slack_message(channel,"unable to find the chart "+filename)
示例#3
0
	def render_widget(self, entity, context, storage={}):
		(widget_name, widget_context) = context 
		widget = get_widget(widget_name)(context=widget_context, storage=storage) 
		request = get_request()
		return widget.render(request)