List of all programming languages in Select Field
Question:
I am trying to create a WtForms SelectField which will show all the various programming languages available to choose from.
Its almost impossible to type all the programming languages listed here in the select field. How to implement this kind of select field.
Code
class SkillForm(Form):
skill = SelectField('Languages', choices=[('c++', 'C++'), ('python', 'Python'), ('text', 'Plain Text')])
submit = SubmitField('Submit')
def validate_skill(self, field):
if Skill.query.filter_by(author_id=current_user.id).filter(Skill.skill==field.data.lower()).first():
raise ValidationError('Skill already exists.')
I have just added three skills for just testing purpose and it works and i need to include all the languages possible and its almost impossible to write them all in choices, so what other option do i get from that.
Any help would be appreciated.
Answers:
You can get all the languages from the website running a script:
#Get the html
import urllib2
response = urllib2.urlopen('http://en.wikipedia.org/wiki/List_of_programming_languages')
html = response.read()
#Parse it with beautifulsoup
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
langs = []
#Parse all the links.
for link in soup.find_all('a'):
#Last link after ZPL, the last language.
if link.get_text() == u'Top':
break
if link.get_text() == u'edit':
pass
else:
langs.append(link.get_text())
# find u'See also'
see_also_index_ = langs.index(u'See also')
# strip out headers
langs = langs[see_also_index_+1:]
print langs
It is for the same reason, I have created a small Github repository with a list of programming languages listed on the Wikipedia – http://en.wikipedia.org/wiki/List_of_programming_languages. It contains HTML checkboxes and dropdowns. Hope this helps someone in the future
You can check out the repo here.
https://github.com/chilarai/list-of-programming-languages
I am trying to create a WtForms SelectField which will show all the various programming languages available to choose from.
Its almost impossible to type all the programming languages listed here in the select field. How to implement this kind of select field.
Code
class SkillForm(Form):
skill = SelectField('Languages', choices=[('c++', 'C++'), ('python', 'Python'), ('text', 'Plain Text')])
submit = SubmitField('Submit')
def validate_skill(self, field):
if Skill.query.filter_by(author_id=current_user.id).filter(Skill.skill==field.data.lower()).first():
raise ValidationError('Skill already exists.')
I have just added three skills for just testing purpose and it works and i need to include all the languages possible and its almost impossible to write them all in choices, so what other option do i get from that.
Any help would be appreciated.
You can get all the languages from the website running a script:
#Get the html
import urllib2
response = urllib2.urlopen('http://en.wikipedia.org/wiki/List_of_programming_languages')
html = response.read()
#Parse it with beautifulsoup
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
langs = []
#Parse all the links.
for link in soup.find_all('a'):
#Last link after ZPL, the last language.
if link.get_text() == u'Top':
break
if link.get_text() == u'edit':
pass
else:
langs.append(link.get_text())
# find u'See also'
see_also_index_ = langs.index(u'See also')
# strip out headers
langs = langs[see_also_index_+1:]
print langs
It is for the same reason, I have created a small Github repository with a list of programming languages listed on the Wikipedia – http://en.wikipedia.org/wiki/List_of_programming_languages. It contains HTML checkboxes and dropdowns. Hope this helps someone in the future
You can check out the repo here.
https://github.com/chilarai/list-of-programming-languages