コード例 #1
0
ファイル: megafeed_tags.py プロジェクト: ff0000/megafeed
	def render(self, context):
#		print self.kwargs
		feed = {}
		for k,v in self.kwargs.iteritems():
			feed[k] = v.resolve(context)
		model = megafeed.load_model(self.model.lower())
		if not model: raise Exception('Feed not found')
		context[self.variable] = megafeed.megafeed(model,
				params=feed, to_dict=None)[self.model.lower()]
		return ''
コード例 #2
0
ファイル: views.py プロジェクト: ff0000/megafeed
def json_feed(request, model=None):
#	if model:
#		model = megafeed.load_model(model)
#		if not model: return megafeed.serial_response(settings.BAD_FEED)
#		prefix = request.REQUEST.get('prefix', settings.DEFAULT_FEED_PREFIX)
#		params = json.loads(request.REQUEST[prefix])
#		return megafeed.serial_response(megafeed.megafeed(model, params, prefix))
#	else:
	response = {}
	for key in request.REQUEST:
		if key != settings.JSONP_PREFIX:
			try: value = json.loads(request.REQUEST[key])
			except: value = {}
			if hasattr(value, '__iter__') and settings.MODEL_SPECIFIER in value:
				model = megafeed.load_model(
					value[settings.MODEL_SPECIFIER])
#				del value[settings.MODEL_SPECIFIER]
			else:
				model = megafeed.load_model(key)
			if not model: response[key] = settings.BAD_FEED
			else:
				response.update(getattr(model, settings.MEGAFEED_ATTR) \
					(params=value, prefix=key, user=request.user))
	return megafeed.serial_response(response)