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 uploadget(self, *args, **kw): if kw: public_dirname = os.path.join(os.path.abspath(resource_filename('ostacct', 'public'))) doc_dirname = os.path.join(public_dirname, 'eventdoc') fn=kw['doc:filename'].filename fn=str(fn).replace(" ","") C= model.Doc() C.name=fn C.description=kw['doc:Description'] model.DBSession.add(C) transaction.commit() model.DBSession.flush() doc=DBSession.query(Doc).filter_by(name=str(fn)).one() doc_path = os.path.join(doc_dirname, str(doc.name)) try: os.makedirs(doc_path) except OSError: #ignore if the folder already exists pass doc_path = os.path.join(doc_path, str(fn)) f = file(doc_path, "w") f.write(kw['doc:filename'].value) f.close() newdoc_path=os.path.join(public_dirname, 'eventdoc') newdoc_path=os.path.join(newdoc_path, str(fn)) shutil.copyfile(doc_path, fn) ostacct.remove_value('AddEvent') flash("Dccument was successfully created.") redirect("AddEvent") else: flash("some sort of problem") redirect("upload")
def advent(self, *args, **kw): if kw: 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") redirect("eventlist") else: 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)
def cal(self, *args, **kw): calendar.setfirstweekday(6) year = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] today = datetime.date(datetime.now()) current = re.split('-', str(today)) current_no = int(current[1]) current_month = year[current_no-1] current_day = int(re.sub('\A0', '', current[2])) current_yr = int(current[0]) month = calendar.monthcalendar(current_yr, current_no) nweeks=len(month) weeklist=[] for w in range(0,nweeks): weeklist.append(month[w]) #event = DBSession.query(Event).filter_by(month=int(current_month)).all() if kw: if int(kw['month'])>current_no: current_no=int(kw['month']) current_yr=int(kw['year']) current_day=50 month= calendar.monthcalendar(current_yr, current_no) nweeks=len(month) current_month = year[current_no-1] weeklist=[] for w in range(0,nweeks): weeklist.append(month[w]) else: if int(kw['year'])>current_yr: current_no=int(kw['month']) current_yr=int(kw['year']) current_day=50 month= calendar.monthcalendar(current_yr, current_no) nweeks=len(month) current_month = year[current_no-1] weeklist=[] for w in range(0,nweeks): weeklist.append(month[w]) even = DBSession.query(TheEvent).filter_by(month=int(current_no)).all() events=[] rawevents=[] doneday=[] dontdouble=False for row in even: if row: if row.doc: doclink=row.doc.name doclinkdesc=row.doc.description public_dirname = os.path.join(os.path.abspath(resource_filename('ostacct', 'public'))) doc_dirname = os.path.join(public_dirname, 'eventdoc') else: doclink=None #doclink = os.path.join(doc_dirname, str(row.docs)) rawevents.append([row.month,row.day,row.year,row.typ,row.Description,doclink]) else: doc="something" doclink="" doclinkdesc="" rawevents.append([row.month,row.day,row.year,row.typ,row.Description,doclink]) doneit=False dontdouble=[] for m, d, y,typ,Desc,doc in rawevents: Thisday=d devent=[] for m, d, y,typ,Desc,doc in rawevents: if d==Thisday: devent.append((typ,Desc,doc)) devent.append(("-----------------------","","")) for row in dontdouble: if row==Thisday: doneit=True dontdouble.append(Thisday) if doneit==False: events.append((m,Thisday,y,devent)) #events.append(("--","--","----","-----")) doneit=False #events.append([row.month.day,row.year,row.typ,row.Description,doclink]) return dict(page='Calendar', year=year, today=today, current=current, current_no=current_no, current_month=current_month, current_day=current_day, current_yr=current_yr, month = month, nweeks = nweeks , weeklist=weeklist,events=events)
def test_query_obj(self): """Model objects can be queried""" obj = DBSession.query(self.klass).one() for key, value in self.attrs.iteritems(): assert_equals(getattr(obj, key), value)
def by_user_name(cls, username): """Return the user object whose user name is ``username``.""" return DBSession.query(cls).filter_by(user_name=username).first()
def by_email_address(cls, email): """Return the user object whose email address is ``email``.""" return DBSession.query(cls).filter_by(email_address=email).first()