Re: Custom manipulator - multiple records

2006-05-01 Thread Winston Lee

No error message, but I don't know how to populate the
_inline_collections property in FormWrapper. FormWrapper has a
fill_inline_collections method:

def fill_inline_collections(self):
if not self._inline_collections:
ic = []
related_objects = self.manipulator.get_related_objects()
for rel_obj in related_objects:
data = rel_obj.extract_data(self.data)
inline_collection =
InlineObjectCollection(self.manipulator, rel_obj, data,
self.error_dict)
ic.append(inline_collection)
self._inline_collections = ic

My manipulator needs to have a get_related_objects method but i'm not
really sure how to implement it. I will need the timesheetdetails
InlineObjectCollection in order to handle {% for ts_detail in
form.timesheetdetails %}


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Custom manipulator - multiple records

2006-04-29 Thread Winston Lee

Hi,

I'm trying to set up a custom manipulator for a timesheet app. I don't
have the code in front of me at the moment but I'll try to create a
extremely simplified example (they'll be errors since I don't have
Django on this computer to validate the code, but it's just to give you
a better idea).

The custom view will display 7 days (Mon->Sun) of timesheets for entry.
The model is for individual days so the view consolidates the entries.
It should also display the timesheet details for the week in a edit
inline (InlineObjectCollection?)

The problems lie in the following areas:
* Manipulator - edit_inline/InlineObjectCollection
* Template - {% for ts_detail in form.timesheetdetails %}

Does anyone know how I can acomplish this?
Should I be subclassing timesheets.AddManipulator instead in my custom
manipulator?

Model
-=-=-
class Timesheet(meta.Model):
timesheet_date = meta.DateField()
start_time = meta.TimeField()
end_time = meta.TimeField()

class TimesheetDetail(meta.Model):
timesheet = meta.ForeignKey(Timesheet, edit_inline=meta.TABULAR,
num_in_admin=3, num_extra_on_change=1)
job = meta.CharField(maxlength=50, core=True)
no_of_hours = meta.TimeField()

Manipulator
-=-=-=-=-=-
class TimesheetWeekAddManipulator(formfields.Manipulator):
def __init__(self):
self.fields = (
formfields.HiddenField(field_name="date_mon",
is_required=True)
formfields.TimeField(field_name="start_time_mon",
is_required=True),
formfields.TimeField(field_name="end_time_mon",
is_required=True),
formfields.HiddenField(field_name="date_tue",
is_required=True)
formfields.TimeField(field_name="start_time_tue",
is_required=True),
formfields.TimeField(field_name="end_time_tue",
is_required=True),
.
.
formfields.HiddenField(field_name="date_sun",
is_required=True)
formfields.TimeField(field_name="start_time_sun",
is_required=True),
formfields.TimeField(field_name="end_time_sun",
is_required=True),
)

##TODO: edit_inline/InlineObjectCollection

def save(self, new_data):
# My save code goes here
pass

View
-=-=
def add_timesheet(request):
manipulator = TimesheetWeekAddManipulator()
if request.POST:
new_data = request.POST.copy()
errors = manipulator.get_validation_errors(new_data)
if not errors:
manipulator.do_html2python(new_data)
return HttpResponseRedirect("/timesheet/success")
else:
errors = new_data = {}
# Set the values for the HiddenFields - can't remember the code but
it would be here!
form = formfields.FormWrapper(manipulator=manipulator,
data=new_data, error_dict=errors, edit_inline=True)
return render_to_response('timesheet/add', {'form': form})


Template
-=-=-=-=
I've removed most of the stuff including error reporting so that it's
easier to read.






MON
TUE
WED
THU
FRI
SAT
SUN




Start
{{ form.date_mon }}{{ form.start_time_mon }}
{{ form.date_tue }}{{ form.start_time_tue }}
{{ form.date_wed }}{{ form.start_time_wed }}
{{ form.date_thu }}{{ form.start_time_thu }}
{{ form.date_fri }}{{ form.start_time_fri }}
{{ form.date_sat }}{{ form.start_time_sat }}
{{ form.date_sun }}{{ form.start_time_sun }}


End
{{ form.end_time_mon }}
{{ form.end_time_tue }}
{{ form.end_time_wed }}
{{ form.end_time_thu }}
{{ form.end_time_fri }}
{{ form.end_time_sat }}
{{ form.end_time_sun }}






job
hours



MON
TUE
WED
THU
FRI
SAT
SUN



{% for ts_detail in form.timesheetdetails %}

{{ ts_detail.job }}
{{ ts_detail.no_of_hours_mon }}
{{ ts_detail.no_of_hours_tue }}
{{ ts_detail.no_of_hours_wed }}
{{ ts_detail.no_of_hours_thu }}
{{ ts_detail.no_of_hours_fri }}
{{ ts_detail.no_of_hours_sat }}
{{ ts_detail.no_of_hours_sun }}

{% endfor %}





--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---