Re: MultiValueField Question

2008-04-23 Thread James Snyder

As above, I have this working now.

Any suggestions on wrapping individual items in items from a
multivaluefield in tds?

Thanks.

-jsnyder
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: MultiValueField Question

2008-04-18 Thread James Snyder

OK, so I've somewhat answered my own question here and gotten things
figured out.

I do, however, have another question.

What would be the proper/clean way to do inline editing with newforms?

In the end I did some extremely hackish things to get the multiwidget/
multivaluefields to render with each item in a row being in a separate
.

Basically I want to have tables like the following:

Name  AttendingEvent1AttendingEvent2
AttendingEvent3
Name1
X
X
Name2   X
etc..

This table is made up of model instances that are tied via foreign key
to a parent group, so this means the form also ends up with items that
don't belong in a tabular format.

What should I be subclassing to do this? I don't want everything in
each row in a single  or , this way it's difficult to associate
the fields with meaning.

Might it make sense to have a different way to display fields in
inline editing mode with labels in a header row, and then instances of
a model showing up in the following rows?

I won't post any of the hacky code I just put together because it is
rather evil, and I'd like to replace it :-)  It does, however, work
quite well!

On Apr 17, 6:31 pm, James Snyder <[EMAIL PROTECTED]> wrote:
> Hi -
>
> I've been attempting to put together a website to use for keeping
> track of information for a wedding, and I'm wanting to use multiple
> inline lists of invitees within each group that has been sent an
> invite.  Basically I want something like the admin interface where one
> can do tabular inline editing.  I'm also new to both python and
> django.
>
> I've tried following along with this:http://www.hoboes.com/Mimsy/?ART=607
>
> I've also read what is on the list here regarding using
> MultiValueFields, and I can get things working with a fixed number of
> elements in a MultiValueField, but things are breaking down for me
> with greater numbers.  I'm getting the following error: 'NoneType'
> object is unsubscriptable
>
> This, I presume has to do with the way that I'm doing/not doing
> compress/decompress on the data for the Fields and Widgets, but I'm
> lost as to what I need to do within these functions to give valid
> output.   Here's a portion of the code I'm using. Any suggestions as
> to why when I do the following:
>
> a = weddingsite.register.views.GroupForm()
> print a
>
> I get:
>
>   File "", line 1, in 
>   File "/Library/Python/2.5/site-packages/django/utils/encoding.py",
> line 25, in __str__
>     return self.__unicode__().encode('utf-8')
>   File "/Library/Python/2.5/site-packages/django/newforms/forms.py",
> line 86, in __unicode__
>     return self.as_table()
>   File "/Library/Python/2.5/site-packages/django/newforms/forms.py",
> line 169, in as_table
>     return self._html_output(u'%(label)s%(errors)s%
> (field)s%(help_text)s', u'%s',
> '', u'%s', False)
>   File "/Library/Python/2.5/site-packages/django/newforms/forms.py",
> line 151, in _html_output
>     output.append(normal_row % {'errors': force_unicode(bf_errors),
> 'label': force_unicode(label), 'field': unicode(bf), 'help_text':
> help_text})
>   File "/Library/Python/2.5/site-packages/django/newforms/forms.py",
> line 265, in __unicode__
>     return self.as_widget()
>   File "/Library/Python/2.5/site-packages/django/newforms/forms.py",
> line 293, in as_widget
>     return widget.render(self.html_name, data, attrs=attrs)
>   File "/Library/Python/2.5/site-packages/django/newforms/widgets.py",
> line 423, in render
>     widget_value = value[i]
> TypeError: 'NoneType' object is unsubscriptable
>
> Here's the relevant code:
> class InviteeNameWidgets(forms.MultiWidget):
>     def __init__(self, attendee_count=1, attrs=None):
>         widgets = (forms.TextInput(),)*attendee_count
>         super(InviteeNameWidgets, self).__init__(widgets=widgets,
> attrs=attrs)
>
>     def decompress(self, value):
>         return value
>
> class EventAttendanceWidgets(forms.MultiWidget):
>     def __init__(self, attendee_count=1, attrs=None):
>         widgets = (forms.CheckboxInput(),)*attendee_count
>         super(EventAttendanceWidgets, self).__init__(widgets=widgets,
> attrs=attrs)
>
>     def decompress(self, value):
>         return value
>
> class InviteeNameFields(forms.MultiValueField):
>     widget = InviteeNameWidgets
>     def __init__(self, required=True, attendee_count=1, **kwargs):
>         fields = (forms.CharField(),)*attendee_count
>         super(InviteeNameFields, self).__init__(**kwargs)
>
>     def compress(self, data_list):
>         return data_list
>
> class EventAttendanceFields(forms.MultiValueField):
>     widget = EventAttendanceWidgets
>     def __init__(self, required=True, attendee_count=1, **kwargs):
>         fields = (forms.BooleanField(),)*attendee_count
>         super(EventAttendanceFields,
> self).__init__(fields=fields,**kwargs)
>
>     def compress(self, data_list):
>         return data_list
>
> class GroupForm(forms.Form):
>     email = 

MultiValueField Question

2008-04-18 Thread James Snyder

Hi -

I've been attempting to put together a website to use for keeping
track of information for a wedding, and I'm wanting to use multiple
inline lists of invitees within each group that has been sent an
invite.  Basically I want something like the admin interface where one
can do tabular inline editing.  I'm also new to both python and
django.

I've tried following along with this: http://www.hoboes.com/Mimsy/?ART=607

I've also read what is on the list here regarding using
MultiValueFields, and I can get things working with a fixed number of
elements in a MultiValueField, but things are breaking down for me
with greater numbers.  I'm getting the following error: 'NoneType'
object is unsubscriptable

This, I presume has to do with the way that I'm doing/not doing
compress/decompress on the data for the Fields and Widgets, but I'm
lost as to what I need to do within these functions to give valid
output.   Here's a portion of the code I'm using. Any suggestions as
to why when I do the following:

a = weddingsite.register.views.GroupForm()
print a

I get:

  File "", line 1, in 
  File "/Library/Python/2.5/site-packages/django/utils/encoding.py",
line 25, in __str__
return self.__unicode__().encode('utf-8')
  File "/Library/Python/2.5/site-packages/django/newforms/forms.py",
line 86, in __unicode__
return self.as_table()
  File "/Library/Python/2.5/site-packages/django/newforms/forms.py",
line 169, in as_table
return self._html_output(u'%(label)s%(errors)s%
(field)s%(help_text)s', u'%s',
'', u'%s', False)
  File "/Library/Python/2.5/site-packages/django/newforms/forms.py",
line 151, in _html_output
output.append(normal_row % {'errors': force_unicode(bf_errors),
'label': force_unicode(label), 'field': unicode(bf), 'help_text':
help_text})
  File "/Library/Python/2.5/site-packages/django/newforms/forms.py",
line 265, in __unicode__
return self.as_widget()
  File "/Library/Python/2.5/site-packages/django/newforms/forms.py",
line 293, in as_widget
return widget.render(self.html_name, data, attrs=attrs)
  File "/Library/Python/2.5/site-packages/django/newforms/widgets.py",
line 423, in render
widget_value = value[i]
TypeError: 'NoneType' object is unsubscriptable

Here's the relevant code:
class InviteeNameWidgets(forms.MultiWidget):
def __init__(self, attendee_count=1, attrs=None):
widgets = (forms.TextInput(),)*attendee_count
super(InviteeNameWidgets, self).__init__(widgets=widgets,
attrs=attrs)

def decompress(self, value):
return value

class EventAttendanceWidgets(forms.MultiWidget):
def __init__(self, attendee_count=1, attrs=None):
widgets = (forms.CheckboxInput(),)*attendee_count
super(EventAttendanceWidgets, self).__init__(widgets=widgets,
attrs=attrs)

def decompress(self, value):
return value

class InviteeNameFields(forms.MultiValueField):
widget = InviteeNameWidgets
def __init__(self, required=True, attendee_count=1, **kwargs):
fields = (forms.CharField(),)*attendee_count
super(InviteeNameFields, self).__init__(**kwargs)

def compress(self, data_list):
return data_list

class EventAttendanceFields(forms.MultiValueField):
widget = EventAttendanceWidgets
def __init__(self, required=True, attendee_count=1, **kwargs):
fields = (forms.BooleanField(),)*attendee_count
super(EventAttendanceFields,
self).__init__(fields=fields,**kwargs)

def compress(self, data_list):
return data_list


class GroupForm(forms.Form):
email = forms.EmailField()
invitee_name = InviteeNameFields(attendee_count=2)
invitee_attend_wedding = EventAttendanceFields(attendee_count=2)
invitee_attend_reception = EventAttendanceFields(attendee_count=2)

 # I know I need to initialize the other default values here, but
right now i'm just trying to get invitee_name working without pulling
from the database
def initialize_invitees(self):
for invitee_id in range(1,3):
name_key = "invitee_name_" + str(invitee_id)
self.data[name_key] = 'testing'


def __init__(self, **kwargs):
self.group_id = 1
super(GroupForm, self).__init__(**kwargs)
self.initialize_invitees()
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---