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)
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)
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
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
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('/')
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())
def get(self, action): get = self.request.get key_name = get('key_name') world = World.get_by_key_name(key_name) if not world: self.flash.msg = "Unknown World" self.redirect('/') return if get("submit_action", "") == "Cancel": self.flash.msg = "%s: Changes Not Saved" % world.name self.redirect(world.url) return if not utils.page_admin(world.author.user) and action != "dismiss_members": self.flash.msg = "Access Denied" self.redirect(world.url) return if action == 'add_members': members = self.request.get('members', '').split(' ') for member in members: if member: result = self.add_member(world, member) if result == "Unknown User": self.flash.msg = "Unknown User: %s" % member self.redirect(world.url) return self.flash.msg = "User: %s added to World: %s" % (', '.join(members), world.name) self.redirect(world.url) return elif action == 'dismiss_members': removed = [] members = self.request.get('members', '').split(' ') for member in members: if member: result = self.remove_member(world, member) if result is True: removed.append(member) # Silly Easter Egg message to Amanda elif result == 'Amanda': logging.info('Amanda Message') self.flash.msg = "You just can\\\'t get rid of me, Amanda <3" self.redirect(world.url) return self.flash.msg = "User: %s removed from World: %s" % (', '.join(removed), world.name) self.redirect(world.url) return get = self.request.get world.about = get('about', '') world.links = get('links', '') world.common = get('common', '') world.open = get('open', 'True') == 'True' world.public = get('public', 'True') == 'True' world.markup = get('markup', 'Textile') world.put() self.flash.msg = "World: %s Saved" % world.name self.redirect(world.url)