Hello Adam,<div><br class="khtml-block-placeholder"></div><div>Great, thanks<br><br><div><span class="gmail_quote">On 9/15/07, <b class="gmail_sendername">Adam Groszer</b> &lt;<a href="mailto:agroszer@gmail.com">agroszer@gmail.com
</a>&gt; wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">





<div>

<p>Hello Jesper,</p>
<p><br></p>
<p>That should be solved already. Look for z3c.widget.country.</p>
<p>svn://svn.zope.org/repos/main/z3c.widget/trunk/src/z3c/widget/country</p><div><span class="e" id="q_11509f9172fc6e86_1">
<p><br></p>
<p>Saturday, September 15, 2007, 6:08:19 PM, you wrote:</p>
<p><br></p>
<div><table border="0" cellpadding="1" cellspacing="2">
<tbody><tr valign="top"><td width="12" style="background-color:#0000ff">
<p><span>&gt;</span></p>
</td><td width="684" style="background-color:#ffffff">
<p><span>Hello!</span></p>
<p><span>I&#39;m trying to implement a DropdownWidget for my country list. In my app i&#39;d like to have a dropdown menu where a user can choose a country (for my main content object, a job). My vocabulary is created from a list of strings, and stored in a local utility:&nbsp;
</span></p>
<p><br></p>
<p><span>&nbsp;</span></p>
<p><span>SimpleVocabulary.fromValues( [u&#39;AD&#39;, u&#39;AE&#39;, &#39;AF&#39;, ...] )</span></p>
<p><br></p>
<p><span>&nbsp;</span></p>
<p><span>But in my dropdown widget i want to display the country name for each option too.. and not just the same value on both the value attribute and inside the element:&nbsp;</span></p>
<p><br></p>
<p><span>&lt;option value=&quot;AD&quot;&gt;Andorra&lt;/option&gt;</span></p>
<p><br></p>
<p><span>So i send in a different vocabulary.. one that looks like this:&nbsp;</span></p>
<p><br></p>
<p><span>[(u&#39;AD&#39;, u&#39;Andorra&#39;),...]</span></p>
<p><br></p>
<p><span>So i coded this:</span></p>
<p><br></p>
<p><span>---------------------------------</span></p>
<p><span>&nbsp;class CountryDropDown(DropdownWidget):</span></p>
<p><br></p>
<p><span>&nbsp; &nbsp; &nbsp;def __init__(self, field, request):</span></p>
<p><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#This returns a dict: {&#39;countrycode&#39;:&#39;countryname&#39;}&nbsp;</span></p>
<p><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;territories = request.locale.displayNames.territories</span></p>
<p><span>&nbsp;</span></p>
<p><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# Invert the territories dict: keys=names, values=ccodes</span></p>
<p><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;self.territories = sorted(territories.items (), key=itemgetter(1))</span></p>
<p><br></p>
<p><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#not using this any longer..</span></p>
<p><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#voc = getUtility(IVocabularyFactory, u&#39;Country codes&#39;)</span></p>
<p><span>&nbsp; &nbsp; &nbsp; &nbsp;</span></p>
<p><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;voc = SimpleVocabulary.fromItems(self.territories)</span></p>
<p><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;super(CountryDropDown, self).__init__(field, voc, request)</span></p>
<p><span>&nbsp;</span></p>
<p><span>&nbsp; &nbsp; &nbsp;def textForValue(self, term):</span></p>
<p><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return term.value</span></p>
<p><span>---------------------------------</span></p>
<p><br></p>
<p><span>But it seems like when i choose a country, e.g Andorra, the constraint fails. I think it is because my modified vocabulary that i sent in which it is now checking constraints against fails.&nbsp;</span></p>
<p><br></p>
<p><span>I want the constraints to be checked in my ordinary vocabulary but i want to use a different one when populating the dropdown.. any ideas?</span></p>
<p><br></p>
<p><br></p>
<p><span>----------</span></p>
<p><span>Instant Foo - Naturally Flavoured</span></p>
</td></tr></tbody></table>
</div>
<p><br></p>
<p><br></p>
<p><br></p>
<p><br></p></span></div>
<p><span>--&nbsp;</span></p>
<p><span>Best regards,</span></p>
<p><span>&nbsp;Adam &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><a href="mailto:agroszer@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">mailto:agroszer@gmail.com</a></p>

</div>

</blockquote></div><br>&nbsp;</div>