Exemplo n.º 1
0
	def post(self, username, name):
		adata	= UserData.load_from_nickname(username)
		author		= adata.user

		get		= self.request.get
		public 	= get('public', 'True') == 'True'
		markup	= get('markup', 'Textile')
		key_name = get('key_name')

		profile = stores.Profile.get_by_key_name(key_name)

		if not profile:
			self.redirect('/create/profile/%s' % self.args_to_url())
			return

		if get("submit_action", "Cancel") == "Cancel":
			self.flash.msg = '%s: Not Updated' % profile.name
			self.redirect(profile.url)
			return

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

		changed = []
		def txn():
			new_args = self.args_to_dict()
			new_args.update({
				'public':public,'markup':markup,
				'updated':datetime.datetime.now()
			})
			if 'name' in new_args:
				del new_args['name'] # Make it impossible to change the name.

			for arg in profile.properties():
				if arg not in new_args:
					continue
				new_arg = new_args.get(arg)
				if new_arg == getattr(profile, arg):
					continue
				changed.append(arg)
				setattr(profile, arg, new_arg)
			profile.word_count = utils.word_count(
				profile.apperence, profile.background, profile.extra_info
			)
			profile.put()
		db.run_in_transaction(txn)
		logging.info("User (%s) has made changes (%s) to a Profile (%s)" %
					 (self.user.email(), ' | '.join(changed), profile.name))

		# Clear the profile from the memcache.
		#Profile.unload(adata.key_name, profile.unix_name)
		# Update the latest profiles list on the front page.
		framework.unmemoize('/', 'profile_listing')

		self.flash.msg = "%s: Updated" % profile.name

		self.redirect(profile.url)
Exemplo n.º 2
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)
Exemplo n.º 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'])
Exemplo n.º 4
0
	def user_words(self, who):
		author = UserData.load_from_nickname(who)
		counter_data = self.counter_data

		counter_data['cls'] = stores.Profile
		counter_data['counter_name'] = '%sTotalWords' % author.key_name
		counter_data['counter_shards'] = 1
		counter_data['flash_msg'] = "%s's Total Words Counted" % author.nickname

		def init_logic():
			"""Return a seed object to use a key from."""
			return stores.Profile.gql(
				'WHERE author = :1 ORDER BY __key__', author).get()

		def query_logic(last_key):
			"""Return a query."""
			return stores.Profile.gql(
				'WHERE author = :1 AND __key__ >= :2 ORDER BY __key__',
				author, last_key
			)

		def counter_logic(objects):
			"""Incriment the counter using the list of objects retrieved"""
			import operator
			count = reduce(
				operator.add, [obj.word_count or 0 for obj in objects], 0)
			c = counter.Counter(counter_data['counter_name'],
								counter_data['counter_shards'])
			c.increment(count)
			return count

		counter_data['init_logic'] = init_logic
		counter_data['query_logic'] = query_logic
		counter_data['counter_logic'] = counter_logic
		self.generic_counter()
Exemplo n.º 5
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)
Exemplo n.º 6
0
	def page_admin(self, user):
		"""page_admin(* user) -> bool

		Return True if `user` matches the current user or
		if current user is an admin.

		Accepts a string or users.User.

		"""

		if isinstance(user, basestring):
			user = UserData.load_from_nickname(recipient)

		if user == self.user or users.is_current_user_admin():
			return True

		return False
Exemplo n.º 7
0
	def remove_member(self, world, username):
		"""remove_member(username: *) -> bool

		Remove `username` from the world and return True if it was a member.

		"""
		udata = UserData.load_from_nickname(username)
		if udata is None:
			return False

		# Silly Easter Egg message to Amanda
		if False and username == "Pakattack161" and self.udata.nickname == 'WillowCall':
			return 'Amanda'

		if not utils.page_admin(world.author.user) and not utils.page_admin(udata.user):
			return False

		member = world.worldmember_set.filter('user ='******'user = '******'world_listing')
				conn.delete()

			logging.info('User (%s) has removed World (%s) Member (%s)' % (
				self.user.email(), world.name, udata.user.email()
				))
			messages = stores.MessageFactory.gen_user_left_world(
				member.world.worldmember_set, member, self.udata
			)
			db.put(messages)

			framework.unmemoize(world.url, 'profile_listing')
			framework.unmemoize('/manage/', 'world_listing', member.user.nickname)
			framework.unmemoize(member.user.url, 'member_listing')
			framework.unmemoize(world.url, 'member_listing')
			member.delete()
			counter.Counter('%sWorldMembers' % world.key_name, 1).increment(-1)
			return True

		return False
Exemplo n.º 8
0
	def get(self, username, output):
		adata	= UserData.load_from_nickname(username)
		author		= adata.user
		page_admin 	= self.page_admin(author)
		get 		= self.request.get
		refresh_cache = get('refresh_cache', False) is not False
		sterile_url	= framework.sterilize_url(self.request.url)

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

		@framework.memoize(sterile_url, 'profile_feed', refresh=refresh_cache)
		def __fetch_feed_data():
			# Orders the profiles most recently created first.
			q = adata.profile_set
			q.order('-created')

			return q.fetch(12)

		profile_data = {'profiles': __fetch_feed_data()}

		self.render(['feed', 'userprofiles'], output=output)
		return
Exemplo n.º 9
0
	def user_worlds(self, who):
		author = UserData.load_from_nickname(who)
		counter_data = self.counter_data

		counter_data['cls'] = stores.World
		counter_data['counter_name'] = '%sWorlds' % author.key_name
		counter_data['counter_shards'] = 1
		counter_data['flash_msg'] = "%s's Worlds Counted" % author.nickname

		def init_logic():
			"""Return a seed object to use a key from."""
			return stores.World.gql(
				'WHERE author = :1 ORDER BY __key__', author).get()

		def query_logic(last_key):
			"""Return a query."""
			return stores.World.gql(
				'WHERE author = :1 AND __key__ >= :2 ORDER BY __key__',
				author, last_key
			)

		counter_data['init_logic'] = init_logic
		counter_data['query_logic'] = query_logic
		self.generic_counter()
Exemplo n.º 10
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
Exemplo n.º 11
0
	def get(self, username, name):
		adata = UserData.load_from_nickname(username)
		author	= adata.user
		get 	= self.request.get
		if name is None:
			name 	= get('name', '')
		output		= get('output', '')

		# If we're loading the user's public page and not a profile
		if not name:
			if output in ["rss", "atom"]:
				self.render_feed(user, author, adata, output)
			else:
				self.render_user(user, author, adata)
			return

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

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

		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 = stores.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

		# Check for actions
		if action:
			if action == 'edit':
				self.render(['edit', 'editprofile'], locals())
			elif action == 'delete':
				self.render(['delete', 'deleteprofile'], locals())
			return

		@framework.memoize(sterile_url, 'world_listing', refresh=refresh_cache)
		def __fetch_world_data():
			# This bit of hackery is used to fetch the actual world objects
			# as opposed to the connection, which don't fetch their references
			# when called inside the html.
			return [conn.world for conn in profile.worldconnection_set.fetch(5)]

		
		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}

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

		context['comment_data'] = __build_comment_data()

		if refresh_cache:
			memcache.delete('markup:%s' % profile.key_name)

		self.render(['view', 'viewProfile'], locals())