def get(self): len_ = self.request.get_range('length', min_value=3, max_value=10, default=6) names = self.get_name_list(5, len_) get = self.request.get refresh_cache = get('refresh_cache', False) is not False if get('logit', False) is not False: from google.appengine.api.labs import taskqueue taskqueue.add(url='/tasks/logging/') context = self.context context['len_'] = len_ context['names'] = names sterile_url = framework.sterilize_url(self.request.url) @framework.memoize(sterile_url, 'profile_listing', refresh=refresh_cache) def __fetch_profile_data(): query = stores.Profile.all() query.filter('public =', True) query.order('-updated') return query.fetch(5) @framework.memoize(sterile_url, 'world_listing', refresh=refresh_cache) def __fetch_world_data(): query = World.all() query.filter('public =', True) query.order('-created') return query.fetch(5) context['profile_data'] = { 'profiles': __fetch_profile_data(), 'list_author': True } context['world_data'] = { 'worlds': __fetch_world_data(), 'list_author': True, } profile_count = counter.Counter('TotalProfiles').get_count(refresh_cache) world_count = counter.Counter('TotalWorlds').get_count(refresh_cache) user_count = counter.Counter('TotalUsers').get_count(refresh_cache) context['profile_count'] = profile_count context['world_count'] = world_count context['user_count'] = user_count self.render(['index', 'index'])
def get(self): delinate = self.udata.nickname refresh_cache = self.request.get('refresh_cache', False) is not False sterile_url = framework.sterilize_url(self.url) self.context['page_admin'] = True self.context['designs'] = const.AVAILABLE_DESIGNS self.context['themes'] = const.AVAILABLE_THEMES self.context['cf_scripts'] = const.CF_SCRIPTS @framework.memoize(sterile_url, 'profile_listing', delinate, refresh=refresh_cache) def __fetch_latest_profiles(): query = Profile.all() query.filter('author =', self.udata) query.order('-created') return query.fetch(5) # TODO: Reimplement the messaging system. The new one will be cache compatable. @framework.memoize(sterile_url, 'message_listing', delinate, refresh=refresh_cache) def __fetch_messages(): q = self.udata.message_recipient_set q.order('-created') return q.fetch(25) @framework.memoize(sterile_url, 'world_listing', delinate, refresh=refresh_cache) def __fetch_world_memberships(): q = self.udata.worldmember_set #q = WorldMember.all() #q.filter('user ='******'profile_data'] = { 'profiles': __fetch_latest_profiles(), 'list_edit': True, } self.context['messages'] = __fetch_messages() self.context['world_data'] = { 'worlds': __fetch_world_memberships(), 'list_leave': True, } self.render(['index', 'indexManage'])
def get(self, output='rss'): user = utils.get_current_user() get = self.request.get refresh_cache = get('refresh_cache', False) is not False sterile_url = framework.sterilize_url(self.url) @framework.memoize(sterile_url, 'world_feed', refresh=refresh_cache) def __fetch_feed_data(): # Orders the profiles most recently created first. q = World.all() q.filter('public =', True) q.order('-created') return q.fetch(12) self.context['world_data'] = {'worlds': __fetch_feed_data()} self.render(['feed', 'latestworlds'], output=output) return
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
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
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())
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())