def group_test_db_init(): db.init_app(app) with app.app_context(): sector = Sectors(id=1, zone="GC", sector="GC_A", description="Arts") db.session.add(sector) sector = Sectors(id=2, zone="GC", sector="GC_BF", description="Banking and Finance") db.session.add(sector) sector = Sectors(id=25, zone="TEST", sector="TEST_DEV", description="Development test cases") db.session.add(sector) db.session.commit() group = Groups(id=1, s_group='GC_A', description='Arts', sector_id=1) db.session.add(group) group = Groups(id=2, s_group='GC_BF', description='Banking and Finance', sector_id=2) db.session.add(group) yield with app.app_context(): Groups.query.delete() Sectors.query.delete() db.session.commit()
def seed_groups(db, app): group = Groups(id=1, s_group='GC_A', description='Arts', sector_id=1) with app.app_context(): db.session.add(group) db.session.commit() group = Groups(id=2, s_group='GC_BF', description='Banking and Finance', sector_id=2) with app.app_context(): db.session.add(group) db.session.commit()
def savegroup(): user_id=request.args.get('user_id') groupname=request.args.get('groupname') g=Groups(groupname=groupname,user_id=user_id) db.session.add(g) db.session.commit() return " "
def add_group(): new_group = Groups() new_group.group_name = request.json["group_name"] new_group.group_emails = request.json["emails"] new_group.owner_id = request.json["owner_id"] if new_group.group_name != "" and new_group.owner_id != "": db.session.add(new_group) db.session.commit() return jsonify(success=True, group_id=new_group.id)
def GroupsView(request): if request.method == 'POST': form = GroupsForm(request.POST) if form.validate(): dataFromForm = {} for field in form: dataFromForm[field.name] = field._value() newRecord = Groups(**dataFromForm) session.add(newRecord) session.commit() # return HttpResponseRedirect('cache/inc.html') # show saved record else: form = GroupsForm() return render(request, 'cache/inpt.html', {'form': form})
def org_test_db_build(): db.init_app(app) with app.app_context(): group = Groups( id=1, s_group='GC_A', description='Arts', ) db.session.add(group) group = Groups( id=2, s_group='GC_BF', description='Banking and Finance', ) db.session.add(group) org = Organizations(id=1, organization='Arts', description='Arts', group_id=1) db.session.add(org) org = Organizations(id=6, organization='BOC', description='BOC - Bank of Canada', group_id=2) db.session.add(org) db.session.commit() yield with app.app_context(): Organizations.query.delete() Groups.query.delete() db.session.commit()
def createGroup(): if request.method == 'GET': courses = Courses.query.all() return render_template('admin/group/create.html', courses=courses) else: #get and validate input params group_name = request.form['name'] group_n = request.form['n'] #group_cfu = request.form['cfu'] group_courses_id = request.form.getlist("course_id[]") #create Group obj and append courses objs group = Groups(name=group_name) group.n = int(group_n) # group.cfu = group_cfu for course_id in group_courses_id: course = Courses.query.get(course_id) group.courses.append(course) if isValidGroup(group): db.session.add(group) db.session.commit() return redirect(url_for('indexGroup'))
def create_group(): teacher = get_current_teacher() user = get_current_user() try: if not user.xojakent_admin and not user.gazalkent_admin and not user.director: return redirect(url_for('home')) except AttributeError: return redirect(url_for('home')) if request.method == 'POST': name = request.form.get("name") teachers = request.form.get("teacher") group_location = request.form.get('location') type_of_course = request.form.get('type_of_course') cost = request.form.get('cost') if group_location == "xojakent": group_location = 1 num = 1 groups_num = All_groups.all_groups + num All_groups.query.filter_by(id=1).update({'all_groups': groups_num}) db.session.commit() teach = Teachers.query.filter_by(id=teachers).first() total = teach.number_groups + num Teachers.query.filter_by(id=teachers).update( {'number_groups': total}) db.session.commit() elif group_location == "gazalkent": group_location = 2 num = 1 groups_num = All_groups.all_groups + num All_groups.query.filter_by(id=1).update({'all_groups': groups_num}) db.session.commit() teach = Teachers.query.filter_by(id=teachers).first() total = teach.number_groups + num Teachers.query.filter_by(id=teachers).update( {'number_groups': total}) db.session.commit() teacher_id = Teachers.query.filter_by(id=teachers).first() teacher_name = Teachers.query.filter_by(id=teachers).first() teacher_surname = Teachers.query.filter_by(id=teachers).first() if user.director: add = Groups(name=name, teacher_1=teacher_id.id, location=group_location, subject=teacher_id.subject, cost=cost, teacher_name=teacher_name.name, teacher_surname=teacher_surname.surname, type_of_course=type_of_course) db.session.add(add) else: add = Groups(name=name, teacher_1=teacher_id.id, location=user.locations, subject=teacher_id.subject, cost=cost, teacher_name=teacher_name.name, teacher_surname=teacher_surname.surname, type_of_course=type_of_course) db.session.add(add) show = Groups.query.filter_by(name=name).all() teachers1 = Teachers.query.filter_by(id=teachers).all() query_teacher = Teachers.query.filter_by(id=teachers).first() for i in show: if query_teacher.group1 is None and query_teacher.group2 is None and query_teacher.group3 is None and \ query_teacher.group4 is None and query_teacher.group5 is None and \ query_teacher.group6 is None and query_teacher.group7 is None and \ query_teacher.group8 is None and query_teacher.group9 is None and query_teacher.group10 is None: Teachers.query.filter_by(id=teachers).update({'group1': i.id}) elif query_teacher.group1 is not None and query_teacher.group2 is None and query_teacher.group3 is None \ and query_teacher.group4 is None and query_teacher.group5 is None and \ query_teacher.group6 is None and query_teacher.group7 is None and \ query_teacher.group8 is None and query_teacher.group9 is None and query_teacher.group10 is None: if query_teacher.group1 == i.id: return 'Bu grda ustoz uje bor' else: Teachers.query.filter_by(id=teachers).update( {'group2': i.id}) elif query_teacher.group1 is not None and query_teacher.group2 is not None and query_teacher.group3 is None \ and query_teacher.group4 is None and query_teacher.group5 is None and \ query_teacher.group6 is None and query_teacher.group7 is None and \ query_teacher.group8 is None and query_teacher.group9 is None and query_teacher.group10 is None: if query_teacher.group1 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group2 == i.id: return 'Bu grda ustoz uje bor' else: Teachers.query.filter_by(id=teachers).update( {'group3': i.id}) elif query_teacher.group1 is not None and query_teacher.group2 is not None and query_teacher.group3 is not None \ and query_teacher.group4 is None and query_teacher.group5 is None and \ query_teacher.group6 is None and query_teacher.group7 is None and \ query_teacher.group8 is None and query_teacher.group9 is None and query_teacher.group10 is None: if query_teacher.group1 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group2 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group3 == i.id: return 'Bu grda ustoz uje bor' else: Teachers.query.filter_by(id=teachers).update( {'group4': i.id}) elif query_teacher.group1 is not None and query_teacher.group2 is not None and query_teacher.group3 is not None \ and query_teacher.group4 is not None and query_teacher.group5 is None and \ query_teacher.group6 is None and query_teacher.group7 is None and \ query_teacher.group8 is None and query_teacher.group9 is None and query_teacher.group10 is None: if query_teacher.group1 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group2 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group3 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group4 == i.id: return 'Bu grda ustoz uje bor' else: Teachers.query.filter_by(id=teachers).update( {'group5': i.id}) elif query_teacher.group1 is not None and query_teacher.group2 is not None and query_teacher.group3 is not None \ and query_teacher.group4 is not None and query_teacher.group5 is not None and \ query_teacher.group6 is None and query_teacher.group7 is None and \ query_teacher.group8 is None and query_teacher.group9 is None and query_teacher.group10 is None: if query_teacher.group1 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group2 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group3 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group4 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group5 == i.id: return 'Bu grda ustoz uje bor' else: Teachers.query.filter_by(id=teachers).update( {'group6': i.id}) elif query_teacher.group1 is not None and query_teacher.group2 is not None and query_teacher.group3 is not None \ and query_teacher.group4 is not None and query_teacher.group5 is not None and \ query_teacher.group6 is not None and query_teacher.group7 is None and \ query_teacher.group8 is None and query_teacher.group9 is None and query_teacher.group10 is None: if query_teacher.group1 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group2 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group3 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group4 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group5 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group6 == i.id: return 'Bu grda ustoz uje bor' else: Teachers.query.filter_by(id=teachers).update( {'group7': i.id}) elif query_teacher.group1 is not None and query_teacher.group2 is not None and query_teacher.group3 is not None \ and query_teacher.group4 is not None and query_teacher.group5 is not None and \ query_teacher.group6 is not None and query_teacher.group7 is not None and \ query_teacher.group8 is None and query_teacher.group9 is None and query_teacher.group10 is None: if query_teacher.group1 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group2 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group3 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group4 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group5 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group6 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group7 == i.id: return 'Bu grda ustoz uje bor' else: Teachers.query.filter_by(id=teachers).update( {'group8': i.id}) elif query_teacher.group1 is not None and query_teacher.group2 is not None and query_teacher.group3 is not None \ and query_teacher.group4 is not None and query_teacher.group5 is not None and \ query_teacher.group6 is not None and query_teacher.group7 is not None and \ query_teacher.group8 is not None and query_teacher.group9 is None and query_teacher.group10 is None: if query_teacher.group1 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group2 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group3 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group4 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group5 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group6 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group7 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group8 == i.id: return 'Bu grda ustoz uje bor' else: Teachers.query.filter_by(id=teachers).update( {'group9': i.id}) elif query_teacher.group1 is not None and query_teacher.group2 is not None and query_teacher.group3 is not None \ and query_teacher.group4 is not None and query_teacher.group5 is not None and \ query_teacher.group6 is not None and query_teacher.group7 is not None and \ query_teacher.group8 is not None and query_teacher.group9 is not None and query_teacher.group10 is None: if query_teacher.group1 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group2 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group3 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group4 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group5 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group6 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group7 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group8 == i.id: return 'Bu grda ustoz uje bor' elif query_teacher.group9 == i.id: return 'Bu grda ustoz uje bor' else: Teachers.query.filter_by(id=teachers).update( {'group10': i.id}) calc = Student.query.filter_by(for_group=True).all() calculate = len(calc) Groups.query.filter_by(name=name).update( {'number_students': calculate}) query = Student.query.filter_by(for_group=True).first() for q in teachers1: for i in show: if query.group1 is None and query.group2 is None and query.group3 is None: if q.subject == query.subject_1: Student.query.filter_by(for_group=True).update({ 'group1': i.id, 'for_group': False, 'subject_1': None }) elif q.subject == query.subject_2: Student.query.filter_by(for_group=True).update({ 'group1': i.id, 'for_group': False, 'subject_2': None }) elif q.subject == query.subject_3: Student.query.filter_by(for_group=True).update({ 'group1': i.id, 'for_group': False, 'subject_3': None }) elif query.group1 is not None and query.group2 is None and query.group3 is None: if query.group1 == i.id: return 'Bu gruppa band' else: if q.subject == query.subject_1: Student.query.filter_by(for_group=True).update({ 'group2': i.id, 'for_group': False, 'subject_1': None }) elif q.subject == query.subject_2: Student.query.filter_by(for_group=True).update({ 'group2': i.id, 'for_group': False, 'subject_2': None }) elif q.subject == query.subject_3: Student.query.filter_by(for_group=True).update({ 'group2': i.id, 'for_group': False, 'subject_3': None }) elif query.group1 is not None and query.group2 is not None and query.group3 is None: if query.group1 == i.id: return 'Bu gruppa band' elif query.group2 == i.id: return 'Bu gruppa band' else: if q.subject == query.subject_1: Student.query.filter_by(for_group=True).update({ 'group3': i.id, 'for_group': False, 'subject_1': None }) elif q.subject == query.subject_2: Student.query.filter_by(for_group=True).update({ 'group3': i.id, 'for_group': False, 'subject_2': None }) elif q.subject == query.subject_3: Student.query.filter_by(for_group=True).update({ 'group3': i.id, 'for_group': False, 'subject_3': None }) experts = Teachers.query.filter_by(teacher=True).all() student1 = Student.query.filter_by(for_group=True).all() student = Student.query.filter_by(for_group=True).first() db.session.commit() return render_template('Groups/create group.html', user=user, teachers=experts, student1=student1, teacher=teacher, student=student)