Example #1
0
	def post(self):
		#Get var from request and pass to data model object
		entry = Icon()
		entry.content = self.request.get('content');
		entry.thum = self.request.get('thumb');
		entry.type = self.request.get('type');
		entry.tag = self.request.get_all('tag');
		entry.put() #save data model object to data base
		self.response.out.write(entry.dumpsJSON());
Example #2
0
	def post(self):
		ENV=tool.readHeader(self.request);
		#Get var from request and pass to data model object
		keyName=self.request.get('keyName');
		callbackJSONP=self.request.get('JSONP');
		if keyName: 
			entry = db.get(db.Key.from_path('Icon',keyName ));
			if entry==None: 
				entry = Icon(key_name=keyName)
			else:
				#keyName exist
				self.response.out.write(json.dumps([]));
		else: entry= Icon();
		
		#pass to model
		try:	
			#check valid json , save as python json
			entry.content=json.dumps( json.loads(self.request.get('content')) );
		except ValueError:
			self.response.out.write(json.dumps([]));	
			return;
		
		entry.thumb = self.request.get('thumb');
		entry.type = self.request.get('type');
		d={};#temporary dict
		entry.tag = [d.setdefault(tag,tag) for tag in self.request.get_all('tag') if tag and tag not in d];
		entry.whereCreated=ENV.CityLatLong;
		entry.whereModified=ENV.CityLatLong;
		entry.put() #save data model object to data base
		#each new create icon should have a makecopy action auto generate right after it is created, so user will see reflection of it right away
		#icons that dont have any makecopy action are likely become garbage (because no one can see or copy it)
		#this can help avoid situtation when icon is created but send makecopy action phase on client is error.
		# write some code here to generate make copy action (need some var from request)
		
		#render
		jsonData=json.dumps( [entry.dictJSON()] )  ;
		
		if callbackJSONP:
			self.response.out.write(callbackJSONP+'('+jsonData+');');
		else: self.response.out.write(jsonData);
		
		return;