Exemplo n.º 1
0
 class Meta:
     model = User
     fields = [a(_f) for _f in (User.id, User.email)]
     read_only_fields = [a(_f) for _f in (
         User.id,
         User.pk,
     )]
Exemplo n.º 2
0
 class Meta:
     model = Comment
     widgets = {
         a(Comment.author): forms.HiddenInput,
         a(Comment.post): forms.HiddenInput,
         a(Comment.parent): forms.HiddenInput,
         a(Comment.message): forms.TextInput(attrs={"size": "30"}),
     }
     fields = [
         a(_f) for _f in (Comment.author, Comment.message, Comment.post,
                          Comment.parent)
     ]
     """[
Exemplo n.º 3
0
 class Meta:
     model = Comment
     widgets = {
         a(Comment.author): forms.HiddenInput,
         a(Comment.post): forms.HiddenInput,
     }
     fields = [
         a(_f)
         for _f in (
             Comment.author,
             Comment.message,
             Comment.post,
         )
     ]
Exemplo n.º 4
0
 class Meta:
     model = Calendar
     fields = "__all__"
     widgets = {
         a(Calendar.ical):
         forms.Textarea(attrs={
             "cols": 100,
             "disabled": 1,
             "rows": 3,
         }),
         a(Calendar.description):
         forms.Textarea(attrs={
             "cols": 100,
             "rows": 3,
         }),
     }
Exemplo n.º 5
0
class AuthProfileAdminModel(ModelAdmin):
    readonly_fields = [
        a(f) for f in (
            AuthProfile.user,
            AuthProfile.verification_code,
            AuthProfile.verified_at,
        )
    ]
Exemplo n.º 6
0
 class Meta:
     model = Reminder
     fields = "__all__"
     read_only_fields = [
         a(_f) for _f in (
             Reminder.created_at,
             Reminder.creator,
             Reminder.id,
             Reminder.notified_at,
             Reminder.pk,
         )
     ]
Exemplo n.º 7
0
Arquivo: xforms.py Projeto: Gul-lug/re
def gen_textinput_admin_form(model_cls: type,
                             model_fields: Iterable[models.Field]) -> type:
    model_field_names = (a(_field) for _field in model_fields)

    class AdminFormWithTextInputs(forms.ModelForm):
        class Meta:
            model = model_cls
            fields = "__all__"
            widgets = {
                _field: forms.TextInput(attrs={"size": "10"})
                for _field in model_field_names
            }

    return AdminFormWithTextInputs
Exemplo n.º 8
0
    class Meta:
        model = Reminder
        fields = [
            a(_f) for _f in (
                Reminder.notify_at,
                Reminder.title,
                Reminder.description,
                Reminder.location,
                Reminder.participants,
            )
        ]

        widgets = {
            "title": forms.TextInput,
        }
Exemplo n.º 9
0
    def test_a(self):
        dataset = {
            1: "1",
            None: "None",
            Permission.content_type: "content_type",
            Permission: "auth_permission",
            User.email: "email",
            User.groups: "groups",
            User.id: "id",
            User: "******",
        }

        for data, expected in dataset.items():
            got = a(data)

            self.assertEqual(
                expected, got, f"{a.__name__}({data!r}) -> {got!r} != {expected!r}"
            )
Exemplo n.º 10
0
def gen_textinput_admin_form(
    model_cls: type,
    model_fields: Iterable[models.Field],
    text_input_size: Optional[int] = 100,
) -> type:
    """
    Give me these:
    :param model_cls - a model you want to be displayed in Django Admin
    :param model_fields: model fields to be displayed as <input type="text">
    :param text_input_size: size attribute of <input type="text">
    And I will generate and
    :return a ModelForm class
    """

    size = text_input_size or 100  # XXX: arbitrary size
    fields = (a(_field) for _field in model_fields)
    widgets = {
        _field: forms.TextInput(attrs={"text_input_size": str(size)})
        for _field in fields
    }

    cls_meta_dict = {
        "model": model_cls,
        "fields": "__all__",
        "widgets": widgets,
    }
    cls_meta = type("Meta", (), cls_meta_dict)

    cls_form_dict = {"Meta": cls_meta}
    cls_form = type(
        f"{model_cls.__name__}AdminFormWithTextInputs",
        (forms.ModelForm, ),
        cls_form_dict,
    )

    return cls_form
Exemplo n.º 11
0
class ProfileAdminModel(ModelAdmin):
    readonly_fields = [a(f) for f in (Profile.user,)]
Exemplo n.º 12
0
 class Meta:
     model = User
     fields = [a(User.email)]