Esempio n. 1
0
def SearchSessionAndModelSearch(searchsession, themodel):
    
    db = query.GetDB()
    db2 = query.GetDB()
    
    
    cursor = db.query(model.AuctionVehicle)\
            .join(model.AuctionVehicle.searchVehicle)\
            .join(model.AuctionVehicle.searchDay)\
            .join(model.AuctionVehicle.searchSession)\
            .filter(model.AuctionVehicle.searchSession_id == searchsession)\
            .filter(model.SearchVehicle.model == themodel)\
            .all()
            
    total =  db2.query(model.AuctionVehicle)\
            .join(model.AuctionVehicle.searchVehicle)\
            .filter(and_(model.AuctionVehicle.searchSession_id == searchsession, model.SearchVehicle.model == themodel))\
            .count()
            
    if request.method == 'POST':
        interests = request.form.getlist('mark_interest')
        
        for item in interests:
            flash(item)
        
        return redirect(url_for('Messages'))
        
       
    
    
    return render_template('vehicle.html', vehicles=cursor, total=total)
Esempio n. 2
0
def SearchFromDate(searchvehicle_id, searchday_id, methods=['POST','GET']):
    
    db = query.GetDB()
    db2 = query.GetDB()
    
    userlist = query.GetAllUsers()
    
    cursor = db.query(model.AuctionVehicle)\
            .join(model.AuctionVehicle.searchVehicle)\
            .join(model.AuctionVehicle.searchDay)\
            .join(model.AuctionVehicle.searchSession)\
            .filter(and_(model.AuctionVehicle.day_id >= searchday_id, model.SearchVehicle.id == searchvehicle_id))\
            .order_by(desc(model.AuctionVehicle.day_id))\
            .all()
            
    total =  db2.query(model.AuctionVehicle)\
            .join(model.AuctionVehicle.searchVehicle)\
            .filter(and_(model.AuctionVehicle.day_id >= searchday_id, model.SearchVehicle.id == searchvehicle_id))\
            .count()
            
    if request.method == 'POST':
            interests = request.form.getlist('mark_interest')
            interestList = []
            interestVehicles = []
            user_id = request.form.get('userselect')
        
            for item in interests:
                flash("http://quadcore:5000/individual/" + str(item))
                interestList.append(item)
            
            for item in interests:
                interestVehicles.append(item)
            
            #send list of id's of selected vehicles to method to pull back new cursor
            
            interestedVehiclesCursor = query.InterestedVehicleOps(interestVehicles)
                
            query.FavouriteOps(interestedVehiclesCursor, user_id)
            
            todaysFavourites = query.GetAllFavouritesToday()
        
            
            #return render_template('vehicle.html', vehicles=todaysFavourites, total=total)
            return redirect(url_for('Favourites'))
            
       
    
    
    return render_template('vehicle.html', vehicles=cursor, total=total, userlist=userlist)
Esempio n. 3
0
def SearchToday(whatday):
    
    if whatday == "today":
       #todays date
       newDay = datetime.now()
       # trim todays date
       date = newDay.replace(hour=0,minute=0,second=0,microsecond=0)
    
    db = query.GetDB()
    
    cursor = db.query(model.AuctionVehicle)\
            .join(model.AuctionVehicle.searchDay)\
            .filter(model.SearchDay.date == date)\
            .all()
    
    count = db.query(model.AuctionVehicle)\
            .join(model.AuctionVehicle.searchDay)\
            .filter(model.SearchDay.date == date)\
            .count()  
            
    if request.method == 'POST':
        interests = request.form.getlist('mark_interest')
        
        for item in interests:
            flash(item)
        
        return redirect(url_for('Messages'))    
    
    
    return render_template('vehicle.html', vehicles=cursor, total=count, message="Searching by Auction day")
Esempio n. 4
0
def Today():
    
    db = query.GetDB()
    
    today = datetime.now()
    dayToday= today.replace(hour=0,minute=0,second=0,microsecond=0)
    
    # Get list of searchvehicles for select box.    
    searchvehicles = db.query(model.Day2SearchVehicle)\
                   .join(model.Day2SearchVehicle.searchvehicle)\
                   .join(model.Day2SearchVehicle.day)\
                   .filter(and_(model.SearchDay.date == dayToday, model.Day2SearchVehicle.totalvehicles > 0))\
                   .order_by(desc(model.Day2SearchVehicle.totalvehicles))\
                   .all()
                   
    users = query.GetAllUsers()
    
    
    dayId = db.query(model.SearchDay).filter(model.SearchDay.date == dayToday).first()

    if request.method == 'POST':
        
        id = request.form.get('svselect')
        #day_id = request.form.get('sdselect') 
               
        
        return redirect(url_for('SearchBySearchVehicleId', searchvehicle_id=int(id), searchday_id=dayId.id))

          
        
    #return redirect(url_for('SearchBySearchVehicleId', searchvehicle_id=int(id)))
    
    
    return render_template('index2.html', searchvehicles=searchvehicles)
Esempio n. 5
0
def ChassisSearch(thechassiscode):
    
    db = query.GetDB()
    
    cursor = db.query(model.AuctionVehicle)\
            .join(model.AuctionVehicle.searchVehicle)\
            .filter(model.AuctionVehicle.chassis == thechassiscode)\
            .all()
    
    return render_template('vehicle.html', vehicles=cursor, message="Searching by Auction LotNumber")
Esempio n. 6
0
def query_all_years_count(searchVehicle, searchSession, date):
    from auctionsearch.auctionbase import query
    db = query.GetDB()

    count = db.query(model.AuctionVehicle)\
    .join(model.AuctionVehicle.searchDay)\
    .join(model.AuctionVehicle.searchVehicle)\
    .filter(and_(model.SearchVehicle.id == searchVehicle, model.SearchDay.date >= date, model.AuctionVehicle.searchSession_id == searchSession))\
    .order_by(desc(model.SearchDay.date))\
    .count()

    return count
Esempio n. 7
0
def Individual(theId):
    
       
    db = query.GetDB()
   
    cursor = db.query(model.AuctionVehicle)\
                .join(model.AuctionVehicle.searchVehicle)\
                .filter(model.AuctionVehicle.id == int(theId))\
                .first()
                
       
    
    
    return render_template('vehicleInd.html', vehicles=cursor, message="Searching by Auction day")
Esempio n. 8
0
def query_sub_2002(searchVehicle, searchSession, date):

    from auctionsearch.auctionbase import query

    db = query.GetDB()

    cursor = db.query(model.AuctionVehicle)\
    .join(model.AuctionVehicle.searchDay)\
    .join(model.AuctionVehicle.searchVehicle)\
    .filter(and_(model.SearchVehicle.id == searchVehicle, model.SearchDay.date >= date, model.AuctionVehicle.searchSession_id == searchSession, model.AuctionVehicle.year < 2002))\
    .order_by(desc(model.SearchDay.date))\
    .all()

    return cursor
Esempio n. 9
0
def SearchFrom():
    
    db = query.GetDB()
    
    
    
    # Get list of searchvehicles for select box.    
    searchvehiclelist = db.query(model.SearchVehicle).all()
    # Get search days for search day select box.
    searchdays = db.query(model.SearchDay).order_by(desc(model.SearchDay.date)).all()
    
    if request.method == 'POST':
        
        id = request.form.get('svselect')
        day_id = request.form.get('sdselect')        
        
        return redirect(url_for('SearchFromDate', searchvehicle_id=int(id), searchday_id=day_id))
    
    
    return render_template('index.html', searchvehicles=searchvehiclelist, searchdays=searchdays)
Esempio n. 10
0
def SearchLast7(numberOfDays, themodel):
    
    if int(numberOfDays) < 8:
       #todays date
        newDay = datetime.now()
    #   # trim todays date
        date = newDay.replace(hour=0,minute=0,second=0,microsecond=0)
       
        date = date - timedelta(days=int(numberOfDays))
    
        db = query.GetDB()
   
        cursor = db.query(model.AuctionVehicle)\
                .join(model.AuctionVehicle.searchDay)\
                .join(model.AuctionVehicle.searchVehicle)\
                .filter(and_(model.SearchVehicle.model == themodel, model.SearchDay.date >= date))\
                .order_by(desc(model.SearchDay.date))\
                .all()
        
        count = db.query(model.AuctionVehicle)\
                .join(model.AuctionVehicle.searchDay)\
                .join(model.AuctionVehicle.searchVehicle)\
                .filter(and_(model.SearchVehicle.model == themodel, model.SearchDay.date >= date))\
                .order_by(desc(model.SearchDay.date))\
                .count()
                
        if request.method == 'POST':
            interests = request.form.getlist('mark_interest')
        
            for item in interests:
                flash(item)
        
        return redirect(url_for('Messages'))       
    
                
    else:
        cursor = None
    
    return render_template('vehicle.html', vehicles=cursor, total=int(count), message="Searching by Auction day")
Esempio n. 11
0
def Index():
    
    db = query.GetDB()
    
    # Get list of searchvehicles for select box.    
#    searchvehicles = db.query(model.VehicleStat)\
#                   .join(model.VehicleStat.SearchVehicle)\
#                   .all()
#                
    searchvehicles = db.query(model.SearchVehicle)\
                    .all()
                

    # Get search days for search day select box.
    searchdays = db.query(model.SearchDay).order_by(desc(model.SearchDay.date)).all()
    
    if request.method == 'POST':
        
        id = request.form.get('svselect')
        day_id = request.form.get('sdselect')        
        return redirect(url_for('SearchBySearchVehicleId', searchvehicle_id=int(id), searchday_id=day_id))
    
    
    return render_template('index.html', searchvehicles=searchvehicles, searchdays=searchdays)
Esempio n. 12
0
def SearchBySearchVehicleId(searchvehicle_id, searchday_id):
    
    db = query.GetDB()
    db2 = query.GetDB()
    
    today = datetime.now()
    dayToday= today.replace(hour=0,minute=0,second=0,microsecond=0)

    year = 2010
    
    userlist = query.GetAllUsers()
    
     # Get list of searchvehicles for select box.    
    searchvehicles = db.query(model.Day2SearchVehicle)\
                   .join(model.Day2SearchVehicle.searchvehicle)\
                   .join(model.Day2SearchVehicle.day)\
                   .filter(model.SearchDay.date == dayToday)\
                   .all()
                   
    
    
    cursor = db.query(model.AuctionVehicle)\
            .join(model.AuctionVehicle.searchVehicle)\
            .join(model.AuctionVehicle.searchDay)\
            .join(model.AuctionVehicle.searchSession)\
            .filter(and_(model.AuctionVehicle.year < year, model.AuctionVehicle.day_id == searchday_id, model.SearchVehicle.id == searchvehicle_id))\
            .order_by(desc(model.AuctionVehicle.day_id))\
            .all()
            
    total =  db2.query(model.AuctionVehicle)\
            .join(model.AuctionVehicle.searchVehicle)\
            .filter(and_(model.AuctionVehicle.day_id == searchday_id, model.SearchVehicle.id == searchvehicle_id))\
            .count()
            
    if request.method == 'POST':
            interests = request.form.getlist('mark_interest')
            # Get vehicles for translation
            vehiclesForTranslation = request.form.getlist('flagTranslation')
            interestList = []
            interestVehicles = []
            user_id = request.form.get('userselect')
        
            for item in interests:
                flash("http://quadcore:5000/individual/" + str(item))
                interestList.append(item)
            
            for item in interests:
                interestVehicles.append(item)
            
            #send list of id's of selected vehicles to method to pull back new cursor
            
            interestedVehiclesCursor = query.InterestedVehicleOps(interestVehicles)
                
            query.FavouriteOps(interestedVehiclesCursor, user_id)
            # Send vehicles for translation to be flagged in the db
            query.TranslateOps(vehiclesForTranslation, user_id)
            
            
            todaysFavourites = query.GetAllFavouritesToday()
        
            
            #return render_template('vehicle.html', vehicles=todaysFavourites, total=total)
            return redirect(url_for('Favourites'))
    
    
    
    return render_template('vehicle.html', vehicles=cursor, total=total, userlist=userlist, searchvehicles=searchvehicles)
Esempio n. 13
0
def send_html_email(searchVehicle):

    global smtp_mail_server

    newDay = datetime.now()
    #   # trim todays date
    date = newDay.replace(hour=0, minute=0, second=0, microsecond=0)

    #Number of historical days of vehicles to get.
    numberOfDays = 1

    date = date - timedelta(days=int(numberOfDays))

    from auctionsearch.auctionbase import query

    db = query.GetDB()

    searchSession = query.QgetLatestSearchSession()

    string_model = db.query(model.SearchVehicle.id).filter(
        model.SearchVehicle.id == searchVehicle).first()

    if string_model == "SAMBAR":
        raw_input("about to do SUBARU SAMBARS!")


# Check type of vehicle to see if should span all years.

    if (string_model[0] == "CAMROAD"):

        cursor = query_all_years(searchVehicle, searchSession, date)
        count = query_all_years_count(searchVehicle, searchSession, date)
    else:
        cursor = query_sub_2002(searchVehicle, searchSession, date)
        count = query_sub_2002_count(searchVehicle, searchSession, date)

    modelName = db.query(model.SearchVehicle.model).filter(
        model.SearchVehicle.id == searchVehicle).first()
    #raw_input("model name just retrieved is " + str(modelName))
    if modelName == "SAMBAR":

        raw_input("about to EMAIL SAMBARS!")

    if count > 0:

        if modelName == "SAMBAR":
            raw_input("now in the emailer function about to email sambars")

        destinationAddress = None
        # Get the destination email address
        destinationAddress = check_vehicle_type(modelName[0])

        if modelName == "SAMBAR":
            raw_input("destination address is" + destinationAddress)

        # Render template to string with Jinja2

        env = Environment(loader=PackageLoader('emailer', 'templates'))

        #t = env.get_template('vehicle_for_render.html')
        t = env.get_template('email_initial_view_lite.html')
        html = t.render(vehicles=cursor, count=count)
        #htmlEncoded = html.encode('utf8')
        #print html
        #raw_input("Destination addresss is " + destinationAddress)

        ## EMAIL STUFF ###
        message = Message()
        message.From = "*****@*****.**"
        message.To = destinationAddress
        message.Subject = "[SC Auto Search] " + "## " + unicode(
            modelName) + " ## " + str(count) + " " + "Vehicles"
        #message.Body = messageBody
        message.Html = html
        mailer = Mailer(smtp_mail_server)
        mailer.send(message)