예제 #1
0
	def get(self, id):
		if id == None:
			return json.dumps(
				[
					{
						"id": f.sequence_id,
						"title": f.title,
						"url": f.url
					}
					for f in Feed.objects
				]
			)
		else:
			f = Feed.objects(sequence_id=id).first()
			if f == None:
				return json.dumps(
					{
						"error":"no feed with id %d" % (id)
					}
				)
			else:
				return json.dumps(
					{
						"id": f.sequence_id,
						"title": f.title,
						"url": f.url
					}
				)
예제 #2
0
	def delete(self, id):
		f = Feed.objects(sequence_id=id).first()
		if f == None:
			return json.dumps(
				{
					"error":"no feed with id %d" % (id)
				}
			)
		else:
			f.delete()
			return json.dumps({"id":id})
예제 #3
0
	def put(self, id):
		f = Feed.objects(sequence_id=id).first()
		if f == None:
			return json.dumps(
				{
					"error":"no feed with id %d" % (id)
				}
			)
		else:
			for key in request.json.keys():
				if key == "title":
					f.update(set__title=request.json[key])
				elif key == "url":
					f.update(set__url=request.json[key])
			return json.dumps({"id":id})
예제 #4
0
	def post(self):
		sequence_id = get_next_sequence("feed")
		f = Feed(sequence_id=sequence_id, title=request.json["title"], url=request.json["url"])
		f.save()
		return json.dumps({"id":sequence_id})