Esempio n. 1
0
	def checkAndCreateIconAutomatic(self):
		ENV=tool.readHeader(self.request);
		user=ENV.CurrentUser;
		keyName='ucon://user/'+user.email();
		userIcon=db.get(db.Key.from_path('Icon',keyName ));
		if not userIcon:
			userIcon=Icon(key_name=keyName);
			userIcon.thumb="http://wwwcdn.net/ev/assets/images/vectors/afbig/user-symbol-blue-clip-art.jpg";
			userIcon.type='user';
			#generate content;
			contentDict={
			'photoURL' :userIcon.thumb , 
			'facetimeID' : user.email(),
			'email' : user.email(),
			'home' : keyName+'/public/home',
			'inbox' : keyName+'/private/inbox',
			'item'	: keyName+'/private/item',
			};	
			userIcon.whereCreated=ENV.CityLatLong;
			userIcon.whereModified=ENV.CityLatLong;
			
			
			itemBarPlaceName=keyName+'/private/item';
			## need: add task (makecopy of toolset icon to user item bar)
			#camera app, upload-photo app
			contentDict['toolset']=["ucon://toolset/camera","ucon://toolset/upload-photo"];
			
			taskqueue.add(url='/icon/'
			,params={'keyName':'ucon://place/'+contentDict.get('home'), 'thumb':"http://theparentplace.files.wordpress.com/2012/04/home1.png", 'type': 'place', 'tag':'home' , 
			'content': json.dumps({
			"placeName": contentDict.get('home'), 
			"title": user.email() + " - Home", 
			"backgroundPhotoURL": "", 
			"photoURL": userIcon.thumb
			})
			}
			,queue_name='fastAndSecure');
			
#			taskqueue.add(url='/action/'
#			,params={'place':itemBarPlaceName, 'type': 'makecopy', 'tag':'toolset' , 'content': json.dumps({"iconID":"ucon://toolset/camera","isKeyName":True}) } 
#			,queue_name='fastAndSecure');
#			#upload photo app
#			taskqueue.add(url='/action/'
#			,params={'place':itemBarPlaceName, 'type': 'makecopy', 'tag':'toolset' , 'content': json.dumps({"iconID":"ucon://toolset/upload-photo","isKeyName":True}) } 
#			,queue_name='fastAndSecure');

			userIcon.content = json.dumps(contentDict);
			userIcon.put();
Esempio n. 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;