예제 #1
0
class SearchForm(Form):
    '''
    Form for searching the user database.
    '''

    questionnaire_area = CallableChoicesSelectField(choices=lambda: [
        ('ZZ', lazy_gettext('Choose an expertise area'))
    ] + [(q['id'], lazy_gettext(q['name'])) for q in QUESTIONNAIRES
         if q['questions']],
                                                    default='ZZ')
    country = CountryField()
    locale = CallableChoicesSelectField(choices=lambda: [
        ('ZZ', lazy_gettext('Choose a language'))
    ] + [(l.language, l.get_language_name(get_locale())) for l in LOCALES],
                                        default='ZZ')
    expertise_domain_name = CallableChoicesSelectField(choices=lambda: [
        ('ZZ', lazy_gettext('Choose a field of work'))
    ] + [(v, lazy_gettext(v)) for v in current_app.config['DOMAINS']],
                                                       default='ZZ')

    # This doesn't actually appear as a field in a form, but as a tab
    # in a result set, so it's a bit unusual.
    skill_level = SelectField(choices=[(level['score'], '')
                                       for level in LEVELS.values()],
                              coerce=int,
                              default=LEVELS['LEVEL_I_CAN_DO_IT']['score'])

    fulltext = StringField()
예제 #2
0
파일: manage.py 프로젝트: batusayici/noi2
def translate():
    """
    Extract translation for all existing locales, creating new mofiles when
    necessary, updating otherwise.  We have to do some tricky stuff to figure
    out which strings are marked for translation in the domains and
    questionnaires.
    """
    locales = set()

    with open('/noi/app/data/deployments.yaml') as deployments_file:
        deployments = yaml.load(deployments_file)

    with open('/noi/app/data/questions.yaml') as questions_file:
        questionnaires = yaml.load(questions_file)

    with codecs.open('/noi/app/templates/translate.tmp.html', 'w', 'utf-8') as totranslate:
        for deployment in deployments.values():
            for domain in deployment.get('domains', []):
                totranslate.write(gettext_for(domain))
            #if 'about' in deployment:
            #    totranslate.write(gettext_for(deployment['about']))
            if 'locale' in deployment:
                locales.add(deployment['locale'])

        for questionnaire in questionnaires:
            totranslate.write(gettext_for(questionnaire['description']))
            totranslate.write(gettext_for(questionnaire['name']))
            if 'topics' in questionnaire:
                for topic in questionnaire['topics']:
                    totranslate.write(gettext_for(topic['topic']))
                    totranslate.write(gettext_for(topic['description']))
                    for question in topic['questions']:
                        totranslate.write(gettext_for(question['question']))

        for level in LEVELS.values():
            totranslate.write(gettext_for(level['label']))

        for org_type in ORG_TYPES.values():
            totranslate.write(gettext_for(org_type))

    # Generate basic messages.pot
    subprocess.check_call(
        'pybabel extract -F /noi/app/babel.cfg -k lazy_gettext -o /noi/app/messages.pot /noi/',
        shell=True)

    # Update all potfiles, create those not yet in existence
    for locale in locales:
        try:
            subprocess.check_call('pybabel update -l {locale} -i /noi/app/messages.pot '
                                  '-d /noi/app/translations/'.format(
                                      locale=locale), shell=True)
        except subprocess.CalledProcessError:
            subprocess.check_call('pybabel init -l {locale} -i /noi/app/messages.pot '
                                  '-d /noi/app/translations/'.format(
                                      locale=locale), shell=True)
        subprocess.check_call('pybabel compile -f -l {locale} -d /noi/app/translations/'.format(
            locale=locale), shell=True)

    return 0
예제 #3
0
파일: factories.py 프로젝트: codybousc/noi2
from factory import LazyAttribute, RelatedFactory, post_generation
from factory.alchemy import SQLAlchemyModelFactory
from factory.fuzzy import FuzzyChoice, FuzzyNaiveDateTime
from faker import Faker
from datetime import datetime
from random import choice, randint, sample

import logging


# Only log warnings from factoryboy, its default DEBUG statements are spammy
logging.getLogger('factory').setLevel(logging.WARNING)
fake = Faker()

LEVEL_SCORES = [lvl['score'] for lvl in LEVELS.values()]


class SharedMessageEventFactory(SQLAlchemyModelFactory):

    class Meta:  # pylint: disable=old-style-class,no-init,too-few-public-methods
        model = SharedMessageEvent
        sqlalchemy_session = db.session

    message = LazyAttribute(lambda o: fake.paragraph())


class EmailFactory(SQLAlchemyModelFactory):

    class Meta:  # pylint: disable=old-style-class,no-init,too-few-public-methods
        model = Email
예제 #4
0
파일: manage.py 프로젝트: tekd/noi2
def translate():
    """
    Extract translation for all existing locales, creating new mofiles when
    necessary, updating otherwise.  We have to do some tricky stuff to figure
    out which strings are marked for translation in the domains and
    questionnaires.
    """
    locales = set()

    with open('/noi/app/data/deployments.yaml') as deployments_file:
        deployments = yaml.load(deployments_file)

    with open('/noi/app/data/questions.yaml') as questions_file:
        questionnaires = yaml.load(questions_file)

    with codecs.open('/noi/app/templates/translate.tmp.html', 'w',
                     'utf-8') as totranslate:
        for deployment in deployments.values():
            for domain in deployment.get('domains', []):
                totranslate.write(gettext_for(domain))
            #if 'about' in deployment:
            #    totranslate.write(gettext_for(deployment['about']))
            if 'locale' in deployment:
                locales.add(deployment['locale'])

        for questionnaire in questionnaires:
            totranslate.write(gettext_for(questionnaire['description']))
            totranslate.write(gettext_for(questionnaire['name']))
            if 'topics' in questionnaire:
                for topic in questionnaire['topics']:
                    totranslate.write(gettext_for(topic['topic']))
                    totranslate.write(gettext_for(topic['description']))
                    for question in topic['questions']:
                        totranslate.write(gettext_for(question['question']))

        for level in LEVELS.values():
            totranslate.write(gettext_for(level['label']))

        for org_type in ORG_TYPES.values():
            totranslate.write(gettext_for(org_type))

    # Generate basic messages.pot
    subprocess.check_call(
        'pybabel extract -F /noi/app/babel.cfg -k lazy_gettext -o /noi/app/messages.pot /noi/',
        shell=True)

    # Update all potfiles, create those not yet in existence
    for locale in locales:
        try:
            subprocess.check_call(
                'pybabel update -l {locale} -i /noi/app/messages.pot '
                '-d /noi/app/translations/'.format(locale=locale),
                shell=True)
        except subprocess.CalledProcessError:
            subprocess.check_call(
                'pybabel init -l {locale} -i /noi/app/messages.pot '
                '-d /noi/app/translations/'.format(locale=locale),
                shell=True)
        subprocess.check_call(
            'pybabel compile -f -l {locale} -d /noi/app/translations/'.format(
                locale=locale),
            shell=True)

    return 0
예제 #5
0
파일: factories.py 프로젝트: toolness/noi2
from flask import current_app

from factory import LazyAttribute, RelatedFactory, post_generation
from factory.alchemy import SQLAlchemyModelFactory
from factory.fuzzy import FuzzyChoice, FuzzyNaiveDateTime
from faker import Faker
from datetime import datetime
from random import choice, randint, sample

import logging

# Only log warnings from factoryboy, its default DEBUG statements are spammy
logging.getLogger('factory').setLevel(logging.WARNING)
fake = Faker()

LEVEL_SCORES = [lvl['score'] for lvl in LEVELS.values()]


class SharedMessageEventFactory(SQLAlchemyModelFactory):
    class Meta:  # pylint: disable=old-style-class,no-init,too-few-public-methods
        model = SharedMessageEvent
        sqlalchemy_session = db.session

    message = LazyAttribute(lambda o: fake.paragraph())


class EmailFactory(SQLAlchemyModelFactory):
    class Meta:  # pylint: disable=old-style-class,no-init,too-few-public-methods
        model = Email
        sqlalchemy_session = db.session