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 add_profile(self, world, profile):
		key_name = stores.WorldConnection.key_name_form % (world.key_name, profile.key_name)
		connection = stores.WorldConnection.get_by_key_name(key_name)
		if not connection:
			logging.info('User (%s) has added Profile (%s) to World (%s) ' %
						 (self.user.email(), profile.name, world.name))
			connection = WorldConnection(
							key_name=key_name,
							profile=profile,
							world=world,
						)
			connection.put()
			counter.Counter('%sWorldProfiles' % world.key_name, 1).increment()

			messages = stores.MessageFactory.gen_profile_joined_world(
				world.worldmember_set, connection, self.udata
			)

			db.put(messages)

			framework.unmemoize(profile.url, 'world_listing')
			framework.unmemoize(world.url, 'profile_listing')
			return True

		return False
Exemplo n.º 3
0
	def add_member(self):
		udata = db.get(self.request.get('udata'))
		world = db.get(self.request.get('world'))

		key_name = stores.WorldMember.key_name_form % (world.key_name, udata.key_name)
		def txn():
			member = WorldMember(key_name=key_name, user=udata, world=world)
			member.put()
			return True

		if db.run_in_transaction(txn):
			framework.unmemoize(world.url, 'member_listing')
Exemplo n.º 4
0
	def post(self):
		get			= self.request.get
		action 		= get('action', 'Cancel')
		name_check	= get('name_check')
		world 		= stores.World.get_by_key_name(get('key_name'))

		if not world:
			self.flash.msg = "Unknown World"
			self.redirect('/')
			return

		if not utils.page_admin(world.author.user):
			self.flash.msg = "Access Denied"
			self.redirect(world.get_absoluete_url())
			return

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

		for connection in world.worldconnection_set:
			framework.unmemoize(connection.profile.url, 'world_listing')
		db.delete(world.worldconnection_set)
		counter.Counter('%sWorldProfiles' % world.key_name, 1).delete()

		for member in world.worldmember_set:
			framework.unmemoize('/manage/', 'world_listing', member.user.nickname)
			framework.unmemoize(member.user.url, 'world_listing')
		db.delete(world.worldmember_set)
		counter.Counter('%sWorldMembers' % world.key_name, 1).delete()

		world.delete()

		c = counter.Counter('TotalWorlds')
		c.increment(-1)

		logging.info('User (%s) deleted World (%s) owned by %s' % (
			self.user.email(), world.name, world.author.user.email()
		))

		framework.unmemoize('/', 'world_listing')
		framework.unmemoize('/discover/', 'world_listing')

		self.flash.msg = "World: %s Deleted" % world.name
		self.redirect('/')
Exemplo n.º 5
0
	def remove_profile(self, world, profile):
		key_name = stores.WorldConnection.key_name_form % (world.key_name, profile.key_name)
		connection = stores.WorldConnection.get_by_key_name(key_name)

		if connection:
			connection.delete()
			counter.Counter('%sWorldProfiles' % world.key_name, 1).increment(-1)

			logging.info('User (%s) has removed Profile (%s) from World (%s)' %
						 (self.user.email(), world.name, profile.author.user.email()))

			messages = stores.MessageFactory.gen_profile_left_world(
				world.worldmember_set, connection, self.udata
			)
			db.put(messages)

			framework.unmemoize(profile.url, 'world_listing')
			framework.unmemoize(world.url, 'profile_listing')
			return True

		return False
Exemplo n.º 6
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.º 7
0
	def add_member(self, world, username):
		"""remove_member(username: *) -> bool

		Add `username` to the world and return True if wasn't a member already.

		"""

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

		udata = stores.UserData.load_from_nickname(username)
		if udata is None:
			return "Unknown User"

		key_name = stores.WorldMember.key_name_form % (world.key_name, udata.key_name)
		member = stores.WorldMember.get_by_key_name(key_name)
		if not member:
			member = WorldMember(key_name=key_name, user=udata, world=world)
			member.put()
			counter.Counter('%sWorldMembers' % world.key_name, 1).increment()

			messages = stores.MessageFactory.gen_user_joined_world(
				world.worldmember_set, member, self.udata
			)
			db.put(messages)

			logging.info('User (%s) has added World (%s) Member (%s)' % (
				self.user.email(), world.name, udata.user.email()))

			framework.unmemoize('/manage/', 'world_listing', udata.nickname)
			framework.unmemoize(member.user.url, 'world_listing')
			framework.unmemoize(world.url, 'member_listing')
			return True

		return False
Exemplo n.º 8
0
    def post(self):
        """Create a new comment and related messages.
		All type functions should return an unput comment."""
        get = self.request.get
        markup = get("markup", "Textile")
        type = get("type").lower()
        host = get("host")

        func_name = "_type_%s" % type
        if hasattr(self, func_name):
            # Build the comment base with common properties.
            comment = stores.Comment(markup=markup)
            # Pass the comment and the host data for final processing
            getattr(self, func_name)(comment, host)
            # Delete a previous cache entry
            logging.info("REFERER: " + self.request.headers["REFERER"])
            framework.unmemoize(self.request.headers["REFERER"], "comment_listing")
        else:
            logging.error(
                "User (%s) attempted to create an unknown type of comment (%s)" % (utils.get_current_user(), type)
            )

        self.redirect(self.request.headers["REFERER"])
Exemplo n.º 9
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.º 10
0
    def post(self):
        get = self.request.get
        name = get("name", "")
        unix_name = utils.unix_string(name)

        if not name:
            self.flash.msg = "Error: Name Required"
            self.redirect(self.args_to_url())
            return

        key_name = stores.Profile.key_name_form % (unix_name, self.udata.key_name)

        if stores.Profile.get_by_key_name(key_name):
            self.flash.msg = "Error: Profile (%s) Already Exists" % name
            self.render(["new", "newProfile"], self.args_to_dict())
            return

        now = datetime.datetime.now()

        def txn():
            profile = stores.Profile(
                key_name=key_name, created=now, updated=now, author=self.udata, name=name, unix_name=unix_name
            )
            profile.public = get("public", "True") == "True"
            profile.markup = get("markup", "Textile")
            profile.age = get("age", "")
            profile.gender = get("gender", "")
            profile.race = get("race", "")
            profile.height = get("height", "")
            profile.weight = get("weight", "")
            profile.apperence = get("apperence", "")
            profile.background = get("background", "")
            profile.extra_info = get("extra_info", "")
            profile.links = get("links", "")
            profile.common = get("common", "")
            profile.word_count = utils.word_count(profile.apperence, profile.background, profile.extra_info)
            profile.put()
            return profile

        try:
            profile = db.run_in_transaction(txn)
        except apiproxy_errors.CapabilityDisabledError:
            self.flash.msg = "Error: App Engine could not create your profile."
            self.render(["new", "newProfile"], self.args_to_dict())
            return
        except (db.Error, apiproxy_errors.Error):
            self.flash.msg = "Error: App Engine could not create your profile for an unknown reason."
            self.render(["new", "newProfile"], self.args_to_dict())
            return

        c = counter.Counter("TotalProfiles")
        c.increment()
        c = counter.Counter("%sProfiles" % self.udata.key_name, 1)
        c.increment()

        logging.info("User (%s) has made a new character (%s)" % (self.udata.user.email(), profile.name))

        framework.unmemoize("/manage/", "profile_listing", self.udata.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 has been created" % name
        self.redirect(profile.url)