1 year ago

#238760

test-img

JThao

How do I add an if statement without breaking my code?

I am working with python zope printing html code and the traceback isn't very helpful. I want to add an if statement to check if "test(highlight_today == 'yes' and DateTime(container.util.getToday(format="%m-%d-%Y")) == DateTime(dmy), 'color:black;; font-weight:900;;', 'color:grey;;')" exists. If it does add "tabindex=0". However I ran into a couple of issues.

First try was making it into a variable.

try1 = test(highlight_today == 'yes' and DateTime(container.util.getToday(format="%m-%d-%Y")) == DateTime(dmy), 'color:black;; font-weight:900;;', 'color:grey;;')

but I get traceback error even before I try to do an if statement. I also try to String it but have similar outcome.

 __traceback_info__: container.Admin.Holiday.printCalendar(current_mo=container.securityUtil.sanitize(path('request/month | nothing')) or container.util.getToday(format='%m'), current_yr=container.securityUtil.sanitize(path('request/year | nothing')) or container.util.getToday(format='%Y'), past_date='no', highlight_today='yes', prev_next='yes', min_height='3em')
  Module PythonExpr, line 1, in <expression>

I also get this traceback if I try to ident after the docstring for readability. I been trying to find resources online about zope string concatenation with html but haven't been successful. Any advice or suggestions helps. There are two parts to the table. From what I can tell this first part had no issues.

print '''
    <table class="scroll_data" style="background-color:white">
        <tr><td class="bold" colspan="7" style="text-align:center">%s<span class="px-2" tabindex="0" aria-label="%s %s schedule">%s %s</span>%s</td></tr>
        <tr>
            <td width="14%%">Sun</td>
            <td width="14%%">Mon</td>
            <td width="14%%">Tue</td>
            <td width="14%%">Wed</td>
            <td width="14%%">Thu</td>
            <td width="14%%">Fri</td>
            <td width="14%%">Sat</td>
        </tr>
    ''' %(test(prev_next=='yes','<input type="button" title="View previous month calendar" id="cal_prev" value="Prev" data-role="none" data-inline="true"/>',''),
    month, current_yr, month, current_yr, test(prev_next=='yes',
    '<input type="button" title="View next month calendar" id="cal_next" value="Next" data-role="none" data-inline="true"/>',''))

Second part

dow = 0
dow_continue = 'false'
current_date = 1
while current_date <= int(date_range):

    current_dt=''
    if int(current_date) < 10:
        current_dt = '0' + str(int(current_date))
        # if current date 1 < 10 dt = 0+1
        # dt = 01
    else:
        current_dt = str(current_date)
        # else dt = 10 or 11 etc.


    if dow == 0:
        print '''   <tr>'''

    if dow_start == dow or dow_continue == 'true':
        dow_continue = 'true'

        dmy = '%s-%s-%s' %(current_month, current_dt, current_yr)

        # This print statement was a one liner, it breaks when I indent it, either I am indenting it wrong or zope doesn't allow me?
        print '''       <td class="%s" id="%s" style="text-align: right; vertical-align: top; %s height:%s;">
        <span style="color:black">%d</span></td>''' 
        %(test(past_date == 'yes', test(DateTime(container.util.getToday(format="%m-%d-%Y")) > DateTime(dmy), 'even', 'odd'), 'odd'), 
        dmy, 
        test(highlight_today == 'yes' and DateTime(container.util.getToday(format="%m-%d-%Y")) == DateTime(dmy), 'color:black;; font-weight:900;;', 'color:grey;;'),
        min_height, 
        current_date)

        current_date = current_date + 1

    else:

        print '''       <td>&nbsp;</td>'''

    if dow == 6:
        print '''   </tr>'''
        dow = -1

    dow = dow + 1

python

html

python-2.x

zope

0 Answers

Your Answer

Accepted video resources