admin.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:edd 作者: JBEI 项目源码 文件源码
def get_form(self, request, obj=None, **kwargs):
        """
        Override default generated admin form to add specialized help text and verification for
        Uniprot accession ID's. This is a bit indirect since type_name is inherited from
        MeasurementTypeAdmin.
        """

        # override the type_name label to indicate it should be a UniProt accession ID
        if settings.REQUIRE_UNIPROT_ACCESSION_IDS:
            labels = kwargs.get('labels')
            if not labels:
                labels = {}
                kwargs['labels'] = labels
            labels['type_name'] = _('Protein Name')
            labels['accession_id'] = _('UniProt Accession ID')

        generated_form = super(ProteinAdmin, self).get_form(request, obj, **kwargs)

        # require that newly-created ProteinIdentifiers have an accession ID matching the
        # expected pattern. existing ID's that don't conform should still be editable
        new_identifier = not obj
        if new_identifier and settings.REQUIRE_UNIPROT_ACCESSION_IDS:
            generated_form.base_fields['type_name'].validators.append(RegexValidator(
                    regex=ProteinIdentifier.accession_pattern,
                    message=_('New entries must be valid UniProt accession IDs')))
        return generated_form
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号