Exemplo n.º 1
0
 def addIssue(self):
     memID = request.params['memberid']
     bkID = request.params['bookid']
     mem = Session.query(Members).filter_by(memberID=memID).first()
     member_allowance = Session.query(Issues).all()
     nameList = []
     for i in member_allowance:
         nameList.append(i.memberID)
     d = {}
     for i in set(nameList):
         d[i] = nameList.count(i)
     if d.get(int(memID), 1) > 2:
         session['flash'] = 'That member may not take out any more books.\
                 Maximum allowance of 3 reached.'
         session.save()
         #self.index()
     else:
         bk = Session.query(Books).filter_by(bookID=bkID).first()
         bk.status = False
         Session.add(bk)
         Session.commit()
         issueDate = datetime.date.today()
         dueDate = issueDate + datetime.timedelta(days=14)
         returned = False
         issue_details = Issues(mem.memberID, bk.bookID, issueDate,
                 dueDate, returned)
         Session.add(issue_details)
         Session.commit()
         session.clear()
         session['flash'] = 'Issue successfully added'
         session.save()
     redirect('/issues/')
Exemplo n.º 2
0
 def report_overdue(self):
     iss = Session.query(Issues).all()
     recordset = []
     now = datetime.date.today()
     for r in iss:
         if r.dueDate < now:
             recordset.append(r)
     return recordset
Exemplo n.º 3
0
 def deleteMember(self):
     mem_id = request.params['memberID']
     mem_details = self.member_q.filter_by(memberID=mem_id).first()
     c.issue = Session.query(Issues).all()
     print 'c.issue dir', type(c.issue), '*' * 500
     for result in c.issue:
         print 'result.memberID', result.memberID, '*' * 100
         print 'mem_id', mem_id, '*' * 100
Exemplo n.º 4
0
 def deleteIssue(self):
     is_id = request.params['issueID']
     is_details = self.issue_q.filter_by(issueID=is_id).first()
     bk = Session.query(Books).filter_by(bookID=is_details.bookID).first()
     bk.status = True
     Session.add(bk)
     Session.commit()
     Session.delete(is_details)
     Session.commit()
     session.clear()
     session['flash'] = 'Issue successfully returned.'
     session.save()
     redirect('/issues/')
Exemplo n.º 5
0
 def download(self):
     name = request.params.get('name', '')
     tables = {'members': Session.query(Members).all(),
             'books': Session.query(Books).all(),
             'issues': Session.query(Issues).all(),
             'overdue': self.report_overdue()}
     generate_file = {'members': 'membersreport.html', 
             'books': 'booksreport.html',
             'issues': 'issuesreport.html',
             'overdue': 'overduereport.html'}
     path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     c.recordset = tables[name]
     template_name = generate_file[name]
     res = render(template_name)
     temp = StringIO()
     pdf_result = pisa.pisaDocument(res, temp)
     pdf_path = os.path.join(path, 'public/pdf%s.pdf') % name
     temp.seek(0)
     filename = '%sreport.pdf' % name
     result = {'temp': temp, 'filename': filename}
     pdf_data = result['temp'].read()
     response.headers['Content-type'] = 'application/pdf'
     return pdf_data
Exemplo n.º 6
0
 def __before__(self):
     self.issue_q = Session.query(Issues)
Exemplo n.º 7
0
 def __before__(self):
     self.member_q = Session.query(Members)
Exemplo n.º 8
0
 def __before__(self):
     self.book_q = Session.query(Books)
Exemplo n.º 9
0
 def loadAddIssue(self):
     c.memberRecords = Session.query(Members).all()
     c.bookRecords = Session.query(Books).all()
     c.recordset = Session.query(Issues).all()
     return render('addissue.html')