A none responsive If statement in the view

47 views
Skip to first unread message

mostwanted

unread,
Jun 11, 2019, 3:04:06 AM6/11/19
to web2py-users
My task is very simple but its failing, I have some words in the database that i am comparing to a list of words in the view, if any of the words from the database matches those in the view all the details of that word from the database should be displayed in a div in the view but if no word from the database matches any word in the list from the view a message of NO LISTINGS should be displayed. The problem i am encountering is that now if there is a match, the word details as well as the NO LISTINGS message are both displayed but its supposed to be one or the other not both at the same time. I must be missing something or doing something wrong somewhere, if anyone can figure out my error please assist.

CODE:
<div id="tab-1" class="tab-content current">
        {{letters=['Finance', 'Accountant']
    for jobs in details:
        if jobs.category in letters:
    }}
       
<div class="jobPosts">
   
<img width="80px" src="{{=URL('download', args=jobs.logo)}}" /><br />
    Company: {{=jobs.company}}
<br />
    Post: {{=jobs.post}}
<br />
    Post Description: {{=jobs.post_description}}
<br />
   
<span style="color: red; font-weight: bold;">Closing Date: {{=jobs.expiry_date}}</span><br />
   
</div><br />
        {{pass}}
        {{pass}}
       
{{if jobs.category not in letters:}}
       
<span style="font-weight: bold; color: red;">NO LISTINGS!</span>
        {{pass}}

   
</div>

Regards;

Mostwanted

Massimiliano

unread,
Jun 11, 2019, 3:59:57 AM6/11/19
to web...@googlegroups.com
Your last if is out of the for loop.
Try this way (not tested )
    
    {{letters=['Finance', 'Accountant']
    for jobs in details:
        if jobs.category in letters:
        }}
        ...
        {{ else: }}
<span style="font-weight: bold; color: red;">NO LISTINGS!</span>
        {{ pass }}
    {{ pass }}

    

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/34db1df5-9f8d-4413-a10d-52c4958f410c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Massimiliano

mostwanted

unread,
Jun 11, 2019, 4:57:31 AM6/11/19
to web2py-users
Still doesn't give desired results, it only duplicates the NO LISTINGS statement!
To unsubscribe from this group and stop receiving emails from it, send an email to web...@googlegroups.com.


--
Massimiliano

Dave S

unread,
Jun 11, 2019, 3:19:46 PM6/11/19
to web2py-users


On Tuesday, June 11, 2019 at 1:57:31 AM UTC-7, mostwanted wrote:
Still doesn't give desired results, it only duplicates the NO LISTINGS statement!

What did you put where Massimaliano had "..."; that's where you have to show the value.
<span>{{=jobs.info}}</span>
 
And to show the No Listing only once, I'd change things to

   
    {{
    letters
=['Finance', 'Accountant']
    found
= False

   
for jobs in details:
       
if jobs.category in letters:

        found
= True
     
}}
     
<span>{{=jobs.info}}</span>
     
{{pass}}
     
{{if not found: }}

     
<span style="font-weight: bold; color: red;">NO LISTINGS!</span>    
     
{{ pass }}


/dps

mostwanted

unread,
Jun 12, 2019, 2:01:47 AM6/12/19
to web2py-users
Now i am in business!!!

This is how i implemented the changes you suggested:


<div id="tab-1" class="tab-content current">

        {{letters=['Finance', 'Accountant']
       
found=False

    for jobs in details:
        if jobs.category in letters:
       
found=True

    }}
       
<div class="jobPosts">

   
<img width="80px" src="{{=URL('download', args=jobs.logo)}}" /><br />
    Company: {{=jobs.company}}
<br />
    Post: {{=jobs.post}}
<br />
    Post Description: {{=jobs.post_description}}
<br />
   
<span style="color: red; font-weight: bold;">Closing Date: {{=jobs.expiry_date}}</span><br />
   
</div><br />

        {{pass}}
        {{pass}}
       
{{if not found:}}
       
<span style="font-weight: bold; color: red;">NO LISTINGS!</span>
        {{pass}}

   
</div>
 With @ Massimiliano's suggestion i replaced the "..." with the div that had details, i think it duplicated the NO LISTINGS message because it was within the for loop, it didnt give me what i wanted! But its working now, thanks alot.

Mostwanted

Dave S

unread,
Jun 12, 2019, 4:50:47 AM6/12/19
to web2py-users


On Tuesday, June 11, 2019 at 11:01:47 PM UTC-7, mostwanted wrote:
Now i am in business!!!

Good to hear!

/dps
 
Reply all
Reply to author
Forward
0 new messages