Can someone advice if this is the optimal solution? I didn't get any
feedback yesterday - and must get this working.
I've been doing Python a short time, so not always sure the best
Pythonic approach...
I built an array of objects like this:
class Language(db.Model): #this is never stored in database
name = db.StringProperty()
imageURL = db.StringProperty()
selected = db.BooleanProperty()
languages = [];
languages.append(Language(name="English",imageURL="
http://3wcloud.com/
images/flags/english.jpg",selected=True));
languages.append(Language(name="Spanish",imageURL="
http://3wcloud.com/
images/flags/portuguese.jpg",selected=False))
languages.append(Language(name="Portuguese",imageURL="http://
3wcloud.com/images/flags/portuguese.jpg",selected=False))
languages.append(Language(name="Spanish",imageURL="
http://3wcloud.com/
images/flags/mandarin.jpg",selected=False))
I used db.Model just to use the "strong typing" of the fields. Good
idea or bad idea???
then I pass the languages array to the template...
TEMPLATE:
{% for language in languages %}
<img src="{{language.imageURL}}"> <span class="wpcf7-
form-control-wrap language_sp"><span class="wpcf7-checkbox"><span
class="wpcf7-list-item">
<input type="checkbox" name="language" value="{{
language.name}}"
{% if language.selected %}
checked
{% endif %}
/>
<span class="wpcf7-list-item-label">{{
language.name}}</span></
span></span></span><br />
{% endfor %}
The downside of this technique is that I have moved templates and
graphics information from the template to the Python code. In my
case, I'm doing both, but in the ideal world we should separate the
GUI from the program. Now, if a new language is added, the programmer
must change the python code, as opposed to the graphic guy just
updating the template.
Thanks,
Neal Walters