def registerCustomer(request): # process form data... if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): try: weekday = date.today().weekday() last_sunday = datetime.date.today() - datetime.timedelta(weekday+1) new_customer = Customer(name=form.cleaned_data['nameBox'], room=form.cleaned_data['roomBox'], email=form.cleaned_data['emailBox'], depts=0, weeklySales=0, salesSince=last_sunday, lastPaid=dt.now(), dept_status=0, isPuente=form.cleaned_data['isPuenteBox'], locked=form.cleaned_data['lockedBox']) new_customer.save() # ... an return to list ... return HttpResponseRedirect("..") except: # .. or something went wrong return render_to_response("plist_register.html", {"error" : "Customer still in database", "registerForm" : form, "version" : version, }) else: # display empty form form = RegisterForm() return render_to_response("plist_register.html", {"registerForm" : form, "version" : version, })
def ok_clicked(self): weekday = date.today().weekday() last_sunday = date.today() - timedelta(weekday + 1) if self.name_field.text() and self.room_field.text() and self.email_field.text(): new_customer = Customer( name=self.name_field.text(), room=self.room_field.text(), email=self.email_field.text(), depts=0, weeklySales=0, salesSince=last_sunday, lastPaid=datetime.now(), dept_status=0, isPuente=self.team_box.isChecked(), locked=self.locked_box.isChecked(), ) new_customer.save() self.emit(SIGNAL("newCustomer()")) self.hide() self.empty_fields()