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 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 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 addnew(request): groups = request.META.get('ADFS_GROUP','') groupsList = groups.split(';') ; ## Check the user has cloudman resource manager privileges userIsSuperUser = isSuperUser(groupsList) '''if not userIsSuperUser: message = "You don't have cloudman resource manager privileges. Hence you are not authorized to add new Group"; html = "<html><body> %s.</body></html>" % message return HttpResponse(html) ''' ## if the request is through form submission, then add the group or else return a new form if request.method == 'POST': ## Validate the form by checking whether all the required values are provided or not form = GroupsForm(request.POST) if form.is_valid(): redirectURL = '/cloudman/message/?msg=' name = form.cleaned_data['name'] groupExists = checkNameIgnoreCase(name) if groupExists: msgAlreadyExists = 'Group ' + name + ' already exists. Hence Add Group Operation Failed' return HttpResponseRedirect(redirectURL + msgAlreadyExists); description = form.cleaned_data['description'] admin_group = form.cleaned_data['admin_group'] comment = form.cleaned_data['comment'] ## check first whether the admin_group exists in the local egroup table ## if not, then in the remote egroup database through ldap. If exists here, then add to the local table egroup = None try: egroup = Egroups.objects.get(name=admin_group) except Egroups.DoesNotExist: if not (checkEGroup(admin_group)): errorMessage = 'Admin E-Group Entered ' + admin_group + ' does not exists' return HttpResponseRedirect(redirectURL + errorMessage) else: egroup = Egroups(name=admin_group) egroup.save() ## Create the group and return a success message to the user groupObj = Groups(name=name, description=description, admin_group=egroup) groupObj.save() groupObj = Groups.objects.get(name=name) if addLog(request,name,comment,groupObj,None,'group','add',True): msgSuccess = 'New group ' + name + ' added successfully' else: transaction.rollback() msgSuccess = 'Error in creating group ' + name html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/group/list/\"></HEAD><body> %s.</body></html>" % msgSuccess return HttpResponse(html) else: form = GroupsForm() return render_to_response('group/addnew.html',locals(),context_instance=RequestContext(request))
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 getCards_Group(cls,user_id): dic={} groups=User.getGroups(user_id) for g in groups: cardlist=[getBrife(card.user_id) for card in Groups.getCards(g)] dic[g.groupname]=cardlist return dic
def getCards_Group(cls, user_id): dic = {} groups = User.getGroups(user_id) for g in groups: cardlist = [getBrife(card.user_id) for card in Groups.getCards(g)] dic[g.groupname] = cardlist return dic
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 submit_group(request, group_name="none"): if request.user.is_authenticated(): top_groups = helper_func.calc_top_groups() saved_groups = helper_func.find_saved_groups(request.user) if request.method == "POST": form = GroupForm(request.POST) if form.is_valid(): if " " in request.POST['group']: form._errors['group'] = ErrorList([u"Spaces are not allowed"]) return render_to_response('submitgroup.html', {'form': form, 'user': request.user, 'top_groups': top_groups, 'saved_groups': saved_groups, 'group_name': group_name}, context_instance=RequestContext(request)) group= Groups(groupname= request.POST['group'], privacy= request.POST['privacy']) group.save() groupname = request.POST['group'] return HttpResponseRedirect('/success/'+ str(groupname)) else: data = {'group': group_name, 'privacy': 0} if group_name == "none": form = GroupForm() else: form = GroupForm(data) return render_to_response('submitgroup.html', {'form': form, 'user': request.user, 'top_groups': top_groups, 'saved_groups': saved_groups, 'group_name': group_name}, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/accounts/login/?next=/submitgroup/')
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 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)
async def get_groups(): return await Group_Pydantic.from_queryset(Groups.all())