Opened 19 years ago

Closed 17 years ago

#872 closed enhancement (wontfix)

fields.TextField should pass 'rows' argument to its formfields.LargeTextField

Reported by: garthk Owned by: Adrian Holovaty
Component: contrib.admin Version: 0.91
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It takes me twenty lines of code to pass a 'rows' argument from my model definition to the admin display:

from django.core import meta, formfields
from django.utils.functional import curry

class HeightAdjustableTextField(meta.TextField):
    """A TextField with adjustable rows."""

    def __init__(self, *args, **kwargs): 
        """Initialise the HeightAdjustableTextField."""
        # Default row count is from django.core.formfields.LargeTextField.
        # Popping removes the keyword argument, if present. 
        self.rows = kwargs.pop('rows', 10) 
        meta.TextField.__init__(self, *args, **kwargs)

    def get_manipulator_field_objs(self):
        return [curry(formfields.LargeTextField, rows=self.rows)]
  
meta.HeightAdjustableTextField = HeightAdjustableTextField

class Post(meta.Model): 
    # ...
    tease = meta.HeightAdjustableTextField(rows=3, blank=True)

Making django.core.meta.fields.TextField three lines longer will save me all that code:

class TextField(Field):
    def __init__(self, *args, **kwargs):
        self.edit_rows = kwargs.pop('rows', 10)
        Field.__init__(self, *args, **kwargs)
    def get_manipulator_field_objs(self):
        return [curry(formfields.LargeTextField, rows=self.edit_rows)]

Attachments (1)

872.diff (650 bytes ) - added by garthk 19 years ago.
Fix (off new-admin branch)

Download all attachments as: .zip

Change History (8)

by garthk, 19 years ago

Attachment: 872.diff added

Fix (off new-admin branch)

comment:1 by Adrian Holovaty, 19 years ago

Resolution: wontfix
Status: newclosed

That's a bit too presentation-centric for inclusion in models. The solution to your problem is to edit your admin CSS file and set height on the field(s) whose height you want to change.

comment:2 by garthk, 19 years ago

Resolution: wontfix
Status: closedreopened

I'm having trouble, here. How can using a field's arguments to configure its admin edit row count be too presentation-centric, but using the same set of arguments to configure it for inline editing somehow *not* be too presentation-centric?

If you'd rather keep it out of the field definition, can you come up with a way for me to tailor form field arguments via meta.Admin()? If you're happy tailoring my administration views complete with collapsible field sets from in there, I'd hope it's not too presentation-centric to pass on a rows= argument for me.

comment:3 by scum, 18 years ago

+1 : I'm gonna have to agree with garthk on this one. I just ran into the need for this functionality and being able to adjust the rows would make sense. While I can understand Adrian's presentation-centric argument, good interface design calls for text fields that are sized to fit the content that will go into them. In some cases, the given 11 rows will be sufficient, but in some cases, it may be too little, and in others, too much. This is a great idea, not to mention intuitive, as I tried putting the 'rows' keyword into my code before researching to see if it existed or not. Please reconsider this enhancement.

comment:4 by anonymous, 18 years ago

It should also have cols.

comment:5 by scum, 18 years ago

Magic removal version for people using this.

from django.db import models
from django import forms
from django.utils.functional import curry

class HeightAdjustableTextField(models.TextField):
	"""A TextField with adjustable rows."""

	def __init__(self, field_name, *args, **kwargs): 
		"""Initialise the HeightAdjustableTextField."""
		# Default row count is from django.core.formfields.LargeTextField.
		# Popping removes the keyword argument, if present. 
		self.rows = kwargs.pop('rows', 10) 
		models.TextField.__init__(self, field_name, *args, **kwargs)

	def get_manipulator_field_objs(self):
		return [curry(forms.LargeTextField, rows=self.rows)]
  
models.HeightAdjustableTextField = HeightAdjustableTextField

Then call this in your model...

body = models.HeightAdjustableTextField("body", rows=30)

comment:6 by anonymous, 18 years ago

Version: new-admin0.91

comment:7 by Chris Beaven, 17 years ago

Resolution: wontfix
Status: reopenedclosed

I'm pretty sure this will change with newforms

Note: See TracTickets for help on using tickets.
Back to Top