Project

General

Profile

Support #10783

best way to add extra attribute kinds?

Added by Frédéric Péters over 3 years ago. Updated over 2 years ago.

Status:
Fermé
Priority:
Normal
Category:
-
Target version:
Start date:
01 May 2016
Due date:
% Done:

100%

Patch proposed:
No
Planning:
No

Description

For now new attribute kinds are defined from config.py, like this:

from django import forms

class NrnField(forms.CharField):
    def validate(self, value):
        super(NrnField, self).validate(value)
        if not value:
            return
        try:
            if (97 - int(value[:9]) % 97) != int(value[-2:]):
                raise ValueError()
        except ValueError:
            raise forms.ValidationError("Invalid format")

A2_ATTRIBUTE_KINDS = [{
            'label': u'National Register Number',
            'name': 'nrn',
            'field_class': NrnField,
        }]

but I'd prefer to have this in a proper module.

I'm guessing we'd need a new extension point in plugins and change get_attribute_kinds to chain through them, but maybe you have a different suggestion?

Associated revisions

Revision 412d09be (diff)
Added by Benjamin Dauvergne over 3 years ago

add helper to collect data from plugins (#10783)

Revision e7248a80 (diff)
Added by Benjamin Dauvergne over 3 years ago

allow plugin to provide attribute kinds (fixes #10783)

History

#1 Updated by Mikaël Ates over 3 years ago

  • Target version set to 2.2.0

#2 Updated by Benjamin Dauvergne over 3 years ago

  • % Done changed from 0 to 100
  • Status changed from Nouveau to Résolu (à déployer)

#3 Updated by Frédéric Péters over 3 years ago

I can dig into the commit but a short explanation would be faster.

#4 Updated by Benjamin Dauvergne over 3 years ago

Just add an attribute_kinds property or method to your plugin, it must return a list of dictionnaries (like A2_ATTRIBUTE_KINDS).

#5 Updated by Benjamin Dauvergne over 2 years ago

  • Status changed from Résolu (à déployer) to Fermé

Also available in: Atom PDF