Exemplo n.º 1
0
    def compress(self, data_list):
        fields = get_fields(self.word_type)
        keys = {key: i for i, key in enumerate(sorted(fields.keys()))}

        word_forms = [
            data_list[keys['%s_%d' % (WORD_FIELD_PREFIX, i)]]
            for i in range(len(utg_data.INVERTED_WORDS_CACHES[self.word_type]))
        ]

        properties = utg_words.Properties()

        for static_property, required in self.word_type.properties.items():
            value = data_list[keys['%s_%s' % (WORD_FIELD_PREFIX,
                                              static_property.__name__)]]

            if not value:
                continue

            properties = utg_words.Properties(properties, value)

        word = utg_words.Word(type=self.word_type,
                              forms=word_forms,
                              properties=properties)

        word.autofill_missed_forms()

        return word
Exemplo n.º 2
0
    def format_output(self, rendered_widgets):
        from the_tale.linguistics.relations import WORD_BLOCK_BASE
        from the_tale.linguistics.word_drawer import Leaf
        from the_tale.linguistics.word_drawer import FormFieldDrawer

        fields = get_fields(self.word_type)
        keys = {key: i for i, key in enumerate(sorted(fields.keys()))}

        leaf = Leaf(type=self.word_type,
                    base=WORD_BLOCK_BASE.C,
                    key={
                        utg_relations.NUMBER: utg_relations.NUMBER.SINGULAR,
                        utg_relations.NOUN_FORM: utg_relations.NOUN_FORM.NORMAL
                    })

        widgets = {key: rendered_widgets[keys[key]] for key in keys}

        drawer = FormFieldDrawer(type=self.word_type,
                                 widgets=widgets,
                                 skip_markers=self.skip_markers,
                                 show_properties=self.show_properties)
        return jinja2.Markup(
            dext_jinja2.render('linguistics/words/simple_noun_field.html',
                               context={
                                   'drawer': drawer,
                                   'leaf': leaf
                               }))
Exemplo n.º 3
0
    def __init__(self,
                 word_type,
                 show_properties=True,
                 skip_markers=(),
                 **kwargs):
        fields = get_fields(word_type)
        keys = sorted(fields.keys())

        self.fields_keys = dict(enumerate(keys))

        requireds = [fields[key].required for key in keys]

        label = kwargs.get('label')
        if label:
            label = mark_safe('<h3>%s</h3>' % label)
            kwargs['label'] = label

        super(WordField, self).__init__(fields=[fields[key] for key in keys],
                                        widget=WordWidget(
                                            word_type=word_type,
                                            skip_markers=skip_markers,
                                            show_properties=show_properties),
                                        **kwargs)
        for key, required in zip(keys, requireds):
            fields[key].required = required

        self.word_type = word_type
Exemplo n.º 4
0
    def __init__(self, word_type, skip_markers=(), show_properties=True, **kwargs):
        fields = get_fields(word_type)
        keys = sorted(fields.keys())

        super(WordWidget, self).__init__(widgets=[fields[key].widget for key in keys],
                                         **kwargs)

        self.word_type = word_type
        self.skip_markers = skip_markers
        self.show_properties = show_properties
Exemplo n.º 5
0
    def format_output(self, rendered_widgets):
        from the_tale.linguistics.word_drawer import FormFieldDrawer

        fields = get_fields(self.word_type)
        keys = {key: i for i, key in enumerate(sorted(fields.keys()))}

        widgets = {key: rendered_widgets[keys[key]] for key in keys}

        drawer = FormFieldDrawer(type=self.word_type, widgets=widgets, skip_markers=self.skip_markers, show_properties=self.show_properties)

        return jinja2.Markup(dext_jinja2.render('linguistics/words/field.html', context={'drawer': drawer}))
Exemplo n.º 6
0
    def __init__(self, word_type, show_properties=True, skip_markers=(), **kwargs):
        fields = get_fields(word_type)
        keys = sorted(fields.keys())

        self.fields_keys = dict(enumerate(keys))

        requireds = [fields[key].required for key in keys]

        label = kwargs.get('label')
        if label:
            label = mark_safe(u'<h3>%s</h3>' % label)
            kwargs['label'] = label

        super(WordField, self).__init__(fields=[fields[key] for key in keys],
                                                     widget=WordWidget(word_type=word_type, skip_markers=skip_markers, show_properties=show_properties),
                                                     **kwargs)
        for key, required in zip(keys, requireds):
            fields[key].required = required

        self.word_type = word_type
Exemplo n.º 7
0
def decompress_word(word_type, value):
    if value:
        initials = get_word_fields_initials(value)

        for static_property, required in value.type.properties.iteritems():

            v = value.properties.is_specified(static_property)

            if not v:
                continue

            initials['%s_%s' % (WORD_FIELD_PREFIX, static_property.__name__)] = value.properties.get(static_property)

    else:
        initials = get_fields(word_type)
        initials = {k: u'' for k in initials.iterkeys()}

    fields = get_fields(word_type)
    keys = sorted(fields.keys())

    return [initials.get(key) for key in keys]
Exemplo n.º 8
0
    def compress(self, data_list):
        fields = get_fields(self.word_type)
        keys = {key: i for i, key in enumerate(sorted(fields.keys()))}

        word_forms = [data_list[keys['%s_%d' % (WORD_FIELD_PREFIX, i)]] for i in xrange(len(utg_data.INVERTED_WORDS_CACHES[self.word_type]))]

        properties = utg_words.Properties()

        for static_property, required in self.word_type.properties.iteritems():
            value = data_list[keys['%s_%s' % (WORD_FIELD_PREFIX, static_property.__name__)]]

            if not value:
                continue

            properties = utg_words.Properties(properties, value)

        word = utg_words.Word(type=self.word_type,
                              forms=word_forms,
                              properties=properties)

        word.autofill_missed_forms()

        return word