Link to home
Start Free TrialLog in
Avatar of jameskane
jameskane

asked on

need cgi page to refresh one time only after launch

I have a number of  cgi pages which I need to automatically refresh ONE time only after it is launched (not every X seconds). At the moment, all I can do after a page is launched is use a manual "ctrl R" . This does the job - but I need to modify the cgi page so that it happens automatically.

I am attaching an example of one of the pages. Could someone show me how to insert  some javascript (maybe ?) to have this ctrl R happen automatically.

Many thanks in advance

james
#!C:\Python34\python.exe
import json
import traceback
import cgi,cgitb
import mysql.connector as conn
import collections
import datetime
import shelve
import copy
def htmlTop():
    print("""Content-type:text/html\n\n
        <!DOCTYPE html>
        <html lang="en">
            <head>

            <style>
            body {
        font-size: 100%; /*to support em text sizing*/
        margin-top: 0;

            }
            #backgrd_repeat_image {
        background-image: url(images/background.png);
        background-position: left top;
        background-repeat: repeat;
        height: 1cm;	/*padding-top: 15px;*/
            }


            </style>


                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
                <title> RESUME DES ACTIVITIES</title>
                #<link href="style.css" rel="stylesheet" type="text/css">
                <link href="registration.css" rel="stylesheet" type="text/css">

                <script>var __adobewebfontsappname__="dreamweaver"</script>
                <script src="http://use.edgefonts.net/source-sans-pro:n2,i2,n3,i3,n4,i4,n6,i6,n7,i7,n9,i9:default;source-serif-pro:n4:default.js" type="text/javascript"></script>
        </head>
        """)


def htmlTail():
    print(""" its done</body>
        </html>""")

def connectDB():
    db=conn.connect(host='localhost' ,user='***' ,passwd='***' ,db='***')
    cursor = db.cursor()
    return db, cursor 

def SelectSales_Discount(db,cursor):
    cursor.execute("""select memberID, YTDPurchases,deductions from transactions  """)
    transactions=cursor.fetchall()
    return transactions  

def cheapbuy_selection():
    db, cursor = connectDB() 
    cursor.execute("SELECT T1ytdlatest,T2ytdlatest,T3ytdlatest,cheapbuy FROM registrations")
    registrations =cursor.fetchall()
    return registrations

def SelectPaidActLibre(db,cursor):
    cursor.execute("""select COUNT(*) from registrations WHERE ALPAID_ytd = "%s" """
    %(1)) 
    PaidActLibreCount = cursor.fetchone()
    return PaidActLibreCount 
    
def SelectRegistrationsMemID(db,cursor):
    cursor.execute("""select memberID from registrations """ )
    registrations=cursor.fetchall()
    return registrations
    

def SelectFees(db,cursor):
    cursor.execute("""select * from fees """ )
    fees=cursor.fetchall()
    return fees

def Select_Activities(db,cursor):
    cursor.execute("""select * from activities """ )
    activities=cursor.fetchall()
    return activities

def unshelve_it():
    import shelve
    shelfFile=shelve.open('gestionIDStore')
    print(list(shelfFile.keys()))
    gestionID = list(shelfFile.values())  # GET YOUR VARIABLE BACK AGAIN
    shelfFile.close() # CLOSE THE DICTIONARY
    gestionID = gestionID[0]# REMEMBER WE ARE DEALING WITH A LIST
    return gestionID # RETURN YOUR VARIABLE

def page1(): 
    print("<body id='backgrd_repeat_image'>")
    print("<div id='grad1'>")
    print("ASSOCIATION DES BEAUX ARTS DE CANNES Deuxieme rue de Barri _ Le Suquet_ 06400_Cannes.")
    print("<a href='mailto:matt@example.com'>")
    print("Matt West")
    print("</a>")
    print("</div>")
    
    
    print("<h3>")
    print("YOU MUST SIGN IN TO SEE THIS INFORMATION")
    print("</h3>")






def page(): 
    print("<body id='backgrd_repeat_image'>")
    print("<div id='grad1'>")
    print("ASSOCIATION DES BEAUX ARTS DE CANNES Deuxieme rue de Barri _ Le Suquet_ 06400_Cannes.")
    print("<a href='mailto:matt@example.com'>")
    print("Matt West")
    print("</a>")
    print("</div>")
    print("<table id='registr_table'  ")
    print("<tbody>")
    print("<tr >")
    print("<th width='397' align='centre' rowspan='2' scope='col'>COURS</th>")
    print("<th width='67' rowspan='2' scope='col'>ANNEE "
          "Ventes (T36)</th>")
    print("<th align='center' colspan='2' scope='col'>1er Trim</th>")
    print("<th align='center' colspan='2' scope='col'>2em Trim</th>")
    print("<th align='center' colspan='2' scope='col'>3em Trim</th>")
    print("<th width='69' rowspan='2' scope='col'>ANNEE "
          "Ventes (T36+12)</th>")
    print("</tr>")
    print("<tr>")
    print("<th width='75' height='26' scope='col'>Adherents</th>")
    print("<th width='62' scope='col'>Ventes(T12)</th>")
    print("<th width='75' scope='col'>Adherents</th>")
    print("<th width='66' scope='col'>Ventes(T12)<//th>")
    print("<th width='79' scope='col'>Adherents</th>")
    print("<th width='69' scope='col'>Ventes(T12)</th>")
    print("</tr>")    
    
    
    T1ytd_Total_Vert = 0
    T2ytd_Total_Vert = 0
    T3ytd_Total_Vert = 0 
    Total_Cheap_Vert = 0
    Total_Cheap_Hors = 0
    T1_Total_insc_vert = 0
    T2_Total_insc_vert = 0
    T3_Total_insc_vert = 0
    
    # Create counters (empty) for each trimester
    counterT1dearbuy = collections.Counter()
    counterT2dearbuy = collections.Counter()
    counterT3dearbuy = collections.Counter()
    counterCheapbuy = collections.Counter()
    
    
    for row in registrations:   # use row instead of each (confusion)
    
        T1ytdlatest = eval(row[0])
        T2ytdlatest = eval(row[1])
        T3ytdlatest = eval(row[2])
        cheapbuy = eval(row[3])
        
        # populate counters by netting each T1ytdxxx with cheapbuy
        counterT1dearbuy.update(set(T1ytdlatest) - set(cheapbuy))
        counterT2dearbuy.update(set(T2ytdlatest) - set(cheapbuy))
        counterT3dearbuy.update(set(T3ytdlatest) - set(cheapbuy)) 
        counterCheapbuy.update(set(cheapbuy))
        # turn the counters into dictionaries
        dict_T1 = dict(counterT1dearbuy)
        dict_T2 = dict(counterT2dearbuy)
        dict_T3 = dict(counterT3dearbuy)
        dict_cheapbuy = dict(counterCheapbuy)
        

        
    
    print("<tr>")
    
    for each in activities:    
        courseNumber = each[0]
        weekday = each[1]
        startime = each[2]
        activity = each[3]
        teacher = str(each[4])
        tariffstwelve = each[5]
        tariffsthirtysix = each[6]
        notes = each[7]
        T1insc_total = each[8]
        T2insc_total = each[9]
        T3insc_total = each[10]
        T1_Total_insc_vert = T1_Total_insc_vert + T1insc_total
        T2_Total_insc_vert = T2_Total_insc_vert + T2insc_total
        T3_Total_insc_vert = T3_Total_insc_vert + T3insc_total
        
        
               
        if not courseNumber in dict_cheapbuy:
            dict_cheapbuy[courseNumber] = 0
            cost_cheapbuy = dict_cheapbuy[courseNumber]*tariffsthirtysix
            Total_Cheap_Vert = Total_Cheap_Vert + cost_cheapbuy
            
        else:
            
            cost_cheapbuy = dict_cheapbuy[courseNumber]*tariffsthirtysix
            Total_Cheap_Vert = Total_Cheap_Vert + cost_cheapbuy
            
        
        if not courseNumber in dict_T1:
            dict_T1[courseNumber] = 0
            cost_T1 = dict_T1[courseNumber]*tariffstwelve
            T1ytd_Total_Vert = T1ytd_Total_Vert + cost_T1
            
        else:
            cost_T1 = dict_T1[courseNumber]*tariffstwelve
            T1ytd_Total_Vert = T1ytd_Total_Vert + cost_T1
                    
        
        if not courseNumber in dict_T2:
            dict_T2[courseNumber] = 0
            cost_T2 = dict_T2[courseNumber]*tariffstwelve
            T2ytd_Total_Vert = T2ytd_Total_Vert + cost_T2
            
        else:
            cost_T2 = dict_T2[courseNumber]*tariffstwelve
            T2ytd_Total_Vert = T2ytd_Total_Vert + cost_T2        
     
        if not courseNumber in dict_T3:
            dict_T3[courseNumber] = 0
            cost_T3 = dict_T3[courseNumber]*tariffstwelve
            T3ytd_Total_Vert = T3ytd_Total_Vert + cost_T3
            
        else:
            cost_T3 = dict_T3[courseNumber]*tariffstwelve
            T3ytd_Total_Vert = T3ytd_Total_Vert + cost_T3
          
                   
        
        print("<tr>")
        print("<td>{a}: <strong>{b}</strong>  ({c} / {d})</td>".format(a=courseNumber, b=activity, c=teacher, d=startime))
        print("<td>{0}</td>".format(round(cost_cheapbuy)))    
        print("<td>{0}</td>".format(T1insc_total))
        print("<td>{0}</td>".format(round(cost_T1)))
        print("<td>{0}</td>".format(T2insc_total))
        print("<td>{0}</td>".format(round(cost_T2)))
        print("<td>{0}</td>".format(T3insc_total))
        print("<td>{0}</td>".format(round(cost_T3)))
        print("<td>{0}</td>".format(round(cost_cheapbuy) + (round(cost_T1)) + (round(cost_T2)) + (round(cost_T3))))
    print("</tr>")  

    print("<tr>")
    print("<th>Sous Total</th>")
    print("<td>{0}</td>".format(round(Total_Cheap_Vert)))
    print("<td>{0}</td>".format(T1_Total_insc_vert))
    print("<td>{0}</td>".format(round(T1ytd_Total_Vert)))
    print("<td>{0}</td>".format(T2_Total_insc_vert))
    print("<td>{0}</td>".format(round(T2ytd_Total_Vert)))
    print("<td>{0}</td>".format(T3_Total_insc_vert))
    print("<td>{0}</td>".format(round(T3ytd_Total_Vert)))
    print("<td>{0}</td>".format(round(Total_Cheap_Vert) + round(T1ytd_Total_Vert) + round(T2ytd_Total_Vert) + round(T3ytd_Total_Vert)))
    print("</tr>")
    
    
    print("<tr>")
    print("<th>Ventilation Academies Libres</th>")
    print("<td>&nbsp;</td>")
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalPaidActLibre/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalPaidActLibre/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalPaidActLibre/3)))
    print("<td>{0}</td>".format(round(TotalPaidActLibre)))
    print("</tr>")
    
    print("<tr>")
    print("<th>Ventilation Cotisations Cours Tarifs Annuelles</th>")
    print("<td>&nbsp;</td>")
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(Total_Cheap_Vert/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(Total_Cheap_Vert/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(Total_Cheap_Vert/3)))
    print("<td>&nbsp;</td>")
    print("</tr>")
    
    print("<tr>")
    print("<th>Ventilation Adhesions Association</th>")
    print("<td>&nbsp;</td>")
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalFees/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalFees/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalFees/3)))
    print("<td>{0}</td>".format(round(TotalFees)))
    print("</tr>")
    
    
    
    print("<tr>")
    print("<th>Grand Total</th>")
    print("<td>&nbsp;</td>")
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(T1ytd_Total_Vert) + round(TotalPaidActLibre/3) + round(Total_Cheap_Vert/3) + round(TotalFees/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(T2ytd_Total_Vert) + round(TotalPaidActLibre/3) + round(Total_Cheap_Vert/3) + round(TotalFees/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(T3ytd_Total_Vert) + round(TotalPaidActLibre/3) + round(Total_Cheap_Vert/3) + round(TotalFees/3)))
    print("<td>{0}</td>".format(round(Total_Cheap_Vert) + round(T1ytd_Total_Vert) + round(T2ytd_Total_Vert) + round(T3ytd_Total_Vert) + round(TotalPaidActLibre) + round(TotalFees)))
    print("</tr>")
    print("</tbody>")
    print("</table>")   
    
    
    
    
    

#main program
if __name__== "__main__":
    try:
        htmlTop()
        db, cursor = connectDB()
        PaidActLibreCount = SelectPaidActLibre(db,cursor) 
        PaidActLibreCount = PaidActLibreCount[0]
        fees = SelectFees(db,cursor)
        activity_libre_fee = fees[0][2]
        Enroll_junior = fees[0][1]
        Enroll_adult = fees[0][0]
        TotalPaidActLibre = PaidActLibreCount * activity_libre_fee 
        
        # FOLLOWING SECTION CALCULATES THE VALUES FOR VENTILATION ADHESIONS ASSOCIATION IN TABLE
        registrations = SelectRegistrationsMemID(db,cursor)
        #print(registrations,"this is registrations****************")
        SeniorMemberCount = 0
        JuniorMemberCount = 0
        for each in registrations:
            eachsearch = each[0]
            #print(eachsearch)
            db, cursor = connectDB()
            cursor.execute("""select Naissance from members2 WHERE memberID = "%s" """
            %(eachsearch)) 
            Naissance = cursor.fetchone()
            birthstatus = Naissance[0]
            #print(birthstatus, "this is birthstatus")
            if birthstatus == 1000 or birthstatus == 0:
                SeniorMemberCount = SeniorMemberCount + 1
            else:
                JuniorMemberCount = JuniorMemberCount + 1
        #print(SeniorMemberCount, "seniors")  
        #print(JuniorMemberCount, "juniors")
        
        TotalFees = SeniorMemberCount * fees[0][0] + JuniorMemberCount * fees[0][1]
        
        #===================== END OF SECTION======================================
        
        db, cursor = connectDB()
        transactions = SelectSales_Discount(db,cursor)
        #print(transactions, "this is transactions")
        memberID = transactions[0][0]
        YTDPurchases = transactions[0][1]
        deductions = transactions[0][2]
             
        
        activities = Select_Activities(db,cursor)
        
        registrations = cheapbuy_selection()
        gestionID = unshelve_it()
        print(gestionID, "this is gestionID")
        if gestionID == 1:
            page()
        else:
            page1()

        
        htmlTail()
    except:
        cgi.print_exception()

Open in new window

s
Avatar of jameskane
jameskane

ASKER

Thanks Robert for the comment.  What's on the page is not the real thing of course, but it's good to be reminded - its easy to forget to change it !!

James
@james i added a javascript refresh function to reload the page after 10 sec you can change it to whatever you want
#!C:\Python34\python.exe
import json
import traceback
import cgi,cgitb
import mysql.connector as conn
import collections
import datetime
import shelve
import copy
def htmlTop():
    print("""Content-type:text/html\n\n
        <!DOCTYPE html>
        <html lang="en">
            <head>

            <style>
            body {
        font-size: 100%; /*to support em text sizing*/
        margin-top: 0;

            }
            #backgrd_repeat_image {
        background-image: url(images/background.png);
        background-position: left top;
        background-repeat: repeat;
        height: 1cm;	/*padding-top: 15px;*/
            }


            </style>


                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
                <title> RESUME DES ACTIVITIES</title>
                #<link href="style.css" rel="stylesheet" type="text/css">
                <link href="registration.css" rel="stylesheet" type="text/css">
                <script>
                function refrech() {
                window.setInterval(function () {
                location.reload();
                }, 10000); //every 10 sec
                }
                refrech();
                </script>
                <script>var __adobewebfontsappname__="dreamweaver"</script>
                <script src="http://use.edgefonts.net/source-sans-pro:n2,i2,n3,i3,n4,i4,n6,i6,n7,i7,n9,i9:default;source-serif-pro:n4:default.js" type="text/javascript"></script>
        </head>
        """)


def htmlTail():
    print(""" its done</body>
        </html>""")

def connectDB():
    db=conn.connect(host='localhost' ,user='***' ,passwd='***' ,db='***')
    cursor = db.cursor()
    return db, cursor 

def SelectSales_Discount(db,cursor):
    cursor.execute("""select memberID, YTDPurchases,deductions from transactions  """)
    transactions=cursor.fetchall()
    return transactions  

def cheapbuy_selection():
    db, cursor = connectDB() 
    cursor.execute("SELECT T1ytdlatest,T2ytdlatest,T3ytdlatest,cheapbuy FROM registrations")
    registrations =cursor.fetchall()
    return registrations

def SelectPaidActLibre(db,cursor):
    cursor.execute("""select COUNT(*) from registrations WHERE ALPAID_ytd = "%s" """
    %(1)) 
    PaidActLibreCount = cursor.fetchone()
    return PaidActLibreCount 
    
def SelectRegistrationsMemID(db,cursor):
    cursor.execute("""select memberID from registrations """ )
    registrations=cursor.fetchall()
    return registrations
    

def SelectFees(db,cursor):
    cursor.execute("""select * from fees """ )
    fees=cursor.fetchall()
    return fees

def Select_Activities(db,cursor):
    cursor.execute("""select * from activities """ )
    activities=cursor.fetchall()
    return activities

def unshelve_it():
    import shelve
    shelfFile=shelve.open('gestionIDStore')
    print(list(shelfFile.keys()))
    gestionID = list(shelfFile.values())  # GET YOUR VARIABLE BACK AGAIN
    shelfFile.close() # CLOSE THE DICTIONARY
    gestionID = gestionID[0]# REMEMBER WE ARE DEALING WITH A LIST
    return gestionID # RETURN YOUR VARIABLE

def page1(): 
    print("<body id='backgrd_repeat_image'>")
    print("<div id='grad1'>")
    print("ASSOCIATION DES BEAUX ARTS DE CANNES Deuxieme rue de Barri _ Le Suquet_ 06400_Cannes.")
    print("<a href='mailto:matt@example.com'>")
    print("Matt West")
    print("</a>")
    print("</div>")
    
    
    print("<h3>")
    print("YOU MUST SIGN IN TO SEE THIS INFORMATION")
    print("</h3>")






def page(): 
    print("<body id='backgrd_repeat_image'>")
    print("<div id='grad1'>")
    print("ASSOCIATION DES BEAUX ARTS DE CANNES Deuxieme rue de Barri _ Le Suquet_ 06400_Cannes.")
    print("<a href='mailto:matt@example.com'>")
    print("Matt West")
    print("</a>")
    print("</div>")
    print("<table id='registr_table'  ")
    print("<tbody>")
    print("<tr >")
    print("<th width='397' align='centre' rowspan='2' scope='col'>COURS</th>")
    print("<th width='67' rowspan='2' scope='col'>ANNEE "
          "Ventes (T36)</th>")
    print("<th align='center' colspan='2' scope='col'>1er Trim</th>")
    print("<th align='center' colspan='2' scope='col'>2em Trim</th>")
    print("<th align='center' colspan='2' scope='col'>3em Trim</th>")
    print("<th width='69' rowspan='2' scope='col'>ANNEE "
          "Ventes (T36+12)</th>")
    print("</tr>")
    print("<tr>")
    print("<th width='75' height='26' scope='col'>Adherents</th>")
    print("<th width='62' scope='col'>Ventes(T12)</th>")
    print("<th width='75' scope='col'>Adherents</th>")
    print("<th width='66' scope='col'>Ventes(T12)<//th>")
    print("<th width='79' scope='col'>Adherents</th>")
    print("<th width='69' scope='col'>Ventes(T12)</th>")
    print("</tr>")    
    
    
    T1ytd_Total_Vert = 0
    T2ytd_Total_Vert = 0
    T3ytd_Total_Vert = 0 
    Total_Cheap_Vert = 0
    Total_Cheap_Hors = 0
    T1_Total_insc_vert = 0
    T2_Total_insc_vert = 0
    T3_Total_insc_vert = 0
    
    # Create counters (empty) for each trimester
    counterT1dearbuy = collections.Counter()
    counterT2dearbuy = collections.Counter()
    counterT3dearbuy = collections.Counter()
    counterCheapbuy = collections.Counter()
    
    
    for row in registrations:   # use row instead of each (confusion)
    
        T1ytdlatest = eval(row[0])
        T2ytdlatest = eval(row[1])
        T3ytdlatest = eval(row[2])
        cheapbuy = eval(row[3])
        
        # populate counters by netting each T1ytdxxx with cheapbuy
        counterT1dearbuy.update(set(T1ytdlatest) - set(cheapbuy))
        counterT2dearbuy.update(set(T2ytdlatest) - set(cheapbuy))
        counterT3dearbuy.update(set(T3ytdlatest) - set(cheapbuy)) 
        counterCheapbuy.update(set(cheapbuy))
        # turn the counters into dictionaries
        dict_T1 = dict(counterT1dearbuy)
        dict_T2 = dict(counterT2dearbuy)
        dict_T3 = dict(counterT3dearbuy)
        dict_cheapbuy = dict(counterCheapbuy)
        

        
    
    print("<tr>")
    
    for each in activities:    
        courseNumber = each[0]
        weekday = each[1]
        startime = each[2]
        activity = each[3]
        teacher = str(each[4])
        tariffstwelve = each[5]
        tariffsthirtysix = each[6]
        notes = each[7]
        T1insc_total = each[8]
        T2insc_total = each[9]
        T3insc_total = each[10]
        T1_Total_insc_vert = T1_Total_insc_vert + T1insc_total
        T2_Total_insc_vert = T2_Total_insc_vert + T2insc_total
        T3_Total_insc_vert = T3_Total_insc_vert + T3insc_total
        
        
               
        if not courseNumber in dict_cheapbuy:
            dict_cheapbuy[courseNumber] = 0
            cost_cheapbuy = dict_cheapbuy[courseNumber]*tariffsthirtysix
            Total_Cheap_Vert = Total_Cheap_Vert + cost_cheapbuy
            
        else:
            
            cost_cheapbuy = dict_cheapbuy[courseNumber]*tariffsthirtysix
            Total_Cheap_Vert = Total_Cheap_Vert + cost_cheapbuy
            
        
        if not courseNumber in dict_T1:
            dict_T1[courseNumber] = 0
            cost_T1 = dict_T1[courseNumber]*tariffstwelve
            T1ytd_Total_Vert = T1ytd_Total_Vert + cost_T1
            
        else:
            cost_T1 = dict_T1[courseNumber]*tariffstwelve
            T1ytd_Total_Vert = T1ytd_Total_Vert + cost_T1
                    
        
        if not courseNumber in dict_T2:
            dict_T2[courseNumber] = 0
            cost_T2 = dict_T2[courseNumber]*tariffstwelve
            T2ytd_Total_Vert = T2ytd_Total_Vert + cost_T2
            
        else:
            cost_T2 = dict_T2[courseNumber]*tariffstwelve
            T2ytd_Total_Vert = T2ytd_Total_Vert + cost_T2        
     
        if not courseNumber in dict_T3:
            dict_T3[courseNumber] = 0
            cost_T3 = dict_T3[courseNumber]*tariffstwelve
            T3ytd_Total_Vert = T3ytd_Total_Vert + cost_T3
            
        else:
            cost_T3 = dict_T3[courseNumber]*tariffstwelve
            T3ytd_Total_Vert = T3ytd_Total_Vert + cost_T3
          
                   
        
        print("<tr>")
        print("<td>{a}: <strong>{b}</strong>  ({c} / {d})</td>".format(a=courseNumber, b=activity, c=teacher, d=startime))
        print("<td>{0}</td>".format(round(cost_cheapbuy)))    
        print("<td>{0}</td>".format(T1insc_total))
        print("<td>{0}</td>".format(round(cost_T1)))
        print("<td>{0}</td>".format(T2insc_total))
        print("<td>{0}</td>".format(round(cost_T2)))
        print("<td>{0}</td>".format(T3insc_total))
        print("<td>{0}</td>".format(round(cost_T3)))
        print("<td>{0}</td>".format(round(cost_cheapbuy) + (round(cost_T1)) + (round(cost_T2)) + (round(cost_T3))))
    print("</tr>")  

    print("<tr>")
    print("<th>Sous Total</th>")
    print("<td>{0}</td>".format(round(Total_Cheap_Vert)))
    print("<td>{0}</td>".format(T1_Total_insc_vert))
    print("<td>{0}</td>".format(round(T1ytd_Total_Vert)))
    print("<td>{0}</td>".format(T2_Total_insc_vert))
    print("<td>{0}</td>".format(round(T2ytd_Total_Vert)))
    print("<td>{0}</td>".format(T3_Total_insc_vert))
    print("<td>{0}</td>".format(round(T3ytd_Total_Vert)))
    print("<td>{0}</td>".format(round(Total_Cheap_Vert) + round(T1ytd_Total_Vert) + round(T2ytd_Total_Vert) + round(T3ytd_Total_Vert)))
    print("</tr>")
    
    
    print("<tr>")
    print("<th>Ventilation Academies Libres</th>")
    print("<td>&nbsp;</td>")
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalPaidActLibre/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalPaidActLibre/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalPaidActLibre/3)))
    print("<td>{0}</td>".format(round(TotalPaidActLibre)))
    print("</tr>")
    
    print("<tr>")
    print("<th>Ventilation Cotisations Cours Tarifs Annuelles</th>")
    print("<td>&nbsp;</td>")
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(Total_Cheap_Vert/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(Total_Cheap_Vert/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(Total_Cheap_Vert/3)))
    print("<td>&nbsp;</td>")
    print("</tr>")
    
    print("<tr>")
    print("<th>Ventilation Adhesions Association</th>")
    print("<td>&nbsp;</td>")
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalFees/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalFees/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(TotalFees/3)))
    print("<td>{0}</td>".format(round(TotalFees)))
    print("</tr>")
    
    
    
    print("<tr>")
    print("<th>Grand Total</th>")
    print("<td>&nbsp;</td>")
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(T1ytd_Total_Vert) + round(TotalPaidActLibre/3) + round(Total_Cheap_Vert/3) + round(TotalFees/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(T2ytd_Total_Vert) + round(TotalPaidActLibre/3) + round(Total_Cheap_Vert/3) + round(TotalFees/3)))
    print("<td>&nbsp;</td>")
    print("<td>{0}</td>".format(round(T3ytd_Total_Vert) + round(TotalPaidActLibre/3) + round(Total_Cheap_Vert/3) + round(TotalFees/3)))
    print("<td>{0}</td>".format(round(Total_Cheap_Vert) + round(T1ytd_Total_Vert) + round(T2ytd_Total_Vert) + round(T3ytd_Total_Vert) + round(TotalPaidActLibre) + round(TotalFees)))
    print("</tr>")
    print("</tbody>")
    print("</table>")   
    
    
    
    
    

#main program
if __name__== "__main__":
    try:
        htmlTop()
        db, cursor = connectDB()
        PaidActLibreCount = SelectPaidActLibre(db,cursor) 
        PaidActLibreCount = PaidActLibreCount[0]
        fees = SelectFees(db,cursor)
        activity_libre_fee = fees[0][2]
        Enroll_junior = fees[0][1]
        Enroll_adult = fees[0][0]
        TotalPaidActLibre = PaidActLibreCount * activity_libre_fee 
        
        # FOLLOWING SECTION CALCULATES THE VALUES FOR VENTILATION ADHESIONS ASSOCIATION IN TABLE
        registrations = SelectRegistrationsMemID(db,cursor)
        #print(registrations,"this is registrations****************")
        SeniorMemberCount = 0
        JuniorMemberCount = 0
        for each in registrations:
            eachsearch = each[0]
            #print(eachsearch)
            db, cursor = connectDB()
            cursor.execute("""select Naissance from members2 WHERE memberID = "%s" """
            %(eachsearch)) 
            Naissance = cursor.fetchone()
            birthstatus = Naissance[0]
            #print(birthstatus, "this is birthstatus")
            if birthstatus == 1000 or birthstatus == 0:
                SeniorMemberCount = SeniorMemberCount + 1
            else:
                JuniorMemberCount = JuniorMemberCount + 1
        #print(SeniorMemberCount, "seniors")  
        #print(JuniorMemberCount, "juniors")
        
        TotalFees = SeniorMemberCount * fees[0][0] + JuniorMemberCount * fees[0][1]
        
        #===================== END OF SECTION======================================
        
        db, cursor = connectDB()
        transactions = SelectSales_Discount(db,cursor)
        #print(transactions, "this is transactions")
        memberID = transactions[0][0]
        YTDPurchases = transactions[0][1]
        deductions = transactions[0][2]
             
        
        activities = Select_Activities(db,cursor)
        
        registrations = cheapbuy_selection()
        gestionID = unshelve_it()
        print(gestionID, "this is gestionID")
        if gestionID == 1:
            page()
        else:
            page1()

        
        htmlTail()
    except:
        cgi.print_exception()

Open in new window

Avatar of arnold
You can use meta tag refresh, and use the same URL with additional marker that when the response is generated will exclude the meta refresh tag.

IE. Http://www.mydomain.com/myfile.cgi
Within you'll have
<meta http-equiv=refresh content="30; URL=http://www.mydomain.com/myfile.cgi?reloaded=1">

When it reloads, the meta tag will be omitted. Note though you run into an issue that someone might bookmark it. To mitigate that, you might have to include a check on http for referrer to see if this is the first or second time usually a referrer will not be set on the first access, but should reflect itself on reload/second access.
Many thanks Arnold for helping me with this.

I have replaced the current meta tag with your recommendation. This is the new line:-
<meta http-equiv=refresh content="30; URL=http://www.localhost/office_python/perf_resume.cgi?reloaded=1;charset=iso-8859-1">

Open in new window


Unfortunately it has not solved the problem.  After 30 seconds the page does refresh - but that is no good as the user will not see the refreshed page for 30 seconds - it  needs to be 1 second.  If I set the timer  to 1 second then the refresh does occur immediately. However it continues  to refresh every second after that.
Use 1 instead of 30 in the meta http-equiv line.
Though 1 might not be enough for the user might not have the chance to see the page before it triggers the refresh.
What is the need that requires the refresh?
Ah, using the 1 is not a problem as far as the user not being able to see the page before it triggers the refresh - in fact that is exactly what I want to happen.

 It is the problem however when it continues (after the initial refresh) to refresh every 1 second thereafter.

Here is a brief context of what I am trying to do here.

1.  when the application launches, the various menu items are automatically displayed as tabs in the chrome browser (only the chrome browser will be used). I use the chrome settings facility to achieve this.
2. The page on the leftmost tab is the one which is automatically displayed (default) on launch and this page is a 'sign in' page, where a user password is demanded.
3. If the user tries to open any of the displayed tabs without signing in, they do not get access to the page in question - just an advice telling them that they must sign in.
4. After 3 above, they will go back to the default sign in form and provide the password. If the password is correct then they must have access to all of the chrome tab pages.

PROBLEM
If you click any of the tabs after completing step 4 - you get the advice telling them that they must sign in. All it takes to remedy this is to do a ctrl R - this immediately launches the page.  However this is not an acceptable thing to expect the users to do.   They need to get immediate access by just clicking on the tab - and not having to  hit ctrl R afterwords.
why not issue on sign-in a location: directive after you set the cookie or send check what the tab selection triggers to see whether it gets an automated response or it checks whether the user has loged in prior to generating the response.

it sounds as your current selection merely responds based on the state of the user when the page is loaded which is why you need a complete reload after the login for the tab's permissions/settings to be adjusted to the new status of user loged in.
Thanks arnold,
could you say a bit more about location:directive. I have not come across it before and am struggling to see how to use it.
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help arnold. Problem not yet solved, but with your help I am on the way.

James