Exemple #1
0
 def __call__(self, environ, start_response):
     """Invoke the Controller"""
     # WSGIController.__call__ dispatches to the Controller method
     # the request is routed to. This routing information is
     # available in environ['pylons.routes_dict']
     try:
         return WSGIController.__call__(self, environ, start_response)
     finally:
         Session.remove()
Exemple #2
0
 def deleteBook(self):
     bk_id = request.params['bkID']
     bk_details = self.book_q.filter_by(bookID=bk_id).first()
     Session.delete(bk_details)
     Session.commit()
     session.clear()
     session['flash'] = 'Book successfully deleted.'
     session.save()
     redirect('/books/')
Exemple #3
0
 def addBook(self):
     title = self.form_result['title']
     author = self.form_result['author']
     status = True
     bk_details = Books(title, author, status)
     Session.add(bk_details)
     Session.commit()
     session.clear()
     session['flash'] = 'Successfully added new book.'
     session.save()
     redirect('/books/')
Exemple #4
0
 def addMember(self):
     name = self.form_result['name']
     address = self.form_result['address']
     suburb = self.form_result['suburb']
     city = self.form_result['city']
     mem_details = Members(name, address, suburb, city)
     Session.add(mem_details)
     Session.commit()
     session.clear()
     session['flash'] = 'New member successfully added.'
     session.save()
     redirect('/members/')
Exemple #5
0
 def editBook(self):
     bk_id = request.params['id']
     bk_details = self.book_q.filter_by(bookID=bk_id).first()
     bk_details.title = self.form_result['title']
     bk_details.author = self.form_result['author']
     #bk_details.status = request.params['status']
     Session.add(bk_details)
     Session.commit()
     session.clear()
     session['flash'] = 'Book successfully edited.'
     session.save()
     redirect('/books/')
Exemple #6
0
 def editMember(self):
     mem_id = request.params['id']
     mem_details = self.member_q.filter_by(memberID=mem_id).first()
     mem_details.name = self.form_result['name']
     mem_details.address = self.form_result['address']
     mem_details.suburb = self.form_result['suburb']
     mem_details.city = self.form_result['city']
     Session.add(mem_details)
     Session.commit()
     session.clear()
     session['flash'] = 'Member successfully edited.'
     session.save()
     redirect('/members/')
Exemple #7
0
 def editIssue(self):
     is_id = request.params['id']
     is_details = self.issue_q.filter_by(issueID=is_id).first()
     is_details.memberID = request.params['memberID']
     is_details.bookID = request.params['bookID']
     i = datetime.datetime.strptime(request.params['issueDate'], '%Y-%m-%d')
     is_details.issueDate = i
     print is_details.issueDate, '*' * 500
     d = datetime.datetime.strptime(request.params['dueDate'], '%Y-%m-%d')
     is_details.dueDate = d
     Session.add(is_details)
     Session.commit()
     session.clear()
     session['flash'] = 'Issue successfully edited.'
     session.save()
     redirect('/issues/')
Exemple #8
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/')
Exemple #9
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
Exemple #10
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
Exemple #11
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
Exemple #12
0
 def __before__(self):
     self.issue_q = Session.query(Issues)
Exemple #13
0
 def __before__(self):
     self.member_q = Session.query(Members)
Exemple #14
0
 def __before__(self):
     self.book_q = Session.query(Books)
Exemple #15
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/')
Exemple #16
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')