示例#1
0
	def post(self, username, name):
		adata	= UserData.load_from_nickname(username)
		author		= adata.user

		choice	= self.request.get('choice')
		name_check	= self.request.get('name_check')
		profile_key = self.request.get('profile_key', '')

		profile = Profile.get(profile_key)

		if not profile:
			self.flash.msg = "Unknown Profile"
			self.redirect(adata.url)
			return

		# Only let admins and the author delete a profile
		if not self.page_admin(self.user):
			self.flash.msg = "Access Denied."
			self.redirect(profile.url)
			return

		if name_check != profile.name or choice != 'Confirm':
			self.flash.msg = "%s: Preserved" % profile.name
			self.redirect(profile.url)
			return

		query = Comment.all()
		query.filter('host =', profile)
		for comment in query:
			comment.delete()
		for conn in profile.worldconnection_set:
			conn.delete()
		# Clear the profile from the memcache.
		#Profile.unload(adata.key_name, profile.unix_name)
		profile.delete()

		c = counter.Counter('TotalProfiles')
		c.increment(-1)
		c = counter.Counter('%sProfiles' % profile.author.key_name, 1)
		c.increment(-1)

		logging.info("%s(%s) deleted %s's Profile (%s)." % (
					 self.user.email(), self.udata.nickname,
					 profile.author.user.email(), profile.name
		))

		framework.unmemoize('/manage/', 'profile_listing', adata.nickname)
		framework.unmemoize('/', 'profile_listing')
		framework.unmemoize('/discover/', 'profile_listing')
		framework.unmemoize('/discover/', 'profile_feed')
		framework.unmemoize(profile.author.url, 'profile_listing')
		framework.unmemoize(profile.author.url, 'profile_feed')

		self.flash.msg = "%s Deleted Sucessfully" % profile.name
		self.redirect(profile.author.url)
示例#2
0
		def __build_comment_data():
			page = self.request.get_range('comments_page', min_value=1, default=1)
			items_per_page = self.request.get_range(
				'comments_items', min_value=1, max_value=25, default=6
			)
			offset = ((page - 1) * items_per_page)
			last_page = True

			key = profile.key()
			q = Comment.all()
			q.filter('host =', key)
			q.order('-created')
			comments = q.fetch((items_per_page + 1), offset)
			if len(comments) > items_per_page:
				last_page = False
				comments.pop()
				
			@framework.memoize(sterile_url, 'comment_listing', refresh=refresh_cache)
			def fetch():
				return comments

			return {'comments': fetch(), 'host': key, 'host_type': 'profile',
					'page': page, 'last_page': last_page}