def _set_common_attributes(self, user): _UserProfileForm._set_common_attributes(self, user) bind_privileges(user.own_privileges, self.data["privileges"], user) bound_groups = set(g.name for g in user.groups) choosen_groups = set(self.data["groups"]) group_mapping = dict((g.name, g) for g in Group.query.all()) # delete groups for group in bound_groups - choosen_groups: user.groups.remove(group_mapping[group]) # and add new groups for group in choosen_groups - bound_groups: user.groups.append(group_mapping[group])
def _set_common_attributes(self, group): forms.set_fields(group, self.data) bind_privileges(group.privileges, self.data["privileges"])