Пример #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 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'])
Пример #3
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)
Пример #4
0
	def load_from_nickname(cls, nick):
		"""Utility Function to UserData"""

		unix_nick = utils.unix_string(nick)
		data = memcache.get("nickpointer:%s" % unix_nick)
		if not data:
			data = UserData.all().filter("unix_nick =", unix_nick).get()
			if data:
				memcache.set("nickpointer:%s" % unix_nick, data)

		return data
Пример #5
0
    def post(self):
        name = self.request.get("name", "")
        unix_name = utils.unix_string(name)

        if not name:
            self.flash.msg = "Error: Name Required"
            self.render(["new", "newWorld"], self.args_to_dict())
            return

        key_name = "w:%s" % unix_name
        if stores.World.get_by_key_name(key_name):
            self.flash.msg = "Error: World already exists"
            self.render(["new", "newWorld"], self.args_to_dict())
            return

        get = self.request.get
        # Due to the nature of the lazy property, using self.udata within the
        # txn may cause the txn to act on two properties (loading the udata).
        adata = self.udata

        def txn():
            now = datetime.datetime.now()
            world = stores.World(created=now, author=adata, name=name, unix_name=unix_name, key_name=key_name)
            world.about = get("about", "")
            world.links = get("links", "")
            world.public = get("public", "True") == "True"
            world.open = get("open", "False") == "True"
            world.markup = get("markup", "Textile")
            world.put()
            return world

        try:
            world = db.run_in_transaction(txn)
        except apiproxy_errors.CapabilityDisabledError:
            self.flash.msg = "Error: Sybil could not create your world."
            self.render(["new", "newWorld"], self.args_to_dict())
            return
        except (db.Error, apiproxy_errors.Error), e:
            logging.error(e)
            self.flash.msg = "Error: Sybil could not create your world for an unknown reason."
            self.render(["new", "newWorld"], self.args_to_dict())
            return
Пример #6
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())
Пример #7
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)
Пример #8
0
	def get(self, name):
		get	= self.request.get
		action = get('action', '')
		if name is None:
			name = get('name', '')
		unix_name = utils.unix_string(name)
		refresh_cache = get("refresh_cache", False) is not False

		if not name:
			self.error(400)
			return

		world = stores.World.get_by_key_name('w:%s' % unix_name)

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

		context = self.context
		context['world'] = world
		context['page_admin'] = utils.page_admin(world.author.user)
		context['page_owner'] = world.author

		if action:
			if action == 'edit':
				self.render(['edit', 'editWorld'])
			elif action == 'delete':
				self.render(['delete', 'deleteWorld'])
			return

		sterile_url = framework.sterilize_url(self.url)

		def __build_profile_data():
			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=6)
			offset = ((page - 1) * items_per_page)
			last_page = True

			connections = world.worldconnection_set.fetch(
				(items_per_page + 1), offset
			)
			# This bit of hackery is used to fetch the actual profile objects
			# as opposed to the connection, which don't fetch their references
			# when called inside the html.
			profiles = [conn.profile for conn in connections]
			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, 'member_listing', refresh=refresh_cache)
		def __fetch_member_data():
			return world.worldmember_set.fetch(25)

		def __build_comment_data():
			page = self.request.get_range('comments_page', min_value=1, default=1)
			# Allow page numbers to be more natural
			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 = world.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': comments, 'host': key,
					'page': page, 'last_page': last_page}

		context['profile_data'] = __build_profile_data()
		context['profile_data']['list_author'] = True
		context['profile_data']['list_remove'] = True
		context['profile_data']['list_pages'] = True

		context['member_data'] = {'members': __fetch_member_data()}

		context['comment_data'] = __build_comment_data()
		context['comment_data']['host_type'] = 'world'


		c = counter.Counter('%sWorldProfiles' % world.key_name)
		context['profile_count'] = c.get_count(refresh_cache)
		c = counter.Counter('%sWorldMembers' % world.key_name)
		context['member_count'] = c.get_count(refresh_cache)

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