def edvent(self, *args, **kw): try: valevent= urlgetit() #if valevent:valevent=int(valevent[valevent.find('=')+1:]) if valevent: thisevent=DBSession.query(TheEvent).filter_by(id=valevent).one() for d in DBSession.query(TheEvent).filter_by(id=int(ThisEvent)): DBSession.delete(d) transaction.commit() model.DBSession.flush() edate=re.split('/', str(kw['Event_Date'])) emonth=int(edate[0]) eday=int(edate[1]) eyear=int(edate[2]) C=model.TheEvent() C.month=emonth C.day=eday C.year=eyear if kw['Event_Type']: C.typ=kw['Event_Type'] C.Description=kw['Description'] try: adddoc=DBSession.query(Doc).filter_by(name=kw["Link_a_Document:0:Select_a_Document_for_Event"]).one() except: adddoc=None C.doc=adddoc model.DBSession.add(C) transaction.commit() model.DBSession.flush() flash(kw['Description'] +" was successfully added.--Add another.") redirect("AddEvent") except: flash("some sort of problem") redirect("AddEvent")
def delevent(self, *args, **kw): try: valevent= urlgetit() if valevent: for d in DBSession.query(TheEvent).filter_by(id=int(valevent)): DBSession.delete(d) transaction.commit() model.DBSession.flush() msg= name + "was deleted" flash(msg) redirect("eventlist") except: msg= " Oh shit" flash(msg) redirect('eventlist') return dict( page='Deleting an Event',msg=msg)
def Chart(self, *args, **kwargs): curS.curSchools=kwargs self.data=kwargs tempsubAll=[] subfundsel=[] subfundAll=[] if kwargs: if 'schools_id' in kwargs: curSchool=kwargs['schools_id'][1:] subtype=kwargs["schools_id"][0] if subtype=="c": flabel="Club Sub Funds" selSchool = DBSession.query(Clubs).filter_by(schools_id=int(curSchool)).order_by(Clubs.SubNo).all() if subtype=="a": flabel="Athletic Sub Funds" selSchool = DBSession.query(Activities).filter_by(schools_id=int(curSchool)).order_by(Activities.SubNo).all() if subtype=="t": flabel="Accounts" selSchool = DBSession.query(Chart).filter_by(schools_id=int(curSchool)).order_by(Chart.AcctNo).all() for a in selSchool: subfundsel.append(str(a.accounts.AcctNo)+" " +str(a.accounts.Description)) for r in DBSession.query(Account).order_by(Account.AcctNo).all(): includeit=True for w in subfundsel: if int(w[:4])==int(r.AcctNo): includeit=False if includeit==True and int(r.AcctNo)>1159: subfundAll.append(str(r.AcctNo)+" " +str(r.Description)) if subtype=="c" or subtype=="a": for a in selSchool: subfundsel.append(str(a.SubNo)+" " +str(a.subs.Description)) for r in DBSession.query(Sub).order_by(Sub.SubNo).all(): if subtype=="c" and int(r.SubNo)>799 and int(r.SubNo)<900: includeit=True for w in subfundsel: if int(w[:4])==int(r.SubNo): includeit=False if includeit==True: subfundAll.append(str(r.SubNo)+" " +str(r.Description)) if subtype=="a" and int(r.SubNo)>599 and int(r.SubNo)<700: includeit=True for w in subfundsel: if int(w[:4])==int(r.SubNo): includeit=False if includeit==True: subfundAll.append(str(r.SubNo)+" " +str(r.Description)) if 'chartsel' in kwargs: forFlash=[] NEWClubs=[] tClub=[] #nSchool=[] nSchool=int(curS.curSchools['schools_id'][1:])#int(curSchool) subtype=subtype=curS.curSchools["schools_id"][0]#str(subtype) nSchool1=DBSession.query(Schools).filter_by(id=int(nSchool)).one() if subtype=="c" or subtype=="a": for r in DBSession.query(Sub).order_by(Sub.SubNo).all(): if subtype=="c" and int(r.SubNo)>799 and int(r.SubNo)<900: tClub.append(r) if subtype=="a" and int(r.SubNo)>599 and int(r.SubNo)<700: tClub.append(r) if subtype=="t": for r in DBSession.query(Account).order_by(Account.AcctNo).all(): tClub.append(r) select=kwargs['chartsel'][0:-1].split(',') Items=() lkw=len(select) #Items=pickle.dumps(kw['itemselector']) Items=(str(kwargs['chartsel'])[1:lkw]) if lkw>0: i=0 while i <lkw: if subtype=="c" or subtype=="a": if select[i][0:3] !="": nClub=select[i][0:3] else: i=i+1 nClub=select[i][0:3] if subtype=="t": if select[i][0:4] !="": nClub=select[i][0:4] else: nClub=select[i][0:4] NEWClubs.append(nClub) if subtype=="c" or subtype=="a" and nClub != "":Club1=DBSession.query(Sub).filter_by(SubNo=str(nClub)).one() if subtype=="t": Acct1=DBSession.query(Account).filter_by(AcctNo=str(nClub)).one() if subtype=="c": schclubs=DBSession.query(Schools).options(eagerload('clubs')).filter_by(id=int(nSchool)).one() schclubClubs=schclubs.clubs if subtype=="a": schclubs=DBSession.query(Schools).options(eagerload('activities')).filter_by(id=int(nSchool)).one() schclubClubs=schclubs.activities if subtype=="t": schclubs=DBSession.query(Schools).options(eagerload('charts')).filter_by(id=int(nSchool)).one() schclubClubs=schclubs.charts doit=True for club in schclubClubs: if str(club)==str(nClub): doit=False if doit==True: if subtype=="c": C=model.Clubs() if subtype=="a": C=model.Activities() if subtype=="t": C=model.Chart() if subtype=="c" or subtype=="a": C.SubNo=str(nClub) C.subs_id=int(Club1.id) C.schools_id=nSchool1.id if subtype=="t": #C.AcctNo=str(nClub) if Acct1.SchoolWide==True and Acct1.SchoolActivity==False:C.fundid=1 if Acct1.SchoolWide==False and Acct1.SchoolActivity==True:C.fundid=2 if Acct1.SchoolWide==True and Acct1.SchoolActivity==True:C.fundid=3 C.AcctNo=str(nClub) C.accounts_id=int(Acct1.id) C.schools_id=int(nSchool1.id) model.DBSession.add(C) i=i+1 transaction.commit() model.DBSession.flush() if subtype=="c": for d in DBSession.query(Clubs).filter_by(schools_id=int(nSchool)): deleteit=True if len(NEWClubs)>0: for row in NEWClubs: if row <>None: if int(d.SubNo)==int(row): deleteit=False if deleteit==True: DBSession.delete(d) transaction.commit() model.DBSession.flush() if subtype=="a": for d in DBSession.query(Activities).filter_by(schools_id=int(nSchool)): deleteit=True if len(NEWClubs)>0: for row in NEWClubs: if row <>None: if int(d.SubNo)==int(row): deleteit=False if deleteit==True: DBSession.delete(d) transaction.commit() model.DBSession.flush() if subtype=="t": always=[1,20,15,16,17,18,19,6,7,8,9,10,11,12,13,14] forFlash=[1100,1170,1410,1420,1430,1810,1910,2100,2300,2600,3200,3300,3400,3500,3600,3999] for d in DBSession.query(Chart).filter_by(schools_id=int(nSchool)): deleteit=True if len(NEWClubs)>0: for row in NEWClubs: if row <>None: if int(d.accounts.AcctNo)==int(row): deleteit=False else: for z in always: if d.accounts.id==z: deleteit=False for tt in forFlash: if int(row)==int(tt):forFlash.remove(tt) if deleteit==True: DBSession.delete(d) transaction.commit() model.DBSession.flush() if len(forFlash)>0: strFlash="" for row in forFlash: strFlash=strFlash+str(row) flash("You tried to delete the following accounts that cannot be deleted!--- " + strFlash) chartsel.child.default_selected=subfundsel chartsel.child.options=subfundAll c.form = chartsel() schoolnam=DBSession.query(Schools).filter('id=%i' %int(curSchool)).one() return dict( page=schoolnam.name)