コード例 #1
0
    def delete(self, group_id=None):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # find the the entry
        group = Group.get_by_id(long(group_id))

        # this member's membership
        membership = GroupMembers.get_by_userid_groupid(
            user_info.key, group.key)

        # list of users that have the group enabled
        members = GroupMembers.get_group_users(group.key)

        # remove this user's membership
        membership.key.delete()

        # if this user is not the group owner, we simply notify we are done
        if not group or group.owner != user_info.key:
            # use the channel to tell the browser we are done and reload
            self.add_message('Group was removed from account.', 'success')
            channel_token = self.request.get('channel_token')
            channel.send_message(channel_token, 'reload')
            return

        # was there more than just this member?
        if len(members) > 1:
            # find the next user by date and assign them as owner
            entry = GroupMembers.get_new_owner(user_info.key, group.key)
            print "new owner is %s" % entry.member
            new_owner = entry.member
            group.owner = new_owner
            group.put()

            # find member's appliances that match this group and remove
            appliances = Appliance.get_by_user_group(user_info.key, group.key)
            for appliance in appliances:
                appliance.group = None  # public group
                appliance.put()

        else:
            # no more members, so delete the group
            group.key.delete()
            self.add_message('Group successfully deleted!', 'success')

            # remove group from any and all appliances (heavy handed)
            appliances = Appliance.get_by_group(group.key)
            for appliance in appliances:
                appliance.group = None  # public group
                appliance.put()

        # hangout for a second
        time.sleep(1)

        # use the channel to tell the browser we are done and reload
        channel_token = self.request.get('channel_token')
        channel.send_message(channel_token, 'reload')
        return
コード例 #2
0
ファイル: grouphandlers.py プロジェクト: StackMonkey/site
	def delete(self, group_id = None):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))

		# find the the entry
		group = Group.get_by_id(long(group_id))

		# this member's membership
		membership = GroupMembers.get_by_userid_groupid(user_info.key, group.key)

		# list of users that have the group enabled
		members = GroupMembers.get_group_users(group.key)

		# remove this user's membership
		membership.key.delete()
		
		# if this user is not the group owner, we simply notify we are done
		if not group or group.owner != user_info.key:
			# use the channel to tell the browser we are done and reload
			self.add_message('Group was removed from account.', 'success')
			channel_token = self.request.get('channel_token')
			channel.send_message(channel_token, 'reload')
			return

		# was there more than just this member?
		if len(members) > 1:
			# find the next user by date and assign them as owner
			entry = GroupMembers.get_new_owner(user_info.key, group.key)
			print "new owner is %s" % entry.member
			new_owner = entry.member
			group.owner = new_owner
			group.put()
		
			# find member's appliances that match this group and remove
			appliances = Appliance.get_by_user_group(user_info.key, group.key)
			for appliance in appliances:
				appliance.group = None # public group
				appliance.put()
		
		else:
			# no more members, so delete the group
			group.key.delete()
			self.add_message('Group successfully deleted!', 'success')

			# remove group from any and all appliances (heavy handed)
			appliances = Appliance.get_by_group(group.key)
			for appliance in appliances:
				appliance.group = None # public group
				appliance.put()

		# hangout for a second
		time.sleep(1)

		# use the channel to tell the browser we are done and reload
		channel_token = self.request.get('channel_token')
		channel.send_message(channel_token, 'reload')
		return
コード例 #3
0
	def get(self, project_id = None):
		project = Project.get_by_id(long(project_id))
		# if no project
		if not project:
			return self.redirect_to('projects')

		# assume this user is not owner
		owner = False

		# print self.render_url(project.json_url, {})

		# determine if we can show the project
		if not project.public:
			# see if we have a user
			try:
				user_info = User.get_by_id(long(self.user_id))
				if user_info.key != project.owner:
					raise Exception
				else:
					owner = True

			except:
				self.add_message("You must be the owner to do this.", "fail")
				return self.redirect_to('projects')
		else:
			try:
				user_info = User.get_by_id(long(self.user_id))
				if user_info.key == project.owner:
					owner = True

			except:
				user_info = None

		# define minimum specifications for the instance
		specs = {
			'vpus': project.vpus,
			'memory': project.memory,
			'disk': project.disk
		}

		# empty forms
		self.form.provider.choices = []
		self.form.flavor.choices = []

		# plenty?
		plenty = False

		# dict of providers
		providers = {}

		# find the all public provider's appliances and add to providers object
		appliances = Appliance.get_by_group(None)
		for appliance in appliances:
			providers[appliance.key.id()] = {
				'name': "%s (Public)" % appliance.name,
				'location': [appliance.location.lat, appliance.location.lon],
				'flavors': []
			}

		# if there is a user, find his groups and do the same with appliances in those groups
		if user_info:
			groups = Group.get_by_owner(user_info.key)
			for group in groups:
				appliances = Appliance.get_by_group(group.key)
				for appliance in appliances:
					providers[str(appliance.key.id())] = {
						'name': "%s of %s (Hybrid Group)" % (appliance.name, group.name),
						'location': [appliance.location.lat, appliance.location.lon],
						'flavors': []
					}

		# iterate over the dictionary of providers
		for provider in providers:
			# find the list of flavors for this provider which support this project
			flavors = Flavor.flavors_with_min_specs_by_appliance_on_sale(
				specs, 
				ndb.Key('Appliance', long(provider))
			)

			# add provider to the form and the flavors to provider object if flavors exist
			if flavors:
				plenty = True
				# insert this provider's appliance into the form
				self.form.provider.choices.insert(0, (provider, providers[provider]['name']))

				# insert flavors into object
				for flavor in flavors:
					providers[provider]['flavors'].append(
						{
							'id': str(flavor.key.id()),
							'name': flavor.name,
							'description': flavor.description
						}
					)

		# setup channel to do page refresh
		channel_token = 'changeme'
		refresh_channel = channel.create_channel(channel_token)

		# params build out
		params = {
			'project': project,
			'providers': json.dumps(providers),
			'plenty': plenty,
			'owner': owner,
			'refresh_channel': refresh_channel,
			'channel_token': channel_token 
		}

		return self.render_template('project/view.html', **params)