コード例 #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, group_id=None):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # get the group in question
        group = Group.get_by_id(long(group_id))

        # scan if this user is a member and/or admin
        if group.owner == user_info.key:
            is_admin = True
            is_member = True  # obvious
        else:
            is_admin = False
            is_member = GroupMembers.is_member(user_info.key, group.key)

        # bail if group doesn't exist or user isn't in the membership list
        if not group or not is_member:
            return self.redirect_to('account-groups')

        # get the members
        members = GroupMembers.get_group_users(group.key)

        # create an object with appliance counts per user
        appliance_count = {}
        for member in members:
            # get the appliance counts per user for this group
            count = Appliance.get_appliance_count_by_user_group(
                member.key, group.key)
            appliance_count[member.key.id()] = count

        # setup channel to do page refresh
        channel_token = user_info.key.urlsafe()
        refresh_channel = channel.create_channel(channel_token)

        # params build out - ugly cause instructions/admin stuff
        params = {
            'is_admin': is_admin,
            'is_member': is_member,
            'group': group,
            'members': members,
            'appliance_count': appliance_count,
            'num_members': len(members),
            'gmform': self.gmform,
            'refresh_channel': refresh_channel,
            'channel_token': channel_token
        }

        return self.render_template('groups/group_manage.html', **params)
コード例 #4
0
ファイル: grouphandlers.py プロジェクト: StackMonkey/site
	def get(self, group_id = None):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))
		
		# get the group in question
		group = Group.get_by_id(long(group_id))

		# scan if this user is a member and/or admin
		if group.owner == user_info.key:
			is_admin = True
			is_member = True # obvious
		else:
			is_admin = False
			is_member = GroupMembers.is_member(user_info.key, group.key)

		# bail if group doesn't exist or user isn't in the membership list
		if not group or not is_member:
			return self.redirect_to('account-groups')

		# get the members
		members = GroupMembers.get_group_users(group.key)

		# create an object with appliance counts per user
		appliance_count = {}
		for member in members:
			# get the appliance counts per user for this group
			count = Appliance.get_appliance_count_by_user_group(member.key, group.key)
			appliance_count[member.key.id()] = count

		# setup channel to do page refresh
		channel_token = user_info.key.urlsafe()
		refresh_channel = channel.create_channel(channel_token)

		# params build out - ugly cause instructions/admin stuff
		params = {
			'is_admin': is_admin,
			'is_member': is_member,
			'group': group,
			'members': members,
			'appliance_count': appliance_count,
			'num_members': len(members),
			'gmform': self.gmform,
			'refresh_channel': refresh_channel,
			'channel_token': channel_token 
		}

		return self.render_template('groups/edit.html', **params)