def edit(): if request.args: n = int(request.args[0]) m = session.models[n] if isinstance(m.labels, str): m.labels = list(m.labels) e = [SQLField("nareas", "integer", default=m.nareas, label="Number of areas", requires=IS_INT_IN_RANGE(2,10))] for i, x in enumerate(m.labels): f = SQLField("area_%s" % i, default=x, label=i, requires=IS_NOT_EMPTY()) e.append(f) form = form_factory(*e) if form.accepts(request.vars, session): for i in range(m.nareas): v = form.vars["area_%s" % i] #print i, v m.labels[i] = v e[i+1].default = v form = form_factory(*e) else: form=None return dict(form=form)
def index(): if request.vars.get('block_user'): db(db.auth_user.id == request.vars.get('block_user')).update( registration_key='blocked') response.flash = "User Blocked" elif request.vars.has_key('del_user'): db(db.auth_user.id == request.vars.get('del_user')).delete() response.flash = "User Deleted" elif request.vars.has_key('approve'): db(db.auth_user.id == request.vars['approve']).update( registration_key='') response.flash = 'Approved user %s' % db( db.auth_user.id == request.vars['approve']).select()[0].first_name elif request.vars.has_key('del_usergroup'): user_id, group_id = request.vars['del_usergroup'].split('_') db(db.auth_membership.user_id == user_id)( db.auth_membership.group_id == group_id).delete() response.flash = "Group Deleted" elif request.vars.has_key('delete'): pass users = db(db.auth_user.id > 0).select( orderby=db.auth_user.registration_key) forms_users_groups = {} for user in users: forms_users_groups[user.id] = form_factory(Field( 'group_id', label="Add Group", requires=IS_IN_DB(db, 'auth_group.id', '%(role)s')), formname='fug%s' % user.id) if forms_users_groups[user.id].accepts(request.vars, formname='fug%s' % user.id): response.flash = 'Added Group 2 User %s ' % user.first_name if not db(db.auth_membership.user_id == user.id)( db.auth_membership.group_id == forms_users_groups[ user.id].vars.group_id).count(): db.auth_membership.insert( user_id=user.id, group_id=forms_users_groups[user.id].vars.group_id) users = db(db.auth_user.id > 0).select( orderby=db.auth_user.registration_key) form_group = SQLFORM(db.auth_group, formname='form_group') if form_group.accepts(request.vars, formname='form_group'): response.flash = 'Created New Group' groups = db(db.auth_group.id > 0).select() #--------------------------------------------------- response.files.append(URL(request.application, 'static', 'data_table.css')) response.files.append( URL(request.application, 'static/dataTables/media/js', 'jquery.dataTables.min.js')) script = SCRIPT('''$(document).ready(function(){ oTable = $('#useradmin-table').dataTable({"bStateSave": true,"sPaginationType": "full_numbers"}); });''') #--------------------------------------------------- return dict(users=users, forms_users_groups=forms_users_groups, form_group=form_group, db_groups=groups, script=script)
def pickle_upload_form(): f = form_factory( SQLField("pickle", "upload", requires=IS_NOT_EMPTY(), label="Upload model from pickle file"), _action="upload_pickle" ) return f
def admin_applicant_list(): if session.login!=1: redirect(URL(r=request,f='index')) return dict() # session.admin_flag = 0 means form not accepted session.admin_flag = '0' records = '' #----- DICT FOR SORTING ------- array = {'Overall CG':'apcgpa', 'Grade In That Course':'grade', 'Previous Experience':'prev_exp',\ 'Programme Of Study':'pname'} form = form_factory( SQLField('course', label = "Select Course ", requires = IS_IN_DB(db, 'Course.id', '%(cname)s ( %(cid)s )')), SQLField('pr1', label = "Priority 1", requires = IS_IN_SET(['Overall CG',\ 'Grade In That Course', 'Previous Experience','Programme Of Study'])), SQLField('pr2', label = "Priority 2", requires = IS_IN_SET(['Overall CG','Grade In That Course',\ 'Previous Experience','Programme Of Study'])), SQLField('pr3', label = "Priority 3", requires = IS_IN_SET(['Overall CG', 'Grade In That Course', \ 'Previous Experience', 'Programme Of Study']))) if form.accepts(request.vars,session): var1 = array[request.vars.pr1] var2 = array[request.vars.pr2] var3 = array[request.vars.pr3] var = var1 + '|~' + var2 + '|~' + var3 # sorting the applicants on the priorities selected by the admin and storing in records records = db((db.AppliedFor.cid == request.vars.course) & (db.Applicant.id == db.AppliedFor.appid) & \ (db.AppliedFor.cid == db.Course.id) & (db.Applicant.program_id == db.Program.id)).select(db.Applicant.apname, \ db.Applicant.aprollno, db.Applicant.apemail_id, db.Program.pname, db.AppliedFor.grade, db.Applicant.apcgpa, orderby=(var)) # form accepted session.admin_flag = '1' # redirecting to next form redirect(URL(r = request, f = 'admin_applicant_list_2', args = [request.vars.course, var1, var2, var3])) return dict(form = form, records = records)
def faculty_applicant_list(): if (session.login!=3) : redirect(URL(r = request, f = 'index')) return dict() session.faculty_flag = 0 records = '' array = {'Overall CG':'apcgpa', 'Grade In That Course':'grade', 'Previous Experience':'prev_exp', 'Programme Of Study':'pname'} courseTaught = db((db.Faculty.femail_id == session.faculty_login_emailid) & (db.Teach.faculty_id == db.Faculty.id)\ & (db.Teach.course_id == db.Course.id)).select() form = form_factory( SQLField('course', label = "Select Course ", requires =\ IS_IN_DB(db((db.Faculty.femail_id == session.faculty_login_emailid)\ & (db.Teach.faculty_id == db.Faculty.id) & \ (db.Teach.course_id == db.Course.id)), 'Course.id', '%(cname)s ( %(cid)s )')), SQLField('pr1', label = "Priority 1", requires = IS_IN_SET(['Overall CG','Grade In That Course', \ 'Previous Experience', 'Programme Of Study'])), SQLField('pr2', label = "Priority 2", requires = IS_IN_SET(['Overall CG','Grade In That Course',\ 'Previous Experience', 'Programme Of Study'])), SQLField('pr3', label = "Priority 3", requires = IS_IN_SET(['Overall CG','Grade In That Course', \ 'Previous Experience', 'Programme Of Study']))) if form.accepts(request.vars,session): var1 = array[request.vars.pr1] var2 = array[request.vars.pr2] var3 = array[request.vars.pr3] var = var1 + '|' + var2 + '|' + var3 records = db((db.AppliedFor.cid == request.vars.course) & (db.Applicant.id == db.AppliedFor.appid) & \ (db.AppliedFor.cid==db.Course.id) & (db.Applicant.program_id == db.Program.id)).select(db.Applicant.apname, \ db.Applicant.aprollno, db.Applicant.apemail_id, db.Program.pname, db.AppliedFor.grade, db.Applicant.apcgpa, orderby=(var)) session.faculty_flag = '1' # request.vars.course = Course.id (id of the course selected by the faculty) redirect(URL(r = request, f = 'faculty_applicant_list_2', args = [request.vars.course,var1,var2,var3])) return dict(form=form, records=records)
def delete_courses(): if session.login != 1: # -------- check if admin has logged in or not ------------------- redirect(URL(r = request, f = 'index')) return dict() form = form_factory( # -------- creating form for the delete course -------------- SQLField('course', label = 'Select Course ', requires = IS_IN_DB(db, 'Course.id', '%(cname)s ( %(cid)s ) ' )), SQLField('cofferto', label = 'Select Program ', requires = IS_IN_DB(db, 'Program.id', '%(pname)s'))) return dict(form=form)
def import_pymantis_strains(): form = form_factory(Field('json_strains','text', label='JSON Strain Data', requires=IS_NOT_EMPTY())) if form.accepts(request.vars, keepvalues=True): from gluon.contrib import simplejson strain_table = simplejson.loads(form.vars.json_strains) for row in strain_table['table']: identifier = row[0] name = row[1] if not db(db.strain.name == name)(db.strain.identifier == identifier).count(): db.strain.insert(name=name, identifier=identifier) return form
def namewise_list(): # ALLOWS ADMIN TO SEE THE APPLICANT LIST NAMEWISE if (session.login != 1) : redirect(URL(r = request, f = 'index')) return dict() r = '' # form for select the applicant name form = form_factory( SQLField('applicantId', label = 'Select Applicant', requires = IS_IN_DB(db, 'Applicant.id',\ '%(apname)s (%(aprollno)s)'))) if form.accepts(request.vars, session): r = db((db.Applicant.id == db.AppliedFor.appid) & (db.Course.id == db.AppliedFor.cid) &\ (db.Applicant.id == request.vars.applicantId)).select() return dict(form = form, msg = r)
def setup_pymantis(): ''' get the mail config from the config file and create a from to edit it ''' #if not auth.has_membership(role = 'admin'): # return 'You need to login as admin to configure the SMTP server.' form = form_factory( Field('url', default = app_config.get('pymantis','url')), Field('login', default = app_config.get('pymantis', 'login'), widget=None if request.vars.show_pass else SQLFORM.widgets.password.widget, label="Login (user:password)") ) if form.accepts(request.vars, keepvalues = True): app_config.set('pymantis','url', form.vars.url) app_config.set('pymantis', 'login', form.vars.login) response.flash = 'pyMantis config saved' return form
def faculty_login(): form = form_factory( SQLField('Username', 'string', label = 'Username ', requires = IS_NOT_EMPTY()), SQLField('Password', 'password', label = 'Password ', requires = IS_NOT_EMPTY())) if form.accepts(request.vars, session): username = request.vars.Username password = request.vars.Password value = match_password(username, password, 'mail.iiit.ac.in') if(value == '1'): session.login = 3 session.faculty_login_emailid = username session.flash = 'Login Succesful' else: response.flash = 'Incorrect Username or Password' return dict(form=form)
def options(): from gluon.sqlhtml import form_factory start_vertex = SQLField('start_vertex', 'integer', default=0, requires=IS_IN_SET(range(0, session.vars['size']))) stop_vertex = SQLField('stop_vertex', 'integer', default=session.vars['size'] - 1, requires=IS_IN_SET(range(0, session.vars['size']))) init_pop_length = SQLField('init_population_length', 'integer', default=1000, requires=IS_INT_IN_RANGE(0, 10 ** 10)) genes_count = SQLField('genes_count', 'integer', default=10, requires=IS_INT_IN_RANGE(0, 10 ** 10)) population_count = SQLField('population_count', 'integer', default=300, requires=IS_INT_IN_RANGE(0, 10 ** 10)) child_cull = SQLField('child_cull', 'integer', default=200, requires=IS_INT_IN_RANGE(0, 10 ** 10)) child_count = SQLField('child_count', 'integer', default=1000, requires=IS_INT_IN_RANGE(0, 10 ** 10)) good_parents = SQLField('good_parents', 'integer', default=10, requires=IS_INT_IN_RANGE(0, 10 ** 10)) mutants = SQLField('mutants', 'double', default=0.1, requires=IS_FLOAT_IN_RANGE(0, 1)) form = form_factory(start_vertex, stop_vertex, init_pop_length, genes_count, population_count, child_cull, child_count, good_parents, mutants) if form.accepts(request.vars, session): session.vars['start_vertex'] = int(request.vars.start_vertex) session.vars['stop_vertex'] = int(request.vars.stop_vertex) session.vars['init_population_length'] = int(request.vars.init_population_length) session.vars['genes_count'] = int(request.vars.genes_count) session.vars['population_count'] = int(request.vars.population_count) session.vars['child_cull'] = int(request.vars.child_cull) session.vars['child_count'] = int(request.vars.child_count) session.vars['good_parents'] = int(request.vars.good_parents) session.vars['mutants'] = float(request.vars.mutants) redirect(URL(r=request, f='end')) return dict(form=form)
def index(): if request.vars.get('block_user'): db(db.auth_user.id == request.vars.get('block_user')).update(registration_key = 'blocked') response.flash = "User Blocked" elif request.vars.has_key('del_user'): db(db.auth_user.id == request.vars.get('del_user')).delete() response.flash = "User Deleted" elif request.vars.has_key('approve'): db(db.auth_user.id==request.vars['approve']).update(registration_key='') response.flash = 'Approved user %s'%db(db.auth_user.id==request.vars['approve']).select()[0].first_name elif request.vars.has_key('del_usergroup'): user_id,group_id = request.vars['del_usergroup'].split('_') db(db.auth_membership.user_id==user_id)(db.auth_membership.group_id==group_id).delete() response.flash = "Group Deleted" elif request.vars.has_key('delete'): pass users = db(db.auth_user.id>0).select(orderby=db.auth_user.registration_key) forms_users_groups = {} for user in users: forms_users_groups[user.id] = form_factory( Field('group_id',label="Add Group",requires = IS_IN_DB(db, 'auth_group.id', '%(role)s')), formname = 'fug%s'%user.id ) if forms_users_groups[user.id].accepts(request.vars,formname='fug%s'%user.id): response.flash = 'Added Group 2 User %s '%user.first_name if not db(db.auth_membership.user_id == user.id)(db.auth_membership.group_id == forms_users_groups[user.id].vars.group_id).count(): db.auth_membership.insert(user_id=user.id ,group_id=forms_users_groups[user.id].vars.group_id ) users = db(db.auth_user.id>0).select(orderby=db.auth_user.registration_key) form_group = SQLFORM(db.auth_group, formname='form_group') if form_group.accepts(request.vars,formname = 'form_group'): response.flash = 'Created New Group' groups = db(db.auth_group.id>0).select() #--------------------------------------------------- response.files.append(URL(request.application,'static','data_table.css')) response.files.append(URL(request.application,'static/dataTables/media/js','jquery.dataTables.min.js')) script = SCRIPT('''$(document).ready(function(){ oTable = $('#useradmin-table').dataTable({"bStateSave": true,"sPaginationType": "full_numbers"}); });''') #--------------------------------------------------- return dict(users=users, forms_users_groups = forms_users_groups, form_group = form_group, db_groups = groups, script = script)
def admin_login(): form = form_factory( SQLField('Username', 'string', requires = IS_NOT_EMPTY()), SQLField('Password', 'password', requires = IS_NOT_EMPTY())) if form.accepts(request.vars, session): username = request.vars.Username password = request.vars.Password #if valid username then check password with the server emailValue = db(db.Admin.adname == username).select(db.Admin.ademail_id) if(emailValue): for row in emailValue: email = row.ademail_id value = match_password(email, password, 'iiit.ac.in') if(value == '1'): # login successful session.login = 1 session.admin_email = email session.flash = 'Login Successful' else: # login failure response.flash = 'Incorrect Username or Password'+str(value) else: response.flash = 'Incorrect Username or Password' # incorrect username return dict(form=form)
def import_pad(): from gluon.sqlhtml import form_factory fi0 = SQLField('import_xls', 'upload', requires=IS_NOT_EMPTY("Please provide a valid PAD file")) fi1 = Field('envi', requires=IS_IN_SET(envs), default=1, widget=SQLFORM.widgets.radio.widget, label='Environment') fields = [fi0, fi1] form = form_factory(*fields, submit_button='Generate a UML schema', formstyle='table2cols') #form=form_factory(,) if form.accepts(request.vars, session): # champs correctement remplis #request.flash='Received: %s'%request.vars.import_xls #app_logging.info(request.vars.envi) #print (request.vars.import_xls.filename) fobj = request.vars.import_xls # ligne suivante indispensable et totalement inexplicable :) str(fobj) fissier = fobj.file.read() taille_fic = len(fissier) response.flash = 'Uploaded PAD : %s, size is %s bytes' % ( fobj.filename, taille_fic) PADxl_path = 'applications/%s/static/upload/%s' % ( request.application, request.vars.import_xls.filename) environment = request.vars.envi # ecrit le fichier uploadé sur le filesystem ficout = open(file=PADxl_path, mode='wb') ficout.write(fissier) ficout.close() plantu = create_plantu(PADxl_path, environment) #app_logging.info("Voila le resulat") #app_logging.info(plantu) # on doit le convertir en "percent encoding" pour qu'il passe en parametre dans l'url de 3 km de long plantu_clean = quote(plantu, safe='') # génère l'image en redirigeant sur le service plantu-service host = request.env.http_host #app_logging.info(request.env) # meme hote que l'application web mais service plantu (svg) grace au reverse-proxy URL = "https://%s/svg/%s" % (host, plantu_clean) #app_logging.info("URL:%s" % URL) redirect(URL) return dict(form=form)
def TA_application(): # checking whether applicant is logged in or not if session.login != 2 : redirect(URL(r = request , f = 'index')) return dict() msg = '' # msg is for returning to the html file record = [] # record stores the info of the applicant if he has already applied session.alreadyThereFlag = 0 # used in the corresponding html file to see if an applicant has already applied or not now = datetime.datetime.now() deadline_start = datetime.datetime(2010,12,27,0,0,0) deadline_end = datetime.datetime(2010,12,29,17,0,0) if now < deadline_start: session.flash = 'Wait till %s'%deadline_start.strftime('%d %B %Y %I:%M%p') redirect(URL(r=request,f='index')) elif now > deadline_end: # and auth.user.id != 149: session.flash = 'Deadline over at %s'%deadline_end.strftime('%d %B %Y %I:%M%p') redirect(URL(r=request,f='home_page')) if db(db.Applicant.apemail_id == session.student_email).select(): # if an applicant is already applied session.alreadyThereFlag = 1 applicantInfo = db((db.Applicant.apemail_id == session.student_email) & (db.Applicant.program_id == db.Program.id)).select() for rows in applicantInfo: record.append(rows.Applicant.apname) record.append(rows.Applicant.aprollno) record.append(rows.Program.pname) record.append(rows.Applicant.apcgpa) record.append(rows.Applicant.phoneno) if rows.Applicant.prev_exp == True : record.append('Yes') else: record.append('No') form = form_factory( # creating a form for the applicant to select course SQLField('course', label = 'Course', requires = IS_IN_DB(db, 'Course.id', '%(cname)s ( %(cid)s )')), SQLField('grade', label = 'Grade In The Course', requires = IS_IN_SET(['A','A-','B','B-','C','NA']))) else: # ------------ else if the applicant has applied for the first time --------------- form = form_factory( SQLField('name', 'string', label = 'Name', requires = IS_NOT_EMPTY()), SQLField('rollno', 'integer', label = 'Roll No',requires = IS_NOT_EMPTY()), SQLField('program', label = 'Program Of Study', requires = IS_IN_DB(db,'Program.id','%(pname)s')), # SQLField('course', label = 'Course', requires = IS_IN_DB(db, 'Course.id', '%(cname)s ( %(cid)s )')), # SQLField('grade', label = 'Grade In The Course', requires = IS_IN_SET(['A','A-','B','B-','C','NA'])), SQLField('CGPA', 'double', requires = IS_FLOAT_IN_RANGE(0,10)), SQLField('phone', 'integer', label = 'Phone No'), SQLField('experience', label = 'Previous Experience', requires = IS_IN_SET(['YES','NO']))) if form.accepts(request.vars, session): # ----------------- if the form is submitted ---------------------------- name = request.vars.name rollno = request.vars.rollno program = request.vars.program course = request.vars.course grade = request.vars.grade cgpa = request.vars.CGPA phone = request.vars.phone exp = request.vars.experience if request.vars.experience == 'YES': exp = True else: exp = False if(session.alreadyThereFlag == 1): r = db(db.Applicant.apemail_id == session.student_email).select() for rows in applicantInfo: appid = rows.Applicant.id else: # ----------- else insert and get the .id of the applicant ---------- appid = db.Applicant.insert(apname = name, aprollno = rollno , apemail_id = session.student_email, \ apcgpa = cgpa, phoneno = phone, prev_exp = exp, program_id = program) mesg = "Profile Successfully Updated !! " s = db((db.AppliedFor.appid == appid) & (db.AppliedFor.cid == course)).select() # ---- if he/she has applied for the course ----------- if(s): a = 1 session.flash = 'You have already applied for this course' redirect(URL(r = request, f = 'TA_application')) else: # else fill info in the database db.AppliedFor.insert(appid = appid , cid = course, noflag = 0, timestamp = datetime.date.today(), grade = grade) if(session.alreadyThereFlag == 1): session.flash = 'Thank You for Application' else : session.flash = mesg redirect(URL(r = request, f = 'TA_application')) return dict(form = form, record = record)
def import_file(): flag = True if request.vars.datafile != None: flise_file_zip = request.vars.datafile.file import zipfile if zipfile.is_zipfile(flise_file_zip): zf = zipfile.ZipFile(flise_file_zip, 'r') for filename in ['flise_file.csv', 'events.csv', 'subintervals.csv', 'solutions.csv', 'file.txt', 'file.rlv']: try: zf.getinfo(filename) except KeyError: flag = False if flag: import csv #strains file_strains = csv.DictReader(zf.read('strains.csv').split('\r\n')) strain_newindex = [] for strain in file_strains: strain_newindex.append([strain['strain.id']]) del strain['strain.id'] strain = dict((key.replace('strain.', ''), value) for (key, value) in strain.items()) if not db(db.strain.name == strain['name'])(db.strain.identifier == strain['identifier']).count(): db_strain = db.strain.insert(**strain) else: db_strain = db(db.strain.name == strain['name'])(db.strain.identifier == strain['identifier']).select().first() strain_newindex[-1].append(db_strain.id) strain_newindex = dict((x[0], x[1]) for x in strain_newindex) #flise file_flise = csv.DictReader(zf.read('flise_file.csv').split('\r\n')).next() del file_flise['flise_file.id'] del file_flise['flise_file.file'] file_flise = dict((key.replace('flise_file.', ''), value if value != '<NULL>' else None) for (key, value) in file_flise.items()) file_flise['series_species'] = [x for x in file_flise['series_species'].split('|')[1:-1]] if file_flise['series_species'] != None else None file_flise['series_show'] = [x for x in file_flise['series_show'].split('|')[1:-1]] if file_flise['series_show'] != None else None file_flise['series_slope'] = [x for x in file_flise['series_slope'].split('|')[1:-1]] if file_flise['series_slope'] != None else None file_flise['series_colors'] = [x for x in file_flise['series_colors'].split('|')[1:-1]] if file_flise['series_colors'] != None else None file_flise['strain_id'] = strain_newindex[file_flise['strain_id']] if file_flise['strain_id'] != None else None file_data = db.flise_file.file.store(zf.open('file.txt')) file_flise['file'] = file_data rlvfile_data = db.flise_file.rlvfile.store(zf.open('file.rlv')) file_flise['rlvfile'] = rlvfile_data db_flise_file = db.flise_file.insert(**file_flise) #solutions file_solutions = csv.DictReader(zf.read('solutions.csv').split('\r\n')) solution_newindex = [] for solution in file_solutions: solution_newindex.append([solution['solution.id']]) del solution['solution.id'] solution = dict((key.replace('solution.', ''), value if value != '<NULL>' else None) for (key, value) in solution.items()) solution['components_name'] = [x for x in solution['components_name'].split('|')[1:-1]] if solution['components_name'] != None else None solution['components_ratio'] = [x for x in solution['components_ratio'].split('|')[1:-1]] if solution['components_ratio'] != None else None db_solution = db(db.solution.name == solution['name'])(db.solution.components_name == solution['components_name'])(db.solution.components_ratio == solution['components_ratio']).select().first() if not db_solution: db_solution = db.solution.insert(**solution) solution_newindex[-1].append(db_solution.id) solution_newindex = dict((x[0], x[1]) for x in solution_newindex) #events file_events = csv.DictReader(zf.read('events.csv').split('\r\n')) event_newindex = [] for event in file_events: event_newindex.append([event['event.id']]) del event['event.id'] event = dict((key.replace('event.', ''), value if value != '<NULL>' else None) for (key, value) in event.items()) event['flise_file_id'] = db_flise_file.id event['solution_id'] = solution_newindex[event['solution_id']] if event['solution_id'] != None else None db_event = db.event.insert(**event) event_newindex[-1].append(db_event.id) #subintervals file_subintervals = csv.DictReader(zf.read('subintervals.csv').split('\r\n')) subint_newindex = [] for subint in file_subintervals: subint_newindex.append([subint['subintervals.id']]) del subint['subintervals.id'] subint = dict((key.replace('subintervals.', ''), value if value != '<NULL>' else None) for (key, value) in subint.items()) subint['flise_file_id'] = db_flise_file.id subint['slope'] = [x for x in subint['slope'].split('|')[1:-1]] if subint['slope'] != None else None subint['intercept'] = [x for x in subint['intercept'].split('|')[1:-1]] if subint['intercept'] != None else None subint['strain_id'] = strain_newindex[subint['strain_id']] if subint['strain_id'] != None else None db_subint = db.subintervals.insert(**subint) subint_newindex[-1].append(db_subint.id) zf.close() else: flag = False from gluon.sqlhtml import form_factory form = form_factory(Field('datafile', 'upload', label='or import "Flise*.zip"', uploadfield=False)) return TAG[''](JS('web2py_ajax_page("GET", "%s", "", "my_records");' % URL(r=request, f='files')) if flag else '', form if flag else TAG[''](DIV('Wrong file, cannot load.', _style='color:red'), form))
def add_courses(): if (session.login != 1) : redirect(URL(r = request, f = 'index')) return dict() #------------------------- CREATING FORM FOR THE NEW COURSE ------------------------------------ form = form_factory( SQLField('Cname', 'string', label = 'Course Name', requires = IS_NOT_EMPTY(error_message = T('fill this'))), SQLField('Cid', 'string', label = 'Course Id', requires = IS_NOT_EMPTY(error_message = T('fill this'))), SQLField('Cofferto', label = 'Course Offered To', requires = IS_IN_DB(db, 'Program.id', '%(pname)s')), SQLField('Profname', label = 'Name Of The Professor',requires = IS_NOT_EMPTY(error_message = T('fill this'))), SQLField('ProfEmail', 'string', label = 'Email Of The Professor', requires = [IS_NOT_EMPTY(error_message = T('fill this')), IS_EMAIL()]), SQLField('No_of_credits', 'integer', label = 'No Of Credits', requires = IS_NOT_EMPTY(error_message = T('fill this'))), # SQLField('NofullTA', label = 'No Of Full TAs Required'), # SQLField('NohalfTA', label = 'No Of Half TAs Required'), # SQLField('NoqrtTA', label = 'No Of Quarter TAs Required'), SQLField('No_of_Hours', label = 'No. Of Hours Per Week'), SQLField('coursetype', 'string', label = 'Type Of Course', requires = IS_IN_SET(['Full','Half'])), SQLField('semester', label = 'Semester', requires = IS_IN_DB(db, 'Semester.id', '%(semname)s'))) if form.accepts(request.vars, session): # STORING THE ENTERED VALUES IN VARIABLES cname = request.vars.Cname cid = request.vars.Cid cofferto = request.vars.Cofferto profname = request.vars.Profname profemail = request.vars.ProfEmail cdts = request.vars.No_of_credits # ft = request.vars.NofullTA # ht = request.vars.NohalfTA # qt = request.vars.NoqrtTA ctype = request.vars.coursetype semid = request.vars.semester hours = request.vars.No_of_Hours r = db(db.Course.cid == cid).select() if(r): # if course is already there in the database a = 1 for i in r: use_id = i.id # if yes then use_id <= Course.id of that course else: # else insert that course use_id = db.Course.insert(cid = cid, cname = cname, cdts = cdts,\ no_of_qta = 0, no_of_hta = 0, no_of_fta = 0, coursetype = ctype, sem_id = semid, hours_per_week = hours) s = db(db.Faculty.femail_id == profemail).select() if(s): # if faculty is already present in the database for i in s: newprof_id = i.id # if yes then newprof_if <= Faculty.id of that faculty else: newprof_id = db.Faculty.insert(fname = profname, femail_id = profemail) # else insert that faculty k = db((db.Teach.faculty_id == newprof_id) & (db.Teach.course_id == use_id)).select() if(k): # if both of them are present in TEACH table do nothing a = 1 else: # else insert db.Teach.insert(faculty_id = newprof_id, course_id = use_id) response.flash = "Course Successfully added !!!" offer = db((db.OfferedTo.cid == use_id) & (db.OfferedTo.programid == cofferto)).select() # insert in OfferedTo table if(offer): a = 1 else: db.OfferedTo.insert(cid = use_id, programid = cofferto) return dict(form=form)