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

		name		= urllib.unquote_plus(urllib.unquote(name))
		unix_name 	= utils.unix_string(name)

		context = self.context
		context['author'] = author
		context['page_author'] = adata
		context['page_admin'] = page_admin

		# Check to see if we already have a profile for that character.
		profile = Profile.get_by_key_name(
			stores.Profile.key_name_form % (unix_name, adata.key_name)
		)

		# If we can't find that character and we're the author we may want to
		# make it, other wise we should move the user back to the user page.
		if not profile or (not profile.public and not page_admin):
			self.flash.msg = "Unknown Profile: %s" % name
			self.redirect(Profile.get_url(username))
			return

		context['profile'] = profile

		self.render(['delete', 'deleteprofile'], context)
示例#2
0
		def __build_profile_data():
			order 	= get('order', 'created').lower()
			page 	= self.request.get_range('profiles_page', min_value=1, default=1)
			# Allow page numbers to be more natural
			items_per_page = self.request.get_range('profiles_items', min_value=1,
											max_value=25, default=10)
			offset = ((page - 1) * items_per_page)
			last_page = True

			# Orders the profiles most recently created first.
			query = Profile.all()
			query.filter('author =', adata)
			if not page_admin:
				query.filter('public =', True)
			if order == 'alpha':
				query.order('name')
			else:
				query.order('-created')
			profiles = query.fetch((items_per_page + 1), offset)

			# Since each page is 6 items long if there are 7 items then we
			# know that there is at least one more page.
			if len(profiles) > items_per_page:
				last_page = False
				profiles.pop()
				
			@framework.memoize(sterile_url, 'profile_listing', refresh=refresh_cache)
			def fetch():
				return profiles
			
			return {'profiles':fetch(), 'page':page, 'last_page':last_page}
示例#3
0
	def get(self, username, name):
		adata	= UserData.load_from_nickname(username)
		author		= adata.user
		page_admin 	= self.page_admin(author)

		name		= urllib.unquote_plus(urllib.unquote(name))
		unix_name 	= utils.unix_string(name)

		context = self.context
		context['author'] = author
		context['page_author'] = adata
		context['page_admin'] = page_admin

		# Check to see if we already have a profile for that character.
		# profile = Profile.gql('WHERE unix_name = :name AND author = :author',
		#					  name=unix_name, author=adata).get()
		profile = Profile.get_by_key_name(
			stores.Profile.key_name_form % (unix_name, adata.key_name)
		)

		# If we can't find that character and we're the author we may want to
		# make it, other wise we should move the user back to the user page.
		if not profile or (not profile.public and not page_admin):
			self.flash.msg = "Unknown Profile: %s" % name
			if author == self.user:
				self.redirect('/create/profile/?name=%s' % name)
			else:
				self.redirect(adata.url)
			return

		context['profile'] = profile

		self.render(['edit', 'editprofile'])
示例#4
0
	def get(self):
		logging.info('PROFILE KEY: %r' % self.request.get('profile_key'))
		profile		= Profile.get_by_key_name(self.request.get('profile_key'))
		world 		= World.get_by_key_name(self.request.get('world_key'))

		if not profile:
			self.flash.msg = "Error: Unable to load profile"
			self.redirect('/')
			return

		if not world:
			self.flash.msg = "Error: Unable to load World"
			self.redirect('/')
			return

		page_admin = utils.page_admin(profile.author.user)
		if not page_admin:
			self.flash.msg = "Access Denied"
			self.redirect(self.request.headers['REFERER'])
			return

		self.remove_profile(world, profile)

		self.flash.msg = "Profile: %s removed from World: %s" % (profile.name, world.name)
		self.redirect(profile.url)
示例#5
0
	def post(self):
		user		= utils.get_current_user()
		name		= self.request.get('name', '')
		unix_name	= utils.unix_string(name)
		profile		= Profile.get(self.request.get('profile_key'))
		world		= stores.World.get_by_key_name('w:%s' % unix_name)

		if not name or not profile or not world:
			self.flash.msg = "Unknown World: %s" % name
			self.redirect(self.request.headers['REFERER'])
			return

		page_admin = utils.page_admin(profile.author.user)
		if not page_admin or not world.user_can_post(self.udata):
			self.flash.msg = "Access Denied"
			self.redirect(profile.url)
			return

		connections = profile.worldconnection_set.fetch(6)
		if len(connections) >= 6:
			self.flash.msg = "Profile: %s in too many worlds (Max = 5)" % profile.name
			self.redirect(profile.url)
			return

		if not self.add_profile(world, profile):
			self.flash.msg = "Profile: %s already in World: %s" % (profile.name, world.name)
		else:
			self.flash.msg = "Profile: %s joined World: %s" % (profile.name, world.name)

		self.redirect(profile.url)
示例#6
0
	def get(self):
		user = utils.get_current_user()
		sort = self.request.get('sort', 'time')
		page = self.request.get_range('page', min_value=1, default=1)
		items_per_page = self.request.get_range('items', min_value=1,
												max_value=25, default=10)
		offset = ((page - 1) * items_per_page)
		last_page = True

		link_template = '<a href="%s">%s</a>'
		sort_links = []
		sort_links.append(link_template % (self.filter_args(['sort', 'page'], sort='time'), 'Time'))
		sort_links.append(link_template % (self.filter_args(['sort', 'page'], sort='words'), 'Word Count'))
		for letter in string.ascii_uppercase:
			sort_links.append(link_template % (self.filter_args(['sort', 'page'], sort=letter.lower()), letter))

		profiles = []
		query = Profile.all()
		query.filter('public =', True)
		if sort == 'time':
			query.order('-created')
		elif sort == 'words':
			query.order('-word_count')
		else:
			query.filter('unix_name >', sort)
			query.filter('unix_name <', sort+u"\ufffd")

		profiles = query.fetch((items_per_page + 1), offset)
		if len(profiles) > items_per_page:
			last_page = False
			profiles.pop()

		self.render(['discover', 'discoverprofile'], locals())
示例#7
0
		def __fetch_feed_data():
			# Orders the profiles most recently created first.
			q = Profile.all()
			q.filter('public =', True)
			q.order('-created')

			return q.fetch(12)
示例#8
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)
示例#9
0
	def get(self):
		query = Profile.all()
		query.filter('public =', True)
		query.order('-created')
		recent_profiles = query.fetch(5)

		query = World.all()
		query.filter('public =', True)
		query.order('-created')
		recent_worlds = query.fetch(5)

		self.render(['index', 'indexdiscover'], locals())
示例#10
0
		def __fetch_latest_profiles():
			query = Profile.all()
			query.filter('author =', self.udata)
			query.order('-created')
			return query.fetch(5)
示例#11
0
	def get(self, username):
		get 		= self.request.get
		name 		= get('name')
		if name:
			# Redriect people to the updated url format.
			self.redirect(Profile.get_url(username, urllib.quote_plus(name)),
						  permanent=True)
			return

		adata	= UserData.load_from_nickname(username)
		if not adata:
			self.redirect('/404/')
			return

		author		= adata.user
		page_admin 	= self.page_admin(author)
		get 		= self.request.get
		action 		= get('action')
		refresh_cache = get('refresh_cache', False) is not False
		sterile_url	= framework.sterilize_url(self.request.url)

		context = self.context
		context['author'] = author
		context['adata'] = adata
		context['page_admin'] = page_admin


		
		def __build_profile_data():
			order 	= get('order', 'created').lower()
			page 	= self.request.get_range('profiles_page', min_value=1, default=1)
			# Allow page numbers to be more natural
			items_per_page = self.request.get_range('profiles_items', min_value=1,
											max_value=25, default=10)
			offset = ((page - 1) * items_per_page)
			last_page = True

			# Orders the profiles most recently created first.
			query = Profile.all()
			query.filter('author =', adata)
			if not page_admin:
				query.filter('public =', True)
			if order == 'alpha':
				query.order('name')
			else:
				query.order('-created')
			profiles = query.fetch((items_per_page + 1), offset)

			# Since each page is 6 items long if there are 7 items then we
			# know that there is at least one more page.
			if len(profiles) > items_per_page:
				last_page = False
				profiles.pop()
				
			@framework.memoize(sterile_url, 'profile_listing', refresh=refresh_cache)
			def fetch():
				return profiles
			
			return {'profiles':fetch(), 'page':page, 'last_page':last_page}

		@framework.memoize(sterile_url, 'world_listing', refresh=refresh_cache)
		def __fetch_world_memberships():
			query = WorldMember.all()
			query.filter('user ='******'profile_data'] = __build_profile_data()
		context['profile_data']['partial_listing'] = True
		context['profile_data']['list_edit'] = True
		context['profile_data']['list_pages'] = True

		context['world_data'] = {
			'worlds': __fetch_world_memberships(),
			'list_author': True,
		}

		c = counter.Counter('%sProfiles' % adata.key_name, 1)
		context['profile_count'] = c.get_count(refresh_cache)

		c = counter.Counter('%sWorlds' % adata.key_name, 1)
		context['world_count'] = c.get_count(refresh_cache)

		c = counter.Counter('%sTotalWords' % adata.key_name, 1)
		context['total_word_count'] = c.get_count(refresh_cache)


		self.render(['view', 'viewUser'])
		return