Projet

Général

Profil

Support #10783

best way to add extra attribute kinds?

Ajouté par Frédéric Péters il y a presque 8 ans. Mis à jour il y a plus de 7 ans.

Statut:
Fermé
Priorité:
Normal
Assigné à:
Catégorie:
-
Version cible:
Début:
01 mai 2016
Echéance:
% réalisé:

100%

Temps estimé:
Patch proposed:
Non
Planning:

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?

Révisions associées

Révision 412d09be (diff)
Ajouté par Benjamin Dauvergne il y a presque 8 ans

add helper to collect data from plugins (#10783)

Révision e7248a80 (diff)
Ajouté par Benjamin Dauvergne il y a presque 8 ans

allow plugin to provide attribute kinds (fixes #10783)

Historique

#1

Mis à jour par Mikaël Ates il y a presque 8 ans

  • Version cible mis à 2.2.0
#2

Mis à jour par Benjamin Dauvergne il y a presque 8 ans

  • Statut changé de Nouveau à Résolu (à déployer)
  • % réalisé changé de 0 à 100
#3

Mis à jour par Frédéric Péters il y a presque 8 ans

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

#4

Mis à jour par Benjamin Dauvergne il y a presque 8 ans

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

#5

Mis à jour par Benjamin Dauvergne il y a plus de 7 ans

  • Statut changé de Résolu (à déployer) à Fermé

Formats disponibles : Atom PDF