CouchDbKit Django ext does not work with choices

オープン
#110 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
django, python
領域
backend, databases

調査の方向性

couchdbkit/ext/django/forms.py の fields_for_document(160 行目)から始め、issue の Work と WorkForm の例を使ってレンダリング失敗を再現します。StringProperty のデフォルト値と choices がフォームフィールドのオプションにどのように変換されるかを確認します。これらの choices を持つドキュメントが、報告された TypeError なしでフォームをレンダリングでき、意図したデフォルト動作を維持できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Here is a code example::

# models.py

from couchdbkit.ext.django import schema

LICENCE_CHOICES = (
    ('gpl', _('GPL')),
    ('lgpl', _('LGPL')),
    ('bsd', _('BSD')),
)

class Work(schema.Document):
    licence = schema.StringProperty(_('Licence'),
            required=True, default='gpl', choices=LICENCE_CHOICES)

# forms.py

from couchdbkit.ext.django.forms import DocumentForm

from .models import Work

class WorkForm(DocumentForm):
    class Meta:
        document = Work

When I try to render this form, I get this error::

Error when calling the metaclass bases
    cannot concatenate 'str' and 'list' objects

Exception Location: .../couchdbkit/ext/django/forms.py in
                                fields_for_document, line 160

This error is caused by this code::

if prop.choices:
    if prop.default:
        defaults['choices'] = prop.default_value() + list(
                        prop.choices)
        defaults['coerce'] = prop.to_python

My default value is 'gpl', why default value is concatenated with choices? Is
this an error or a feature which I don't know how to use?

主要言語
Python
スター
261
フォーク
90
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

benoitc/couchdbkit のほかの issue

benoitc/couchdbkit の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。