Ejemplo n.º 1
0
	def post(self):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))

		# load form values
		name = self.form.name.data.strip()
		description = self.form.description.data.strip()

		# check if we have it already
		if Group.get_by_name(name):
			self.add_message("A group with that name already exists!", "error")
			return self.redirect_to('account-groups')

		# check what was returned from form validates
		if not self.form.validate():          
			self.add_message("The new group form did not validate.", "error")
			return self.get()

		# create the group
		group = Group(
			name = name,
			description = description,
			owner = user_info.key,
		)
		group.put()

		# create the group member entry
		groupmember = GroupMembers(
			group = group.key,
			member = user_info.key,
			invitor = user_info.key, # same same
			active = True
		)
		groupmember.put()
		
		# log to alert
		self.add_message("Group %s successfully created!" % name, "success")

		# give it a few seconds to update db, then redirect
		time.sleep(1)
		return self.redirect_to('account-groups-configure', group_id = group.key.id())
Ejemplo n.º 2
0
    def post(self):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # load form values
        name = self.form.name.data.strip()
        description = self.form.description.data.strip()

        # check if we have it already
        if Group.get_by_name(name):
            self.add_message("A group with that name already exists!", "error")
            return self.redirect_to('account-groups')

        # check what was returned from form validates
        if not self.form.validate():
            self.add_message("The new group form did not validate.", "error")
            return self.get()

        # create the group
        group = Group(
            name=name,
            description=description,
            owner=user_info.key,
        )
        group.put()

        # create the group member entry
        groupmember = GroupMembers(
            group=group.key,
            member=user_info.key,
            invitor=user_info.key,  # same same
            active=True)
        groupmember.put()

        # log to alert
        self.add_message("Group %s successfully created!" % name, "success")

        # give it a few seconds to update db, then redirect
        time.sleep(1)
        return self.redirect_to('account-groups-configure',
                                group_id=group.key.id())
Ejemplo n.º 3
0
    def post(self):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # initialize form choices for group
        self.form.group.choices = []

        # add list of user's groups, if any
        groups = GroupMembers.get_user_groups(user_info.key)
        for group in groups:
            self.form.group.choices.insert(0,
                                           (str(group.key.id()), group.name))

        # public group
        self.form.group.choices.insert(0, ('public', "Public"))

        # check if we are getting a custom group entry
        if self.form.group.data == "custom":
            # check if the group exists
            if Group.get_by_name(self.form.custom.data.strip()):
                self.add_message("A group with that name already exists!",
                                 "error")
                return self.redirect_to('account-appliances')

            # make the new group
            group = Group(name=self.form.custom.data.strip(),
                          owner=user_info.key)
            group.put()
            group_key = group.key

            # create the group member entry
            groupmember = GroupMembers(
                group=group_key,
                member=user_info.key,
                invitor=user_info.key,  # same same
                active=True)
            groupmember.put()

            # hack the form with new group
            self.form.group.choices.insert(0, ('custom', "Custom"))
        else:
            # grab an existing group
            if self.form.group.data.strip() == 'public':
                # no group for public appliances
                group_key = None
            else:
                # check membership
                group = Group.get_by_id(int(self.form.group.data.strip()))
                if GroupMembers.is_member(user_info.key, group.key):
                    group_key = group.key
                else:
                    group_key = None

        # check what was returned from the rest of the form validates
        if not self.form.validate():
            self.add_message("The new appliance form did not validate.",
                             "error")
            return self.get()

        # load form values
        name = self.form.name.data.strip()
        token = self.form.token.data.strip()

        # check if we have it already - all that work bitches?
        if Appliance.get_by_token(token):
            self.add_message("An appliance with that token already exists!",
                             "error")
            return self.redirect_to('account-appliances')

        # save the new appliance in our database
        appliance = Appliance(name=name,
                              token=token,
                              group=group_key,
                              owner=user_info.key)
        appliance.put()

        # log to alert
        self.add_message("Appliance %s successfully created!" % name,
                         "success")

        # give it a few seconds to update db, then redirect
        time.sleep(1)
        return self.redirect_to('account-appliances')
Ejemplo n.º 4
0
    def post(self):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # initialize form choices for group
        self.form.group.choices = []

        # add list of user's groups, if any
        groups = GroupMembers.get_user_groups(user_info.key)
        for group in groups:
            self.form.group.choices.insert(0, (str(group.key.id()), group.name))

            # public group
        self.form.group.choices.insert(0, ("public", "Public"))

        # check if we are getting a custom group entry
        if self.form.group.data == "custom":
            # check if the group exists
            if Group.get_by_name(self.form.custom.data.strip()):
                self.add_message("A group with that name already exists!", "error")
                return self.redirect_to("account-appliances")

                # make the new group
            group = Group(name=self.form.custom.data.strip(), owner=user_info.key)
            group.put()
            group_key = group.key

            # create the group member entry
            groupmember = GroupMembers(
                group=group_key, member=user_info.key, invitor=user_info.key, active=True  # same same
            )
            groupmember.put()

            # hack the form with new group
            self.form.group.choices.insert(0, ("custom", "Custom"))
        else:
            # grab an existing group
            if self.form.group.data.strip() == "public":
                # no group for public appliances
                group_key = None
            else:
                # check membership
                group = Group.get_by_id(int(self.form.group.data.strip()))
                if GroupMembers.is_member(user_info.key, group.key):
                    group_key = group.key
                else:
                    group_key = None

                    # check what was returned from the rest of the form validates
        if not self.form.validate():
            self.add_message("The new appliance form did not validate.", "error")
            return self.get()

            # load form values
        name = self.form.name.data.strip()
        token = self.form.token.data.strip()

        # check if we have it already - all that work bitches?
        if Appliance.get_by_token(token):
            self.add_message("An appliance with that token already exists!", "error")
            return self.redirect_to("account-appliances")

            # save the new appliance in our database
        appliance = Appliance(name=name, token=token, group=group_key, owner=user_info.key)
        appliance.put()

        # log to alert
        self.add_message("Appliance %s successfully created!" % name, "success")

        # give it a few seconds to update db, then redirect
        time.sleep(1)
        return self.redirect_to("account-appliances")