Commits

Ivan Melnikov committed fb71ea2 Draft

Store user for page and files

Comments (0)

Files changed (3)

 from creole import Parser
 from creole.html_emitter import HtmlEmitter
 
+from user import User, get_user
+
 
 ##################
 ###   Models   ###
 	path = db.StringProperty(required=True)
 	updated = db.DateTimeProperty(auto_now_add=True)
 	html = db.TextProperty() #required=True
+	user_id = db.IntegerProperty()
 	# title = db.StringProperty()
 	# access = db.StringProperty()
 
 	page = db.ReferenceProperty(reference_class=Page, collection_name='history', required=True)
 	zipp = db.BlobProperty(required=True)
 	updated = db.DateTimeProperty(auto_now=True)
+	user_id = db.IntegerProperty()
 
 	def html(self):
 		return zlib.decompress(self.zipp).decode('utf-8')
 
 class PageFile(db.Model):
 	page = db.ReferenceProperty(reference_class=Page, collection_name='files', required=True)
+	user_id = db.IntegerProperty()
 	name = db.StringProperty(required=True)
 	size = db.IntegerProperty()
 	date = db.DateTimeProperty()
 		else:
 			return '%d MB' % (n/10**6)
 
+def user_name(user_id):
+	return get_user(user_id).name
+
 def encode(url):
 	return urllib.quote(url.encode('utf-8'))
 
     loader=jinja2.FileSystemLoader(os.path.dirname(__file__) + '/template/page'))
 jinja_environment.filters['format'] = dateformat
 jinja_environment.filters['size'] = size
+jinja_environment.filters['user_name'] = user_name
 jinja_environment.filters['urlencode'] = encode
 jinja_environment.tests['not_empty'] = not_empty
 
 			page = Page(path=unicode(path, 'utf-8'))
 			new = True
 
+		user = get_user()
+
 		# save page
 		text = self.request.get('text')
 		page.html = convert(text)
+		page.user_id = user.key().id()
 		page.put()
 
 		# update cache
 		set_page(path, page)
 
 		# update revision history
-		history = PageHistory(page=page.key(), zipp=zlib.compress(text.encode('utf-8'), 9))
+		zipp = zlib.compress(text.encode('utf-8'), 9)
+		history = PageHistory(page=page.key(), zipp=zipp, user_id=user.key().id())
 		history.put()
 
 		# add path index
 		upload_files = self.get_uploads('data')  # 'file' is file upload field in the form
 		blob_info = upload_files[0]
 
+		user = get_user()
+
 		name = unicode(blob_info.filename, 'utf-8')
 		size = blob_info.size
 		date = blob_info.creation
-		data = PageFile(page=page.key(), blob=blob_info.key(), name=name, size=size, date=date)
+		data = PageFile(page=page.key(), blob=blob_info.key(), user_id=user.key().id(), name=name, size=size, date=date)
 		data.put()
 
 		memcache.delete(CACHE_FILES + path)

template/page/get.html

 	<div class="page-menu-item">
 		<a href="{{ page.upath() }}/.log" class="page-updated">Обновлен</a>
 		<span style="font-size: 15px;">{{ page.updated | format }}<span>
+		<span>{{ page.user_id | user_name | escape }}</span>
 	</div>
 </div>
 
 def get_user(user_id=None):
 	if user_id:
 		# get by key
-		key = CACHE_USER_ID + user_id
+		key = CACHE_USER_ID + str(user_id)
 		result = memcache.get(key)
 		if not result:	
 			result = User.get_by_id(int(user_id))