def index(self): """ Simply returns the more-or-less static index.mako template. The actual data loading etc. is done in Javascript once the page has loaded (see getitems() further down). """ print "index() called" c.pagetitle = "DOB/DOA Tracker" c.itemcount = self.item_q.count() return render('/index.mako')
def logout(self): """ Logout the user and display a confirmation message """ if 'user' in session: del session['user'] session.save() c.pagetitle = "Please Log In" return render('login.mako')
def submit(self): """ Verify username and password """ # Both fields filled? form_username = str(request.params.get('username')).lower() form_password = str(request.params.get('password')) # Get user data from database #db_user = model.WebUser.query(User).get_by(name=form_username) #if db_user is None: # User does not exist valid_users = { "admin": "luminous", "hsbc": "rainwater", "tesco": "lightning", "hbos": "autumn", "specsavers": "blossom", "lloyds": "orchard", "boots": "cluster1" } try: valid_users[form_username] except KeyError: c.pagetitle = "Incorrect Username" return render('login.mako') # Wrong password? (MD5 hashes used here) #if db_user.passwd != md5.md5(form_password).hexdigest(): if form_password != valid_users[form_username]: c.pagetitle = "Incorrect Password" return render('login.mako') # Mark user as logged in session['user'] = form_username session.save() # Send user back to the page he originally wanted to get to if session.get('path_before_login'): return redirect(session['path_before_login']) else: # if previous target is unknown, send the user to a welcome page return redirect("/")
def rtsform(self, id): import datetime c.item = self.item_q.filter_by(rep=id).first() repstring = "REP{0:0=7}".format(c.item.rep) c.printrep = repstring[0:6] + " " + repstring[6:10] c.pagetitle = "RTS form for # %s" % c.item.rep now = datetime.datetime.now() if not c.item.rtsdate: c.item.rtsdate = "%s/%s/%s" % (now.day, now.month, now.year) Session.commit() return render("/rtsform.mako")
def upload(self): """ Really nasty CSV importer that does minimal error checking and expects everything to be laid out in a particular manner. """ import csv csvfile = request.POST['csvfile'] csvreader = csv.reader(csvfile.file, delimiter="\t", quotechar='"') rowsadded = 0 repsadded = [] c.duplicatereps = [] c.unknowncustomers = [] for row in csvreader: rep = row[3][3:][:7] if rep == '': rep = rowsadded # Skip over duplicate REP numbers if rep not in repsadded: newitem = Item(rep=int(rep), kind=row[0].decode('utf-8', 'ignore')[:3], initials=row[1].decode('utf-8', 'ignore')[:3], customer=row[4].decode('utf-8', 'ignore')[:30], costcentre=row[6].decode('utf-8', 'ignore')[:20], ordernum=row[7].decode('utf-8', 'ignore')[:20], make=row[8].decode('utf-8', 'ignore')[:30], model=row[9].decode('utf-8', 'ignore')[:50], part=row[10].decode('utf-8', 'ignore')[:30], serial=row[11].decode('utf-8', 'ignore')[:30], asset=row[12].decode('utf-8', 'ignore')[:30], issue=row[14].decode('utf-8', 'ignore')[:300], state=row[15].decode('utf-8', 'ignore')[:300], location=row[16].decode('utf-8', 'ignore')[:300], solution=row[17].decode('utf-8', 'ignore')[:300], sap=row[18].decode('utf-8', 'ignore')[:8], grn=row[19].decode('utf-8', 'ignore')[:8]) # Sometimes Excel doesn't include the last column (or the CSV # reader doesn't read it properly). if len(row) >= 21: # Sometimes the Folio column has non-numbers in it try: newitem.folio = int(row[21]) except ValueError: newitem.folio = 0 # Ditto for Value column, particularly items added long ago # by a certain "JH". try: f = float(row[5]) except ValueError: f = 0.0 # Store values as integers r = round(f, 2) newitem.value = int(r*100) newitem.datein = parsedate(row[2].decode('utf-8', 'ignore')[:20]) newitem.warranty = parsedate(row[13].decode('utf-8', 'ignore')[:20]) newitem.rtsdate = parsedate(row[20].decode('utf-8', 'ignore')[:20]) # Return custs = ["TESCO", "HSBC", "SPECSAVERS", "HBOS", "RBSG"] def detectcust(cust): for acust in custs: if cust[:len(acust)] == acust: return acust if cust != "UNKNOWN": c.unknowncustomers.append({"rep": newitem.rep, "customer": cust}) return "UNKNOWN" newcust = detectcust(newitem.customer) # If there's a "/" in the customer name, assume it's owned # by Fujitsu if the character after the "/" is an "F" slash = newitem.customer.find("/") if slash != -1: if newitem.customer[slash + 1] == "F": newitem.fujitsuowned = True else: newitem.fujitsuowned = False newitem.customer = newcust Session.add(newitem) rowsadded = rowsadded + 1 repsadded += [rep] else: c.duplicatereps += [rep] print "[dobtrack] Ignoring duplicate rep of %s" % rep Session.commit() print "[dobtrack] Unrecognised 'customer' entries:" print c.unknowncustomers c.rowsadded = rowsadded c.pagetitle = "CSV file uploaded successfully" return render('/upload.mako')
def importcsv(self): c.pagetitle = "Import data from CSV file" return render('/importcsv.mako')
def tableprint(self): c.pagetitle = "DOB/DOA Tracker" return render("/tableprint.mako")
def login(self): """ Show login form. """ c.pagetitle = "Please Log In" return render("login.mako")