Skip to content
This repository has been archived by the owner on May 5, 2020. It is now read-only.

Commit

Permalink
Make edit and delete ajax calls work
Browse files Browse the repository at this point in the history
  • Loading branch information
Dusty Phillips committed Jan 28, 2011
1 parent 52bc19d commit b6e7405
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions prickle/controllers/timesheet.py
Expand Up @@ -75,8 +75,8 @@ def logit(self):
return redirect(path)

def delete(self, id):
timesheet = Timesheet.load(id)
timesheets.delete(timesheet)
timesheet = Timesheet.objects.get(id=id)
timesheet.delete()
return "deleted"

def date(self, date):
Expand Down Expand Up @@ -123,17 +123,28 @@ def types_for_project(self, id):
return json.dumps(ProjectType.type_list(id))

def edit(self, id):
c.timesheet = Timesheet.load(id)
c.timesheet = Timesheet.objects.get(id=id)
return render('/timesheet/edit_timesheet_form.html')

@validate(schema=EditTimesheetForm, form='edit')
def save_edit(self, id):
c.timesheet = Timesheet.load(id)
c.timesheet.date=self.form_result['date']
c.timesheet = Timesheet.objects.get(id=id)
c.timesheet.date=datetime.datetime(
self.form_result['date'].year,
self.form_result['date'].month,
self.form_result['date'].day,
)
c.timesheet.duration=self.form_result['duration']
c.timesheet.project=self.form_result['project']
c.timesheet.type=self.form_result['type']
project, created = Project.objects.get_or_create(
name=self.form_result['project'])
if self.form_result['type']:
type, created = ProjectType.objects.get_or_create(
project=project, type=self.form_result['type'])
else:
type = None
c.timesheet.project=project
c.timesheet.type=type
c.timesheet.description=self.form_result['description']
c.timesheet.store()
c.timesheet.save()
c.delete_column = True
return render('/timesheet/timesheet_row_direct.html')
2 changes: 1 addition & 1 deletion prickle/templates/timesheet/edit_timesheet_form.html
Expand Up @@ -2,7 +2,7 @@

<form id="logtimeform" onsubmit="return save_edit_timesheet('{{c.timesheet.id}}');" >
<td>
<input id='edit_date' class="required date" type="date" name="date" value="{{c.timesheet.date}}" />
<input id='edit_date' class="required date" type="date" name="date" value="{{c.timesheet.date.strftime('%Y-%m-%d')}}" />
</td>
<td><input id='edit_duration' class="required duration" type="text" name="duration" autofocus placeholder="time" value="{{h.decimal_to_hours(c.timesheet.duration)}}" /></td>
<td></td>
Expand Down

0 comments on commit b6e7405

Please sign in to comment.