def add_member_to_homegroup(homegroup_id, member_id): inactive_homegroup_members = db.get_homegroup_inactive_members(homegroup_id) new = 'Y' for members in inactive_homegroup_members: print(members['member_id']) if int (members['member_id']) == int(member_id): new = 'N' db.reactive_homegroup_member(homegroup_id, member_id) print(new) if new == 'Y': db.add_member_to_homegroup(homegroup_id, member_id) member = db.find_member(member_id) flash ("Member {} added to homegroup".format(member['first_name'] + " " + member['last_name'])) return redirect (url_for('get_homegroup_members', homegroup_id = homegroup_id))
def test_split_homegroup(self): hg_status = self.create_homegroup() self.assertEqual(hg_status['rowcount'], 1) to_split_id = hg_status['id'] members = [] for idx in range(0, 10): member_status = self.create_test_member(suffix=str(idx)) member_id = member_status['id'] members.append(member_id) db.add_member_to_homegroup(to_split_id, member_id) hg_status = self.create_homegroup() split1_id = hg_status['id'] hg_status = self.create_homegroup() split2_id = hg_status['id'] cnt = 0 for member in members: if cnt % 2 == 0: group = 'one' else: group = 'two' cnt += 1 #/split_member/<member_id>/<homegroup_id>/<homegroup_id1>/<homegroup_id2>/<group> resp = self.post( url_for('split_member', member_id=member, homegroup_id=to_split_id, homegroup_id1=split1_id, homegroup_id2=split2_id, group=group), {}) new_members = db.get_homegroup_members(to_split_id) self.assertEqual(len(new_members), 0) new_members1 = db.get_homegroup_members(split1_id) self.assertEqual(len(new_members1), 5) new_members2 = db.get_homegroup_members(split1_id) self.assertEqual(len(new_members2), 5) for idx in range(0, 10): home_group = db.find_member_homegroup(members[idx]) if idx % 2 == 0: self.assertEqual(home_group['homegroup_id'], split1_id) else: self.assertEqual(home_group['homegroup_id'], split2_id)
def create_new_member_for_homegroup(homegroup_id): member = CreateMemberForm() if request.method == "POST" and member.validate(): first_name = member.first_name.data last_name = member.last_name.data email = member.email.data phone_number = member.phone_number.data gender = member.gender.data birthday = request.form['Birthday'] baptism_status = member.baptism_status.data marital_status = member.marital_status.data join_date = request.form['JoinDate'] rowcount = db.create_member(first_name, last_name, email, phone_number, gender, birthday, baptism_status, marital_status, join_date) if rowcount == 1: row = db.recent_member() member_id = row['id'] db.add_member_to_homegroup(homegroup_id, member_id) flash("Member {} Created!".format(member.first_name.data, member.last_name.data)) return redirect(url_for('get_homegroup_members', homegroup_id=homegroup_id)) return render_template('create_member.html', form=member, homegroup_id=homegroup_id)