Code

Opened 8 years ago

Closed 7 years ago

#872 closed enhancement (wontfix)

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

Reported by: garthk Owned by: adrian
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: UI/UX:

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 8 years ago.
Fix (off new-admin branch)

Download all attachments as: .zip

Change History (8)

Changed 8 years ago by garthk

Fix (off new-admin branch)

comment:1 Changed 8 years ago by adrian

  • Resolution set to wontfix
  • Status changed from new to closed

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 Changed 8 years ago by garthk

  • Resolution wontfix deleted
  • Status changed from closed to reopened

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 Changed 8 years ago by scum

+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 Changed 8 years ago by anonymous

It should also have cols.

comment:5 Changed 8 years ago by scum

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 Changed 8 years ago by anonymous

  • Version changed from new-admin to 0.91

comment:7 Changed 7 years ago by SmileyChris

  • Resolution set to wontfix
  • Status changed from reopened to closed

I'm pretty sure this will change with newforms

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.